victory-gta6: this fork's changes on top of VIctory main (ffe310e)
World rendering, lighting, frame-rate and memory work for Grand Theft Auto VI (Xbox Series X profile) on one Windows PC with an NVIDIA RTX 4070. The README describes the state, the changes and the credits. Based on VIctory by Marvisak and contributors (GPL-3.0-or-later); XCL by ivall and contributors was used as a reference. No game files are included. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
1 parent
ffe310eb20
commit
578d459c34
61 files changed
+32259
-1274
No files matched your search
@@ -114,6 +114,11 @@ fn heap_alloc(size: usize, align: usize) -> Option<(*mut u8, u32)> {
|
||||
heap.blocks
|
||||
.insert(ptr as usize, Block { size, apu, layout });
|
||||
heap.by_apu.insert(apu, ptr as usize);
|
||||
// The big ones are named in the log: they are the title's audio memory
|
||||
// given out of our allocator, which the memory line counts as ours.
|
||||
if size >= 32 << 20 {
|
||||
tracing::info!(mb = size >> 20, at = ?ptr, "audio memory for the title from our allocator");
|
||||
}
|
||||
Some((ptr, apu))
|
||||
}
|
||||
|
||||
|
||||
@@ -976,6 +976,16 @@ fn into_destination(
|
||||
if super::xmem::write_physical(pages, offset, &data[..n]) {
|
||||
Ok(())
|
||||
} else {
|
||||
// Said aloud: Grand Theft Auto VI never reads a request's result
|
||||
// (it only polls for completion), so a destination left unwritten
|
||||
// is a model or texture that silently holds whatever its pages
|
||||
// held before.
|
||||
tracing::warn!(
|
||||
offset,
|
||||
len,
|
||||
pages = pages.len(),
|
||||
"dstorage: a destination's physical pages could not be written (unknown page or a host failure); its request fails"
|
||||
);
|
||||
Err(E_INVALIDARG)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1144,7 +1144,21 @@ mod host {
|
||||
return None;
|
||||
}
|
||||
self.empty_until[slot] = None;
|
||||
Some(convert(&state.Gamepad))
|
||||
#[allow(unused_mut)]
|
||||
let mut pad = convert(&state.Gamepad);
|
||||
// The scripted keys (`VICTORY_KEYS`) also press the first
|
||||
// pad's buttons, by the stand-in pad's table: with a real pad
|
||||
// connected the stand-in is not there, and a title that listens
|
||||
// to the pad (Grand Theft Auto VI's start screen) saw nothing.
|
||||
#[cfg(feature = "diagnostics")]
|
||||
if slot == 0 {
|
||||
for vk in scripted() {
|
||||
if let Some(&(_, button)) = super::FALLBACK_BUTTONS.iter().find(|(key, _)| *key == vk) {
|
||||
pad.buttons |= button;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(pad)
|
||||
}
|
||||
|
||||
fn keys(&mut self) -> Vec<KeyState> {
|
||||
|
||||
@@ -428,6 +428,9 @@ pub extern "system" fn XMemAllocatePhysicalPages(
|
||||
flags = format_args!("{flags:#x}"),
|
||||
"XMemAllocatePhysicalPages"
|
||||
);
|
||||
// For the GPU side's in-place census: only a committed section can be
|
||||
// opened as a host heap.
|
||||
victory_gpu::title_memory_section(handle as usize, size as u64, on_wine());
|
||||
let section = Arc::new(Section(handle));
|
||||
let mut physical = physical();
|
||||
let first = physical.next_page;
|
||||
@@ -596,6 +599,11 @@ pub extern "system" fn XMemMapPhysicalPages(
|
||||
) -> *mut c_void {
|
||||
let base = address as usize;
|
||||
let mut physical = physical();
|
||||
// Until the pages are mapped again: `unmap` takes whole views away and
|
||||
// maps what stays of them again, and a mapped view is a reservation
|
||||
// until it is committed. A read of title memory in place must not fall
|
||||
// into that gap (`victory_gpu::title_memory_remapping`).
|
||||
let _changing = victory_gpu::title_memory_remapping();
|
||||
unmap(&mut physical, base, n * PAGE);
|
||||
if pages.is_null() {
|
||||
return address;
|
||||
@@ -663,6 +671,8 @@ pub extern "system" fn XMemMapPhysicalPagesScatter(
|
||||
pub fn map_alias(to: u64, from: u64, len: u64) -> bool {
|
||||
let (to, from, len) = (to as usize, from as usize, len as usize);
|
||||
let mut physical = physical();
|
||||
// As in `XMemMapPhysicalPages`: no read in place meets the gap.
|
||||
let _changing = victory_gpu::title_memory_remapping();
|
||||
unmap(&mut physical, to, len);
|
||||
for k in (0..len).step_by(PAGE) {
|
||||
if from == 0 {
|
||||
@@ -728,6 +738,8 @@ fn map(physical: &mut Physical, base: usize, len: usize, slice: Slice) -> bool {
|
||||
}
|
||||
// New contents, read-write: the GPU side's copies no longer guard it.
|
||||
victory_gpu::title_memory_remapped(base, len);
|
||||
// What the range shows now, for the GPU side's in-place census.
|
||||
victory_gpu::title_memory_view(base, len, slice.section.0 as usize, (slice.index * PAGE) as u64);
|
||||
physical.views.insert(base, (len, slice));
|
||||
true
|
||||
}
|
||||
@@ -868,6 +880,25 @@ pub extern "system" fn XMemGetWorkingSetStatistics(_which: u32, out: *mut Workin
|
||||
gpu_optimal_limit: gpu_optimal,
|
||||
..Default::default()
|
||||
};
|
||||
// What the title is told, logged at the first asking and at every
|
||||
// 1,024th: "used" is all the process has committed, the layer's own
|
||||
// memory and the card's included (27 GB in run 60's gameplay against a
|
||||
// limit of 13.5 GB). A title that budgets its streaming from these two
|
||||
// figures believes it is far over its limit.
|
||||
// shortcut: the figure is not yet the title's own memory alone (its
|
||||
// heaps and the pages it mapped); count those if this line shows the
|
||||
// title asking.
|
||||
static ASKED: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
|
||||
let asked = ASKED.fetch_add(1, Ordering::Relaxed);
|
||||
if asked % 1024 == 0 {
|
||||
tracing::info!(
|
||||
asked = asked + 1,
|
||||
which = _which,
|
||||
limit_mb = stats.title_limit >> 20,
|
||||
used_mb = stats.title_used >> 20,
|
||||
"the title asks how much memory it uses"
|
||||
);
|
||||
}
|
||||
// SAFETY: checked non-null; the title passes room for the structure.
|
||||
unsafe { out.write(stats) };
|
||||
1
|
||||
@@ -1112,6 +1143,57 @@ mod tests {
|
||||
assert_eq!(XMemIsToolsMemAvailable(), 0);
|
||||
}
|
||||
|
||||
/// A thread that reads a mapped page in place, as the GPU side reads a
|
||||
/// texture, never meets the moment in which the runtime has taken the
|
||||
/// page's view away to map it again: mapping the same pages at the same
|
||||
/// address unmaps the view and maps a new one, and without the lock the
|
||||
/// reader faults on a page "reserved, never committed" (the crashes of
|
||||
/// runs 71 and 74).
|
||||
#[test]
|
||||
fn a_read_in_place_never_meets_the_gap_of_a_remapping() {
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
let mut pages = [0usize; 3];
|
||||
let mut n = 3;
|
||||
assert_eq!(XMemAllocatePhysicalPages(0, &mut n, pages.as_mut_ptr()), 1);
|
||||
let a = XMemVirtualAlloc(
|
||||
std::ptr::null_mut(),
|
||||
3 * PAGE,
|
||||
MEM_RESERVE | PAGES_64K,
|
||||
0,
|
||||
PAGE_READWRITE,
|
||||
);
|
||||
assert!(!a.is_null());
|
||||
assert_eq!(XMemMapPhysicalPages(a, 3, pages.as_ptr()), a);
|
||||
// SAFETY: mapped read-write.
|
||||
unsafe { a.cast::<u8>().write(1) };
|
||||
let first = a as usize;
|
||||
let stop = std::sync::Arc::new(AtomicBool::new(false));
|
||||
let reader = {
|
||||
let stop = stop.clone();
|
||||
std::thread::spawn(move || {
|
||||
let mut reads = 0u64;
|
||||
while !stop.load(Ordering::Relaxed) {
|
||||
let _reading = victory_gpu::title_memory_reading();
|
||||
// SAFETY: the page is mapped whenever no change of
|
||||
// mapping is under way, and none is while `_reading`
|
||||
// is held.
|
||||
assert_eq!(unsafe { (first as *const u8).read_volatile() }, 1);
|
||||
reads += 1;
|
||||
}
|
||||
reads
|
||||
})
|
||||
};
|
||||
for _ in 0..2000 {
|
||||
// The same pages at the same address: the view goes and comes
|
||||
// back, with the same bytes.
|
||||
assert_eq!(XMemMapPhysicalPages(a, 3, pages.as_ptr()), a);
|
||||
}
|
||||
stop.store(true, Ordering::Relaxed);
|
||||
assert!(reader.join().expect("the reader never faulted") > 0);
|
||||
assert_eq!(XMemMapPhysicalPages(a, 3, std::ptr::null()), a);
|
||||
assert_eq!(XMemFreePhysicalPages(3, pages.as_ptr()), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mapping_no_pages_changes_nothing() {
|
||||
let pages = allocate(2);
|
||||
|
||||
Reference in new issue
Block a user