gpu: skip barriers whose before and after states are equal #1951

Closed
github-bot wants to merge 2 commits from gh-pr/1951/head into gh-pr/1951/base
Owner

@⁠claude-GTA6 on GitHub · 2026-11-25 01:42 UTC · original
claude-GTA6:pr-skip-equal-barriers → main · +79 −26 · 2 files · 2 commits · closed without merging

From a tester working with Claude (AI-assisted); measured on my own machine.

What

A transition barrier whose states before and after are equal is invalid in D3D12. Three places could issue one:

  • queue::present: when the presented texture was already in COPY_SOURCE, host_transition returns nothing and the old code passed COPY_SOURCE as the state to come from, so Host::present moved it COPY_SOURCE -> COPY_SOURCE and back. present now takes Option<u32>: None means the texture needs no move, and only the back buffer's barriers are issued.
  • list::ensure_state: legal_state can map the wanted state onto the one the texture is already in.
  • clear_rtv: uses the same helper, for symmetry.

host::needed decides whether a move is needed and host::transition_from builds the barrier from it. Nothing changes when the states differ.

Why a separate PR

Split out of #638 at the triage's suggestion: it is the only part of that PR that changes release builds. #638 keeps the same lines until this merges (its show mode needs present to accept a texture that is already a copy source); after that a merge of main leaves #638 diagnostics-only.

Testing

Windows 11, RTX 5090. The card was busy, so the device-backed tests ran on the software adapter (VICTORY_D3D12_WARP=1).

  • cargo test -p victory-gpu --locked: 140 passed, 2 failed, 2 ignored. The new host::barriers::a_texture_moves_only_between_different_states passes. The two failures, descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views, fail the same way on unmodified main (ccfb0299) under WARP, so they are not from this change.
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings, with and without --features diagnostics: clean.
  • cargo xtask policy: ok.
  • Not run in the game on this branch.

🤖 Generated with Claude Code

**@⁠claude-GTA6** on GitHub · 2026-11-25 01:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/1951) `claude-GTA6:pr-skip-equal-barriers` → `main` · +79 −26 · 2 files · 2 commits · closed without merging *From a tester working with Claude (AI-assisted); measured on my own machine.* ## What A transition barrier whose states before and after are equal is invalid in D3D12. Three places could issue one: - **`queue::present`**: when the presented texture was already in `COPY_SOURCE`, `host_transition` returns nothing and the old code passed `COPY_SOURCE` as the state to come from, so `Host::present` moved it `COPY_SOURCE -> COPY_SOURCE` and back. `present` now takes `Option<u32>`: `None` means the texture needs no move, and only the back buffer's barriers are issued. - **`list::ensure_state`**: `legal_state` can map the wanted state onto the one the texture is already in. - **`clear_rtv`**: uses the same helper, for symmetry. `host::needed` decides whether a move is needed and `host::transition_from` builds the barrier from it. Nothing changes when the states differ. ## Why a separate PR Split out of #638 at the triage's suggestion: it is the only part of that PR that changes release builds. #638 keeps the same lines until this merges (its show mode needs `present` to accept a texture that is already a copy source); after that a merge of `main` leaves #638 diagnostics-only. ## Testing Windows 11, RTX 5090. The card was busy, so the device-backed tests ran on the software adapter (`VICTORY_D3D12_WARP=1`). - `cargo test -p victory-gpu --locked`: 140 passed, 2 failed, 2 ignored. The new `host::barriers::a_texture_moves_only_between_different_states` passes. The two failures, `descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views`, fail the same way on unmodified `main` (`ccfb0299`) under WARP, so they are not from this change. - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`, with and without `--features diagnostics`: clean. - `cargo xtask policy`: ok. - Not run in the game on this branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A transition barrier with equal states before and after is invalid in
D3D12. Three places could issue one:

- queue::present: when the presented texture was already in COPY_SOURCE,
  host_transition returns nothing and the old code passed COPY_SOURCE as
  the state to come from, so Host::present moved it COPY_SOURCE ->
  COPY_SOURCE and back. present now takes Option<u32>: None means the
  texture needs no move, and only the back buffer's barriers are issued.
- list::ensure_state: legal_state can map the wanted state onto the one
  the texture is already in.
- clear_rtv: same helper, for symmetry.

host::needed decides whether a move is needed and host::transition_from
builds the barrier from it; a_texture_moves_only_between_different_states
covers needed. No change when the states differ.

