Skip to content

GPU/present: transition presented texture via HostList prelude under submitted lock - #564

Open
AscilCH wants to merge 1 commit into
fxceless:mainfrom
AscilCH:fix/gpu-present-copy-source-barrier-and-state-race
Open

AscilCH wants to merge 1 commit into
fxceless:mainfrom
AscilCH:fix/gpu-present-copy-source-barrier-and-state-race

Conversation

@AscilCH

@AscilCH AscilCH commented Nov 25, 2026

Copy link
Copy Markdown

Problem

Two bugs in the presentation state-tracking path across crates/victory-gpu/src/queue.rs and crates/victory-gpu/src/host.rs:

  1. Illegal COPY_SOURCE -> COPY_SOURCE D3D12 barriers: When the presented texture was already in D3D12_RESOURCE_STATE_COPY_SOURCE (0x800), resource::host_transition(resource, COPY_SOURCE) returned None, defaulting state = COPY_SOURCE. Host::present() then unconditionally recorded two COPY_SOURCE -> COPY_SOURCE barriers (StateBefore == StateAfter, violating D3D12 barrier rules).
  2. Unlocked HostTexture::state race: queue.rs mutated HostTexture::state to COPY_SOURCE before Host::present() acquired host.submitted, and unconditionally swapped it back afterwards. A concurrent Host::submit() running list.prelude() in that window saw the bogus COPY_SOURCE state, emitted a mismatched barrier, and then had its resulting HostTexture::state clobbered by queue.rs. (Passing &ID3D12Resource instead of Arc<HostTexture> also did not retain the texture on async late_free_present copy lists.)

Fix

  • Pass an owned Arc<HostTexture> (resource::host_copy) into Host::present() and remove the unlocked host_transition swaps from queue.rs (scoping resource::host_transition to #[cfg(all(windows, test))]).
  • Call copy.settle(texture, D3D12_RESOURCE_STATE_COPY_SOURCE.0 as u32) on the present copy list so copy.prelude() transitions texture from its true state to COPY_SOURCE atomically under self.submitted, skips the barrier completely when already in COPY_SOURCE, and retains Arc<HostTexture> until copy.reset().
  • Add synthetic D3D12 test present_settle_skips_redundant_copy_source_barrier_and_tracks_state_at_prelude.

Verification

  • cargo test -p victory-gpu --locked host::batch -- --test-threads=1: 5 passed, 0 failed (1 pre-existing ignored benchmark)
  • cargo test -p victory-gpu --locked queue::tests -- --test-threads=1: 4 passed, 0 failed
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings: clean (default-features build on c96b4f2 has only the pre-existing dead_code warning on placed_filler_twins, tracked in GPU: keep clippy green without the diagnostics feature #491)

(AI-assisted; synthetic unit tests only, no game data.)

…submitted lock

- Replace unlocked `resource::host_transition` swaps around `host.present()` in
  `queue.rs` with passing an owned `Arc<HostTexture>` (`resource::host_copy`)
  into `Host::present()`.
- Record `copy.settle(texture, D3D12_RESOURCE_STATE_COPY_SOURCE)` on the
  present copy list so `copy.prelude()` runs atomically under `self.submitted`:
  - Eliminates illegal `COPY_SOURCE -> COPY_SOURCE` D3D12 barriers when the
    presented texture is already in `COPY_SOURCE`.
  - Eliminates the race where a concurrent `Host::submit()` observed the
    unlocked `COPY_SOURCE` swap and had its resulting `HostTexture::state`
    overwritten on `present()`'s return.
  - Retains the `Arc<HostTexture>` on the present copy list until reset after
    GPU completion (including `late_free_present` flights).
- Add synthetic D3D12 unit test verifying `settle` + `prelude` emits no
  no-op barrier for `COPY_SOURCE` and updates `HostTexture::state` only at
  prelude/submission time.
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.

1 participant