GPU: serialize PresentX texture state reads and barriers under Host::submitted #3202

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/3204 into main
fuzeofficlal commented 2026-11-26 12:30:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T12:30:58Z.


Problem

All regular GPU submissions read and update HostTexture::state under Host::submitted inside HostList::prelude. queue::present and Host::present violated that invariant:

  1. queue::present called resource::host_transition(resource, COPY_SOURCE) before entering Host::present and without holding Host::submitted, publishing a phantom COPY_SOURCE (0x800) state while the host resource was still in its prior GPU state (e.g. RENDER_TARGET = 0x4). Any concurrent Host::execute on another queue observed that phantom state in HostList::prelude and emitted a mismatched StateBefore transition barrier.
  2. Host::present_with_compositor recorded p.copy's before/after transition barriers using that pre-call state snapshot before Host::execute acquired Host::submitted. If a concurrent submission transitioned the texture before p.copy ran, p.copy executed with a stale StateBefore barrier.
  3. After Host::present returned (having already released Host::submitted before IDXGISwapChain::Present and Meter::frame), queue::present unconditionally called resource::host_transition(resource, state) outside Host::submitted, overwriting any state change made by an intervening submission and permanently desynchronizing HostTexture::state from the GPU.

Fix

  • Introduce PresentPlane::Tracked(&HostTexture) and Host::present_planes so queue::present passes live Arc<HostTexture> handles directly instead of mutating HostTexture::state before and after presentation.
  • Acquire Host::submitted inside Host::present_planes_with_compositor (preserving the existing presenter -> submitted lock order) before reading each plane's live HostTexture::state, recording p.copy's barriers, and executing p.copy via Host::execute_locked. Because p.copy transitions each plane back to its observed state before Host::submitted is released, HostTexture::state stays in lockstep with the GPU without unsynchronized mutations.
  • Scope resource::host_transition to #[cfg(all(windows, test))], as queue::present was its only non-test caller.

Tests

  • queue::tests::present_does_not_expose_copy_source_or_clobber_concurrent_state: fails on main (exposes phantom COPY_SOURCE = 2048 instead of RENDER_TARGET = 4, causes barrier replay mismatches on concurrent/present submissions, and clobbers HostTexture::state afterward); passes with this fix.
  • host::present_state_sync_tests::present_planes_reads_live_state_under_submission_lock: deterministically runs an intervening Host::execute during compositor preparation and verifies via host::tests::replay that both single-plane fallback and multi-plane composite paths read the live GPU state under Host::submitted and emit matching transition barriers.
  • Verified with rustfmt --edition 2024, RTX 5090 + WARP with VICTORY_D3D12_DEBUG=1, full WARP victory-gpu suite (248 passed, 0 failed, 1 ignored), cargo clippy --workspace --all-targets --locked -- -D warnings (default and --all-features), and xtask policy check.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6626690322 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3204). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T12:30:58Z. --- ### Problem All regular GPU submissions read and update `HostTexture::state` under `Host::submitted` inside `HostList::prelude`. `queue::present` and `Host::present` violated that invariant: 1. `queue::present` called `resource::host_transition(resource, COPY_SOURCE)` before entering `Host::present` and without holding `Host::submitted`, publishing a phantom `COPY_SOURCE` (`0x800`) state while the host resource was still in its prior GPU state (e.g. `RENDER_TARGET = 0x4`). Any concurrent `Host::execute` on another queue observed that phantom state in `HostList::prelude` and emitted a mismatched `StateBefore` transition barrier. 2. `Host::present_with_compositor` recorded `p.copy`'s before/after transition barriers using that pre-call state snapshot before `Host::execute` acquired `Host::submitted`. If a concurrent submission transitioned the texture before `p.copy` ran, `p.copy` executed with a stale `StateBefore` barrier. 3. After `Host::present` returned (having already released `Host::submitted` before `IDXGISwapChain::Present` and `Meter::frame`), `queue::present` unconditionally called `resource::host_transition(resource, state)` outside `Host::submitted`, overwriting any state change made by an intervening submission and permanently desynchronizing `HostTexture::state` from the GPU. ### Fix - Introduce `PresentPlane::Tracked(&HostTexture)` and `Host::present_planes` so `queue::present` passes live `Arc<HostTexture>` handles directly instead of mutating `HostTexture::state` before and after presentation. - Acquire `Host::submitted` inside `Host::present_planes_with_compositor` (preserving the existing `presenter -> submitted` lock order) before reading each plane's live `HostTexture::state`, recording `p.copy`'s barriers, and executing `p.copy` via `Host::execute_locked`. Because `p.copy` transitions each plane back to its observed state before `Host::submitted` is released, `HostTexture::state` stays in lockstep with the GPU without unsynchronized mutations. - Scope `resource::host_transition` to `#[cfg(all(windows, test))]`, as `queue::present` was its only non-test caller. ### Tests - `queue::tests::present_does_not_expose_copy_source_or_clobber_concurrent_state`: fails on `main` (exposes phantom `COPY_SOURCE = 2048` instead of `RENDER_TARGET = 4`, causes barrier replay mismatches on concurrent/present submissions, and clobbers `HostTexture::state` afterward); passes with this fix. - `host::present_state_sync_tests::present_planes_reads_live_state_under_submission_lock`: deterministically runs an intervening `Host::execute` during compositor preparation and verifies via `host::tests::replay` that both single-plane fallback and multi-plane composite paths read the live GPU state under `Host::submitted` and emit matching transition barriers. - Verified with `rustfmt --edition 2024`, RTX 5090 + WARP with `VICTORY_D3D12_DEBUG=1`, full WARP `victory-gpu` suite (248 passed, 0 failed, 1 ignored), `cargo clippy --workspace --all-targets --locked -- -D warnings` (default and `--all-features`), and `xtask` policy check.
