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

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

@⁠fuzeofficlal on GitHub · 2026-11-24 04:55 UTC · original
fuzeofficlal:fix/texture2d-mip-states → main · +754 −83 · 8 files · 1 commits · open

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-24 04:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/559) `fuzeofficlal:fix/texture2d-mip-states` → `main` · +754 −83 · 8 files · 1 commits · open ## 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.
Track per-mip states for non-array 2D color targets, restore uniform state before whole-resource transitions and at list close, and cover close reconciliation plus two-mip sampling and rendering.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:08:19 +00:00
Author
Owner

@⁠fromthemoonx on GitHub · 2026-11-24 09:14 UTC · original

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.

**@⁠fromthemoonx** on GitHub · 2026-11-24 09:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/559#issuecomment-7127143113) 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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 16:39 UTC · original

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-24 16:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/559#issuecomment-7138003777) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:25 UTC · original · edited 2026-11-26 01:23 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 00:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/559#issuecomment-7148495669) · edited 2026-11-26 01:23 UTC <!-- 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)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/559/head:github-bot/gh-559'
git switch 'github-bot/gh-559'

Merge

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