GPU: flush before depth-twin copies and coalesce duplicate transitions in ResourceBarrier #3127

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/3129 into main
fuzeofficlal commented 2026-11-26 09:20:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T09:20:32Z.


Root cause

crates/victory-gpu/src/list.rs::barrier collects every translated host barrier from a title's ResourceBarrier batch into a local Vec<Barrier> and submits the entire slice once at the end of the call. That causes two D3D12 barrier correctness bugs:

  1. Out-of-order barriers around depth-twin copies (D3D12 Debug Layer ERROR #527 RESOURCE_BARRIER_BEFORE_AFTER_MISMATCH):
    • An earlier transition in the same batch updates HostList::states immediately while staying buffered in the local Vec<Barrier>.
    • When a later barrier in the same batch calls HostList::transition on a depth texture with an initialized writable twin (crate::twin::route -> Twin::copy), Twin::copy records its own barriers (starting from the already-updated tracked state) and CopyTextureRegion calls directly onto list.list before the buffered barrier is flushed.
    • As a result, DEPTH_WRITE -> PIXEL_SHADER_RESOURCE is recorded after PIXEL_SHADER_RESOURCE -> COPY_SOURCE, failing D3D12 validation at both recording time and ExecuteCommandLists, and leaving the real GPU resource state diverged from HostTexture::state for subsequent submissions.
  2. Duplicate whole-resource transitions in a single ResourceBarrier call (D3D12 Debug Layer ID #1008 RESOURCE_BARRIER_DUPLICATE_SUBRESOURCE_TRANSITIONS):
    • Because texture transitions map onto ALL_SUBRESOURCES (0xffff_ffff), a single ResourceBarrier batch naming multiple subresources of one texture, a round-trip (A -> B -> A), two aliased placed title textures sharing one HostTexture, or transitions separated by a UAV/aliasing barrier emits multiple transitions for the same host ID3D12Resource in one list.list.ResourceBarrier call.

Before-fix reproduction

Running the new synthetic tests on origin/main (63bcca43) with VICTORY_D3D12_DEBUG=1 --features diagnostics fails on both RTX 5090 and WARP:

  • barrier_flushes_pending_transitions_before_depth_twin_copy fails with two D3D12 id=527 errors:
    • recording: Before state (0x10: D3D12_RESOURCE_STATE_DEPTH_WRITE) ... does not match with the state (0x800: D3D12_RESOURCE_STATE_COPY_SOURCE)
    • execution: Before state (0x80: D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE) ... does not match with the state (0x10: D3D12_RESOURCE_STATE_DEPTH_WRITE)
  • barrier_coalesces_duplicate_transitions_and_splits_across_uav and barrier_coalesces_aliased_title_textures_sharing_one_host_texture emit D3D12 id=1008 (Called on the same subresource(s) of Resource(...) in separate Barrier Descs ... (subresource : 4294967295)).

Change

Scoped cleanly to crates/victory-gpu/src/list.rs:

  • Flush buffered host barriers (emit_barriers) before calling HostList::transition on a texture whose HostTexture has an initialized writable twin, keeping earlier transitions and ordering barriers strictly ahead of twin::route copies.
  • Coalesce sequential whole-resource transitions for the same host ID3D12Resource in push_host_barrier (A -> B + B -> C => A -> C; A -> B + B -> A removed), and flush earlier barriers before pushing the new transition whenever a UAV or aliasing barrier sits between two transitions of the same resource.
  • Record emitted transition barriers in host::tests::ISSUED under #[cfg(test)] and add 4 synthetic regression tests covering batch coalescing/splitting, depth-twin flush ordering across consecutive submissions, and aliased placed textures.

Verification

  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked -- list::tests:: on RTX 5090: 8 passed, 0 failed (0 D3D12 debug errors/warnings)
  • VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked -- list::tests:: on WARP: 8 passed, 0 failed (0 D3D12 debug errors/warnings)
  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked on WARP: 250 passed, 0 failed, 1 ignored
  • cargo test -p victory-gpu --locked -- list::tests:: / twin::tests:: / indirect::tests:: on RTX 5090: all passed
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo test -p xtask --locked policy::tests::repository_passes_policy: passed
<!-- greyfinch-sync:Marvisak/VIctory:issue:6623460133 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3129). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T09:20:32Z. --- ## Root cause `crates/victory-gpu/src/list.rs::barrier` collects every translated host barrier from a title's `ResourceBarrier` batch into a local `Vec<Barrier>` and submits the entire slice once at the end of the call. That causes two D3D12 barrier correctness bugs: 1. **Out-of-order barriers around depth-twin copies (D3D12 Debug Layer ERROR #527 `RESOURCE_BARRIER_BEFORE_AFTER_MISMATCH`)**: - An earlier transition in the same batch updates `HostList::states` immediately while staying buffered in the local `Vec<Barrier>`. - When a later barrier in the same batch calls `HostList::transition` on a depth texture with an initialized writable twin (`crate::twin::route` -> `Twin::copy`), `Twin::copy` records its own barriers (starting from the already-updated tracked state) and `CopyTextureRegion` calls directly onto `list.list` *before* the buffered barrier is flushed. - As a result, `DEPTH_WRITE -> PIXEL_SHADER_RESOURCE` is recorded *after* `PIXEL_SHADER_RESOURCE -> COPY_SOURCE`, failing D3D12 validation at both recording time and `ExecuteCommandLists`, and leaving the real GPU resource state diverged from `HostTexture::state` for subsequent submissions. 2. **Duplicate whole-resource transitions in a single `ResourceBarrier` call (D3D12 Debug Layer ID #1008 `RESOURCE_BARRIER_DUPLICATE_SUBRESOURCE_TRANSITIONS`)**: - Because texture transitions map onto `ALL_SUBRESOURCES` (`0xffff_ffff`), a single `ResourceBarrier` batch naming multiple subresources of one texture, a round-trip (`A -> B -> A`), two aliased placed title textures sharing one `HostTexture`, or transitions separated by a UAV/aliasing barrier emits multiple transitions for the same host `ID3D12Resource` in one `list.list.ResourceBarrier` call. ## Before-fix reproduction Running the new synthetic tests on `origin/main` (`63bcca43`) with `VICTORY_D3D12_DEBUG=1 --features diagnostics` fails on both RTX 5090 and WARP: - `barrier_flushes_pending_transitions_before_depth_twin_copy` fails with two D3D12 `id=527` errors: - recording: `Before state (0x10: D3D12_RESOURCE_STATE_DEPTH_WRITE) ... does not match with the state (0x800: D3D12_RESOURCE_STATE_COPY_SOURCE)` - execution: `Before state (0x80: D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE) ... does not match with the state (0x10: D3D12_RESOURCE_STATE_DEPTH_WRITE)` - `barrier_coalesces_duplicate_transitions_and_splits_across_uav` and `barrier_coalesces_aliased_title_textures_sharing_one_host_texture` emit D3D12 `id=1008` (`Called on the same subresource(s) of Resource(...) in separate Barrier Descs ... (subresource : 4294967295)`). ## Change Scoped cleanly to `crates/victory-gpu/src/list.rs`: - Flush buffered host barriers (`emit_barriers`) before calling `HostList::transition` on a texture whose `HostTexture` has an initialized writable twin, keeping earlier transitions and ordering barriers strictly ahead of `twin::route` copies. - Coalesce sequential whole-resource transitions for the same host `ID3D12Resource` in `push_host_barrier` (`A -> B` + `B -> C` => `A -> C`; `A -> B` + `B -> A` removed), and flush earlier barriers before pushing the new transition whenever a UAV or aliasing barrier sits between two transitions of the same resource. - Record emitted transition barriers in `host::tests::ISSUED` under `#[cfg(test)]` and add 4 synthetic regression tests covering batch coalescing/splitting, depth-twin flush ordering across consecutive submissions, and aliased placed textures. ## Verification - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked -- list::tests::` on RTX 5090: 8 passed, 0 failed (0 D3D12 debug errors/warnings) - `VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked -- list::tests::` on WARP: 8 passed, 0 failed (0 D3D12 debug errors/warnings) - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked` on WARP: 250 passed, 0 failed, 1 ignored - `cargo test -p victory-gpu --locked -- list::tests::` / `twin::tests::` / `indirect::tests::` on RTX 5090: all passed - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo test -p xtask --locked policy::tests::repository_passes_policy`: passed
Dukestar69 commented 2026-11-26 13:04:06 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

  • cargo test -p victory-gpu --lib list:: -- --test-threads=1: passed.
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed; twin::: 2/2 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly flushes pending barriers before depth-twin copies and coalesces duplicate transitions in ResourceBarrier.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6074175640 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3129#pullrequestreview-6074175640). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T12:32:30Z. **Review:** APPROVED --- Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib list:: -- --test-threads=1`: passed. - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 20/20 passed; `twin::`: 2/2 passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly flushes pending barriers before depth-twin copies and coalesces duplicate transitions in `ResourceBarrier`. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Jackster commented 2026-11-26 23:10:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T23:10:48Z.


Windows 11, 63bcca4 + this PR, Radeon RX 7900 XTX:

  • cargo test -p victory-gpu --lib: 235 passed / 0 failed / 1 ignored (unpatched 63bcca4 here: 231; +4).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.

The four added tests pass: push_host_barrier_coalesces_cancels_and_splits_batches, barrier_coalesces_duplicate_transitions_and_splits_across_uav, barrier_flushes_pending_transitions_before_depth_twin_copy, barrier_coalesces_aliased_title_textures_sharing_one_host_texture. Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7205321810 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3129#issuecomment-7205321810). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T23:10:48Z. --- Windows 11, `63bcca4` + this PR, Radeon RX 7900 XTX: - `cargo test -p victory-gpu --lib`: 235 passed / 0 failed / 1 ignored (unpatched `63bcca4` here: 231; +4). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. The four added tests pass: `push_host_barrier_coalesces_cancels_and_splits_batches`, `barrier_coalesces_duplicate_transitions_and_splits_across_uav`, `barrier_flushes_pending_transitions_before_depth_twin_copy`, `barrier_coalesces_aliased_title_textures_sharing_one_host_texture`. Synthetic only. AI-assisted.
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/3129:upstream-pr/3129'
git switch 'upstream-pr/3129'

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