GPU: read same-list GPU writes in placed buffer-to-texture copies #1374
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1374"
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?
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T17:39:26Z.
Fixes #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.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:49:52Z.
Review: COMMENTED
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; this is source review of a large diff plus the PR's own Windows tests.
Placed buffer-to-texture copies now read same-list GPU writes: has_gpu_write/written_shadow walk the deferred Step::GpuWrite records backwards, require every requested range to be covered by writes into ONE shadow (Arc::ptr_eq, mixed shadows → None), subtract covered ranges, and only then fall back to CPU copies. The interval subtraction and the chosen-shadow consistency check are the right conservatism. 3 tests including a debug-layer guard. Please confirm on Windows that the placed-copy path actually hits this (the tests look host-gated).
Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T20:48:35Z.
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.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:24:38Z.
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
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T04:06:04Z.
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).Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T05:15:59Z.
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).upstream-sync referenced this pull request2026-11-25 07:03:17 +00:00
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:00:38Z.
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