GPU: read same-list GPU writes in placed buffer-to-texture copies #1374
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!1374
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1374/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?
@fuzeofficlal on GitHub · 2026-11-24 17:39 UTC · original
fuzeofficlal:fix/placed-copy-after-gpu-write-785→main· +1402 −25 · 5 files · 1 commits · closed without mergingFixes #785.
Summary
CopyTextureRegionfootprint orpSrcBox(including pitched multi-row boxes and partial subsequent overwrites on the sameShadowbuffer) was produced on the GPU earlier in the same command list without an intervening CPU write (HostList::written_shadow+PlacedFootprint::box_reads).Shadowbuffer (UNORDERED_ACCESS -> COPY_SOURCE -> UNORDERED_ACCESS), or rebase non-512-byte-aligned placed offsets onto a temporary aligned host buffer on the GPU while preservingD3D12_BOX-relative byte offsets.CopyBufferRegionand bufferCopyResourceon the GPU when their source bytes come from an earlier GPU write in the same command list, keeping deferred CPU upload snapshots unchanged otherwise.Verification
box_readsand end-to-end synthetic GPU readback tests covering whole-texture copies,D3D12_BOXsub-box copies, unaligned placed offsets, pitched multi-row GPU writes, partial GPU overwrites, and chainedDispatch -> CopyBufferRegion -> CopyTextureRegion:VICTORY_D3D12_DEBUG=1): passed (0debug errors)VICTORY_D3D12_DEBUG=1): passed (0debug errors)VICTORY_D3D12_DEBUG=1): passed (0debug errors)cargo clippy --workspace --all-targets --all-featuresandcargo xtask policy: passed.@wbkepler on GitHub · 2026-11-24 20:48 UTC · original
I audited
5dd1e71against main. The placed path orders correctly when the source copy really is inUNORDERED_ACCESS. The explicitUNORDERED_ACCESS -> COPY_SOURCEtransition waits for the earlier dispatch's writes, and the copy reads them on the GPU with no CPU round trip. The pending range also keeps the submission-time refresh from overwriting them. I found one state problem, in the buffer-forwarding part:record_gpu_buffer_copyinfers the destination's state fromStep::GpuWriteonly (list.rs:505,has_gpu_write). A shadow buffer can also sit in explicitUNORDERED_ACCESSwith noGpuWritestep.indirect::done(indirect.rs:186, called fromdraw.rs:1031/1055) leaves the argument buffer there, and the indirect path only records aRefreshfor it. This sequence in one list breaks:ExecuteIndirectwith arguments in title buffer B. B is now explicitlyUNORDERED_ACCESS.CopyBufferRegionfrom A to B, for example refilling the arguments for a second indirect pass.Step 3 takes the
dst_was_uav == falsebranch. It recordsCopyBufferRegioninto B while B is inUNORDERED_ACCESS; a buffer that was explicitly transitioned out ofCOMMONis not implicitly promoted toCOPY_DEST. It then records aCOPY_DEST -> UNORDERED_ACCESSbarrier whose before-state doesn't match. The debug layer should flag both, and nothing orders step 1's argument reads and clamp writes before the copy. Before this PR the copy happened on the CPU at submission, so B's GPU state was never touched.The same thing can happen the other way, though it's less likely.
readable()records theGpuWriteinsidebind(), and the draw can still be dropped after that:table_failedatdraw.rs:463, a missing index buffer copy, or the indirect!ranpath. So aGpuWritestep doesn't guarantee the buffer was ever promoted to UAV in this list. In that case the source-sideUNORDERED_ACCESS -> COPY_SOURCEbarriers name a state the buffer isn't in; it is stillCOMMON.Suggestion: track, per list, which shadow buffers are known to be in explicit
UNORDERED_ACCESS. Set it fromindirect::done, from this PR's restore barriers, and from UAV bindings only once the draw or dispatch is actually recorded. Use that instead ofhas_gpu_write. A focused test for the indirect-then-copy sequence above underVICTORY_D3D12_DEBUG=1would cover it.AI-assisted review (Claude Code); checked on Windows 11 / RTX 5090.
@Marvisak on GitHub · 2026-11-25 01:24 UTC · original · edited 2026-11-25 16:17 UTC
Automated triage for the maintainers.
Recommendation: merge candidate (rebased; reviewed again against current
main).When the bytes a placed
CopyTextureRegionreads, or aCopyBufferRegion/ bufferCopyResourcereads, were written on the GPU earlier in the same list, this PR copies them on the GPU (list.rs:placed_copy_source,copy_buffer_bytes,record_gpu_buffer_copy). Otherwise it keeps the CPU snapshot taken at submission. I checked these points:HostList::written_shadowgives up on any overlapping deferred CPU copy orStep::Run.PlacedFootprint::box_readscomputes block-compressed and volume rows correctly, matching the new unit test.unorderedset lives inDeferred, soResetclears it.mark/commit/discard_gpu_writeswrap every draw and dispatch path indraw.rs,indirect::donemarks its buffers, and the count buffer gets UAV <-> INDIRECT_ARGUMENT barriers.CI
checkpasses on this head. The barrier correctness rests on the author's debug-layer runs (RTX 5090, AMD, WARP). Given the size (about 900 lines are GPU tests), a maintainer run withVICTORY_D3D12_DEBUG=1on a real frame would be worthwhile.Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-25 04:06 UTC · original
Rebased onto
940d32f(64afee48) and addressed both explicitUNORDERED_ACCESSstate-tracking cases pointed out by @wbkepler:UNORDERED_ACCESShost-buffer tracking (Deferred::unorderedviaset_unordered/is_unordered), marked fromindirect::done, GPU copy restore barriers, and committed UAV bindings.draw,draw_indexed,dispatch,dispatch_mesh,execute_indirect, andclear_unorderedwithmark_gpu_writes/commit_gpu_writes/discard_gpu_writesso dropped draws or dispatches neither leave unexecutedStep::GpuWriterecords behind nor transitionCOMMONbuffers fromUNORDERED_ACCESS.gpu_buffer_copy_tracks_indirect_and_dropped_uav_statescoveringExecuteIndirect(B) -> Dispatch(UAV A) -> CopyBufferRegion(A -> B) -> CopyTextureRegion(B -> tex)and dropped-draw fallback underVICTORY_D3D12_DEBUG=1(0 debug layer errors on RTX 5090, AMD Radeon Graphics, and WARP).@fuzeofficlal on GitHub · 2026-11-25 05:15 UTC · original
Pushed
7593572etightening two follow-up details on top of64afee48:ExecuteIndirectpCountBuffertransitions: whencounteris distinct fromargsand is tracked in explicitUNORDERED_ACCESSon the current list (is_unordered),execute_indirectnow wraps it in symmetricUNORDERED_ACCESS -> INDIRECT_ARGUMENT -> UNORDERED_ACCESSbarriers.ExecuteIndirect+Resetend-to-end verification on Windows (@wbkepler, @catminou4):gpu_buffer_copy_tracks_indirect_and_dropped_uav_statesnow executes realExecuteIndirect(buf_b)([1, 1, 1]) -> dropped draw (discard_gpu_writes) -> UAVDispatch(buf_a)->CopyBufferRegion(buf_a -> buf_b)-> secondExecuteIndirect(buf_b)([3, 1, 1], verifying atomic tally1 + 3 = 4) ->CopyTextureRegion(buf_b -> tex)->Resetreuse across RTX 5090, AMD Radeon Graphics, and WARP withVICTORY_D3D12_DEBUG=1(0debug layer errors).@Marvisak on GitHub · 2026-11-25 22:00 UTC · original
Automated triage for the maintainers, second look (a review against current
main, with builds and tests where they could change the verdict).Closing because it is wrong against current
main. Its own testgpu_buffer_copy_tracks_indirect_and_dropped_uav_states, run with the debug layer, fails onmainplus this PR with three D3D12 state errors in the sequence raised in the thread: ExecuteIndirect(B), a dispatch that writes A, CopyBufferRegion(A to B), ExecuteIndirect(B). Since315cea18the indirect clamp reads the title's records through a root SRV, which puts B's copy in a shader-resource state this PR does not model. More broadly, it brings back explicit transitions on the copies of title buffers, which that commit removed by design after they caused state errors in the world. The gap in #785 is real in principle; a fix would have to keep that rule (for example by copying through a buffer the list owns) and needs a case from the title first.If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.
Pull request closed