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

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

@⁠antikohza on GitHub · 2026-11-25 06:03 UTC · original
antikohza:feat/texture-mip-drop-v2 → main · +679 −34 · 4 files · 1 commits · open

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).
**@⁠antikohza** on GitHub · 2026-11-25 06:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2146) `antikohza:feat/texture-mip-drop-v2` → `main` · +679 −34 · 4 files · 1 commits · open 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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:56:04 +00:00
github-bot force-pushed github-bot/gh-2146 from 773414a058 to 53a2b3590b 2026-11-26 07:27:55 +00:00 Compare
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-25 06:11 UTC · original

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.

**@⁠DrDarkDK** on GitHub · 2026-11-25 06:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/2146#issuecomment-7154534289) 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.*
Author
Owner

@⁠antikohza on GitHub · 2026-11-25 06:34 UTC · original

@⁠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).
**@⁠antikohza** on GitHub · 2026-11-25 06:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2146#issuecomment-7154936014) @⁠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)).
Author
Owner

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

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

**@⁠Marvisak** on GitHub · 2026-11-25 11:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2146#issuecomment-7161037959) · edited 2026-11-26 07:20 UTC <!-- 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)_
Author
Owner

@⁠antikohza on GitHub · 2026-11-25 12:07 UTC · original

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** on GitHub · 2026-11-25 12:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/2146#issuecomment-7161956975) 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).
Author
Owner

@⁠antikohza on GitHub · 2026-11-25 12:29 UTC · original

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).

**@⁠antikohza** on GitHub · 2026-11-25 12:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2146#issuecomment-7162455665) 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).
github-bot force-pushed github-bot/gh-2146 from 53a2b3590b to 9f1a3cfb8b 2026-11-26 17:09:13 +00:00 Compare
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 06:24 UTC · original · approved these changes

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).

**@⁠DenRakEiw** on GitHub · 2026-11-25 06:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2146#pullrequestreview-6052794696) · **approved these changes** 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).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 06:33 UTC · original · reviewed

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.

**@⁠catminou4** on GitHub · 2026-11-25 06:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2146#pullrequestreview-6052889407) · **reviewed** 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.
Author
Owner

@⁠Xvania7 on GitHub · 2026-11-25 11:46 UTC · original · approved these changes

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.

**@⁠Xvania7** on GitHub · 2026-11-25 11:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/2146#pullrequestreview-6057016252) · **approved these changes** 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.
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/2146/head:github-bot/gh-2146'
git switch 'github-bot/gh-2146'

Merge

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