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

Open
AscilCH wants to merge 1 commit from upstream-pr/564 into main
AscilCH commented 2026-11-25 02:17:18 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T02:17:18Z.


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 #491)

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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6595632568 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/564). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T02:17:18Z. --- ## 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 #491) *(AI-assisted; synthetic unit tests only, no game data.)*
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/564:upstream-pr/564'
git switch 'upstream-pr/564'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/564'
git switch 'upstream-pr/564'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/564'
git switch 'upstream-pr/564'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/564'
git switch 'main'
git merge --squash 'upstream-pr/564'
git switch 'main'
git merge --ff-only 'upstream-pr/564'
git switch 'main'
git merge 'upstream-pr/564'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
fxceless/victory-fork!564
No description provided.