GPU: track direct buffer states in HostList and restore COPY_DEST to COMMON in place_copy (#350) #424
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!424
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-424"
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?
@BE29ZZ on GitHub · 2026-11-27 00:53 UTC · original
BE29ZZ:fix/issue-350-buffer-state→a-publier· +837 −27 · 5 files · 2 commits · openFixes #350.
Root cause
Card-side title buffers (
Shadow::buffer) start inD3D12_RESOURCE_STATE_COMMONand are expected to stay inCOMMON(or read-promoted) between operations and lists of a submission:HostList::place_copy(crates/victory-gpu/src/host/place.rs) recordsCopyBufferRegion(&to.buffer, ...)(implicitly promotingto.bufferfromCOMMONtoCOPY_DEST) and follows it only withwait_for_all, leavingto.bufferinCOPY_DEST. It also callsto.gpu_writes(...), socard_beforeappendsplan.check(an unnamed list frommake_prelude) to the sameExecuteCommandListsbatch, whereplan.checkbindsto.bufferwithSetComputeRootShaderResourceView(host.rs) while it is still promoted toCOPY_DEST— producing D3D12 Debug Layer error ID 538 (Severity 1). Any later root view or indirect clamp in the same list/batch hits the same violation.place_copy's same-buffer branch (from.buffer == to.buffer), copyingfrom -> betweenpromotes the buffer toCOPY_SOURCE, and copyingbetween -> tothen wrote to the same buffer without transitioningCOPY_SOURCE -> COPY_DEST.COPY_DEST -> COMMONafterplace_copywould break whenever the buffer had already been promoted to a read (or write) state earlier in the sameHostListor an earlierHostListof the sameExecuteCommandListsbatch.Changes
crates/victory-gpu/src/host/buffers.rs(new module): per-HostListD3D12 direct buffer state tracker (Track,LiveState,HostList::buffer_read/buffer_write/buffer_*_barrier/prelude_buffer_barriers, andcheck_barriers):COPY_DEST/UNORDERED_ACCESS), and explicit-> COMMONresets.ExecuteCommandListsmerge without prelude transitions.ExecuteCommandListsbatch writes a buffer (or emits an internal barrier whoseStateBeforeassumed entry inCOMMON),HostList::preludebridgesprev -> COMMONfirst;live_buffersresets cleanly atExecuteCommandListsboundaries (partscuts andVICTORY_GPU_TIMING).plan.checkdispatches,check_barrierstransitions any compared shadow buffer left in an incompatible non-read state (e.g. a direct root UAV) toNON_PIXEL_SHADER_RESOURCE.crates/victory-gpu/src/host/place.rs:place_copyallocatesbetweenbefore mutating state, pre-transitionsfrom/towhen already in an incompatible state, transitionsfrom == tothroughCOPY_SOURCE -> COPY_DEST -> COMMON, and restores bothto(COPY_DEST -> COMMON) andfrom(-> COMMON) after copying.place_sourcetracksCOPY_SOURCEand restoresfrom.buffertoCOMMONalongsidebetween's transition in oneResourceBarriercall.crates/victory-gpu/src/host.rs: wiresbuffer_statesintoHostList(make_list,reset,untouched,prelude) andlive_buffersintoHost::submitandHost::card_before.crates/victory-gpu/src/indirect.rs&crates/victory-gpu/src/draw.rs: records direct buffer promotions (indirect::clamp_into,indirect::open_batch,IASetVertexBuffers,IASetIndexBuffer, direct root CBV/SRV/UAVs) onHostListonly when the draw/dispatch actually runs, soplace_copyand cross-list preludes have the exactStateBeforemask.Verification (Windows 11 x64, RTX 3060, Rust
1.98.1, MSVC)cargo clippy --workspace --all-targets --locked -- -D warnings— passed (0 warnings)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings— passed (0 warnings)cargo test -p victory-gpu --lib --locked -- --test-threads=1— 402 passed, 0 failed (34 ignored), including 5 newhost::buffers::testsstate-machine tests and the new end-to-end GPU testhost::place::tests::place_copy_restores_buffer_to_common_and_runs_cleanlycargo test -p victory-gpu --lib --all-features --locked host::buffers&host::place— 6 passed, 0 failedcargo test -p xtask --locked— 9 passed, 0 failed (includingrepository_passes_policy)(Note: this machine does not have Windows Graphics Tools /
d3d12SDKLayers.dllinstalled, so liveVICTORY_D3D12_DEBUG=1verification against the title is still welcome from a machine with the debug layer enabled;place_copy_restores_buffer_to_common_and_runs_cleanlyalso asserts zerohost.log_messages()whenVICTORY_D3D12_DEBUG=1is active.)@MamaLeVrai on GitHub · 2026-11-27 01:37 UTC · original
Independent check on an RDNA 2 card (RX 6950 XT, driver 32.0.21045.29003, Windows 11 build 26300, release), at
91192d2. I had opened #425 for the same issue a few minutes after you, with only the COMMON reset. Yours goes further (the per-list buffer state tracking covers the earlier-read case mine left open), so I'll close mine in favor of this one.My #425 had a debug-layer test you may want.
host::place::tests::copies_in_place_leave_their_buffers_to_root_viewsis ignored, and wants--features diagnosticsandVICTORY_D3D12_DEBUG=1. It listens withID3D12InfoQueue1::RegisterMessageCallback, because the host's submission empties the message queue. It runs 4 cases (copy then root SRV, copy then the card compare, the same-buffer copy, ...) for a 256 KiB host copy in PC memory and an 8 MiB one on the card. Results:a-publier4eb6cfd: 7 of 8 cases get layer messages (id 538 among them);host/place.rs's tests: 0 messages in all 8 cases, and the compare ran in each card case.cargo test --release -p victory-gpu --libon this PR, twice: 402 passed, 0 failed, 34 ignored.The test is at https://github.com/MamaLeVrai/VIctory-Belobug-AMD/blob/copy-dest-root-srv/crates/victory-gpu/src/host/place.rs (the
testsmodule:title_of,listen,messages,out_gpuand the test). Feel free to take it.AI-assisted (Claude Code); no game data.
@BE29ZZ on GitHub · 2026-11-27 01:52 UTC · original
Thank you @MamaLeVrai for the independent verification on your RX 6950 XT with the D3D12 debug layer (0 messages across all 8 cases!) and for sharing the test!
I've incorporated
copies_in_place_leave_their_buffers_to_root_viewsintocrates/victory-gpu/src/host/place.rs(withCo-authored-bycredit) and added a 5th case (case 4) covering an earlier root SRV read of the destination buffer beforeplace_copyin the same list. Re-verified locally with bothcargo clippypasses (--all-targetsand--all-features -- -D warnings),host::buffers,host::place, andxtaskpolicy tests — all green.@adrianmjim on GitHub · 2026-11-27 06:49 UTC · original
Tested on RX 7900 XT (RDNA 3), driver 32.0.32029.2010, Windows 11 26300, Rust 1.98.1. Head
7f42a52vs basea-publier4eb6cfd(0 behind). Lib tests built with the dev test profile and with--profile diag --features diagnostics. No debug layer on this machine.cargo test -p victory-gpu --lib, dev, 2 runs each side: base 396 passed / 34 ignored, head 402 passed / 35 ignored. 0 failed on both sides.timeline::report::tests::real_waits_are_recorded_with_who_ended_themfails on base too.watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_viewfailed once on head in the suite. It passed 3/3 alone on each side. It is the known flakywatch::test.host::buffers::tests: 5/5 passed, 3 runs.place_copy_restores_buffer_to_common_and_runs_cleanly: passed 3/3 on dev, 3/3 on diag, and 1/1 withVICTORY_CARD_ALL=1. The destination is a real copy here, not in place, so the test does not return early.4eb6cfdI ran the new GPU test without the parts that need the PR's code (the tracker state asserts,buffer_readandprelude_buffer_barriers). The sameplace_copycalls and byte checks stayed. It passes 4/4 there,VICTORY_CARD_ALL=1included. So on this card the copied bytes are right without the fix. Without the debug layer, this test catches a regression only through its tracker asserts.Not tested: the debug-layer test (no d3d12SDKLayers here), release profile, the game.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.