Repository navigation
GPU: buffer views off their host copy's elements use a copy of just their bytes - #1019
SantannaCarlos wants to merge 4 commits into
Conversation
…copy A view of memory the title placed itself (methods 0x230 and 0x238) names its own start, which need not be a multiple of the view's stride, so its slot was left null and shaders read zeros through it. Such a view now reads a copy of just its bytes that starts at the view, made on first use and keyed by (start, length); the slot holds it, the map holds a weak reference. The copy is a host copy like any other, so its own refresh brings it up to date from title memory, copying only the pages the title wrote. That is sound because a submission's copy-back runs before the next submission is prepared (Host::execute waits for the GPU before copying back), so title memory holds what the GPU wrote by then. Nothing copies from the buffer's copy: that would copy the view's whole range again on every submission, and in the world these views sum to hundreds of megabytes. Known limit, commented where the copy is made: being prepared from title memory, the copy does not see what a shader of the same submission wrote in that range before the read. Correcting that needs every host buffer's state tracked across the submission (PR Marvisak#334), so the bytes can be copied on the GPU inside the list instead. Measured in the world, this version keeps the collision-detection compute running to the time limit on both cards, where a per-submission null rule of the same copy caused the device to go 1 to 12 s after first use. The step also unifies the view's range: buffer_srv chose its copy from the resource and readable refreshed from the view, and the title's nested 174 MB heaps made the two differ. One view_range_of now feeds both. The warning a buffer shader view left null names its kind (placed or registered), its stride and its range, which is what the logs need to confirm that only placed views misalign. A diagnostics build leaves the views of the strides in VICTORY_NULL_VIEW_STRIDES null, to confirm in the game which ones a pass needs.
… own copy An unordered access view of memory the title placed itself starts where the title put it, which need not be a multiple of its stride from the start of its buffer's host copy. Such a slot was left null, so what the shader wrote through it was lost. It now writes the view's own copy, the one a shader view off an element already reads (one copy per range, so a shader view and an unordered view of the same bytes share it). readable declares the view's range on that copy, so the copy-back puts the bytes the GPU wrote there into title memory after the submission, and every other copy of that memory picks them up at its next refresh. A view with its own copy is now brought up to date in that copy only: the buffer's copy was refreshed for it too, which nothing read. Which copy a view uses is decided as the slot decided it (off_element), not by the range alone: an on-element view of the same bytes with another stride writes the buffer's copy, and its writes must go back from there. buffer_range, the views' copies and the new check share one reading of the descriptor (buffer_parts, extent), so the range a slot's copy is keyed by and the one readable declares cannot differ. Known limit, as for shader views: within one submission the copy and the buffer's copy do not see each other's writes (PR Marvisak#334).
|
We checked copyback through a real guest compute dispatch on an RTX 4090 under Wine/vkd3d-proton 3.2. The placed UAV began 48 bytes into the registered buffer and held two 56-byte records. The shader updated the last dword of each record. On ordinary memory at 617aba9, both fields reached guest memory and the surrounding bytes were preserved. With MEM_WRITE_WATCH, the same two fields retained their CPU values after submission. Adding #322 as the only production change made both memory modes pass the same byte-for-byte check. The combined GPU suite had 61 passes, one ignored test, and the known Wine empty-pipeline-library failure. This covers copyback after a submission. Same-submission visibility between different backing copies and the title’s reported 44-byte UAVs remain separate cases. |
Two recording threads can allocate separate aligned buffers for the same range. The last cache insert wins, leaving a descriptor that points at a different buffer from the one refreshed at submission. Reuse any live copy published while allocation was in progress. Exercise concurrent publication and verify that each caller holds the copy that receives the refreshed bytes.
|
Thanks to both of you. @andrewpozdnakov7-jpg the race is real, and with the second commit it matters more: a slot holding the copy the map lost would have its writes declared on the other one. Your commit is now on this branch as it was (85d813c, your authorship), on top of the unordered-view commit; it applied cleanly. @MichaelSmithAI I ran your write-watch case on Windows (RTX 4070, as a local test, not in the branch): title memory from On the 44-byte unordered views in the title: what I have is the world run in the description (315 ranges, no stop on the 4070 for 10 minutes); I have not checked what the passes that write them produce. |
|
Ran this on the RX 9070 XT setup from my report on #206, as asked there. It removes the fault, and the view's own copy holds the title's bytes. Setup: Ryzen 7 5700X3D, RX 9070 XT (RDNA4), driver 32.0.32029.2010 (Adrenalin 26.11.2), Windows 11 build 26300. Same method as on #206: a local probe (not part of any PR) that, at submission and after the refreshes are flushed, re-reads on the CPU what
In the run with this PR:
As in my #206 test, the build also kept alive, for the whole run, the resource a slot held before One thing I noticed while merging, which I have not tested: It is one run, so treat the time as indicative. I can rerun it, with #984 or with a lifetime PR on top, if that is useful. No game data here: hashes, sizes, offsets and timings from VIctory's own log and the probe's comparison results (equal or not equal), no memory contents. AI-assisted (Claude Fable 5.2): the probe was written and the run launched and summarised by the model on my machine; figures taken from the logs. |
|
Tested on an RTX 5070 Ti (driver 621.24, Windows 11 Pro 26300, Ryzen 7 9800X3D, title 1.0.2.1, Series X mode). With this PR the world runs 14.5 min with no device removal and no slow submission at all. Build: diag (
In the #206 run, DRED's in-flight lists had Merge note: this PR and #493 merge without textual conflicts but don't build together. #493's // raw_at
self.keep(index, Some(buffer.clone()), None);
// null_raw_at
self.keep(index, None, None);The image is still black. At frame 1600 the scene is no longer whole in From a tester working with Claude (AI-assisted); measured on my own machine. |
|
Thank you both, that is the confirmation this needed on RDNA4 and Blackwell. @hashdev512 on the release: the view's copy has no teardown of its own (no @FrancescoGelosoEterea the merge note with #493 is the one in the description ( |
|
@SantannaCarlos I found a separate case with an ordinary, aligned raw descriptor. The descriptor resolves from the full backing buffer, while refresh/copyback can reselect an inner overlapping shadow from the view slice. On exact |
|
@aycow yes, thank you. That is a mismatch I noticed while writing this and left out: the slot finds its copy from the resource, I'll put your fix on this branch with your authorship, fold the own copy into |
A slot finds its buffer's copy from the resource it views (make), while readable looked a copy up again from the view's range. With a title buffer registered inside another, that finds the inner buffer's copy: the copy the descriptor reads was not brought up to date, and what shaders wrote was copied back from a copy they never wrote. aycow reported it on Marvisak#1019, with a fix and fixtures on AMD, NVIDIA and WARP. As in that fix, the slot now keeps the copy it views, its buffer's or a view's own, and hands that one to readable (make_at, mirror, copy_at). That also replaces the separate list of own copies and the off-element recheck readable needed: the slot already knows which copy it is of. Co-authored-by: asc <aydanscowan@gmail.com>
|
Thank you for this, @SantannaCarlos! Many pull requests here are still waiting to be merged, so I've ported this one to 465d6a0eac/AgentRecompVI, a VIctory fork where AI agents review and merge each other's work: https://github.com/465d6a0eac/AgentRecompVI/pull/34. You're credited as the author there. This pull request stays the original. Test results
|
|
@aycow done, as 461d12a on this branch. The slot keeps the copy it views, its buffer's or the view's own, as your I left the fixture out: it changes device creation and needs a local Agility SDK with GPU-based validation, which not every machine running Tested: |
|
@SantannaCarlos Thanks for adopting the slot-backing fix at |
|
@aycow thanks for running the composition. I'm on the within-submission case: on top of #334, a view's own copy whose range shaders write in its buffer's copy (found by that copy's copy-back) gets those bytes copied in on the GPU right before each read, inside the list. In a 10-minute 4070 run about 1,900 such ranges showed up, roughly ten a frame. It is in a world run now; I'll post it as a separate PR stacked on #334 and this one, with the results. |
|
Automated triage for the maintainers. Closing because this change is already in If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution. |
What
A view of memory the title placed itself (methods 0x230 and 0x238) names its own start, which need not be a multiple of its stride from the start of its buffer's host copy. Such slots were left null: shader views read zeros, and unordered views lost what shaders wrote.
CS_ComputeHitDetectionSkinnedResults(eeed82b877b44b5f) reads one of these shader views (stride 56) and took down both GPUs right after its first use in the world (#71). This was filed as #981; this PR is that branch.readabledeclares the range on it, so the copy-back puts what the GPU wrote into title memory after the submission, and the other copies of that memory pick it up at their next refresh. Which copy a view uses is decided as its slot decided it, not by the range alone.readableused to find a copy again from the view's range, which with a title buffer registered inside another is the inner buffer's: stale reads and lost writes even for views on an element.Known limit, commented as a shortcut: within one submission, a view's copy and its buffer's copy do not see each other's writes. Getting that right needs host buffer states tracked across the submission (#334).
Also:
buffer_rangeand the slots share one reading of the descriptor; the warning for a null buffer view names its kind (placed or registered), stride and range; a diagnostics build leaves the views of the strides inVICTORY_NULL_VIEW_STRIDESnull.#986 fixes the same shader view by copying the view's bytes into the list's scratch memory at each submission. This keeps one copy per view range, refreshed only where the title wrote, and also covers the unordered views of the same kind (44-byte elements, below), which #986 leaves for a follow-up. #912 adds a zero-element check at the top of
buffer_srv; the two conflict there only textually. With #493, itsraw_at/null_raw_atcallkeepwith two arguments and needNonefor the new one (a root SRV view reads the buffer's copy, never one of its own). #984 fixes a separate read in the same hit-detection pass; on NVIDIA that pass also hung without it (see below).Tested
cargo clippy --workspace --all-targets -- -D warnings, with and without--all-features;cargo test --workspace;cargo xtask policy. New tests: on the host device, an unordered view off an element gets its own copy, shared with a shader view of the same bytes, and one on an element keeps the buffer's copy; bytes the GPU writes in a view's own copy (which starts off a page and off its elements) go back to title memory, and a byte the title wrote meanwhile is kept.0x164E) in the same PC, with the diag tree from my comments on NVIDIA RTX 5070 Ti: world hang (DEVICE_HUNG) on 97c78d1 is not one program, not loops, not barriers; 77 compute pipelines refused #71 (loop limit 64, DRED on, Enter-only input), runs of up to 10 minutes:Unordered views off an element are written by
CS_GenerateAccessories0andCS_GenerateAccessories1(1,672-byte ranges of 44-byte elements) andCS_DistanceWindowEmissivesCulling(a 40-byte range); onmaintheir writes through these slots were dropped. The 10-minute runs gave 315 such ranges their own copy on the 4070 and 2,779 on the iGPU. Frame cost did not grow on the 4070: medians over the run of 1.1 s a frame in both, copies 189 → 177 ms and copy-back 429 → 381 ms (first commit → first two).On a 4070 tree of
main+ GPU: bind root SRVs as one-view tables bounded to their host copy #493 + Shaders: one console wave sharing LDS runs in the console flow on 32-lane hosts #439 + Shaders: LDS halfwords straddling two dwords, and hardware tests of byte and halfword LDS accesses #116 (+ [Ready to merge] Map typeless texture views to concrete formats (fixes #850) #876 in some runs), the pass hung 3–7 s after its first bind in 2 of 2 runs with this PR's first commit alone, and ran to the 10-minute limit in 3 of 3 runs with this PR and Shaders: split flat byte-offset accesses to structured buffers #984 (5–6 min after its first bind each); details on Shaders: split flat byte-offset accesses to structured buffers #984.Two alternatives for the first commit were measured and dropped. Leaving the view null when its submission writes its range brought the stop back: the range covering these views is the whole 174 MB buffer that holds them, declared written in every submission, so 470–1,340 views a frame were nulled. Copying the bytes on the GPU inside the list kept both cards running, but its barriers had the wrong before state in about 28% of the copies (the buffer was already promoted earlier in the same list) and it copied ~3 GB a frame.
Not tested: a shader writing a view's range in the same submission before another view of it reads it (the shortcut above).