Skip to content

GPU: track Shadow buffer states per command list and transition between UAV and read uses - #583

Open
Lewandox wants to merge 2 commits into
fxceless:mainfrom
Lewandox:fix/gpu-shadow-buffer-barriers
Open

Lewandox wants to merge 2 commits into
fxceless:mainfrom
Lewandox:fix/gpu-shadow-buffer-barriers

Conversation

@Lewandox

Copy link
Copy Markdown

Summary

Shadow::buffer host copies are created in D3D12_RESOURCE_STATE_COMMON with D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, but HostList only tracked texture states (states), never buffer states. Once a shader bound a Shadow buffer as a UAV in a command list (promoting it to UNORDERED_ACCESS), binding that same buffer later in the list for IASetVertexBuffers, IASetIndexBuffer, root CBV/SRV, table SRV/CBV, or ExecuteIndirect left it in UNORDERED_ACCESS — triggering D3D12 validation errors (Actual State: UNORDERED_ACCESS, Expected State: VERTEX_AND_CONSTANT_BUFFER) and NVIDIA GPU hangs/device removals.

Changes

  • crates/victory-gpu/src/host.rs:
    • Added per-list BufferStates tracking on HostList (cleared on HostList::reset, matching D3D12's automatic buffer decay back to COMMON at the end of ExecuteCommandLists).
    • Added HostList::buffer_state, HostList::buffer_read (GENERIC_READ), and HostList::buffer_uav (UNORDERED_ACCESS, guarded on D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS).
    • Holds a clone of each tracked ID3D12Resource until
      eset() so COM pointer keys cannot alias freed buffers.
  • crates/victory-gpu/src/draw.rs:
    • Calls list.buffer_read(&shadow.buffer) before IASetVertexBuffers, IASetIndexBuffer, direct/tabled root CBVs & SRVs, table SRVs/CBVs, and ExecuteIndirect argument/count buffers.
    • Calls list.buffer_uav(&shadow.buffer) before direct/tabled root UAVs and table UAVs.

Verification

  • Added host::batch::buffer_states_track_transitions_and_execute_on_d3d12: verifies the BufferStates state machine and executes a real D3D12 direct command list on WARP (COMMON -> UNORDERED_ACCESS -> GENERIC_READ -> IASetVertexBuffers/IASetIndexBuffer -> UNORDERED_ACCESS across two submissions/resets) checking GetDeviceRemovedReason() == Ok(()) and zero D3D12 debug-layer errors when the debug layer is installed.
  • Ran cargo test -p victory-gpu --lib -- --test-threads=4: 114 passed, 0 failed (1 ignored benchmark).
  • Not run on a retail game build.

AI-assisted.

Copy link
Copy Markdown

Lewandox, PortBridge checked the submission boundary on exact f176c477. The first Shadow barrier in each list assumes COMMON, while Host::submit can execute multiple prelude/list pairs in one call. D3D12 only decays buffers at the queue-call boundary. The appended card compare can also read a Shadow that is still in UAV state.

I extracted the exact tracker and submission code into a CPU state check. At the current head the mock detects both cases. The candidate keeps disjoint lists in one call, splits a repeated tracked Shadow at a queue-call boundary, and puts the card compare after decay. The check then passes in ordinary, late, relay and timed modes while preserving logical fences and prelude adjacency.

Patch, test and raw log. The fixture models D3D12 state and doesn't run a native device. Raw-address and dynamic heap buffers outside BufferStates are a separate path. AI-assisted PortBridge review (OpenAI Codex).

KyleS98 added a commit to KyleS98/VIctory-Neo that referenced this pull request Nov 25, 2026
…ck Shadow buffer states per command list and transition between UAV and read uses

Upstream pull request 583, applied unchanged on c96b4f2 for this integration branch. All credit to its author.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KyleS98 added a commit to KyleS98/VIctory-Neo that referenced this pull request Nov 25, 2026
…ck Shadow buffer states per command list and transition between UAV and read uses

Upstream pull request 583, applied unchanged on 8dd30ab for this integration branch. All credit to its author.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Lewandox

Copy link
Copy Markdown
Author

Thanks @akimfomin — great catch on the ExecuteCommandLists decay boundary.

Updated this PR with a follow-up commit that adds shadow_decay_calls in crates/victory-gpu/src/host.rs:

  • Splits [prelude?, list] run spans into consecutive ExecuteCommandLists calls whenever a tracked Shadow buffer identity repeats in the current call, while keeping disjoint runs batched in one call and preserving each prelude alongside its list.
  • Places the optional trailing card_compare list in a separate following ExecuteCommandLists call whenever any preceding run in that batch tracked a Shadow buffer (across ordinary, late/relay, and diagnostics timed paths), while preserving the existing logical fence signals and self.submitted lock scope.
  • Added unit tests for all batching/compare cases plus a D3D12 debug-layer test (shadow_decay_calls_multi_list_same_shadow_clean_under_d3d12) running two lists sharing a UAV Shadow under a single logical fence with zero validation errors; checked with both default features and --features diagnostics.

@Lewandox
Lewandox force-pushed the fix/gpu-shadow-buffer-barriers branch from 01912bd to ad0a3cd Compare November 25, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants