A write through one view of a page is seen at its other views; page writes counted; levels on demand (off); warm-up; card memory numbers
Memory sync: - The guard over every view of a physical page (code by myokex, victory-amd c6dc4d8, after pull request #115 by Spexivus, its correction by joroyt and a part of VIctory #1122 by tightfall): the title shows one page at several addresses and a copy was guarded at one only. 0.8 to 1.0 million writes through another view in a five-minute run on the test machine. VICTORY_VIEW_GUARD=0 turns it off. - Kernel reads into title memory are read beside and copied in (Joshua Odom, 10ea38e). - Writes of the storage layer into physical pages are counted where the title has the pages mapped and can open the guards there (VICTORY_PAGE_WRITES, off: counted only). Failed page-destination reads are retried. Card memory: - Levels on demand, off unless VICTORY_LEVELS_ON_DEMAND=1: a texture the title fills takes card memory for the levels the title holds; held levels get memory only while the card has room and are asked for again. Its test runs on the software adapter; not run on a card yet. - Refused texture slots are held back so a pass reaches the slots behind them; room can be kept for card copies of title buffers (off). Tools: translate --warm all; the shader cache is keyed on the translator's source; counters for copy-back races, page writes and the copies the texture sweep never lets go; a walls trace. Game runs of these changes on an RTX 4070: five five-minute runs without a device loss or a failed request. This merged tree was built; its test suites were run on the tree the changes come from (gpu 129, hle 97). Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
1 parent
310c6eb6c1
commit
8dd30ab472
25 files changed
+4218
-240
No files matched your search
@@ -863,8 +863,25 @@ fn execute(request: &Request) -> Result<(), HRESULT> {
|
||||
return Err(fail(E_INVALIDARG, "source larger than destination"));
|
||||
}
|
||||
let size = request.source_size as usize;
|
||||
return into_destination(request, size, |out| read_into(request, out).map(|()| size))
|
||||
.map_err(|hr| fail(hr, "copying"));
|
||||
// A file read into a title address is the kernel's write, and the
|
||||
// kernel does not fault into the GPU side's guard: a block guarded
|
||||
// again between `kernel_will_write` and the read (the guard over all
|
||||
// the views of a page protects other views from other threads) made
|
||||
// the read fail with ERROR_INVALID_USER_BUFFER, and the title stops
|
||||
// at the failed request (runs amd-C and amd-C2, seconds after the
|
||||
// world's first frame). It is read beside and copied in: our copy
|
||||
// faults into the guard like the title's own writes.
|
||||
let bounce = options & (PAGE_DESTINATION | MEMORY_SOURCE) == 0;
|
||||
return into_destination(request, size, |out| {
|
||||
if !bounce {
|
||||
return read_into(request, out).map(|()| size);
|
||||
}
|
||||
let mut data = vec![0; size];
|
||||
read_into(request, &mut data)?;
|
||||
out.copy_from_slice(&data);
|
||||
Ok(size)
|
||||
})
|
||||
.map_err(|hr| fail(hr, "copying"));
|
||||
}
|
||||
let tables = if bc != 0 { Some(bcpack_tables()?) } else { None };
|
||||
let source = read_source(request).map_err(|hr| fail(hr, "reading the source"))?;
|
||||
@@ -1034,13 +1051,22 @@ fn into_destination(
|
||||
fill: impl FnOnce(&mut [u8]) -> Result<usize, HRESULT>,
|
||||
) -> Result<(), HRESULT> {
|
||||
if request.options & PAGE_DESTINATION == 0 {
|
||||
// Raw reads land through the kernel, which does not fault into the
|
||||
// GPU side's guard on title buffers; open them first.
|
||||
// Opens the guarded blocks and tells the GPU side a placed texture
|
||||
// there changes. `fill` writes from user mode (a file read is read
|
||||
// beside first, see `execute`), so a block guarded again meanwhile
|
||||
// faults into the guard instead of failing the write.
|
||||
victory_gpu::kernel_will_write(request.destination as usize, len);
|
||||
// SAFETY: the title's destination holds `destination_size` bytes, at
|
||||
// least `len`, and nothing else writes it until completion.
|
||||
let out = unsafe { std::slice::from_raw_parts_mut(request.destination.cast::<u8>(), len) };
|
||||
return fill(out).map(drop);
|
||||
let filled = fill(out).map(drop);
|
||||
// Said again now that the bytes are there (upstream's c75fdba holds
|
||||
// the blocks open over the read and marks them once more at its
|
||||
// end): a copy or a texture pass that took the memory while the
|
||||
// read was under way took what was there before. Counted; acted on
|
||||
// only with `VICTORY_PAGE_WRITES=all`.
|
||||
victory_gpu::title_memory_written(request.destination as usize, len, false);
|
||||
return filled;
|
||||
}
|
||||
let offset = (request.page_offset & 0xffff) as usize;
|
||||
// SAFETY: the title passes a page number per 64 KiB of destination,
|
||||
@@ -1054,20 +1080,33 @@ fn into_destination(
|
||||
// Consecutive pages of one allocation (the usual case): written in
|
||||
// place through one view.
|
||||
if let Some(mut window) = super::xmem::page_window(pages, offset, len) {
|
||||
return fill(window.bytes()).map(drop);
|
||||
let filled = fill(window.bytes()).map(drop);
|
||||
drop(window);
|
||||
// The title maps pages where the card reads them and has them
|
||||
// filled afterwards: the GPU side's copies of those addresses
|
||||
// learn of the bytes only from this (upstream c75fdba, fork PR
|
||||
// #571). After a decode that failed part way too: what it wrote
|
||||
// is there.
|
||||
super::xmem::pages_written(pages, offset, len);
|
||||
return filled;
|
||||
}
|
||||
let mut data = vec![0; len];
|
||||
let n = fill(&mut data)?;
|
||||
// A page the title has just made, or a view the host refuses for a moment (commit
|
||||
// or address space short while a load maps many at once), can come right a little
|
||||
// later: tried again before the request fails (`VICTORY_DSTORAGE_RETRIES`, default 12,
|
||||
// about 1.5 s in all).
|
||||
// A page the title has just made, or a view the host refuses for a
|
||||
// moment, comes right a little later: the write is tried again before
|
||||
// the request fails (`VICTORY_DSTORAGE_RETRIES`, 12 tries, about 0.9 s
|
||||
// in all; 0: not tried again, as before). Runs 175-178 lost 12 to 446
|
||||
// reads a launch here, all in one second of the loading; the one build
|
||||
// that tried again (run 165) lost none of 13.
|
||||
static RETRIES: std::sync::OnceLock<u32> = std::sync::OnceLock::new();
|
||||
let retries = *RETRIES.get_or_init(|| {
|
||||
std::env::var("VICTORY_DSTORAGE_RETRIES").ok().and_then(|v| v.parse().ok()).unwrap_or(12)
|
||||
std::env::var("VICTORY_DSTORAGE_RETRIES").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(12)
|
||||
});
|
||||
// Since the start: writes that succeeded on a later try, and writes
|
||||
// given up.
|
||||
static RETRIED: [AtomicU64; 2] = [AtomicU64::new(0), AtomicU64::new(0)];
|
||||
let mut written = super::xmem::write_physical(pages, offset, &data[..n]);
|
||||
let mut tries = 0;
|
||||
let mut tries = 0u32;
|
||||
while !written && tries < retries {
|
||||
std::thread::sleep(std::time::Duration::from_millis((2u64 << tries.min(6)).min(128)));
|
||||
tries += 1;
|
||||
@@ -1075,12 +1114,28 @@ fn into_destination(
|
||||
}
|
||||
if written {
|
||||
if tries > 0 {
|
||||
tracing::info!(offset, len, tries, "dstorage: a destination's physical pages written after a retry");
|
||||
let on_a_retry = RETRIED[0].fetch_add(1, Ordering::Relaxed) + 1;
|
||||
tracing::info!(
|
||||
offset,
|
||||
len,
|
||||
tries,
|
||||
on_a_retry,
|
||||
given_up = RETRIED[1].load(Ordering::Relaxed),
|
||||
"dstorage: a destination's physical pages written after a retry"
|
||||
);
|
||||
}
|
||||
// As above, after the write that succeeded.
|
||||
super::xmem::pages_written(pages, offset, n);
|
||||
Ok(())
|
||||
} else {
|
||||
let known = super::xmem::pages_known(pages, offset, len);
|
||||
tracing::warn!(known, last_error = std::io::Error::last_os_error().raw_os_error(), "dstorage: retries used up");
|
||||
let given_up = RETRIED[1].fetch_add(1, Ordering::Relaxed) + 1;
|
||||
tracing::warn!(
|
||||
known = super::xmem::pages_known(pages, offset, len),
|
||||
tries,
|
||||
given_up,
|
||||
on_a_retry = RETRIED[0].load(Ordering::Relaxed),
|
||||
"dstorage: retries used up (VICTORY_DSTORAGE_RETRIES)"
|
||||
);
|
||||
// Said aloud: the title 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
|
||||
|
||||
Reference in new issue
Block a user