Skip to content

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

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

antikohza wants to merge 1 commit into
Marvisak:mainfrom
antikohza:feat/texture-mip-drop-v2

Conversation

@antikohza

@antikohza antikohza commented Nov 25, 2026 •

Copy link
Copy Markdown

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

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

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

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

@antikohza antikohza changed the title GPU: add VICTORY_TEXTURE_MIP_DROP and DXGI high-performance adapter selection (fixes #737, #1226) GPU: add opt-in VICTORY_TEXTURE_MIP_DROP quality switch (fixes #737) Nov 25, 2026
@antikohza

Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown
Author

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
antikohza force-pushed the feat/texture-mip-drop-v2 branch from 773414a to 53a2b35 Compare November 26, 2026 07:11
flipflapov pushed a commit to flipflapov/victory_upifork that referenced this pull request Nov 26, 2026
…res that many levels down (off by default)

Port of ztrx PR #84 (antikohza, after Marvisak/VIctory#2146; in fork/z2 as
082f8b19 / merge cb0ac38) onto cool_fox's held levels instead of its own
subresource remapping: a placed 2D texture the title fills, of at least
VICTORY_TEXTURE_MIP_DROP_MIN_SIZE (1024) on both sides, gets its host copy
from level min(drop, levels - 2) on (resource::base_level), so views below
that level show it (descriptor::host::from_base), uploads read from it, and
a view of a larger level never makes the copy grow past it (want_level).
Such a texture is not made level by level (VICTORY_LEVELS_ON_DEMAND); with
the held levels on (LEVELS_ON_DEMAND unset) the copy starts at the larger
of the dropped level and the first level viewed. The held-levels line is
logged when the drop is on and names its value.

No automatic drop by VRAM size (fork/z2 enables 1 on <= 8 GB cards).

Co-Authored-By: antikohza <244305127+antikohza@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TsTmwWj9LVy4o3qDH52Jas
Signed-off-by: Impre-visible <69050895+Impre-visible@users.noreply.github.com>
r4tedx pushed a commit to r4tedx/VIctory that referenced this pull request Nov 26, 2026
…res that many levels down (off by default)

Port of ztrx PR Marvisak#84 (antikohza, after Marvisak#2146; in fork/z2 as
082f8b1 / merge cb0ac38) onto cool_fox's held levels instead of its own
subresource remapping: a placed 2D texture the title fills, of at least
VICTORY_TEXTURE_MIP_DROP_MIN_SIZE (1024) on both sides, gets its host copy
from level min(drop, levels - 2) on (resource::base_level), so views below
that level show it (descriptor::host::from_base), uploads read from it, and
a view of a larger level never makes the copy grow past it (want_level).
Such a texture is not made level by level (VICTORY_LEVELS_ON_DEMAND); with
the held levels on (LEVELS_ON_DEMAND unset) the copy starts at the larger
of the dropped level and the first level viewed. The held-levels line is
logged when the drop is on and names its value.

No automatic drop by VRAM size (fork/z2 enables 1 on <= 8 GB cards).

[cool/play-2: applied unchanged from Impre-visible/victory-gtx1660 (GPL-3.0-or-later) patches/0002 at d5c5a0cb (sha256 cbf20ea4...7a). The chain: antikohza's ztrx PR Marvisak#84 (fork/z2 082f8b1, merge cb0ac38), after Marvisak#2146, ported onto cool_fox f4b48ad by Impre-visible. Off by default: VICTORY_TEXTURE_MIP_DROP unset or 0 changes nothing.]

Co-Authored-By: antikohza <244305127+antikohza@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TsTmwWj9LVy4o3qDH52Jas
Signed-off-by: Impre-visible <69050895+Impre-visible@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Patch (fork): add VICTORY_TEXTURE_MIP_DROP quality switch for low-VRAM budgets (75%–93% texture memory savings on 6GB/8GB GPUs)

6 participants