GPU: buffer views off their host copy's elements use a copy of just their bytes #1019
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1019
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1019/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@SantannaCarlos on GitHub · 2026-11-24 15:06 UTC · original
SantannaCarlos:fix/view-off-element→main· +679 −118 · 3 files · 4 commits · closed without mergingWhat
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 #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+ #493 + #439 + #116 (+ #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 #984 (5–6 min after its first bind each); details on #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).
@MichaelSmithAI on GitHub · 2026-11-24 15:10 UTC · original
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.
@SantannaCarlos on GitHub · 2026-11-24 15:17 UTC · original
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.cargo test -p victory-gpu(56 passed, 1 ignored, your test included), clippy with and without--all-features, and the asset policy pass.@MichaelSmithAI I ran your write-watch case on Windows (RTX 4070, as a local test, not in the branch): title memory from
VirtualAllocwithMEM_WRITE_WATCH, a view copy 48 bytes into a 64 KiB page, refreshed withupdateas at submission, the GPU's bytes put in one element, a title byte written meanwhile.copy_backwrote the element into title memory and kept the title's byte, and the nextupdateleft the element in the copy (the page is marked current, so our own write is not taken for the title's). So on WindowsWriteProcessMemoryreaches write-watched pages. What you saw looks like Wine'sWriteProcessMemoryon such pages, which every copy-back goes through, not only this one; #322 replaces that call for all of them, which fits with it fixing your run.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.
@Zipettte on GitHub · 2026-11-24 15:40 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
85d813c:cargo test -p victory-gpupasses, 56 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@hashdev512 on GitHub · 2026-11-24 16:06 UTC · original
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.
mainatffe310ewith this PR (head85d813c) merged locally,diagbuild with--features diagnostics,VICTORY_D3D12_DRED=1, Series X mode, package v1.0.2.1. 56victory-gputests pass. The only merge conflict was with my own local diagnostics.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
eeed82b877b44b5freads, from title memory and from the host side, and looks at what the slot of the stride-56 view holds. For this PR it also reads the slot's own copy.ffe310e(3 runs)ffe310e+ #206 (1 run)ffe310e+ this PR (1 run)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
HostHeap::keepreplaced it and the host copy of every released title texture, so that the freed-texture fault (#557) did not end the run first. That is a local diagnostic switch, not a lifetime fix.One thing I noticed while merging, which I have not tested:
keepreplaces the slot's previous own copy in place (*slot = copy), so the previousArc<Shadow>is dropped right there. If the late release #575 does for the slot's resource matters, the same may apply to that copy. In my run the switch above kept the buffer alive through the slot's resource, so the run says nothing either way.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.
@FrancescoGelosoEterea on GitHub · 2026-11-24 16:08 UTC · original
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.
compute eeed82b877b44b5fno longer shows up.Build: diag (
--profile diag --features diagnostics) ofmainffe310e+ #493 + #454 + this PR + #984. I left #206 out, because it conflicts with this PR inbuffer_srv/buffer_uavand covers the same views. Settings:VICTORY_SHADER_LOOP_LIMIT=1024,VICTORY_D3D12_DRED=1,VICTORY_NO_WATCHDOG=1, stock TDR, Enter every 5 s throughVICTORY_KEYS, target dumps at frames 1600/2000/2400. Same input and settings as my #71 run with #206 in this PR's place.device removed, 5,334 ms submissionslow host submissionIn the #206 run, DRED's in-flight lists had
dispatch 12x1x1 [compute eeed82b877b44b5f]with SRVs42991392x1and182452224x1. With this PR it is in no slow submission.Merge note: this PR and #493 merge without textual conflicts but don't build together. #493's
HostHeap::raw_atandnull_raw_atcallself.keep(index, …)with two arguments, and this PR giveskeepa third (copy). I passedNonein both places, since those slots view a list's buffer and not a copy of a view's bytes:The image is still black. At frame 1600 the scene is no longer whole in
f62, where the #206 run had all of it. Only the tyres are there now. The 2560x1440f28G-buffer target shows a fine diagonal hatching over a larger area instead of a few spiky triangles. 520 shaders are still refused at translation (447 compute, 43 pixel, 25 mesh, 5 vertex), and 130 compute pipelines are refused by D3D12 withE_INVALIDARG. So on this card the hang looks fixed by this PR, and the black scene is a separate problem.From a tester working with Claude (AI-assisted); measured on my own machine.
@SantannaCarlos on GitHub · 2026-11-24 16:19 UTC · original
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
DroponShadow); dropping the lastArcreleases itsID3D12Resource, and that is the same COM object the slot'skeptentry holds (Kept::Resource { resource: shadow.buffer.clone(), .. }). So with #575, whosekeephands the slot's previous resource torelease_late, the copy's buffer also stays alive behind the queue, with no change here. Onmaintoday it goes when the slot is remade, as every slot's resource does.@FrancescoGelosoEterea the merge note with #493 is the one in the description (
Noneinraw_at/null_raw_at). Onf62at frame 1600 holding only the tyres where the #206 run had the whole scene: one difference between the two is the limit noted in the description. A view's own copy is brought up to date from title memory when the submission is prepared, so it does not see what a shader wrote in that range earlier in the same submission, while #206's raw view of the shared copy does. If a culling pass writes what a draw then reads through such a view, that would drop geometry. Your two runs also differ by #984, so it is not settled; I'll comparef62with and without the copy on the 4070 and report here.@aycow on GitHub · 2026-11-24 16:34 UTC · original
@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
ffe310ethis produced stale SRV data and lost UAV writes in the synthetic tests. Retaining the shadow selected by the native slot passed all six ordinary/rebuilt table cases on AMD, NVIDIA, and WARP with full GPU-based validation. Synthetic fixture and focused fix. This test establishes the aligned case. The reported pixel hang remains unassigned. Would you be interested in reviewing the interaction with your per-slot off-element backing?@SantannaCarlos on GitHub · 2026-11-24 16:52 UTC · original
@aycow yes, thank you. That is a mismatch I noticed while writing this and left out: the slot finds its copy from the resource,
readablefinds one again from the view's range, and nested registered buffers make the two differ. Keeping the copy in the slot and handing that one toreadableis the right fix, and it fits this PR: the slot can hold a view's own copy the same way (yourBacking::Buffer), which removes this PR'skept_copyand theoff_elementrecheck inreadable, since the slot already knows which copy it views.I'll put your fix on this branch with your authorship, fold the own copy into
Backing::Buffer, take your fixture if it fits the tests here, and report the tests and a world run on this thread.@SantannaCarlos on GitHub · 2026-11-24 17:12 UTC · original
@aycow done, as
461d12aon this branch. The slot keeps the copy it views, its buffer's or the view's own, as yourBacking::Bufferdoes, andmake_at,mirrorand a newcopy_athand that one toreadable. That replaced this PR's separate list of own copies and the off-element recheck inreadable. I wrote it on top of the PR's commits rather than cherry-picking yours, since both change what a slot keeps; you are co-author on the commit.I left the fixture out: it changes device creation and needs a local Agility SDK with GPU-based validation, which not every machine running
cargo testhas. A unit test covers the case instead: a raw view of an outer registered buffer whose bytes lie in an inner registered one, checking that the slot hands out the outer buffer's copy and not the one a lookup by the view's range finds.Tested:
cargo test --workspace(victory-gpu57 passed, 1 ignored), clippy with and without--all-features, the asset policy. In the world on the 4070 (same setup as the description): 623 s with no stop, the hit-detection pass ran 6 min 47 s from its first bind, and frames got slightly cheaper (medians 1.07 → 0.97 s a frame, copies 168 → 139 ms), since a view now refreshes only the copy it reads.@465d6a0eac on GitHub · 2026-11-24 17:02 UTC · original · edited 2026-11-24 17:20 UTC
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
cargo clippy(both variants) andcargo test --workspacepass (407 passed, 0 failed).buffer view not on an element of its host copy offset=9171600 element=32; with it that warning is gone.@aycow on GitHub · 2026-11-24 17:24 UTC · original
@SantannaCarlos Thanks for adopting the slot-backing fix at
461d12a. The #1019/#185/#387 composition passed four focused cases on AMD, NVIDIA and WARP with full GPU validation. Translated off-element stride-56 producer/consumer passed across submissions. Distinct-shadow visibility within one native submission remains open.@SantannaCarlos on GitHub · 2026-11-24 17:32 UTC · original
@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.
@SantannaCarlos on GitHub · 2026-11-24 17:47 UTC · original
The within-submission case is now #1405, stacked on #334 and this PR.
@Marvisak on GitHub · 2026-11-25 00:30 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.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.
Pull request closed