GPU: opt-in VICTORY_PARTIAL_MIP_CLAMP, shader views start at the first mip with memory (off by default) #3647

Open
TG0000 wants to merge 2 commits from upstream-pr/3647 into main
TG0000 commented 2026-11-28 01:53:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TG0000 on 2026-11-28T01:53:44Z.


What

VICTORY_PARTIAL_MIP_CLAMP=1, off by default (unset or 0: no change).

A streamed texture gets its smallest mips first. The finer ones read as zeros in the host texture until their pages arrive, so a view that starts at mip 0 samples black up close while the same texture looks right further away. With the switch on:

  • each refresh of a texture in the runtime's memory finds the first mip from which every mip has memory (Layout::first_present_mip, victory-formats);
  • shader views of its host texture (2D and 2D array) start there (MostDetailedMip; ResourceMinLODClamp is left alone);
  • when that mip changes (more pages arrived, or the host wrote the texture), the heap slots viewing it are made again before the submission's lists run.

Limits

  • While a view is clamped, the shader sees the smaller texture: its size queries and explicit mip numbers count from the clamped mip.
  • A view whose own mip range ends before the first mip with memory gets exactly one mip, that first one, which the title's descriptor excluded (documented on start_view_at in 5a99fb53).
  • A table made afresh in dynamic slots keeps the view it was made with, so it can show the previous mip range during the submission that finds the change. A view without a description is not clamped.
  • Only single-slice textures with write tracking.
  • Cost with the switch on: a 1-byte kernel read per 64 KiB page of each texture that changed. Not measured.

Where it comes from, and what is not shown

The idea comes from our fork, whose texture path differs from main's. There, on an RX 6800, a build with this clamp and two other changes to its texture queue fixed close-up surfaces that had rendered black (a railing among them), but character skin stayed black. A later build, adding three more changes to the fork's handling of one-shot texture bakes, showed lit skin and face at native 1440p; with upscaling on, skin was still black. These were single runs, in an area that varies from run to run, and the clamp's own share was never isolated.

The fork's other changes hook into a texture queue and bake handling that main does not have, so they are not here. Do not read this PR as a fix for black skin on main.

Tested

  • cargo clippy --workspace --all-targets -- -D warnings, with and without --all-features, for x86_64-pc-windows-msvc (cross-built on macOS): clean.
  • cargo test -p victory-formats -p xtask (asset policy): passed, including two new tests for the mip search and the view arithmetic.
  • Both of the above rerun on 5a99fb53, which changes a comment only.
  • We have not run this branch on a GPU or in the title. There is no GPU test of the view remake in the branch; the rest of the tests are left to CI.
  • Independent WARP checks of aa51c796, with thanks: andrewpozdnakov7-jpg read back the view rewrite (and pointed out the one-mip case); TheGrayOrange checked uploads, found registered views follow mip availability and the switch-off control matches, and measured the dynamic-slot limit above. See the comments.

Our hardware, for the fork runs above: AMD Radeon RX 6800 16 GB (ReBAR), Adrenalin 26.11.2, Ryzen 9 5900X, Windows 11.

Overlaps

  • #2859 uploads the small mips of textures without write tracking; this changes what views of tracked ones show. Both add a method to Layout.
  • #2149 uploads a texture from the first level its views read; #2389 gives video memory only to held levels. Neither moves a view away from a level that has no memory, and both touch the same files.
  • #1210 changes when a host-written texture is uploaded again.