Dukestar69 commented 2026-11-26 13:04:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T12:48:32Z.

Review: APPROVED


Verified on RTX 5090 against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib queue:: -- --test-threads=1: 6/6 passed (including present_does_not_expose_copy_source_or_clobber_concurrent_state).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly serializes PresentX texture state reads and barriers under Host::submitted.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6074390380 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3204#pullrequestreview-6074390380). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T12:48:32Z. **Review:** APPROVED --- Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib queue:: -- --test-threads=1`: 6/6 passed (including `present_does_not_expose_copy_source_or_clobber_concurrent_state`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly serializes `PresentX` texture state reads and barriers under `Host::submitted`. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
oni-swr commented 2026-11-26 15:02:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T14:05:03Z.


WARP test report: head f76d3f47 (parent and control base: main 63bcca43)

  • Adapter: Microsoft Basic Render Driver (WARP). A local, uncommitted probe asserted the host device's adapter name before each run; it passed and was reverted.
  • Environment: VICTORY_WARP=1, VICTORY_D3D12_WARP=1, cargo test -j 4 -p victory-gpu --features diagnostics --lib, rustc 1.98.1, Windows 11, dxil.dll from the Windows SDK 10.0.26100.0.
  • Head: host::present_state_sync_tests::present_planes_reads_live_state_under_submission_lock and queue::tests::present_does_not_expose_copy_source_or_clobber_concurrent_state both pass. The whole victory-gpu lib suite passes: 249 passed (248 plus the probe), 0 failed, 1 ignored.
  • Control 1: main's queue.rs code with this PR's test module (and this PR's host.rs). present_does_not_expose_copy_source_or_clobber_concurrent_state fails: present must not mutate tracked state before acquiring the submission lock (left 2048, right 4).
  • Control 2: the host test uses present_planes_with_compositor, which main doesn't have, so it can't be built on main. I used a mutation of this head instead: the tracked states are read at the start of present_planes_with_compositor, before the compositor callback and before Host::submitted is locked. With that mutation, both tests fail: present_planes_reads_live_state_under_submission_lock (left 4, right 2048) and present_does_not_expose_copy_source_or_clobber_concurrent_state (present copy barriers: before 0x4, but the resource is in 0x80). Moving only the lock, with the state read still after the callback, did not fail the host test, so that test doesn't check lock order on its own.
  • Not tested: synthetic textures only, with the intervening submission injected from the compositor callback, so the concurrency is simulated and not a real two-thread race. No physical GPU and no title.

AI-assisted: verification by Claude Code (Claude Sonnet 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7194253000 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3204#issuecomment-7194253000). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T14:05:03Z. --- **WARP test report: head `f76d3f47`** (parent and control base: main `63bcca43`) - Adapter: Microsoft Basic Render Driver (WARP). A local, uncommitted probe asserted the host device's adapter name before each run; it passed and was reverted. - Environment: `VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`, `cargo test -j 4 -p victory-gpu --features diagnostics --lib`, rustc 1.98.1, Windows 11, `dxil.dll` from the Windows SDK 10.0.26100.0. - Head: `host::present_state_sync_tests::present_planes_reads_live_state_under_submission_lock` and `queue::tests::present_does_not_expose_copy_source_or_clobber_concurrent_state` both pass. The whole `victory-gpu` lib suite passes: 249 passed (248 plus the probe), 0 failed, 1 ignored. - Control 1: main's `queue.rs` code with this PR's test module (and this PR's `host.rs`). `present_does_not_expose_copy_source_or_clobber_concurrent_state` fails: `present must not mutate tracked state before acquiring the submission lock` (left 2048, right 4). - Control 2: the host test uses `present_planes_with_compositor`, which main doesn't have, so it can't be built on main. I used a mutation of this head instead: the tracked states are read at the start of `present_planes_with_compositor`, before the compositor callback and before `Host::submitted` is locked. With that mutation, both tests fail: `present_planes_reads_live_state_under_submission_lock` (left 4, right 2048) and `present_does_not_expose_copy_source_or_clobber_concurrent_state` (`present copy barriers`: `before 0x4, but the resource is in 0x80`). Moving only the lock, with the state read still after the callback, did not fail the host test, so that test doesn't check lock order on its own. - Not tested: synthetic textures only, with the intervening submission injected from the compositor callback, so the concurrency is simulated and not a real two-thread race. No physical GPU and no title. AI-assisted: verification by Claude Code (Claude Sonnet 5.5).
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/3204:upstream-pr/3204'
git switch 'upstream-pr/3204'

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/3204'
git switch 'upstream-pr/3204'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3204'
git switch 'upstream-pr/3204'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3204'
git switch 'main'
git merge --squash 'upstream-pr/3204'
git switch 'main'
git merge --ff-only 'upstream-pr/3204'
git switch 'main'
git merge 'upstream-pr/3204'
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
Marvisak/VIctory!3202
No description provided.