GPU: track texture subresource states #594

Open
github-bot wants to merge 1 commit from github-bot/gh-594 into main AGit
Owner

@⁠broccolize on GitHub · 2026-11-24 05:17 UTC · original
broccolize:gpu/track-texture-subresource-states → main · +829 −416 · 11 files · 1 commits · open

Track texture states per subresource during command recording and submission. CopyTextureRegion can now keep two slices of the same texture in COPY_SOURCE and COPY_DEST at the same time. Whole-texture barriers handle mixed states.

The synthetic regression copies slice 0 to slice 1, verifies the destination bytes, and checks that slice 2 stays in COMMON. It fails when the old whole-texture copy transitions are restored.

On Windows GNU, 44 GPU tests passed with default settings and 46 passed with diagnostics on WARP. Asset-policy checks passed. The workspace suite passed with one loader fixture skipped because its MSVC linker flag also fails on GNU at upstream main. The D3D12 debug layer could not initialize on this machine.

This touches state-tracking code also used by the render-view mip work in #559.

AI-assisted with Codex. All verification used synthetic inputs.

**@⁠broccolize** on GitHub · 2026-11-24 05:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/594) `broccolize:gpu/track-texture-subresource-states` → `main` · +829 −416 · 11 files · 1 commits · open Track texture states per subresource during command recording and submission. `CopyTextureRegion` can now keep two slices of the same texture in `COPY_SOURCE` and `COPY_DEST` at the same time. Whole-texture barriers handle mixed states. The synthetic regression copies slice 0 to slice 1, verifies the destination bytes, and checks that slice 2 stays in `COMMON`. It fails when the old whole-texture copy transitions are restored. On Windows GNU, 44 GPU tests passed with default settings and 46 passed with diagnostics on WARP. Asset-policy checks passed. The workspace suite passed with one loader fixture skipped because its MSVC linker flag also fails on GNU at upstream `main`. The D3D12 debug layer could not initialize on this machine. This touches state-tracking code also used by the render-view mip work in #559. AI-assisted with Codex. All verification used synthetic inputs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:09:31 +00:00
github-bot force-pushed github-bot/gh-594 from 71bc6daea0 to c6e6daaee8 2026-11-26 06:29:39 +00:00 Compare
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 05:39 UTC · original · edited 2026-11-24 07:15 UTC

I tried #559's synthetic draw on 3070871. The direct D3D12 control passed on RTX 5090 and WARP. Through normal draw setup, the debug layer still reported that the SRV's mip 0 was in RENDER_TARGET at the bind. That case stopped before submission.

The small follow-up selects the mip ranges of plane-zero 2D color SRVs and RTVs using this PR's tracker. On both adapters and with both same-list and separate-list readback, all 64 pixels of mip 0 were preserved and all 16 pixels of mip 1 matched the sampled color. The D3D12 debug callback reported zero errors through submission. This PR's existing array-slice copy regression also passed on both adapters. Incremental commit on 3070871

I tested the adjacent UAV case on top of that follow-up. The synthetic compute shader reads mip 0 through a restricted SRV and writes one texel in mip 1 through a UAV on the same 2D color texture. On 77a3e30, descriptor-table preparation put both mips in UNORDERED_ACCESS. The RTX 5090 debug layer reported the mip 0 state at bind, and I stopped that run before submission.

The patch uses the existing tracker to transition only the mip selected by the UAV. On RTX 5090 and WARP, both descriptor orders now leave mip 0 shader-readable and mip 1 writable. All 64 source texels were preserved, the one intended write matched, the other 15 destination texels were unchanged, and the debug callback reported zero errors through submission. The diagnostics GPU suite passed (46 passed, one benchmark ignored). UAV follow-up commit

I also tested a 1×1 ClearRenderTargetView on an explicit 2D-array view of mip 1 in slices 1 and 2. On 3070871, the debug layer caught the untouched slice 0 leaving COPY_SOURCE; the test stopped before submission. With the array-clear follow-up on top of 1b333b3, only the two subresources in the view transitioned. RTX 5090 and WARP each read back both expected changes and all 58 untouched texels, with zero D3D12 errors. Array clear follow-up commit

**@⁠fuzeofficlal** on GitHub · 2026-11-24 05:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/594#issuecomment-7123160111) · edited 2026-11-24 07:15 UTC I tried #559's synthetic draw on `3070871`. The direct D3D12 control passed on RTX 5090 and WARP. Through normal draw setup, the debug layer still reported that the SRV's mip 0 was in `RENDER_TARGET` at the bind. That case stopped before submission. The small follow-up selects the mip ranges of plane-zero 2D color SRVs and RTVs using this PR's tracker. On both adapters and with both same-list and separate-list readback, all 64 pixels of mip 0 were preserved and all 16 pixels of mip 1 matched the sampled color. The D3D12 debug callback reported zero errors through submission. This PR's existing array-slice copy regression also passed on both adapters. [Incremental commit on `3070871`](https://github.com/fuzeofficlal/VIctory/commit/77a3e3080024724c3255547deab3d5acd4b7e50d) I tested the adjacent UAV case on top of that follow-up. The synthetic compute shader reads mip 0 through a restricted SRV and writes one texel in mip 1 through a UAV on the same 2D color texture. On `77a3e30`, descriptor-table preparation put both mips in `UNORDERED_ACCESS`. The RTX 5090 debug layer reported the mip 0 state at bind, and I stopped that run before submission. The patch uses the existing tracker to transition only the mip selected by the UAV. On RTX 5090 and WARP, both descriptor orders now leave mip 0 shader-readable and mip 1 writable. All 64 source texels were preserved, the one intended write matched, the other 15 destination texels were unchanged, and the debug callback reported zero errors through submission. The diagnostics GPU suite passed (46 passed, one benchmark ignored). [UAV follow-up commit](https://github.com/fuzeofficlal/VIctory/commit/1b333b39b933bc9a0443c53fa5337c49fc9109df) I also tested a 1×1 `ClearRenderTargetView` on an explicit 2D-array view of mip 1 in slices 1 and 2. On `3070871`, the debug layer caught the untouched slice 0 leaving `COPY_SOURCE`; the test stopped before submission. With the array-clear follow-up on top of `1b333b3`, only the two subresources in the view transitioned. RTX 5090 and WARP each read back both expected changes and all 58 untouched texels, with zero D3D12 errors. [Array clear follow-up commit](https://github.com/fuzeofficlal/VIctory/commit/edb6a6def5716593cc5eefd33f95ba3aef167147)
Author
Owner

@⁠broccolize on GitHub · 2026-11-24 07:29 UTC · original

Thanks @⁠fuzeofficlal for verifying the array-slice regression on RTX 5090 and WARP and for sharing the three tested view-state fixes.

Would the maintainers prefer to include those fixes in this PR or land the tracker first and handle the view fixes in follow-up PRs? #559 already covers some of the SRV/RTV work.

**@⁠broccolize** on GitHub · 2026-11-24 07:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/594#issuecomment-7125047047) Thanks @⁠fuzeofficlal for verifying the array-slice regression on RTX 5090 and WARP and for sharing the three tested view-state fixes. Would the maintainers prefer to include those fixes in this PR or land the tracker first and handle the view fixes in follow-up PRs? #559 already covers some of the SRV/RTV work.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:29 UTC · original · edited 2026-11-26 07:20 UTC

Automated triage for the maintainers.

Merge candidate. Rebased; merges cleanly. crates/victory-gpu/src/host/states.rs replaces HostTexture's single AtomicU32 state with per-subresource tracking:

  • States stay Uniform until a command needs to split them.
  • RecordedTexture keeps each list's first and last state per subresource.
  • reconcile adds prelude barriers and commits the final states in submission order.

The subresource count includes plane count and treats 3D depth slices correctly. The array-slice copy test in resource.rs checks mixed COPY_SOURCE/COPY_DEST states and an untouched slice, both on readback and in the committed states. Note for whoever merges: this overlaps #559 (mip ranges for SRV/RTV), and the view-state follow-ups mentioned in the comments are not part of this PR.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/594#issuecomment-7148558806) · edited 2026-11-26 07:20 UTC <!-- victory-triage v1 head=c6e6daaee8ea288591decbbfdef5810b0e941cf1 verdict=merge-candidate at=2026-11-26T07:20:34Z --> Automated triage for the maintainers. **Merge candidate.** Rebased; merges cleanly. `crates/victory-gpu/src/host/states.rs` replaces `HostTexture`'s single `AtomicU32` state with per-subresource tracking: - States stay `Uniform` until a command needs to split them. - `RecordedTexture` keeps each list's first and last state per subresource. - `reconcile` adds prelude barriers and commits the final states in submission order. The subresource count includes plane count and treats 3D depth slices correctly. The array-slice copy test in `resource.rs` checks mixed `COPY_SOURCE`/`COPY_DEST` states and an untouched slice, both on readback and in the committed states. Note for whoever merges: this overlaps #559 (mip ranges for SRV/RTV), and the view-state follow-ups mentioned in the comments are not part of this PR. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 14:15 UTC · original · approved these changes

Reviewed and verified head c6e6daaee8ea288591decbbfdef5810b0e941cf1 (clean merge with origin/main 63bcca43) on Windows 11 x64 with NVIDIA GeForce RTX 5090 and D3D12 WARP (VICTORY_D3D12_WARP=1, VICTORY_D3D12_DEBUG=1, Rust 1.98.1).

Code review

  • crates/victory-gpu/src/host/states.rs:
    • TextureStates (L8) and Subresources<T> (L79) keep uniform textures allocation-free until a command distinguishes subresources, and HostTexture::subresource_count (L23) properly treats 3D textures as array_size = 1 while querying D3D12_FEATURE_FORMAT_INFO for PlaneCount (covering 2-plane depth-stencil formats).
    • RecordedTexture::record (L117) and reconcile (L169) handle all Uniform/Split combinations cleanly: first uses defer to the prelude, identical transitions emit zero barriers, out-of-range guest subresource indices are safely ignored (L146), and reconcile collapses split committed states back to Uniform once all subresources match.
  • crates/victory-gpu/src/host.rs & queue.rs:
    • execute_texture_read (L1167) and present_with_compositor (L3225) now hold Host::submitted across state snapshots through execute_locked, closing the prior lockless host_transition race during present (and execute_locked drops submitted before dump_submission, so there is no self-deadlock).
    • prelude (L1967) runs twin copies via temporary_barriers before reconciling list start/end states, and multi-plane present transitions only subresource 0 (L3433-3439) to preserve other mips/slices.
  • crates/victory-gpu/src/list.rs: host_barrier (L498) flushes pending barriers before routing a depth twin (L523-527), and copy_texture_region (L801-804), read_back (L905), and resolve (L1000) transition individual subresources while sharing one Arc<HostTexture> for self-copies.
  • Coordination notes (non-blocking): conflicts in capture.rs with open #2732/#2702 (which still read copy.state), and overlaps #559 for view-range narrowing as already noted.

Verification

  • cargo xtask policy: 192 files ok; cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default & --all-features): 0 warnings
  • WARP (--features diagnostics, --test-threads=1): 247 passed, 0 failed, 1 ignored; with VICTORY_D3D12_DEBUG=1 (skipping compositor_failure_presents_primary_in_the_same_frame, which already aborts with exit code 2173 under VICTORY_D3D12_DEBUG=1 on origin/main 63bcca43 due to a pre-existing 64×64 vs 32×32 fallback CopyResource mismatch): 246 passed, 0 failed, 1 ignored
  • RTX 5090: full default victory-gpu --lib --test-threads=1 (skipping only the 2 pre-existing 1M view-heap tests): 230 passed, 0 failed, 1 ignored (including texture_copy_keeps_array_slice_states_separate and compositor_failure_presents_primary_in_the_same_frame); diagnostics + VICTORY_D3D12_DEBUG=1 core suites (draw, resource, texture, queue, twin, placed_uav_tests, host, bindless, list, capture): 101/101 passed
  • Additional local D3D12 Debug Layer probe on both RTX 5090 and WARP verified out-of-order multi-list recording on a 2-mip×2-slice texture array, OOB subresource handling, zero redundant before == after barriers, execute_texture_read state preservation, ALL_SUBRESOURCES collapse back to Uniform, 2-plane D24_UNORM_S8_UINT, 3D 2-mip (depth=4) subresource count, and 64×64 multi-plane compositor present with a mixed-mip overlay — 0 D3D12 Debug Layer messages.