AI-assisted (Claude).

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:5535557385 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3647). Originally posted by [TG0000](https://github.com/TG0000) on 2026-11-28T01:53:44Z. --- ## What `VICTORY_PARTIAL_MIP_CLAMP=1`, **off by default** (unset or `0`: no change). A streamed texture gets its smallest mips first. The finer ones read as zeros in the host texture until their pages arrive, so a view that starts at mip 0 samples black up close while the same texture looks right further away. With the switch on: - each refresh of a texture in the runtime's memory finds the first mip from which every mip has memory (`Layout::first_present_mip`, `victory-formats`); - shader views of its host texture (2D and 2D array) start there (`MostDetailedMip`; `ResourceMinLODClamp` is left alone); - when that mip changes (more pages arrived, or the host wrote the texture), the heap slots viewing it are made again before the submission's lists run. ## Limits - While a view is clamped, the shader sees the smaller texture: its size queries and explicit mip numbers count from the clamped mip. - A view whose own mip range ends before the first mip with memory gets exactly one mip, that first one, which the title's descriptor excluded (documented on `start_view_at` in 5a99fb53). - A table made afresh in dynamic slots keeps the view it was made with, so it can show the previous mip range during the submission that finds the change. A view without a description is not clamped. - Only single-slice textures with write tracking. - Cost with the switch on: a 1-byte kernel read per 64 KiB page of each texture that changed. **Not measured.** ## Where it comes from, and what is not shown The idea comes from our fork, whose texture path differs from `main`'s. There, on an RX 6800, a build with this clamp and two other changes to its texture queue fixed close-up surfaces that had rendered black (a railing among them), but character skin stayed black. A later build, adding three more changes to the fork's handling of one-shot texture bakes, showed lit skin and face at native 1440p; with upscaling on, skin was still black. These were single runs, in an area that varies from run to run, and **the clamp's own share was never isolated**. The fork's other changes hook into a texture queue and bake handling that `main` does not have, so they are not here. **Do not read this PR as a fix for black skin on `main`.** ## Tested - `cargo clippy --workspace --all-targets -- -D warnings`, with and without `--all-features`, for `x86_64-pc-windows-msvc` (cross-built on macOS): clean. - `cargo test -p victory-formats -p xtask` (asset policy): passed, including two new tests for the mip search and the view arithmetic. - Both of the above rerun on 5a99fb53, which changes a comment only. - **We have not run this branch on a GPU or in the title.** There is no GPU test of the view remake in the branch; the rest of the tests are left to CI. - Independent WARP checks of aa51c796, with thanks: `andrewpozdnakov7-jpg` read back the view rewrite (and pointed out the one-mip case); `TheGrayOrange` checked uploads, found registered views follow mip availability and the switch-off control matches, and measured the dynamic-slot limit above. See the comments. Our hardware, for the fork runs above: AMD Radeon RX 6800 16 GB (ReBAR), Adrenalin 26.11.2, Ryzen 9 5900X, Windows 11. ## Overlaps - #2859 uploads the small mips of textures *without* write tracking; this changes what views of *tracked* ones show. Both add a method to `Layout`. - #2149 uploads a texture from the first level its views read; #2389 gives video memory only to held levels. Neither moves a view away from a level that has no memory, and both touch the same files. - #1210 changes when a host-written texture is uploaded again. **AI-assisted** (Claude). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
andrewpozdnakov7-jpg commented 2026-11-28 02:14:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T02:14:46Z.


I checked the SRV rewrite from aa51c796 on app-local WARP 1.0.22 with D3D12 Agility 1.620.2. The standalone compute test used the PR's exact start_view_at to generate the descriptors. It ran 13 views each with distinct values in all mips and with mip 0/1 zeroed to model a partial upload.

The resource was a 16×16 R32_FLOAT texture. Mip 2 held 30, mip 3 held 40, and mip 4 held 50. With mip 0/1 zeroed and the first present mip set to 2, I read back:

SRV GetDimensions(0) Load(0) Load(1) point SampleLevel(0)
Original all-mip view 16×16, 5 levels 0 0 0
PR, all mips from 2 4×4, 3 levels 30 40 30
PR, original view covered mip 0 only 4×4, 1 level 30 0 30
PR, original view covered mips 0–3 with ResourceMinLODClamp=3 4×4, 2 levels 0 40 40
Control, original all-mip view with only ResourceMinLODClamp=2 16×16, 5 levels 0 0 30

The one-mip case is worth documenting. When there is no overlap with the original range, the view exposes one mip that the original descriptor excluded. The min-LOD-only control keeps the original dimensions and redirects point samples, while explicit loads into the clamped mips still return zero. This probe covers the shader-visible SRV behavior. Upload tracking, descriptor remakes, and the game were outside the probe.

If you reuse the test, please retain Git authorship on a cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if you fold it into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7232232069 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3647#issuecomment-7232232069). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T02:14:46Z. --- I checked the SRV rewrite from `aa51c796` on app-local WARP 1.0.22 with D3D12 Agility 1.620.2. The standalone compute test used the PR's exact `start_view_at` to generate the descriptors. It ran 13 views each with distinct values in all mips and with mip 0/1 zeroed to model a partial upload. The resource was a 16×16 `R32_FLOAT` texture. Mip 2 held 30, mip 3 held 40, and mip 4 held 50. With mip 0/1 zeroed and the first present mip set to 2, I read back: | SRV | `GetDimensions(0)` | `Load(0)` | `Load(1)` | point `SampleLevel(0)` | | --- | --- | ---: | ---: | ---: | | Original all-mip view | 16×16, 5 levels | 0 | 0 | 0 | | PR, all mips from 2 | 4×4, 3 levels | 30 | 40 | 30 | | PR, original view covered mip 0 only | 4×4, 1 level | 30 | 0 | 30 | | PR, original view covered mips 0–3 with `ResourceMinLODClamp=3` | 4×4, 2 levels | 0 | 40 | 40 | | Control, original all-mip view with only `ResourceMinLODClamp=2` | 16×16, 5 levels | 0 | 0 | 30 | The one-mip case is worth documenting. When there is no overlap with the original range, the view exposes one mip that the original descriptor excluded. The min-LOD-only control keeps the original dimensions and redirects point samples, while explicit loads into the clamped mips still return zero. This probe covers the shader-visible SRV behavior. Upload tracking, descriptor remakes, and the game were outside the probe. If you reuse the test, please retain Git authorship on a cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if you fold it into another commit. AI-assisted with OpenAI Codex.
TheGrayOrange commented 2026-11-28 03:03:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TheGrayOrange on 2026-11-28T03:03:17Z.


Independent WARP verification at aa51c79 using actual synthetic texture uploads confirms that registered SRVs correctly follow streamed mip availability, avoid incomplete mip chains and preserve ResourceMinLODClamp.

However, dynamic SRVs retain their previous mip range during the submission that discovers the availability change:

  • Initial coarse mip upload: registered view samples 96, dynamic view samples 0.
  • Completed mip chain: registered view samples 32, dynamic view still samples 96.

The disabled-feature parity control passes.

The dynamic descriptors created through HostHeap::make_at appear to be skipped by remake_views because they lack a made record.

I have a focused reproduction and can prepare a correction that refreshes affected dynamic SRVs while preserving the existing allocation lifetime and disabled-feature behavior. Are you already working on this?

<!-- greyfinch-sync:Marvisak/VIctory:comment:7232763628 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3647#issuecomment-7232763628). Originally posted by [TheGrayOrange](https://github.com/TheGrayOrange) on 2026-11-28T03:03:17Z. --- Independent WARP verification at `aa51c79` using actual synthetic texture uploads confirms that registered SRVs correctly follow streamed mip availability, avoid incomplete mip chains and preserve ResourceMinLODClamp. However, dynamic SRVs retain their previous mip range during the submission that discovers the availability change: - Initial coarse mip upload: registered view samples 96, dynamic view samples 0. - Completed mip chain: registered view samples 32, dynamic view still samples 96. The disabled-feature parity control passes. The dynamic descriptors created through `HostHeap::make_at` appear to be skipped by `remake_views` because they lack a `made` record. I have a focused reproduction and can prepare a correction that refreshes affected dynamic SRVs while preserving the existing allocation lifetime and disabled-feature behavior. Are you already working on this?
TG0000 commented 2026-11-28 09:51:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TG0000 on 2026-11-28T09:51:05Z.


Thank you both for checking aa51c796 on WARP independently.

@andrewpozdnakov7-jpg: agreed, the one-mip fallback needed saying. 5a99fb53 documents it on start_view_at (comment only, no behaviour change) and it is now listed under Limits. Your test code is not reused in the branch.

@TheGrayOrange: you're right. make_at leaves no made record, so remake_views skips those dynamic slots, and a table made before the upload keeps the old range for that submission. This is the "table made afresh in dynamic slots" line under Limits (and the shortcut: note on partial_mip_clamp); your readback shows what it looks like. This push does not change it. To your question: I have no fix for it in progress.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7237507898 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3647#issuecomment-7237507898). Originally posted by [TG0000](https://github.com/TG0000) on 2026-11-28T09:51:05Z. --- Thank you both for checking `aa51c796` on WARP independently. @andrewpozdnakov7-jpg: agreed, the one-mip fallback needed saying. 5a99fb53 documents it on `start_view_at` (comment only, no behaviour change) and it is now listed under Limits. Your test code is not reused in the branch. @TheGrayOrange: you're right. `make_at` leaves no `made` record, so `remake_views` skips those dynamic slots, and a table made before the upload keeps the old range for that submission. This is the "table made afresh in dynamic slots" line under Limits (and the `shortcut:` note on `partial_mip_clamp`); your readback shows what it looks like. This push does not change it. To your question: I have no fix for it in progress. AI-assisted (Claude).
TheGrayOrange commented 2026-11-28 17:25:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TheGrayOrange on 2026-11-28T17:25:14Z.


I've prepared and independently verified a follow-up implementation addressing the dynamic SRV refresh issue.

The correction refreshes eligible dynamic SRVs when streamed mip availability changes, using the saved descriptor description and the host texture retained by the allocation.

Verified on WARP and RTX 4070 Ti SUPER:

  • Registered and dynamic SRVs agree during mip availability transitions.
  • Incomplete mip chains correctly retain coarse sampling.
  • Completed chains return to full-resolution sampling.
  • Resource-relative minimum LOD is preserved.
  • Refreshed descriptors retain the correct texture.
  • Disabled-feature sampling remains unchanged.

A test-only descriptor binding correction eliminated the four D3D12 validation errors observed during initial NVIDIA verification. Existing startup and heap-capacity messages remain unchanged.

The implementation is ready locally. Would you prefer a follow-up commit, a patch, or a reference branch on my fork?

Original implementation by TG0000. Follow-up development and independent verification were AI-assisted using Strata and Codex. All verification used synthetic textures.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7243002240 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3647#issuecomment-7243002240). Originally posted by [TheGrayOrange](https://github.com/TheGrayOrange) on 2026-11-28T17:25:14Z. --- I've prepared and independently verified a follow-up implementation addressing the dynamic SRV refresh issue. The correction refreshes eligible dynamic SRVs when streamed mip availability changes, using the saved descriptor description and the host texture retained by the allocation. Verified on WARP and RTX 4070 Ti SUPER: - Registered and dynamic SRVs agree during mip availability transitions. - Incomplete mip chains correctly retain coarse sampling. - Completed chains return to full-resolution sampling. - Resource-relative minimum LOD is preserved. - Refreshed descriptors retain the correct texture. - Disabled-feature sampling remains unchanged. A test-only descriptor binding correction eliminated the four D3D12 validation errors observed during initial NVIDIA verification. Existing startup and heap-capacity messages remain unchanged. The implementation is ready locally. Would you prefer a follow-up commit, a patch, or a reference branch on my fork? Original implementation by TG0000. Follow-up development and independent verification were AI-assisted using Strata and Codex. All verification used synthetic textures.
TG0000 commented 2026-11-28 18:36:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TG0000 on 2026-11-28T18:36:54Z.


@TheGrayOrange Thank you for taking this further and for checking it on WARP and an RTX 4070 Ti. A reference branch on your fork would suit best: I'll read it, run our tests on an RX 6800, and fold it in with your authorship if it holds up.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7243924808 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3647#issuecomment-7243924808). Originally posted by [TG0000](https://github.com/TG0000) on 2026-11-28T18:36:54Z. --- @TheGrayOrange Thank you for taking this further and for checking it on WARP and an RTX 4070 Ti. A reference branch on your fork would suit best: I'll read it, run our tests on an RX 6800, and fold it in with your authorship if it holds up. AI-assisted (Claude).
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/3647:upstream-pr/3647'
git switch 'upstream-pr/3647'

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