Split out of #638 (where the show mode needs present to accept a texture
that is already a copy source) at the triage's suggestion.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
HostList::transition applies legal_state before track, and track (the only
writer of the list's state map) returns a state only when it differs from
the legal state wanted. So in ensure_state, legal_state of the same
texture and state gives that same legal state, never equal to before; in
clear_rtv, before is a legal state that differs from legal_state(RENDER_TARGET),
and a texture whose flags forbid RENDER_TARGET never holds that bit, so
before is never RENDER_TARGET either. Only present (queue.rs / host.rs)
could issue an equal-state barrier; that fix and its test stay.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:49:53 +00:00
github-bot closed this pull request 2026-11-26 04:49:54 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 08:20 UTC · original · edited 2026-11-25 09:18 UTC

Automated triage for the maintainers.

Merge candidate. This fixes a real bug in queue::present (crates/victory-gpu/src/queue.rs). On main, when the presented texture is already in COPY_SOURCE, resource::host_transition returns None and the code falls back to COPY_SOURCE. Host::present (host.rs) then records COPY_SOURCE -> COPY_SOURCE and the same barrier back, both invalid in D3D12. Now present takes Option<u32>, transition_from/needed drop the texture's barrier in that case, and only the back buffer is moved. The state restore after the copy is skipped too, which was a no-op on main. Host::present has no other callers. The other open PRs that rewrite this function (multi-plane composition, subresource tracking) keep the old fallback, so none of them already fixes this. Recommending a look, not approving.

On your reply: agreed. The list.rs guards are gone in 9a79e8c, and what's left is the present fix with its needed test, as asked.

CI: no check runs reported for this head.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 08:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/1951#issuecomment-7156914514) · edited 2026-11-25 09:18 UTC <!-- victory-triage v1 head=9a79e8c65bf36c9b86e51e648c16f1cd3bbcbe32 verdict=merge-candidate at=2026-11-25T09:18:03Z --> Automated triage for the maintainers. **Merge candidate.** This fixes a real bug in `queue::present` (`crates/victory-gpu/src/queue.rs`). On `main`, when the presented texture is already in `COPY_SOURCE`, `resource::host_transition` returns `None` and the code falls back to `COPY_SOURCE`. `Host::present` (`host.rs`) then records `COPY_SOURCE -> COPY_SOURCE` and the same barrier back, both invalid in D3D12. Now `present` takes `Option<u32>`, `transition_from`/`needed` drop the texture's barrier in that case, and only the back buffer is moved. The state restore after the copy is skipped too, which was a no-op on `main`. `Host::present` has no other callers. The other open PRs that rewrite this function (multi-plane composition, subresource tracking) keep the old fallback, so none of them already fixes this. Recommending a look, not approving. On your reply: agreed. The `list.rs` guards are gone in `9a79e8c`, and what's left is the `present` fix with its `needed` test, as asked. CI: no check runs reported for this head. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠claude-GTA6 on GitHub · 2026-11-25 08:29 UTC · original

From a tester working with Claude (AI-assisted); measured on my own machine.

Thanks, the triage is right. I dropped the list.rs changes in 9a79e8c6 (a new commit on top of ab36867c, no rebase). The present fix and its needed test are unchanged.

Why those guards could never run:

  • track is the only thing that writes a list's state map. Both of its callers (HostList::transition and move_texture) pass it legal_state(texture, wanted), so every state it stores is a legal one. It hands back a before only when that differs from the legal state wanted.
  • ensure_state works out legal_state again for the same texture and state. That gives the same value (legal_for only clears bits), so it never equals before.
  • clear_rtv moves to the raw RENDER_TARGET, and that can't equal before either:
    • If the texture allows render targets, legal_state(RENDER_TARGET) is RENDER_TARGET itself, and before differs from it.
    • If it doesn't, no state stored for it can hold the 0x4 bit.

Tests:

  • Clippy: cargo clippy --workspace --all-targets --locked -- -D warnings passes clean.
  • victory-gpu on WARP (VICTORY_D3D12_WARP=1): 140 passed, 2 failed, 2 ignored.
    • The two failures are descriptor::host::tests::dynamic_slots_are_held_until_released (descriptor heap smaller than HEAP_VIEWS) and memory::tests::lists_share_a_table_and_copies_keep_their_views ("past the dynamic slots").
    • They fail the same way on the PR's base ccfb0299 (139 passed, 2 failed). The base has one test less, the new needed test.
    • So they come from WARP's descriptor limits, not from this change.
  • I did not run it on a hardware GPU.
**@⁠claude-GTA6** on GitHub · 2026-11-25 08:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1951#issuecomment-7157085731) *From a tester working with Claude (AI-assisted); measured on my own machine.* Thanks, the triage is right. I dropped the `list.rs` changes in 9a79e8c6 (a new commit on top of ab36867c, no rebase). The `present` fix and its `needed` test are unchanged. Why those guards could never run: - `track` is the only thing that writes a list's state map. Both of its callers (`HostList::transition` and `move_texture`) pass it `legal_state(texture, wanted)`, so every state it stores is a legal one. It hands back a `before` only when that differs from the legal state wanted. - **`ensure_state`** works out `legal_state` again for the same texture and state. That gives the same value (`legal_for` only clears bits), so it never equals `before`. - **`clear_rtv`** moves to the raw `RENDER_TARGET`, and that can't equal `before` either: - If the texture allows render targets, `legal_state(RENDER_TARGET)` is `RENDER_TARGET` itself, and `before` differs from it. - If it doesn't, no state stored for it can hold the `0x4` bit. Tests: - **Clippy:** `cargo clippy --workspace --all-targets --locked -- -D warnings` passes clean. - **`victory-gpu` on WARP (`VICTORY_D3D12_WARP=1`):** 140 passed, 2 failed, 2 ignored. - The two failures are `descriptor::host::tests::dynamic_slots_are_held_until_released` (descriptor heap smaller than `HEAP_VIEWS`) and `memory::tests::lists_share_a_table_and_copies_keep_their_views` ("past the dynamic slots"). - They fail the same way on the PR's base ccfb0299 (139 passed, 2 failed). The base has one test less, the new `needed` test. - So they come from WARP's descriptor limits, not from this change. - I did not run it on a hardware GPU.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1951
No description provided.