Solid state-tracking foundation; approving.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 14:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/594#pullrequestreview-6075626699) · **approved these changes** Reviewed and verified head `c6e6daaee8ea288591decbbfdef5810b0e941cf1` (clean merge with `origin/main` `63bcca43`) on Windows 11 x64 with **NVIDIA GeForce RTX 5090** and **D3D12 WARP** (`VICTORY_D3D12_WARP=1`, `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1). **Code review** - `crates/victory-gpu/src/host/states.rs`: - `TextureStates` (`L8`) and `Subresources<T>` (`L79`) keep uniform textures allocation-free until a command distinguishes subresources, and `HostTexture::subresource_count` (`L23`) properly treats 3D textures as `array_size = 1` while querying `D3D12_FEATURE_FORMAT_INFO` for `PlaneCount` (covering 2-plane depth-stencil formats). - `RecordedTexture::record` (`L117`) and `reconcile` (`L169`) handle all `Uniform`/`Split` combinations cleanly: first uses defer to the prelude, identical transitions emit zero barriers, out-of-range guest subresource indices are safely ignored (`L146`), and `reconcile` collapses split committed states back to `Uniform` once all subresources match. - `crates/victory-gpu/src/host.rs` & `queue.rs`: - `execute_texture_read` (`L1167`) and `present_with_compositor` (`L3225`) now hold `Host::submitted` across state snapshots through `execute_locked`, closing the prior lockless `host_transition` race during present (and `execute_locked` drops `submitted` before `dump_submission`, so there is no self-deadlock). - `prelude` (`L1967`) runs twin copies via `temporary_barriers` before reconciling list start/end states, and multi-plane `present` transitions only subresource 0 (`L3433-3439`) to preserve other mips/slices. - `crates/victory-gpu/src/list.rs`: `host_barrier` (`L498`) flushes pending barriers before routing a depth twin (`L523-527`), and `copy_texture_region` (`L801-804`), `read_back` (`L905`), and `resolve` (`L1000`) transition individual subresources while sharing one `Arc<HostTexture>` for self-copies. - Coordination notes (non-blocking): conflicts in `capture.rs` with open #2732/#2702 (which still read `copy.state`), and overlaps #559 for view-range narrowing as already noted. **Verification** - `cargo xtask policy`: `192 files ok`; `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default & `--all-features`): 0 warnings - **WARP (`--features diagnostics`, `--test-threads=1`)**: **247 passed, 0 failed, 1 ignored**; with `VICTORY_D3D12_DEBUG=1` (skipping `compositor_failure_presents_primary_in_the_same_frame`, which already aborts with exit code 2173 under `VICTORY_D3D12_DEBUG=1` on `origin/main` `63bcca43` due to a pre-existing 64×64 vs 32×32 fallback `CopyResource` mismatch): **246 passed, 0 failed, 1 ignored** - **RTX 5090**: full default `victory-gpu --lib --test-threads=1` (skipping only the 2 pre-existing 1M view-heap tests): **230 passed, 0 failed, 1 ignored** (including `texture_copy_keeps_array_slice_states_separate` and `compositor_failure_presents_primary_in_the_same_frame`); `diagnostics` + `VICTORY_D3D12_DEBUG=1` core suites (`draw`, `resource`, `texture`, `queue`, `twin`, `placed_uav_tests`, `host`, `bindless`, `list`, `capture`): **101/101 passed** - Additional local D3D12 Debug Layer probe on both RTX 5090 and WARP verified out-of-order multi-list recording on a 2-mip×2-slice texture array, OOB subresource handling, zero redundant `before == after` barriers, `execute_texture_read` state preservation, `ALL_SUBRESOURCES` collapse back to `Uniform`, 2-plane `D24_UNORM_S8_UINT`, 3D 2-mip (`depth=4`) subresource count, and 64×64 multi-plane compositor present with a mixed-mip overlay — **0 D3D12 Debug Layer messages**. Solid state-tracking foundation; approving.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 14:36 UTC · original

The conflict with the clear and MSAA capture changes is resolved in integration 5e2e85a. The standalone capture submission takes the existing state snapshot lock and restores only the captured slice. Your array-slice copy test and both capture regressions pass on app-local WARP. The maintainers can use the conflict resolution in whichever merge order they choose. WARP results and test details.

Please retain the Git authors on pickup. If folding the resolution into another commit, use Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 14:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/594#issuecomment-7195067910) The conflict with the clear and MSAA capture changes is resolved in [integration `5e2e85a`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/5e2e85acbaaade435ecbed7fb48438df715ed864). The standalone capture submission takes the existing state snapshot lock and restores only the captured slice. Your array-slice copy test and both capture regressions pass on app-local WARP. The maintainers can use the conflict resolution in whichever merge order they choose. [WARP results and test details](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2702). Please retain the Git authors on pickup. If folding the resolution into another commit, use `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/594/head:github-bot/gh-594'
git switch 'github-bot/gh-594'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-594'
git switch 'github-bot/gh-594'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-594'
git switch 'github-bot/gh-594'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-594'
git switch 'main'
git merge --squash 'github-bot/gh-594'
git switch 'main'
git merge --ff-only 'github-bot/gh-594'
git switch 'main'
git merge 'github-bot/gh-594'
git push origin 'main'
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!594
No description provided.