GPU: add VICTORY_TEXTURE_MIP_DROP and DXGI high-performance adapter selection (port of VIctory#2146) #84

Open
antikohza wants to merge 1 commit from upstream-pr/84 into main
antikohza commented 2026-11-25 10:11:20 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by antikohza on 2026-11-25T09:22:41Z.


Clean port of Marvisak/VIctory#2146 (originating from #737 / #1296) onto Zettrox/ztrx:main (082f8b1), tested for 6–8 GB GPUs and hybrid laptops (relevant to #76, #74, #71, #62).

What It Adds

  1. Quality / VRAM Switch (VICTORY_TEXTURE_MIP_DROP=0..=3, VICTORY_TEXTURE_MIP_DROP_MIN_SIZE, texture.rs / resource.rs):
    • Drops top mip levels on large pure-sampled power-of-two textures (flags & 0x7 == 0, non-MSAA, non-3D), saving ~1–3 GB of host VRAM and Windows commit memory on 6–8 GB GPUs.
    • Automatically defaults to drop = 1 when unset on GPUs with <= 8.5 GiB dedicated VRAM (matched via the actual device LUID); explicit VICTORY_TEXTURE_MIP_DROP=0..=3 always overrides.
    • Explicitly preserves non-power-of-two UI/loading artwork (1920×1080, 1280×720, etc.) and textures below VICTORY_TEXTURE_MIP_DROP_MIN_SIZE (default 1024), while maintaining BCn 4×4 block alignment.
  2. High-Performance DXGI Adapter Selection (host.rs):
    • best_adapter() prefers IDXGIFactory6::EnumAdapterByGpuPreference(DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE) (respecting Windows per-app GPU preferences and discrete/eGPU selection, avoiding 128 MiB iGPUs on hybrid laptops), falling back to EnumAdapters1 max dedicated VRAM.
    • supports_fl12() probes D3D_FEATURE_LEVEL_12_0 via null out-pointer without instantiating throwaway D3D12 devices.
  3. SRV Windowing, Subresource Remapping & HostWritten Bitmask (descriptor/host.rs, list.rs, texture.rs):
    • Adjusts MostDetailedMip, MipLevels, and ResourceMinLODClamp across all 7 SRV dimensions (1D..CubeArray).
    • Remaps copy_texture_region and resolve subresource indices, handles mismatched mip_drop CopyResource across same-family DXGI formats (e.g. UNORM -> UNORM_SRGB) via copy_overlapping_mips, and tracks per-subresource host writes (HostWritten u128 bitmask + HashSet<u32> fallback) while preserving ztrx's hosted() lazy creation, host_wrote(), unlike(), twin_use(), and read_back().

Verification

  • Windows MSVC CI (run 45584166709): Clippy clean, Clippy (--all-features) clean, xtask policy clean, all workspace unit & doc tests passed (503 passed, 0 failed, 7 ignored).
  • Upstream lineage (#737 / #1296 / #2146) verified across RTX 3060 Ti 8 GB (~9,200 -> ~6,000 MB, 16+ min), RTX 5070 Laptop 8 GB + Intel iGPU, RTX 3070 Laptop Linux/Proton (7,843 -> 6,664 MiB), RTX 4070 SUPER 12 GB (11.3 -> 10.3 GiB), RTX 4070 Ti + WARP (bit-exact MSAA resolve), and RX 9060 XT 16 GB.
<!-- greyfinch-sync:Zettrox/ztrx:issue:6601245793 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/84). Originally posted by [antikohza](https://github.com/antikohza) on 2026-11-25T09:22:41Z. --- Clean port of [Marvisak/VIctory#2146](https://github.com/Marvisak/VIctory/pull/2146) (originating from `#737` / `#1296`) onto `Zettrox/ztrx:main` (`082f8b1`), tested for 6–8 GB GPUs and hybrid laptops (relevant to `#76`, `#74`, `#71`, `#62`). ### What It Adds 1. **Quality / VRAM Switch (`VICTORY_TEXTURE_MIP_DROP=0..=3`, `VICTORY_TEXTURE_MIP_DROP_MIN_SIZE`, `texture.rs` / `resource.rs`):** - Drops top mip levels on large pure-sampled power-of-two textures (`flags & 0x7 == 0`, non-MSAA, non-3D), saving ~1–3 GB of host VRAM and Windows commit memory on 6–8 GB GPUs. - Automatically defaults to `drop = 1` when unset on GPUs with `<= 8.5 GiB` dedicated VRAM (matched via the actual device LUID); explicit `VICTORY_TEXTURE_MIP_DROP=0..=3` always overrides. - Explicitly preserves non-power-of-two UI/loading artwork (`1920×1080`, `1280×720`, etc.) and textures below `VICTORY_TEXTURE_MIP_DROP_MIN_SIZE` (default `1024`), while maintaining BCn 4×4 block alignment. 2. **High-Performance DXGI Adapter Selection (`host.rs`):** - `best_adapter()` prefers `IDXGIFactory6::EnumAdapterByGpuPreference(DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE)` (respecting Windows per-app GPU preferences and discrete/eGPU selection, avoiding 128 MiB iGPUs on hybrid laptops), falling back to `EnumAdapters1` max dedicated VRAM. - `supports_fl12()` probes `D3D_FEATURE_LEVEL_12_0` via null out-pointer without instantiating throwaway D3D12 devices. 3. **SRV Windowing, Subresource Remapping & `HostWritten` Bitmask (`descriptor/host.rs`, `list.rs`, `texture.rs`):** - Adjusts `MostDetailedMip`, `MipLevels`, and `ResourceMinLODClamp` across all 7 SRV dimensions (`1D`..`CubeArray`). - Remaps `copy_texture_region` and `resolve` subresource indices, handles mismatched `mip_drop` `CopyResource` across same-family DXGI formats (e.g. `UNORM` -> `UNORM_SRGB`) via `copy_overlapping_mips`, and tracks per-subresource host writes (`HostWritten` `u128` bitmask + `HashSet<u32>` fallback) while preserving `ztrx`'s `hosted()` lazy creation, `host_wrote()`, `unlike()`, `twin_use()`, and `read_back()`. ### Verification - **Windows MSVC CI ([run `45584166709`](https://github.com/antikohza/VIctory/actions/runs/45584166709)):** `Clippy` clean, `Clippy` (`--all-features`) clean, `xtask policy` clean, all workspace unit & doc tests passed (`503 passed, 0 failed, 7 ignored`). - Upstream lineage (`#737` / `#1296` / `#2146`) verified across RTX 3060 Ti 8 GB (`~9,200 -> ~6,000 MB`, 16+ min), RTX 5070 Laptop 8 GB + Intel iGPU, RTX 3070 Laptop Linux/Proton (`7,843 -> 6,664 MiB`), RTX 4070 SUPER 12 GB (`11.3 -> 10.3 GiB`), RTX 4070 Ti + WARP (bit-exact MSAA resolve), and RX 9060 XT 16 GB.
ThomasHFWright commented 2026-11-25 11:10:49 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by ThomasHFWright on 2026-11-25T10:37:57Z.


Tested this PR (082f8b19c21a60c150b0b0eb0991be9c5dd8d338) on a separate local integration with #50 and #36. RTX 5090 / NVIDIA 620.73.04 / CachyOS Linux 7.3.6, GE-Proton11-14 with Experimental D3D12 DLLs (2576c0b4adfae4a76d4c89d8cf5ec4f5ca795cff).

  • Clean cherry-pick onto the combined tree; diagnostics build and native asset-policy check pass.
  • GPU unit tests under distro Wine 11.22 + those native D3D12 DLLs: 124 passed, 2 failed, 1 ignored. All seven added tests pass. The two failures are unchanged from the pre-PR baseline: pipeline::host::tests::a_mesh_pipeline_loads_from_the_library and pipeline::library::tests::a_rejected_blob_gives_an_empty_library.
  • Actual title run: fresh prefix/cache, retained setup data, VICTORY_TEXTURE_MIP_DROP=2 confirmed in the log, default buffer/descriptor paths and no shader skips. Setup/loading artwork renders, but still Xid 13 / MMU fault at world entry, then exit 5 after 129.98 s; no world scene captured. The pre-PR integration also faults here, so this is not evidence of a regression from this PR.
  • Sampled cgroup resident peak 7.40 GiB, swap 7.85 GiB, no OOM/kill; minimum host available RAM about 1.63 GiB. Host has about 30 GiB RAM; test cgroup high/max/swap caps 10/14/8 GiB. Total GPU memory peak 12050 MiB includes other clients. Memory pressure remains a confounder and these runs are not a controlled measurement of VRAM savings.

AI-assisted local testing. Title/tests offline; no game files, generated shaders, raw title logs or captures attached.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7159960414 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/84#issuecomment-7159960414). Originally posted by [ThomasHFWright](https://github.com/ThomasHFWright) on 2026-11-25T10:37:57Z. --- Tested this PR (`082f8b19c21a60c150b0b0eb0991be9c5dd8d338`) on a separate local integration with #50 and #36. RTX 5090 / NVIDIA 620.73.04 / CachyOS Linux 7.3.6, GE-Proton11-14 with Experimental D3D12 DLLs (`2576c0b4adfae4a76d4c89d8cf5ec4f5ca795cff`). - Clean cherry-pick onto the combined tree; diagnostics build and native asset-policy check pass. - GPU unit tests under distro Wine 11.22 + those native D3D12 DLLs: **124 passed, 2 failed, 1 ignored**. All seven added tests pass. The two failures are unchanged from the pre-PR baseline: `pipeline::host::tests::a_mesh_pipeline_loads_from_the_library` and `pipeline::library::tests::a_rejected_blob_gives_an_empty_library`. - Actual title run: fresh prefix/cache, retained setup data, `VICTORY_TEXTURE_MIP_DROP=2` confirmed in the log, default buffer/descriptor paths and no shader skips. Setup/loading artwork renders, but still Xid 13 / MMU fault at world entry, then exit 5 after 129.98 s; no world scene captured. The pre-PR integration also faults here, so this is not evidence of a regression from this PR. - Sampled cgroup resident peak 7.40 GiB, swap 7.85 GiB, no OOM/kill; minimum host available RAM about 1.63 GiB. Host has about 30 GiB RAM; test cgroup high/max/swap caps 10/14/8 GiB. Total GPU memory peak 12050 MiB includes other clients. Memory pressure remains a confounder and these runs are not a controlled measurement of VRAM savings. AI-assisted local testing. Title/tests offline; no game files, generated shaders, raw title logs or captures attached.
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/84:upstream-pr/84'
git switch 'upstream-pr/84'

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