GPU: transition shadow buffers between UAV and vertex/index/CBV states #588
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!588
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/588/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?
@LAKSHYA-cmd-tech on GitHub · 2026-11-24 05:14 UTC · original
LAKSHYA-cmd-tech:fix/buffer-uav-vertex-state-transition→main· +79 −6 · 2 files · 1 commits · closed without mergingSummary
Resolves #548 (D3D12 debug layer ERROR id=538 and device hung on RTX 30-series GPUs during world execution).
Problem
In #548, the D3D12 debug layer repeatedly reported:
\`nDrawIndexedInstanced / IASetVertexBuffers on 'title buffer 0x159f0000+0xae00000' (182,452,224 bytes): state UNORDERED_ACCESS, expected VERTEX_AND_CONSTANT_BUFFER.
\`nFollowed by GPU device hung (\DXGI_ERROR_DEVICE_HUNG, \
@iurysf on GitHub · 2026-11-24 08:06 UTC · original
Tested on an RTX 4070 (driver 32.0.16.2101) on top of #493 + #483, the pair that stops the device removal on this GPU. Run with
VICTORY_D3D12_DEBUG=1+VICTORY_D3D12_GBV=1+DRED=1, one run each.IASetVertexBuffers ... Resource state (0x2: INDEX_BUFFER) of resource 'title memory 0xd04800000+0x400000' is invalid for use as a vertex buffer; Expected 0x1 VERTEX_AND_CONSTANT_BUFFER.Before state (0xC0 NON_PIXEL|PIXEL_SHADER_RESOURCE) of 'title buffer 0x3d60000+0xae00000' ... does not match the state (0x8 UNORDERED_ACCESS) specified in preceding ResourceBarrier.VERTEX_AND_CONSTANT_BUFFER | INDEX_BUFFERread state may be what's needed there.AI-assisted.
@dpalacios69 on GitHub · 2026-11-24 09:53 UTC · original
Thanks for working on #548! After reviewing the diff and cross-checking with @iurysf's D3D12 debug-layer test results above, there are a few D3D12 state-tracking issues in this approach that explain both the new
id=538andid=527errors:Exclusive single-bit read states clobber simultaneous bindings in the same draw (causes the 17,152
id=538errors)In
draw.rs,prepare_forcallsself.bind(ensure_state(0xC0)/0x1), then the vertex-buffer loop (ensure_state(0x1)), and then the index-buffer bind (ensure_state(0x2)). Because title heaps and 4 MiB loose windows (Shadowbuffers) commonly back multiple bindings in the same draw (VB + IB + SRV + CBV), transitioning the sameShadow::buffertoINDEX_BUFFER (0x2)immediately invalidates itsVERTEX_AND_CONSTANT_BUFFER (0x1)state right beforeDrawIndexedInstanced. Read-only buffer states need to be combined (e.g.D3D12_RESOURCE_STATE_GENERIC_READ) rather than replacing each other one bit at a time.indirect::boundandindirect::donetransitionShadow::bufferdirectly without updatingShadow::state(causesid=527)In
execute_indirect(draw.rs:1015–1055),indirect::boundassumesargs.bufferis inUNORDERED_ACCESSand transitions it toINDIRECT_ARGUMENT, andindirect::donetransitions it back toUNORDERED_ACCESS(indirect.rs:174–193) without updatingShadow::state. That leavesShadow::stateout of sync with the actual D3D12 state (matching theBefore state 0xC0 ... does not match 0x8 UNORDERED_ACCESSid=527error reported above), andprepare/bindbetweenboundandExecuteIndirectcan also clobberINDIRECT_ARGUMENTon the same shared heap.Global
Shadow::state: AtomicU32is unsound across command lists and submissionshost.rs:290–296). Mutating a single globalAtomicU32at recording time (Ordering::Relaxed) means barriers are emitted against recording order rather than execution order (which is why textures use per-listHostList::states+HostList::prelude).D3D12_RESOURCE_STATE_COMMONafterExecuteCommandListscompletes. BecauseShadow::stateis never reset afterHost::execute, subsequent submissions emit barriers with a staleStateBeforeinstead ofCOMMON.Missing UAV barrier and
before == 0skip on dropped drawsUNORDERED_ACCESS -> UNORDERED_ACCESSuses on the same buffer need aD3D12_RESOURCE_BARRIER_TYPE_UAVbarrier, whereasensure_stateis a no-op whenbefore == wanted.before == 0relies on implicit promotion fromCOMMON, which breaks if the firstensure_statehappens on a draw/dispatch that is later dropped (table_failed, missing index shadow, orrectangles()failure): no GPU command promotes the buffer, yetShadow::stateis already non-zero.Unit test coverage
shadow_buffer_transitions_state_when_requesteddoesn't close/execute the command list or check D3D12 debug-layer messages, so it only verifies theAtomicU32::swapvalue rather than actual D3D12 barrier validity.Note that #334 already takes the per-list
BufferStates(GENERIC_READvsUNORDERED_ACCESS) +prelude/close+indirect.rsintegration approach along with a debug-layer execution test — it may be worth coordinating with or building on that design instead of tracking a globalAtomicU32onShadow.Reviewed against the diff and the code on
main; not run on hardware. AI-assisted.@Headache3318 on GitHub · 2026-11-24 14:26 UTC · original
Second-read endorsement plus one nit not in @dpalacios69's list. Our independent read of this diff converged on the same prescription he names at the end: main already ships the per-list tool —
list::ensure_stateatlist.rs:391, used for textures/render-targets/depth atdraw.rs:403/406/1128/1145— so extending that to shadow buffers beats hand-rolling a second global tracker; and the #548id=538class is not AMD-only, it reproduces on NVIDIA where the DRED report stops atop 42(DispatchMesh). The nit:root_viewsetslet wanted = if srv { 0x40 | 0x80 }, which areCOPY_DEST | COPY_SOURCEbits, not a shader-read state — so the SRV read path asks for the wrong state whatever tracker design lands, though it becomes moot by default once #493c48b240merges and bypassesroot_viewfor SRVs (onlyVICTORY_ROOT_SRV_DIRECT=1reaches it). AI-assisted diff-read at head54c7c89eon baseffe310eb, Arch Linux; nothing built or run from this box.@dpalacios69 on GitHub · 2026-11-24 14:38 UTC · original
@Headache3318 thanks for the second read, and agreed that extending
list::ensure_statebeats a second global tracker.One correction on the nit: in
D3D12_RESOURCE_STATES,0x40isNON_PIXEL_SHADER_RESOURCEand0x80isPIXEL_SHADER_RESOURCE(COPY_DESTis0x400andCOPY_SOURCE0x800). So0x40 | 0x80inroot_viewis a shader-read state, the same one @iurysf's debug-layer output prints above as0xC0 NON_PIXEL|PIXEL_SHADER_RESOURCE. The problem with that line is the one in my list:ensure_statesets a single exclusive state, so a buffer that is also bound as a vertex or index buffer in the same draw ends up in the wrong one.AI-assisted.
@Headache3318 on GitHub · 2026-11-24 18:44 UTC · original
windows-gnu cross-target gate on this head merged onto
ffe310e(AI-assisted, Arch Linux kernel 7.3.5, rustc 1.98.1,cargo test --no-run --locked --profile diag --features diagnostics --target x86_64-pc-windows-gnu, exit-code judged — a target upstream CI does not compile): all six device-removed-cluster heads pass in 38-41 s each with 0 warnings — #5683a37896e, #501934a8361, #24275f7f205, #12366d06de4e, #427033e906f, #588 merged1074aaab.#588's raw head alone fails
E0061 'this function takes 2 arguments but 1 argument was supplied'atemit/lower.rs:6963— NOT windows-gnu-only: it reproduces rc 101 on Linux AND MSVC scoped controls (-p victory-shader); it is staleness inherited from its recorded base58fed370(lowers(&words)fixed in main by8e79c80), #588's own commit toucheslower.rszero lines, and the real 3-way merge compiles clean (rc 0, 40 s, 0 warnings).API fact for the merge decision: #588's head
54c7c89ehas zero CI check-runs — GitHub Actions (introduced in8e79c80) has never executed on this PR, so there is no CI signal on either side of the merge.@Marvisak on GitHub · 2026-11-25 00:25 UTC · original
Automated triage for the maintainers. Closing because by our reading the change is incorrect or would break something that works today.
Tracks one D3D12 state per buffer copy in a global atomic and emits transitions from it, but lists are recorded in parallel and in another order than they run, and buffers decay to the common state after every submission: the 'before' state of these barriers is wrong in general. Also carries unrelated reformatting. The promotion problem it reports (#548) deserves a per-list fix.
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