Repository navigation
Conversation
After a submission, copy_back writes into title memory the bytes of a declared range that differ from the snapshot taken before the GPU ran, unless the title's byte already equals the copy's. That is meant to be what shaders wrote and nothing else: the title's threads write the same memory while the GPU runs. Two things made other bytes differ from the snapshot, and the copy's older value then went back over a byte the title had written since: - The snapshot spans the gaps between the ranges declared so far, taken from the copy as it was then. A range declared later inside such a gap was refreshed after that, so every byte its refresh brought in looked like a shader's write. writing now takes the parts of a range no earlier range declared again, where the snapshot already held them. - copy_back leaves the copy holding the title's bytes for each piece it handled, but the snapshot kept the old ones, so a second declared range overlapping the first saw those bytes as a shader's. The snapshot now takes them too. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Tested current PR head
The fixtures use a host shared buffer and return early if no host GPU is available, so the result is conditional on that resource. They do not run a title. |
|
Supporting data for this PR's direction. On main (and on my local branch before the fix), copy-back reads a 64 KiB piece of title memory, merges the GPU's bytes in and writes the whole piece back. The title keeps CPU-side records inside its GPU heap, so any title write elsewhere in that piece between the read and the write is undone. In GTA VI that showed up as a title crash: a hash-map value pointer the title had just stored reverted to null, and several worker threads faulted on it at once. Writing back only the runs of bytes the shader changed stopped it: about 1,100 s of world time across 5 runs with no recurrence. One performance note: one |
The tester tree (upstream main ffe310e plus its PRs, update 8; see its INTEGRATION.md) ran 11-25 minutes in the world on an RTX 5070 without a device removal. Where both sides carry the same PR (the wave64 stack #223/#233/#320 with #439 and #180, #454, #336, #259, #331 and others), the tester tree's newer head is taken; our own work and the PRs only we merged are kept. Conflicts, file by file: - descriptor/host.rs: the tester layout (`spare`, the guard slot after the dynamic slots, `free_table`, the capped sampler heap). A capped view heap keeps `capped_reserve()` dynamic slots, now 2^18 by default (the tester measurement, and our 91fed158), still `VICTORY_DYNAMIC_SLOTS` in diagnostics builds; uncapped hosts keep our 2^19. Our slot statistics (TAKEN/PEAK/SHORT), the bindless plan cache (`CommittedRegions`, `timed_valid_title_address`, `timed_find`, `title_bounds`) and the revision triple are kept beside the tester's `guard_slot`. - Buffer states: the tester tree's buffer-state tracker (#334: every list moves host copies of title memory between GENERIC_READ and UNORDERED_ACCESS and back to common before it closes) and depth twins (#469) are taken. #40's enhanced/legacy indirect barriers (the indirect prelude, `use_indirect_buffers`, the title buffer handoff mirrored in `host_barrier`) cannot share buffers with that tracker and are dropped; #40's argument checks (`byte_len`, exact spans, overflow-safe clamp shader, aligned counts) stay. `indirect::bound` and #282's `rectangles` go through `buffer_state`, and `indirect::execute` (#334) replaces `done`. #178's DXC fallback compiles both of our passes. Our segments (#387: `close` ends the segment, `close_native` closes a native list) carry the tracker: each native list returns its buffers to common and its twins to their depth targets, and each prelude also holds our texture uploads. - shadow.rs: our write flow (`queue_write`, one `snapshot` after the batch's refreshes, `finish_writes`, the unchanged-page cache) with #261's copy-back that also gives the snapshot the title's bytes; its tests run through our flow. - pipeline/make.rs: #275's per-frame budget and per-pipeline wake pair, with our compute waits (a dispatch waits for its pipeline, up to 20 s). - pipeline/library.rs: the tester version (#347, #275's saver thread); our concurrent-write test kept. shader_cache.rs: our byte-returning cache API with #358's "translated, only not kept". - draw.rs: #493's root SRV tables; where no table can stand in, our drop of a draw whose root view is unset or outside title buffers. Our refusal of a table offset past the capped heap stays. - resource.rs: `HostTexture` has both our `staged` generation and the depth twin. - Shaders: the tester's lower.rs for the wave64 stack, #160's image sampling (it covers our #73 and #136 sample forms) and #453/#587; kept from our side: #136's preference for an image or buffer use of a descriptor read as data and its `s_buffer_` arm, #422's nearest-even narrowing (also for #169's d16 loads and #453's interpolation), #452's spin-wait limit, #391's LDS limit, #302's spilled root arguments (now in `NativeProgram::translation_ir`), #136's PSV0 interpolation beside the tester's row harmonisation. split_tests.rs, lane_read_loop_tests.rs and docs/wave64-on-wave32.md are the tester versions (the same PRs at newer heads). - Tests: #483's heap guard dwords filled in our GPU tests of #200 (v_div_scale) and #437 (scalar loads from a raw view), which read through the guard slot otherwise; #334's debug-layer test passes an offset to our `indirect::bound`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Needs rebase. This PR does not merge cleanly into current The content has not been reviewed yet; it will be once the branch is rebased onto Generated by Claude Code |
What
Shadow::copy_backcan still write an older byte of the host copy over a byte the title wrote while the GPU ran: the failure its own comment describes ("putting back the copy's older bytes there broke the title's own records"), through two paths that are left.copy_backtakes every byte of a declared range that differs from the snapshot (before) for a shader's write, and puts it into title memory unless the title's byte already equals it. So anything else that makes the copy differ from the snapshot goes back as if a shader had written it.1. A range declared inside a gap the snapshot already spans. There is one snapshot per copy and submission, grown to span every declared range, so it also holds the gaps between them, as the copy was when the snapshot grew over them. If a later range of the same submission lies in such a gap, its refresh runs after that and brings the title's current bytes into the copy;
writingthen finds the snapshot already spans the range and returns. For every byte that refresh changed, copy ≠ snapshot. If the title writes that byte again before the copy-back, the refresh's value is written over it.The world declares views of its 174 MB heap dozens of times per submission, in no particular order, so ranges inside earlier gaps are the normal case there.
2. Two declared ranges that overlap. For each 64 KiB piece it handles,
copy_backleaves the copy holding the title's bytes (*h = *t), but the snapshot kept the old ones. A second range over the same piece (host.rsonly folds identical ranges) then sees the bytes the first pass took from the title as shader writes, and puts them back over whatever the title wrote between the two passes.The fix, in
shadow.rsonly:writingworks out the parts of the range that no earlier range of the submission declared (new helperoutside). A refresh leaves declared ranges alone, so only those parts can have been refreshed since the snapshot took them; where the snapshot already held them, they are taken again from the copy. No shader has written yet at that point: every list's deferred steps run before the submission executes.copy_backgives the snapshot the title's bytes along with the copy (*o = *t), so a piece that was handled no longer differs.Cost: a byte is copied a second time only if it was first captured as part of a gap and declared later, at most once per submission; ranges declared again, and ranges that extend the snapshot, cost what they did. The body of
writingmoved under anif, hence the size of the diff.I have not run a title (I have no game files), so I cannot say which of its symptoms this accounts for; what it does is intermittent corruption of title memory in buffers shaders write.
Tested
Windows 11 Pro 10.0.26200, NVIDIA RTX 3080 Ti (driver 32.0.16.1656), rustc 1.98.1 (
x86_64-pc-windows-msvc), no game data.shadow.rshad no tests. Two new ones, on a real host buffer (Host::shared_buffer; they return early without a host GPU, like the crate's other device tests) over three pages of plain heap memory standing in for title memory (not write-watched, so refreshes copy whole ranges). "The title writes" and "a shader writes" are single-byte writes into that memory and into the mapped copy.a_range_between_earlier_ones_keeps_the_titles_newer_bytes: the sequence in the diagram. Checks the title's newer byte survives; controls: a byte the title wrote before the refresh and not after keeps its value, and the two bytes "the shader" wrote (one in an outer range, one in the late range) do go back to title memory; the snapshot is released at the end.overlapping_ranges_keep_the_titles_newer_bytes:[a, a+1 page)and[a, a+2 pages)declared, a shader's byte and a title's byte in the first page, the title's byte written again between the two copy-backs. Checks the newer byte survives and the shader's byte went back.Results:
main(d2a4bae) + the tests only:cargo test -p victory-gpu --lib shadow::tests: both fail withthe title's newer byte: left: 1, right: 2.cargo test -p victory-gpu --lib: 45 passed, 0 failed, 1 ignored, three runs in a row.cargo clippy -p victory-gpu --tests: nothing inshadow.rs.rustfmt --check: nothing in the lines changed (one existing difference, thehostclosure line inwriting).cargo xtask policy: 151 files ok.git merge-tree): clean with GPU: occlusion, statistics and timestamp queries run on the host #159 and GPU: maintain shadow-buffer coherency for directly indexed SRVs #185; conflicts with GPU: reuse unchanged page checks across shadow copy-back ranges #124, which restructures the same two functions (the snapshot moves into aBeforestruct). The two changes are independent in what they do; whichever goes in second needs a rebase, and I will do this one's if GPU: reuse unchanged page checks across shadow copy-back ranges #124 goes first.Not tested: a title run; frame time in the world.
AI-assisted (Claude Code); the tests above were run on the machine described.
🤖 Generated with Claude Code