Skip to content

D3D12.X: sampled textures go without their top mips while video memory fills up - #2385

Open
NWProgramming00 wants to merge 1 commit into
xcl-dev:mainfrom
NWProgramming00:vram/budget-top-mips
Open

NWProgramming00 wants to merge 1 commit into
xcl-dev:mainfrom
NWProgramming00:vram/budget-top-mips

Conversation

@NWProgramming00

@NWProgramming00 NWProgramming00 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

When the device's video memory fills up, new sampled title textures get no memory for their largest mips. Every view of such a texture is clamped to the first mip it has. A texture then gets less sharp up close instead of pushing the card past its budget. Part of #1773.

What it does

  • When it applies. Local video memory is read from QueryVideoMemoryInfo, at most every 100 ms. Past 75 % of the budget, a new sampled texture keeps a largest side of at most:
    • 2048 from 75 %,
    • 1024 from 85 %,
    • 512 from 92 %.
  • Which tiles go. The top mips' tiles are not taken from the pools and stay unmapped. With tiled resources tier 2 they read as zero.
    • The resource keeps its shape and mip numbering.
    • The title's uploads still go to it; the ones into those mips go nowhere.
    • Render targets, depth buffers and UAV textures always keep all their memory.
  • Views. Every SRV of such a texture gets ResourceMinLODClamp = the mips left out, so sampling never reaches them. The clamp counts from the resource's first mip, not the view's; the new GPU test checks this.
  • Switches.
    • XCL_TEXTURE_BUDGET=0 turns it off.
    • XCL_TEXTURE_MAX=<texels> caps every new sampled texture at that size, whatever the fill. It is meant for tests and measurements.
  • Log. XCL_ACTIVITY's memory: line gives the textures alive now without their top mips, and the MB of tiles they leave unmapped.

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs:
    • the fill check and the cap (texture_cap, cap_for_fill, mips_to_skip);
    • the tiles of the top mips (top_mip_tiles, top_mip_mask);
    • Pages::bind / bind_range map all tiles but the masked ones; the mask is kept for remap_if_unmapped;
    • with lazy levels (XCL_TEXTURE_LEVEL_PAGES=1, D3D12.X: video memory use is high, title memory and textures are mirrored into VRAM #1773) the left-out levels never get pages in map_levels (groups_to_map);
    • the per-resource record, dropped when the resource goes, and clamp_skipped_mips.
  • crates/xcl/src/hle/d3d12x/real.rs: dev_create_srv_x clamps the views of such a texture. When the title passes no description, it builds the default 2D view first.
  • crates/xcl/src/host.rs: the counts on the memory: line.
  • Tests in vram.rs:
    • the_cap_follows_how_full_video_memory_is and top_mips_go_until_the_largest_side_fits_and_one_tiled_mip_stays.
    • lazy_levels_never_map_the_top_mips_left_out: with lazy levels, the left-out levels never get pages, the others once.
    • gpu_a_texture_without_its_top_mip_samples_the_first_it_has, a GPU test. It binds a 512×512 4-mip reserved texture without mip 0 through Pages::bind and uploads every mip. Then it samples through three views:
      • clamped to mip 1, it reads mip 1;
      • a view from mip 1 clamped to 2 reads mip 2, not mip 3;
      • unclamped, it reads zero from mip 0.

Tested

  • Windows 11, NVIDIA GeForce RTX 5070 Ti 16 GB and an AMD Radeon RDNA2 iGPU (gfx1036, XCL_ADAPTER=radeon), AMD Ryzen 7 9700X, drivers 32.0.16.2124 (NVIDIA) and 32.0.21042.62 (AMD), Rust 1.100 MSVC, release.
  • The new GPU test passes on both adapters. Each of three deliberate mistakes makes it fail on both:
    • the clamp one mip too low;
    • the mask ignored in bind;
    • mip 0 left out of the mask.
  • The whole suite: cargo build --release --workspace, then cargo test --release --workspace --no-fail-fast -- --test-threads=4, with and without XCL_DIRECT_DXIL=all, against base 68a284a on the same machine:
Adapter Mode base 68a284a this PR (d790a29)
RTX 5070 Ti default 1285 passed, 5 failed, 46 ignored 1289 passed, 5 failed, 46 ignored
RTX 5070 Ti XCL_DIRECT_DXIL=all 1284 passed, 6 failed, 46 ignored 1288 passed, 6 failed, 46 ignored
Radeon gfx1036 default 1288 passed, 2 failed, 46 ignored 1292 passed, 2 failed, 46 ignored
Radeon gfx1036 XCL_DIRECT_DXIL=all 1287 passed, 3 failed, 46 ignored 1291 passed, 3 failed, 46 ignored

The +4 are the new tests. The failing tests are the same on base and PR: fuzz_validate_and_gpu_0..3 on NVIDIA (#1905), fuzz_validate_and_gpu_1 on RDNA2 (#2115, #2170), offline_compute_pipeline_is_reused_by_a_second_process with direct DXIL (#1674), and a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier on both adapters in both modes (it came with 254a058 and fails on base too). SKIPPED lines: 37 on NVIDIA, 19 on the Radeon, the same on base and PR.

  • A retail title, 300 s runs that reach world loading (XCL_ACTIVITY=1, A pressed at 15–65 s, RTX 5070 Ti; made before the rebase onto 68a284a, on base 06c9f55):
run video memory, end texture pages, end textures without top mips now frames
main 06c9f55 12,366 MB 7,843 MB – 4,055
this PR, default 12,824 MB 8,551 MB 126 (331 MB) 3,270
this PR, XCL_TEXTURE_MAX=1024 10,775 MB 6,331 MB 1,500 (3,709 MB) 6,751

Regression run
Base (main), NVIDIA GeForce RTX 5070 Ti:

xcl-smoke v1
commit: 68a284a596bd558b6bd9db6eedda6d6aa178c360
gpu: NVIDIA GeForce RTX 5070 Ti
title: title-a
seconds: 60
exit: 0x0
frames shown: 781 (PresentX 782)
presents per 2 s (last 3): 3 24 21
device removals: 0
crashes: 0
peak commit: 15245 MB

This PR, same card:

xcl-smoke v1
commit: d790a29160a81f2c27f4684bfb94d6b0534a3e71
gpu: NVIDIA GeForce RTX 5070 Ti
title: title-a
seconds: 60
exit: 0x0
frames shown: 728 (PresentX 728)
presents per 2 s (last 3): 0 0 1
device removals: 0
crashes: 0
peak commit: 12159 MB

These 60 s runs end in the title's menus, before any texture is left without its top mips (video memory stays far under 75 % of the budget there), so they check that nothing else changed; the 300 s runs above are the ones that reach this code.

Not tested

AI use

  • Claude Code (Claude Opus 5.5) did the work: it wrote the code and the tests, ran the mutation checks, the suites and the title runs, and wrote this description.

🤖 Generated with Claude Code

…y fills up

When the device's local video memory passes 75 % of its budget, a new sampled
title texture gets no pool tiles for its largest mips (the largest side kept:
2048 from 75 %, 1024 from 85 %, 512 from 92 %). Those tiles stay unmapped and
every view of the texture is clamped to the first mip that has memory
(ResourceMinLODClamp, which counts from the resource's first mip). With lazy
levels (XCL_TEXTURE_LEVEL_PAGES=1) those levels never get pages.
XCL_TEXTURE_BUDGET=0 turns it off; XCL_TEXTURE_MAX caps every new texture.

Part of xcl-dev#1773.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head 61b2f2c8d5200eb2c8bd1f2506af89595e46d122 (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1266 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.
    • The PR's test passed: hle::d3d12x::vram::tests::the_cap_follows_how_full_video_memory_is.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on unmodified main on this GPU.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release; 16 GB VRAM so this run does not hit the high-fill mip-skipping threshold)

xcl-smoke v1
commit: 61b2f2c8d5200eb2c8bd1f2506af89595e46d122
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1569 (PresentX 1569)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15174 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • Low-VRAM (8 GB) pressure path in the retail title; D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.

@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants