GPU: track mip states for 2D color targets #559

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/559 into main
fuzeofficlal commented 2026-11-24 04:55:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T04:55:41Z.


Reproduction

Bind mip 0 of a two-mip RGBA8 Texture2D as an SRV, with only that mip visible to the shader, and bind mip 1 as the RTV. On d2a4bae, draw setup transitions the entire texture to render-target state. The D3D12 debug layer then reports that mip 0 is in RENDER_TARGET when the shader needs PIXEL_SHADER_RESOURCE. The baseline check stopped at command recording.

Change

Use the selected mip range for plane-zero SRVs and RTVs of non-array 2D color targets. Track only the mips that differ from the command list's uniform texture state. Restore those mips before a whole-resource transition and at list close, so the submission prelude can continue using one state per texture. The compact regression test checks the split states and the ordering of the reconciliation barriers.

Verified

On native D3D12 with RTX 5090 and WARP, the synthetic draw left all 64 pixels of mip 0 intact and changed all 16 pixels of mip 1 from the clear color to the sampled color. Both same-list readback and readback from a second command list passed, with zero D3D12 debug errors through submission.

  • cargo test --locked --workspace -- --test-threads=1 — 265 passed, 0 failed, 4 ignored.
  • cargo xtask policy --staged and cargo xtask policy — passed.

The pixel fixture uses a synthetic pipeline. Nearby changes in #469 and #485 touch the tracker and SRV preparation respectively, which may need a mechanical rebase if either lands first.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5466341611 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/559). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T04:55:41Z. --- ## Reproduction Bind mip 0 of a two-mip RGBA8 Texture2D as an SRV, with only that mip visible to the shader, and bind mip 1 as the RTV. On `d2a4bae`, draw setup transitions the entire texture to render-target state. The D3D12 debug layer then reports that mip 0 is in `RENDER_TARGET` when the shader needs `PIXEL_SHADER_RESOURCE`. The baseline check stopped at command recording. ## Change Use the selected mip range for plane-zero SRVs and RTVs of non-array 2D color targets. Track only the mips that differ from the command list's uniform texture state. Restore those mips before a whole-resource transition and at list close, so the submission prelude can continue using one state per texture. The compact regression test checks the split states and the ordering of the reconciliation barriers. ## Verified On native D3D12 with RTX 5090 and WARP, the synthetic draw left all 64 pixels of mip 0 intact and changed all 16 pixels of mip 1 from the clear color to the sampled color. Both same-list readback and readback from a second command list passed, with zero D3D12 debug errors through submission. - `cargo test --locked --workspace -- --test-threads=1` — 265 passed, 0 failed, 4 ignored. - `cargo xtask policy --staged` and `cargo xtask policy` — passed. The pixel fixture uses a synthetic pipeline. Nearby changes in #469 and #485 touch the tracker and SRV preparation respectively, which may need a mechanical rebase if either lands first.
fromthemoonx commented 2026-11-24 10:03:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fromthemoonx on 2026-11-24T09:14:26Z.


Tested ca896f6 merged onto current main (8e79c80; it merges cleanly, with auto-merges in host.rs and list.rs) on NVIDIA.

Environment: Windows 11 Pro build 26300, AMD Ryzen 7 5700X, 16 GB, NVIDIA GeForce RTX 3060 12 GB (driver 610.88), Rust 1.98.1 x86_64-pc-windows-msvc.

CI's commands, on the merge

  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo test --workspace --locked: 312 passed, 0 failed, 6 ignored (main: 311 / 0 / 6, plus the new test)

What the regression test covers. I checked it by breaking the change locally:

local mutation transitions_keep_color_target_mips_independent
HostList::transition ignores the mip range (mips.filter(|_| false)) fails at resource.rs:1626
HostList::close drops its reconciliation barriers (barriers.clear() before ResourceBarrier) passes

So the test guards the per-mip tracking and the order of the barriers before a whole-resource transition, but not the close-time reconciliation the description relies on ("Restore those mips before a whole-resource transition and at list close, so the submission prelude can continue using one state per texture"). If close stopped restoring, the next submission's prelude would transition the texture from a whole-resource state that some of its mips aren't in, and no test would notice. One way to cover it: have close collect its barriers through a function the test can call, the way transition takes a record callback. Then assert that a list left with mip 0 in PIXEL_SHADER_RESOURCE emits (0, PIXEL_SHADER_RESOURCE → RENDER_TARGET) at close.

Reading the change: the rest looks consistent to me. A texture's first use through a mip range sets only the uniform state, so the prelude still gets one state. srv_mips returns None for a view of all mips, so those keep the whole-resource path. A title split barrier is mapped per mip only for non-array 2D color targets (color_mip) and keeps ALL_SUBRESOURCES otherwise.

Not tested:

  • The two-submission sequence under the D3D12 debug layer. I wrote a local test for it (list A leaves mip 0 sampled, list B uses the whole texture as a copy source), but this machine doesn't have Graphics Tools (d3d12SDKLayers.dll). The debug layer didn't load, and a deliberately wrong before-state also went unreported, so that run proves nothing either way.
  • Your pixel fixture, which isn't in the PR.
  • Title data.

