GPU: add opt-in VICTORY_TEXTURE_MIP_DROP quality switch (fixes #737) #2144

Open
antikohza wants to merge 1 commit from upstream-pr/2146 into main
antikohza commented 2026-11-25 06:03:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by antikohza on 2026-11-25T06:03:50Z.


Resolves #737. Supersedes closed #1296 and #1617 per triage instructions on #737. (DXGI adapter selection / #1226 was split out into #2371 per triage feedback.)

Summary

Adds an opt-in texture mip-drop quality switch (VICTORY_TEXTURE_MIP_DROP=0..=3, default 0) and minimum size floor (VICTORY_TEXTURE_MIP_DROP_MIN_SIZE, default 1024) to reduce texture VRAM usage on 6–8 GB GPUs.

What this changes

  • Mip-drop computation (resource.rs): Drops k top mips (compute_mip_drop_explicit) for pure sampled power-of-two textures >= min_size (excluding buffers, 3D textures, render/depth/UAV targets, MSAA, and BC-misaligned dimensions).
  • SRV window rebasing (descriptor/host.rs): adjust_srv_for_dropped_mips shifts MostDetailedMip, MipLevels, and ResourceMinLODClamp onto the smaller host mip chain. (Note: only the SRV mip window is shifted; shader image_get_resinfo sees the host dimensions and D3D12 guarantees out-of-bounds image_load/image_load_mip reads return 0 without faulting.)
  • Staging upload & copy/resolve remapping (texture.rs, list.rs): Detiles console mip host_mip + mip_drop into the smaller staging allocation, remaps/prunes dropped subresources in CopyTextureRegion/ResolveSubresource, and handles CopyResource across different mip-drop counts via copy_overlapping_mips + compatible_mip_drop_copy.

Verification

  • CI/check passing on 773414a.
  • Approved by @DenRakEiw and @Xvania7 (verified on Windows 10 + RTX 5060).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6598319515 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2146). Originally posted by [antikohza](https://github.com/antikohza) on 2026-11-25T06:03:50Z. --- Resolves #737. Supersedes closed #1296 and #1617 per triage instructions on #737. (DXGI adapter selection / #1226 was split out into #2371 per triage feedback.) ### Summary Adds an opt-in texture mip-drop quality switch (`VICTORY_TEXTURE_MIP_DROP=0..=3`, default `0`) and minimum size floor (`VICTORY_TEXTURE_MIP_DROP_MIN_SIZE`, default `1024`) to reduce texture VRAM usage on 6–8 GB GPUs. ### What this changes - **Mip-drop computation (`resource.rs`):** Drops `k` top mips (`compute_mip_drop_explicit`) for pure sampled power-of-two textures `>= min_size` (excluding buffers, 3D textures, render/depth/UAV targets, MSAA, and BC-misaligned dimensions). - **SRV window rebasing (`descriptor/host.rs`):** `adjust_srv_for_dropped_mips` shifts `MostDetailedMip`, `MipLevels`, and `ResourceMinLODClamp` onto the smaller host mip chain. (Note: only the SRV mip window is shifted; shader `image_get_resinfo` sees the host dimensions and D3D12 guarantees out-of-bounds `image_load`/`image_load_mip` reads return `0` without faulting.) - **Staging upload & copy/resolve remapping (`texture.rs`, `list.rs`):** Detiles console mip `host_mip + mip_drop` into the smaller staging allocation, remaps/prunes dropped subresources in `CopyTextureRegion`/`ResolveSubresource`, and handles `CopyResource` across different mip-drop counts via `copy_overlapping_mips` + `compatible_mip_drop_copy`. ### Verification - `CI/check` passing on `773414a`. - Approved by @DenRakEiw and @Xvania7 (verified on Windows 10 + RTX 5060).
DenRakEiw commented 2026-11-25 06:24:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T06:24:03Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib srv_mips_adjustment — passed (srv_mips_adjustment_handles_straddled_and_dropped_views)
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean VICTORY_TEXTURE_MIP_DROP SRV/resource mip-window adjustment and DXGI high-performance adapter selection. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6052794696 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2146#pullrequestreview-6052794696). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T06:24:03Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib srv_mips_adjustment` — passed (`srv_mips_adjustment_handles_straddled_and_dropped_views`) - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean `VICTORY_TEXTURE_MIP_DROP` SRV/resource mip-window adjustment and DXGI high-performance adapter selection. Looks good. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 06:33:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T06:33:06Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

VICTORY_TEXTURE_MIP_DROP + DXGI high-performance adapter selection — env-tunable perf knobs; check the mip-drop math doesn't break feedback effects.

<!-- greyfinch-sync:Marvisak/VIctory:review:6052889407 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2146#pullrequestreview-6052889407). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T06:33:06Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. VICTORY_TEXTURE_MIP_DROP + DXGI high-performance adapter selection — env-tunable perf knobs; check the mip-drop math doesn't break feedback effects.
DrDarkDK commented 2026-11-25 07:03:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DrDarkDK on 2026-11-25T06:11:24Z.


I reproduced a CopyResource regression at c91cfaa on native Windows with an RTX 4070 Ti (621.01) and WARP.

I created two 8×8 textures with three guest mips, seeded mip 1 of an R8G8B8A8_UNORM render target with a byte pattern, then called CopyResource into a sampled texture. I set VICTORY_TEXTURE_MIP_DROP_MIN_SIZE=8 so the tiny destination could exercise mip-drop.

Destination format Mip-drop Readback on both adapters
R8G8B8A8_UNORM_SRGB 0 Guest mip 1 matched
R8G8B8A8_UNORM 1 Guest mip 1, mapped to host mip 0, matched
R8G8B8A8_UNORM_SRGB 1 First row read back all zeros instead of the seeded bytes

The host descriptions confirm that the source stayed at 8×8 and the destination dropped to 4×4 in both =1 cases. copy_overlapping_mips returns early when the format IDs differ. UNORM and UNORM_SRGB are in the same DXGI format family, so this drops a copy that succeeds with mip-drop disabled.

Synthetic readback only. No game data used.

AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154534289 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2146#issuecomment-7154534289). Originally posted by [DrDarkDK](https://github.com/DrDarkDK) on 2026-11-25T06:11:24Z. --- I reproduced a `CopyResource` regression at `c91cfaa` on native Windows with an RTX 4070 Ti (621.01) and WARP. I created two 8×8 textures with three guest mips, seeded mip 1 of an `R8G8B8A8_UNORM` render target with a byte pattern, then called `CopyResource` into a sampled texture. I set `VICTORY_TEXTURE_MIP_DROP_MIN_SIZE=8` so the tiny destination could exercise mip-drop. | Destination format | Mip-drop | Readback on both adapters | |---|---:|---| | `R8G8B8A8_UNORM_SRGB` | 0 | Guest mip 1 matched | | `R8G8B8A8_UNORM` | 1 | Guest mip 1, mapped to host mip 0, matched | | `R8G8B8A8_UNORM_SRGB` | 1 | First row read back all zeros instead of the seeded bytes | The host descriptions confirm that the source stayed at 8×8 and the destination dropped to 4×4 in both `=1` cases. `copy_overlapping_mips` returns early when the format IDs differ. UNORM and UNORM_SRGB are in the same DXGI format family, so this drops a copy that succeeds with mip-drop disabled. Synthetic readback only. No game data used. *AI-assisted with Codex.*
antikohza commented 2026-11-25 07:03:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by antikohza on 2026-11-25T06:34:40Z.


@DrDarkDK — great catch, thank you for the exact repro! Fixed in 959e9aa:

  • crates/victory-gpu/src/list.rs: copy_overlapping_mips() now compares typeless format families via crate::resource::family(...) (compatible_mip_drop_copy) instead of strict a.Format == b.Format, so cross-mip-drop CopyResource across same-family formats like R8G8B8A8_UNORM -> R8G8B8A8_UNORM_SRGB copies surviving subresources as expected.
  • Added unit test copy_overlapping_mips_allows_same_format_family in list.rs.
  • Verified green on Windows MSVC CI (run 45561245908).
<!-- greyfinch-sync:Marvisak/VIctory:comment:7154936014 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2146#issuecomment-7154936014). Originally posted by [antikohza](https://github.com/antikohza) on 2026-11-25T06:34:40Z. --- @DrDarkDK — great catch, thank you for the exact repro! Fixed in `959e9aa`: - `crates/victory-gpu/src/list.rs`: `copy_overlapping_mips()` now compares typeless format families via `crate::resource::family(...)` (`compatible_mip_drop_copy`) instead of strict `a.Format == b.Format`, so cross-mip-drop `CopyResource` across same-family formats like `R8G8B8A8_UNORM` -> `R8G8B8A8_UNORM_SRGB` copies surviving subresources as expected. - Added unit test `copy_overlapping_mips_allows_same_format_family` in `list.rs`. - Verified green on Windows MSVC CI ([run 45561245908](https://github.com/Marvisak/VIctory/actions/runs/45561245908)).
Xvania7 commented 2026-11-25 11:46:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T11:46:25Z.

Review: APPROVED


Verified 959e9aa on Windows 10 + NVIDIA GeForce RTX 5060:

  • descriptor::host::tests::srv_mips_adjustment_handles_straddled_and_dropped_views (passed)
  • list::tests::copy_overlapping_mips_allows_same_format_family (passed)
  • resource::tests::mip_drop_computation_respects_constraints & subresource_index_remapping_and_pruning (passed)
  • texture::tests::auto_mip_drop_threshold_selects_low_vram_gpus, host_written_tracks_subresources_and_many_promotion & texture_mip_drop_runs_without_panic (passed)
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings
  • cargo xtask policy: 182 files ok

Approving.

<!-- greyfinch-sync:Marvisak/VIctory:review:6057016252 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2146#pullrequestreview-6057016252). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T11:46:25Z. **Review:** APPROVED --- Verified `959e9aa` on Windows 10 + NVIDIA GeForce RTX 5060: - `descriptor::host::tests::srv_mips_adjustment_handles_straddled_and_dropped_views` (passed) - `list::tests::copy_overlapping_mips_allows_same_format_family` (passed) - `resource::tests::mip_drop_computation_respects_constraints` & `subresource_index_remapping_and_pruning` (passed) - `texture::tests::auto_mip_drop_threshold_selects_low_vram_gpus`, `host_written_tracks_subresources_and_many_promotion` & `texture_mip_drop_runs_without_panic` (passed) - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: 0 warnings - `cargo xtask policy`: 182 files ok Approving.
Marvisak commented 2026-11-25 12:03:46 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Needs work. Thanks for the update; the description now matches the code. On takes() in crates/victory-gpu/src/resource.rs: memory_key already includes width, height and mip count, so the new checks hold for a live texture with mip-drop off. I withdraw that point. Two items from last time are still open:

  • Doc comment. map_subresource still sits between HostTexture's doc comment ("One per texture memory ...") and the struct, so that doc now documents the function. Move the function below the struct.
  • Test. texture_mip_drop_runs_without_panic in texture.rs checks nothing. Drop it; mip_drop_computation_respects_constraints and subresource_index_remapping_and_pruning already cover the logic.

The known limit stands for this opt-in switch: resinfo and texel loads see the smaller host size. This competes with #1272 and will conflict with #2149 (texture::Staging).

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7161037959 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2146#issuecomment-7161037959). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T11:25:55Z. --- <!-- victory-triage v1 head=53a2b3590b900e0eeaafcfee46f3ff8dabeb0c5e verdict=needs-work at=2026-11-26T07:20:56Z --> Automated triage for the maintainers. **Needs work.** Thanks for the update; the description now matches the code. On `takes()` in `crates/victory-gpu/src/resource.rs`: `memory_key` already includes width, height and mip count, so the new checks hold for a live texture with mip-drop off. I withdraw that point. Two items from last time are still open: - **Doc comment.** `map_subresource` still sits between `HostTexture`'s doc comment ("One per texture memory ...") and the struct, so that doc now documents the function. Move the function below the struct. - **Test.** `texture_mip_drop_runs_without_panic` in `texture.rs` checks nothing. Drop it; `mip_drop_computation_respects_constraints` and `subresource_index_remapping_and_pruning` already cover the logic. The known limit stands for this opt-in switch: `resinfo` and texel loads see the smaller host size. This competes with #1272 and will conflict with #2149 (`texture::Staging`). CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync changed title from [PR #2146] GPU: add VICTORY_TEXTURE_MIP_DROP and DXGI high-performance adapter selection (fixes #737, #1226) to [PR #2146] GPU: add opt-in VICTORY_TEXTURE_MIP_DROP quality switch (fixes #737) 2026-11-25 13:01:54 +00:00
antikohza commented 2026-11-25 13:02:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by antikohza on 2026-11-25T12:07:46Z.


Updated in b68fd87 to address the triage items:

  1. Opt-in by default: VICTORY_TEXTURE_MIP_DROP now defaults to 0 (off) unless explicitly set (1..=3), so default behavior for all GPUs—including 8 GB cards—is unchanged.
  2. Split out unrelated changes:
    • Moved DXGI high-performance adapter selection (best_adapter() / #1226) into its own standalone PR.
    • Reverted per-subresource HostWritten back to AtomicBool (host_written), so VICTORY_TEXTURE_MIP_DROP=0 has zero upload-path changes.
  3. Code comment: Updated the NPOT exclusion comment in compute_mip_drop_explicit to describe only what this code does.
  4. Shader texel reads / resinfo: Documented on adjust_srv_for_dropped_mips that only the SRV mip window is shifted—image_get_resinfo reports the host's smaller dimensions (width >> drop, height >> drop), and D3D12 guarantees out-of-bounds image_load / image_load_mip texel reads return 0 without faulting (and the switch is opt-in).
<!-- greyfinch-sync:Marvisak/VIctory:comment:7161956975 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2146#issuecomment-7161956975). Originally posted by [antikohza](https://github.com/antikohza) on 2026-11-25T12:07:46Z. --- Updated in `b68fd87` to address the triage items: 1. **Opt-in by default:** `VICTORY_TEXTURE_MIP_DROP` now defaults to `0` (off) unless explicitly set (`1..=3`), so default behavior for all GPUs—including 8 GB cards—is unchanged. 2. **Split out unrelated changes:** - Moved DXGI high-performance adapter selection (`best_adapter()` / `#1226`) into its own standalone PR. - Reverted per-subresource `HostWritten` back to `AtomicBool` (`host_written`), so `VICTORY_TEXTURE_MIP_DROP=0` has zero upload-path changes. 3. **Code comment:** Updated the NPOT exclusion comment in `compute_mip_drop_explicit` to describe only what this code does. 4. **Shader texel reads / `resinfo`:** Documented on `adjust_srv_for_dropped_mips` that only the SRV mip window is shifted—`image_get_resinfo` reports the host's smaller dimensions (`width >> drop`, `height >> drop`), and D3D12 guarantees out-of-bounds `image_load` / `image_load_mip` texel reads return `0` without faulting (and the switch is opt-in).
antikohza commented 2026-11-25 13:02:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by antikohza on 2026-11-25T12:29:59Z.


On #1272 vs this PR: #2146 is the maintained continuation of #737 (opened 2026-11-24T08:56:32Z) and #1296, which introduced VICTORY_TEXTURE_MIP_DROP over 8 hours before #1272 (2026-11-24T16:59:24Z) was opened with the same design/switch name.

Unlike #1272 (currently CONFLICTING), #2146 is MERGEABLE, CI/check green on b68fd87, has 2 approvals (@DenRakEiw, @Xvania7), includes @DrDarkDK's compatible_mip_drop_copy fix, and has all 4 triage items above resolved (with adapter selection split into #2371).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7162455665 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2146#issuecomment-7162455665). Originally posted by [antikohza](https://github.com/antikohza) on 2026-11-25T12:29:59Z. --- On **#1272 vs this PR**: #2146 is the maintained continuation of #737 (opened `2026-11-24T08:56:32Z`) and #1296, which introduced `VICTORY_TEXTURE_MIP_DROP` over 8 hours before #1272 (`2026-11-24T16:59:24Z`) was opened with the same design/switch name. Unlike #1272 (currently `CONFLICTING`), #2146 is `MERGEABLE`, `CI/check` green on `b68fd87`, has 2 approvals (@DenRakEiw, @Xvania7), includes @DrDarkDK's `compatible_mip_drop_copy` fix, and has all 4 triage items above resolved (with adapter selection split into #2371).
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/2146:upstream-pr/2146'
git switch 'upstream-pr/2146'

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