Skip to content

GPU: add VICTORY_TEXTURE_MIP_DROP and DXGI high-performance adapter selection (fixes #737, #1226) - #2146

Open
antikohza wants to merge 2 commits into
Marvisak:mainfrom
antikohza:feat/texture-mip-drop-v2
Open

antikohza wants to merge 2 commits into
Marvisak:mainfrom
antikohza:feat/texture-mip-drop-v2

Conversation

@antikohza

Copy link
Copy Markdown

Resolves #737, resolves #1226. Supersedes closed #1296 and #1617 per triage instructions on #737 (rebased cleanly onto main 940d32f).

Summary

Introduces a proactive texture mip-drop subsystem and quality switch (VICTORY_TEXTURE_MIP_DROP, clamped 0..=3), plus high-performance DXGI adapter selection and LUID-matched VRAM detection that defaults drop = 1 on GPUs with <= 8.5 GiB dedicated VRAM.

Primary verified result: Eliminates E_OUTOFMEMORY (0x8007000E) host allocation failures and commit exhaustion during world loading on 8 GB GPUs (~1.1–3.0 GB VRAM saved depending on card/stack), allowing 8 GB desktop and laptop GPUs to survive world streaming instead of crashing at 79 packs (#1226) or after 2.5–6 min (#1296).


Changes Since Closed #1296

  1. Cleanly rebased onto current main (940d32f, 225 merged PRs):
    • Integrated with shared per-memory HostTexture (#127 / 13bbd6f): apply_mip_drop() preserves already-allocated full-resolution textures (mip_drop == 0) when sharing MemoryKey, while takes() prevents incompatible mip-dropped / full-res mixing.
    • HostWritten now lives directly on HostTexture (eliminating global map leaks on resource drop) and tracks per-subresource host writes (u128 bitmask + HashSet<u32> overflow) across copy_overlapping_mips, copy_texture_region, resolve, upload, and upload_changed.
    • Kept subresource_len() staging-bounds clamping in Staging::detile alongside console_mip = host_mip + self.mip_drop detiling.
    • Handled desc.mip_levels == 0 full mip chains via mip_count(desc) in both compute_mip_drop_explicit() and apply_mip_drop().
  2. Incorporated @ericomeehan's DXGI review feedback (host.rs):
    • best_adapter() now prefers IDXGIFactory6::EnumAdapterByGpuPreference(DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE) so Windows per-app GPU preferences and eGPU/discrete selections take priority, falling back to EnumAdapters1 max dedicated VRAM when IDXGIFactory6 is unavailable.
    • supports_fl12() probes D3D12 Feature Level 12.0 with a null out-pointer (std::ptr::null_mut::<Option<ID3D12Device>>()) instead of creating full throwaway devices per adapter.

How It Differs from #1272

  • Rebased cleanly on current main (940d32f) with zero merge conflicts (also synced with shared_texture, upload_changed, subresource_len, and twin.rs).
  • Fixes hybrid-laptop iGPU selection (host.rs): avoids D3D12CreateDevice(None, ...) picking 128 MiB iGPUs (0x887A0004) via EnumAdapterByGpuPreference(HIGH_PERFORMANCE) + LUID-matched DEVICE_MEMORY.
  • Originates from #737 (opened 8h earlier) with live hardware validation across NVIDIA desktop/laptop, AMD RDNA4, WARP, and Linux/Proton.

Hardware & CI Verification

@DrDarkDK

Copy link
Copy Markdown

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.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@antikohza

Copy link
Copy Markdown
Author

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

RecompLive added a commit to RecompLive/victory-fork that referenced this pull request Nov 25, 2026
Ports Marvisak/VIctory#2146 (GPL-3.0-or-later, antikohza; fixes fxceless#737,
#1226). Textures with a full mip chain get their top `mip_drop` console
mips omitted (VICTORY_TEXTURE_MIP_DROP, default 1 at <= 8.5 GiB
dedicated VRAM), views are adjusted to the reduced chain, and title
memory maps console subresources to host ones. Host writes are tracked
per subresource so untouched mips still upload. The DXGI adapter pick
prefers EnumAdapterByGpuPreference(HIGH_PERFORMANCE) and probes FL 12.0
without creating a device.

Adapted to our tree: the "first readable level" upload keeps console
mip numbers (first is compared as host_mip + mip_drop against the
console layout); test calls to make_texture pass 1, 0.

Co-Authored-By: antikohza <noreply@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants