gpu(place): return placed copy buffers to COMMON after CopyBufferRegion #4590

Closed
github-bot wants to merge 15 commits from github-bot/gh-4589 into main AGit
Owner

@⁠gnostic-snakes on GitHub · 2026-11-30 23:22 UTC · original
gnostic-snakes:fix/d3d12-placed-copy-barriers → main · +972 −849 · 33 files · 15 commits · closed without merging

Fixes two D3D12 debug layer message 538 state mismatches observed in a 17-minute diagnostics run with VICTORY_D3D12_DEBUG=1 (RTX 5060 Ti 16 GB, driver 621.40, Windows 11 10.0.26200):

1. CopyBufferRegion source buffer left in COPY_DEST (0x400) (68,246 occurrences)

  • HostList::place_copy promotes o.buffer from COMMON to COPY_DEST via CopyBufferRegion, then calls wait_for_all (global/UAV barrier) without transitioning o.buffer back to COMMON.
  • Subsequent place_copy or place_constant calls on the same command list that read from that buffer (CopyBufferRegion(..., &from.buffer, ...)) fail validation (Actual: COPY_DEST (assumed at first use), Expected: COPY_SOURCE).

2. ExecuteCommandLists / SetComputeRootShaderResourceView seeing COPY_DEST (0x400) (98,637 occurrences)

  • Because place_copy leaves o.buffer promoted from COMMON to COPY_DEST at list end, the card-compare list (plan.check) executed in the same ExecuteCommandLists batch hits SetComputeRootShaderResourceView while the buffer is still tracked as COPY_DEST instead of NON_PIXEL_SHADER_RESOURCE.

Fix (crates/victory-gpu/src/host/place.rs)

  • In place_copy, transition o.buffer from COPY_DEST back to COMMON before wait_for_all.
  • Leave rom.buffer untouched: D3D12 read-state promotion combines COPY_SOURCE with other read states (e.g. VERTEX_AND_CONSTANT_BUFFER | COPY_SOURCE), so an explicit COPY_SOURCE -> COMMON barrier trips message 527.

Verification

  • cargo check -p victory-gpu --all-targets --all-features --locked (0 errors, 0 new warnings)
  • cargo test -p victory-gpu --lib --locked -- place::tests (20 passed, 0 failed, including GPU test place_constant_reads_what_place_copy_wrote)
  • cargo xtask policy --staged (sset policy: 1 files ok)
  • Live 25-minute gameplay run (diag build, VICTORY_D3D12_DEBUG=1):
    • CopyBufferRegion id=538: 68,246 → 0
    • SetComputeRootShaderResourceView id=538: 98,637 → 0
    • COPY_DEST ResourceBarrier id=527: 0
**@⁠gnostic-snakes** on GitHub · 2026-11-30 23:22 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4589) `gnostic-snakes:fix/d3d12-placed-copy-barriers` → `main` · +972 −849 · 33 files · 15 commits · closed without merging Fixes two D3D12 debug layer message 538 state mismatches observed in a 17-minute diagnostics run with VICTORY_D3D12_DEBUG=1 (RTX 5060 Ti 16 GB, driver 621.40, Windows 11 10.0.26200): ### 1. CopyBufferRegion source buffer left in COPY_DEST (0x400) (68,246 occurrences) - HostList::place_copy promotes o.buffer from COMMON to COPY_DEST via CopyBufferRegion, then calls wait_for_all (global/UAV barrier) without transitioning o.buffer back to COMMON. - Subsequent place_copy or place_constant calls on the same command list that read from that buffer (CopyBufferRegion(..., &from.buffer, ...)) fail validation (Actual: COPY_DEST (assumed at first use), Expected: COPY_SOURCE). ### 2. ExecuteCommandLists / SetComputeRootShaderResourceView seeing COPY_DEST (0x400) (98,637 occurrences) - Because place_copy leaves o.buffer promoted from COMMON to COPY_DEST at list end, the card-compare list (plan.check) executed in the same ExecuteCommandLists batch hits SetComputeRootShaderResourceView while the buffer is still tracked as COPY_DEST instead of NON_PIXEL_SHADER_RESOURCE. ### Fix ([crates/victory-gpu/src/host/place.rs](crates/victory-gpu/src/host/place.rs)) - In place_copy, transition o.buffer from COPY_DEST back to COMMON before wait_for_all. - Leave rom.buffer untouched: D3D12 read-state promotion combines COPY_SOURCE with other read states (e.g. VERTEX_AND_CONSTANT_BUFFER | COPY_SOURCE), so an explicit COPY_SOURCE -> COMMON barrier trips message 527. ### Verification - cargo check -p victory-gpu --all-targets --all-features --locked (0 errors, 0 new warnings) - cargo test -p victory-gpu --lib --locked -- place::tests (20 passed, 0 failed, including GPU test place_constant_reads_what_place_copy_wrote) - cargo xtask policy --staged (sset policy: 1 files ok) - Live 25-minute gameplay run (diag build, VICTORY_D3D12_DEBUG=1): - CopyBufferRegion id=538: **68,246 → 0** - SetComputeRootShaderResourceView id=538: **98,637 → 0** - COPY_DEST ResourceBarrier id=527: **0**
Fixes the remaining two D3D12 debug layer message 538 errors observed
in a 17-minute diagnostics run with VICTORY_D3D12_DEBUG=1:

1. ID3D12CommandList::CopyBufferRegion: source buffer left in COPY_DEST
   (assumed at first use), expected COPY_SOURCE (68,246 occurrences).
2. ID3D12CommandQueue1::ExecuteCommandLists (SetComputeRootShaderResourceView):
   buffer promoted from COMMON to COPY_DEST, expected
   NON_PIXEL_SHADER_RESOURCE (98,637 occurrences).

HostList::place_copy promoted to.buffer to COPY_DEST (and from.buffer to
COPY_SOURCE) via CopyBufferRegion, then only emitted wait_for_all (which
does not update D3D12's legacy resource-state tracking). Subsequent
placed copies/place_constant reads on the same command list saw the
buffer still in COPY_DEST, and the card compare list in the same
ExecuteCommandLists batch bound it with SetComputeRootShaderResourceView
while still promoted to COPY_DEST.

Transition to.buffer (COPY_DEST -> COMMON) and from.buffer
(COPY_SOURCE -> COMMON) in place_copy, place_constant, and place_source
(plus to.buffer COPY_SOURCE -> COPY_DEST between the two copies in the
same-buffer branch of place_copy).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 23:25:15 +00:00
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 23:44 UTC · original · reviewed

I checked the placed-copy state transitions with Claude. The source transitions need coverage for an already-promoted read state.

**@⁠tyr0nsur** on GitHub · 2026-11-30 23:44 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4589#pullrequestreview-6122551312) · **reviewed** I checked the placed-copy state transitions with Claude. The source transitions need coverage for an already-promoted read state.
@ -654,0 +669,4 @@
if let Some(from) = &own
&& from.buffer.as_raw() != to.buffer.as_raw()
{
back.push(transition(&from.buffer, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COMMON));
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 23:44 UTC · original · edited 2026-11-30 23:50 UTC

The new COPY_SOURCE -> COMMON transition assumes this shadow buffer has only been promoted to COPY_SOURCE. A previous root SRV read of the same buffer can leave NON_PIXEL_SHADER_RESOURCE in its promoted state, and the copy adds COPY_SOURCE without clearing that bit. Then this StateBefore omits a valid read state. A buffer also retains its promotion across command lists in the same ExecuteCommandLists call. D3D12 promotion and decay rules

Could we exercise root SRV read -> placed copy in one list with the debug layer? The existing placed-constant test starts with fresh shadows and exercises a scratch source, so it leaves this case uncovered. The same assumption is present in the new source resets in place_constant and place_source.

Local check of 4bcfd16a: five placed-copy tests passed with VICTORY_NARROW_BARRIERS=0, including data readback; the benchmark was ignored. The installed runtime returns DXGI_ERROR_SDK_COMPONENT_MISSING for D3D12GetDebugInterface, so this run verifies functional output only. The promoted-SRV case still needs debug-layer coverage.

**@⁠tyr0nsur** on GitHub · 2026-11-30 23:44 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4589#discussion_r4747113120) · edited 2026-11-30 23:50 UTC The new `COPY_SOURCE -> COMMON` transition assumes this shadow buffer has only been promoted to `COPY_SOURCE`. A previous root SRV read of the same buffer can leave `NON_PIXEL_SHADER_RESOURCE` in its promoted state, and the copy adds `COPY_SOURCE` without clearing that bit. Then this `StateBefore` omits a valid read state. A buffer also retains its promotion across command lists in the same `ExecuteCommandLists` call. [D3D12 promotion and decay rules](https://learn.microsoft.com/en-us/windows/win32/direct3d12/using-resource-barriers-to-synchronize-resource-states-in-direct3d-12#common-state-promotion) Could we exercise `root SRV read -> placed copy` in one list with the debug layer? The existing placed-constant test starts with fresh shadows and exercises a scratch source, so it leaves this case uncovered. The same assumption is present in the new source resets in `place_constant` and `place_source`. Local check of `4bcfd16a`: five placed-copy tests passed with `VICTORY_NARROW_BARRIERS=0`, including data readback; the benchmark was ignored. The installed runtime returns `DXGI_ERROR_SDK_COMPONENT_MISSING` for `D3D12GetDebugInterface`, so this run verifies functional output only. The promoted-SRV case still needs debug-layer coverage.
Live testing with VICTORY_D3D12_DEBUG=1 confirmed CopyBufferRegion
(68,246 -> 0) and SetComputeRootShaderResourceView (98,637 -> 0) both
dropped to zero, while explicitly transitioning from.buffer
(COPY_SOURCE -> COMMON) tripped D3D12 message 527 because D3D12
read-state promotion combines COPY_SOURCE with other read states
(e.g. VERTEX_AND_CONSTANT_BUFFER | COPY_SOURCE, NON_PIXEL_SHADER_RESOURCE).

Keep only the to.buffer (COPY_DEST -> COMMON) transition in place_copy.
Author
Owner

@⁠tyr0nsur on GitHub · 2026-12-01 01:05 UTC · original

I checked 18438462: the legacy copy now transitions the destination alone and leaves the source's promoted read bits intact. That addresses my earlier concern about the source's StateBefore.

The current branch still shows a merge conflict with main and inherited files in the PR diff. I applied only the final legacy barrier hunk to 7d93ee07, keeping main's enhanced-barrier path. cargo test --locked -p victory-gpu --lib --features diagnostics host::place::tests:: passed (5 passed, 1 benchmark ignored). This is functional coverage. This local run did not validate D3D12 debug messages on Intel.

The new Arc B580 report #4643 has the same two ID 538 categories. With card-buffer copies disabled it still sees the copy-source error and a device hang, so the destination-state validation and the remaining hang need separate A/B results. A branch based on current main with this one hunk would make that comparison easier.

**@⁠tyr0nsur** on GitHub · 2026-12-01 01:05 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4589#issuecomment-7297084127) I checked `18438462`: the legacy copy now transitions the destination alone and leaves the source's promoted read bits intact. That addresses my earlier concern about the source's `StateBefore`. The current branch still shows a merge conflict with `main` and inherited files in the PR diff. I applied only the final legacy barrier hunk to `7d93ee07`, keeping main's enhanced-barrier path. `cargo test --locked -p victory-gpu --lib --features diagnostics host::place::tests::` passed (5 passed, 1 benchmark ignored). This is functional coverage. This local run did not validate D3D12 debug messages on Intel. The new Arc B580 report #4643 has the same two ID 538 categories. With card-buffer copies disabled it still sees the copy-source error and a device hang, so the destination-state validation and the remaining hang need separate A/B results. A branch based on current main with this one hunk would make that comparison easier.
Author
Owner

@⁠eleboucher on GitHub · 2026-12-01 14:27 UTC · original

Tested on an RTX 4070 Ti SUPER (16 GB, 32 GB RAM), Series X, native 1440p, hardware RT on (main 5fabb46e + #4694 #3067 #3063 #4171 #4760 #4338, then this PR's hunk cherry-picked unchanged). D3D12 debug layer on, 6-minute in-game leg each, same scene.

Debug-layer message Before With this PR
CopyBufferRegion: source in COPY_DEST 54,093 0
SetComputeRootShaderResourceView: buffer in COPY_DEST (promoted from COMMON) 68,012 5,004
new: ResourceBarrier "Before state COPY_DEST" mismatch 0 5,059
new: CopyBufferRegion state message 0 5,083

So it removes most of what it targets. The two new kinds look like the edge cases #194 covers (a destination already moved out of COPY_DEST before the added transition). The new unit test place_copy_leaves_its_destination_readable_in_the_same_execute passes on this card with the debug layer. No change in device losses either way in our runs; the global barrier after each placed copy already ordered the data, so this reads as a state-legality fix.

**@⁠eleboucher** on GitHub · 2026-12-01 14:27 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4589#issuecomment-7314290622) Tested on an RTX 4070 Ti SUPER (16 GB, 32 GB RAM), Series X, native 1440p, hardware RT on (main 5fabb46e + #4694 #3067 #3063 #4171 #4760 #4338, then this PR's hunk cherry-picked unchanged). D3D12 debug layer on, 6-minute in-game leg each, same scene. | Debug-layer message | Before | With this PR | |---|---|---| | CopyBufferRegion: source in COPY_DEST | 54,093 | 0 | | SetComputeRootShaderResourceView: buffer in COPY_DEST (promoted from COMMON) | 68,012 | 5,004 | | new: ResourceBarrier "Before state COPY_DEST" mismatch | 0 | 5,059 | | new: CopyBufferRegion state message | 0 | 5,083 | So it removes most of what it targets. The two new kinds look like the edge cases #194 covers (a destination already moved out of COPY_DEST before the added transition). The new unit test `place_copy_leaves_its_destination_readable_in_the_same_execute` passes on this card with the debug layer. No change in device losses either way in our runs; the global barrier after each placed copy already ordered the data, so this reads as a state-legality fix.
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:36 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:36 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4589#issuecomment-7321218932) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
github-bot closed this pull request 2026-12-01 18:42:59 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!4590
No description provided.