AI-assisted (Claude Code) ran the checks and drafted this comment.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7127143113 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/559#issuecomment-7127143113). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-11-24T09:14:26Z. --- Tested `ca896f6` merged onto current `main` (`8e79c80`; it merges cleanly, with auto-merges in `host.rs` and `list.rs`) on NVIDIA. **Environment:** Windows 11 Pro build 26300, AMD Ryzen 7 5700X, 16 GB, NVIDIA GeForce RTX 3060 12 GB (driver 610.88), Rust 1.98.1 `x86_64-pc-windows-msvc`. **CI's commands, on the merge** - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo test --workspace --locked`: 312 passed, 0 failed, 6 ignored (`main`: 311 / 0 / 6, plus the new test) **What the regression test covers.** I checked it by breaking the change locally: | local mutation | `transitions_keep_color_target_mips_independent` | |---|---| | `HostList::transition` ignores the mip range (`mips.filter(\|_\| false)`) | **fails** at `resource.rs:1626` | | `HostList::close` drops its reconciliation barriers (`barriers.clear()` before `ResourceBarrier`) | **passes** | So the test guards the per-mip tracking and the order of the barriers before a whole-resource transition, but not the close-time reconciliation the description relies on ("Restore those mips before a whole-resource transition and at list close, so the submission prelude can continue using one state per texture"). If `close` stopped restoring, the next submission's prelude would transition the texture from a whole-resource state that some of its mips aren't in, and no test would notice. One way to cover it: have `close` collect its barriers through a function the test can call, the way `transition` takes a `record` callback. Then assert that a list left with mip 0 in `PIXEL_SHADER_RESOURCE` emits `(0, PIXEL_SHADER_RESOURCE → RENDER_TARGET)` at close. **Reading the change:** the rest looks consistent to me. A texture's first use through a mip range sets only the uniform state, so the prelude still gets one state. `srv_mips` returns `None` for a view of all mips, so those keep the whole-resource path. A title split barrier is mapped per mip only for non-array 2D color targets (`color_mip`) and keeps `ALL_SUBRESOURCES` otherwise. **Not tested:** - The two-submission sequence under the D3D12 debug layer. I wrote a local test for it (list A leaves mip 0 sampled, list B uses the whole texture as a copy source), but this machine doesn't have Graphics Tools (`d3d12SDKLayers.dll`). The debug layer didn't load, and a deliberately wrong before-state also went unreported, so that run proves nothing either way. - Your pixel fixture, which isn't in the PR. - Title data. AI-assisted (Claude Code) ran the checks and drafted this comment.
fuzeofficlal commented 2026-11-24 17:04:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T16:39:21Z.


Thanks for catching the close() mutation gap — rebased onto ffe310e, extracted HostList::close_transitions so transitions_keep_color_target_mips_independent directly asserts close-time per-mip reconciliation (plus clearing on close()), and included the synthetic two-mip sample-and-render readback test covering both single-list and cross-submission paths on RTX 5090 (VICTORY_D3D12_DEBUG=1) and WARP.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7138003777 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/559#issuecomment-7138003777). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T16:39:21Z. --- Thanks for catching the `close()` mutation gap — rebased onto `ffe310e`, extracted `HostList::close_transitions` so `transitions_keep_color_target_mips_independent` directly asserts close-time per-mip reconciliation (plus clearing on `close()`), and included the synthetic two-mip sample-and-render readback test covering both single-list and cross-submission paths on RTX 5090 (`VICTORY_D3D12_DEBUG=1`) and WARP.
Marvisak commented 2026-11-25 01:07:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:25:30Z.


Automated triage for the maintainers.

Merge candidate (unchanged). The new head is one commit on current main and merges cleanly. Only non-array, multi-mip 2D render-target textures get per-mip tracking (host::color_mip_count). The mip ranges come from SRVs (descriptor::host::srv_mips), RTVs and clears (descriptor::rtv_mips, list::ensure_mips), and title barriers (list::color_mip). HostList::transition stores the mips that differ from the uniform state in TrackedTexture::mips. A whole-resource transition, and close through close_transitions, first move those mips back, so the submission prelude still sees one state per texture.

I checked that move_texture/track, which don't unify mips, are only reached for twin planes, depth textures and first-use uploads, none of which have diverged mips at that point. The test transitions_keep_color_target_mips_independent covers divergence, reunification and close.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148495669 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/559#issuecomment-7148495669). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:25:30Z. --- <!-- victory-triage v1 head=61b17eae3b3177bbea904ae74de04b1ca7666283 verdict=merge-candidate at=2026-11-26T01:23:14Z --> Automated triage for the maintainers. **Merge candidate (unchanged).** The new head is one commit on current `main` and merges cleanly. Only non-array, multi-mip 2D render-target textures get per-mip tracking (`host::color_mip_count`). The mip ranges come from SRVs (`descriptor::host::srv_mips`), RTVs and clears (`descriptor::rtv_mips`, `list::ensure_mips`), and title barriers (`list::color_mip`). `HostList::transition` stores the mips that differ from the uniform state in `TrackedTexture::mips`. A whole-resource transition, and `close` through `close_transitions`, first move those mips back, so the submission prelude still sees one state per texture. I checked that `move_texture`/`track`, which don't unify mips, are only reached for twin planes, depth textures and first-use uploads, none of which have diverged mips at that point. The test `transitions_keep_color_target_mips_independent` covers divergence, reunification and close. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-27 00:52:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-27T00:52:12Z.

Review: APPROVED


LGTM — verified on Windows (RTX 5090):

  • cargo test -p victory-gpu --lib passed (231/231, skipping the 2 pre-existing origin/main RTX 5090 failures)
  • cargo clippy -p victory-gpu --all-targets -- -D warnings passed with 0 warnings
  • cargo xtask policy passed (191 files ok)

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6082083858 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/559#pullrequestreview-6082083858). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-27T00:52:12Z. **Review:** APPROVED --- LGTM — verified on Windows (RTX 5090): - `cargo test -p victory-gpu --lib` passed (231/231, skipping the 2 pre-existing `origin/main` RTX 5090 failures) - `cargo clippy -p victory-gpu --all-targets -- -D warnings` passed with 0 warnings - `cargo xtask policy` passed (`191 files ok`) Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/559:upstream-pr/559'
git switch 'upstream-pr/559'

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