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 e44af70 on the same machine:
Adapter Mode base e44af70 this PR (005a442)
RTX 5070 Ti default 1335 passed, 5 failed, 46 ignored 1339 passed, 5 failed, 46 ignored
RTX 5070 Ti XCL_DIRECT_DXIL=all 1334 passed, 6 failed, 46 ignored 1338 passed, 6 failed, 46 ignored
Radeon gfx1036 default 1338 passed, 2 failed, 46 ignored 1342 passed, 2 failed, 46 ignored
Radeon gfx1036 XCL_DIRECT_DXIL=all 1337 passed, 3 failed, 46 ignored 1341 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 e44af70, 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: e44af7062dc610a9f889de2dcf11450e3e4884b3
gpu: NVIDIA GeForce RTX 5070 Ti
title: title-a
seconds: 60
exit: 0x0
frames shown: 800 (PresentX 800)
presents per 2 s (last 3): 27 26 27
device removals: 0
crashes: 0
peak commit: 14966 MB

This PR, same card:

xcl-smoke v1
commit: 005a4427d2926f29d96ea28bf6747dc70321806c
gpu: NVIDIA GeForce RTX 5070 Ti
title: title-a
seconds: 60
exit: 0x0
frames shown: 892 (PresentX 892)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15389 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
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…#2404, xcl-dev#2405

Integrates VRAM top-mip pressure shedding (xcl-dev#2385), DXC wanted-compile
prioritization & worker headroom (xcl-dev#2423), inline split pipeline foreground
path (xcl-dev#2424), ExecuteIndirect split program dispatch (xcl-dev#2404), and hosted
view heap exhaustion null-pair fallback (xcl-dev#2405).

Assisted-by: Antigravity (Gemini 4 Neon)
@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #640 solves the same problem (for #1773) in a different way: #1607, group D111. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…#2404, xcl-dev#2405

Integrates VRAM top-mip pressure shedding (xcl-dev#2385), DXC wanted-compile
prioritization & worker headroom (xcl-dev#2423), inline split pipeline foreground
path (xcl-dev#2424), ExecuteIndirect split program dispatch (xcl-dev#2404), and hosted
view heap exhaustion null-pair fallback (xcl-dev#2405).

Assisted-by: Antigravity (Gemini 4 Neon)

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

No concrete code defect found, and the mapping/SRV clamping coverage is useful. Before merge, please provide low-VRAM (8-12 GB) title and visual/image validation, since this deliberately changes texture fidelity in the scenario it targets. The disclosed Load/mip-query zeros for skipped mips and discarded CPU detiling should remain explicit. Also reconcile intended coexistence with #640, which targets the same #1773 VRAM-pressure problem, to avoid competing strategies.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…extures)

Integrates xcl-dev#2436 cleanly alongside xcl-dev#2385 (top-mip shedding) and xcl-dev#2474
(foreign-thread release_cleanup).

Assisted-by: Antigravity (Gemini 4 Neon)
@anes66

anes66 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

CPU coverage on exact head 005a442 on native Windows, with an optional test-only companion commit: bb26dd5.

Tested

  • Windows 10 22H2 (19045), Ryzen 7 9800X3D, Rust 1.100.0 MSVC, debug. CPU tests only; no adapter query, GPU device creation or dispatch.
  • Unmodified head, selected pure CPU tests the_cap_follows_how_full_video_memory_is, top_mips_go_until_the_largest_side_fits_and_one_tiled_mip_stays and lazy_levels_never_map_the_top_mips_left_out: 3 passed, 0 failed, 0 ignored, 0 skipped.
  • With bb26dd5, those three plus the three new cpu_* tests: 6 passed, 0 failed, 0 ignored, 0 skipped. Command: cargo test --locked -p xcl --lib -j2 -- --nocapture --test-threads=1 hle::d3d12x::vram::tests::cpu_ the_cap_follows_how_full_video_memory_is top_mips_go_until_the_largest_side_fits_and_one_tiled_mip_stays lazy_levels_never_map_the_top_mips_left_out.

The 97-line companion commit adds:

  • 270 tile-mask cases over 1/2/6 slices, different mip counts, gaps, reversed tile placement and packed tails. A separate tile-owner map defines the expected mask.
  • 1,040 checks that mip skipping is minimal, monotone in the cap and keeps the final standard mip.
  • 144 view-clamp cases over 2D, arrays, cubes and cube arrays. Existing stronger LOD clamps, view ranges, plane slices, format and component mapping are preserved.

Negative controls, restored before the final passing run: limiting the mask to the first slice fails the array cases; replacing the LOD clamp instead of taking its maximum fails the existing-clamp cases.

Not tested

  • Your GPU sampling regression, adapter budget queries, full workspace suite or a title with this PR on this machine. The tests establish CPU helper behavior, not visual correctness or a measured memory saving.

The companion commit is authored as anes66; please preserve its author if you carry the tests into your branch. The runtime change remains yours.


RTX 3060 12 GB manual title follow-up, 25 November

One manual run on Windows 10 22H2, release head f169760 (main 6d12f58 + XG ABI fix #1435 + your exact head 005a442 + test-only commits). XCL_TEXTURE_BUDGET=1, no forced XCL_TEXTURE_MAX, XCL_PSO_TRACE=1. Both huge-compile worker limits were set to 1; the earlier comparison run set only XCL_HUGE_PSO_CONCURRENCY=1, leaving the wanted limit at its default 2. Existing saves/caches were retained.

At approximately the same elapsed time (~764 s), XCL's memory lines report the following (MB as logged):

Metric 6d12f58 + #1435 (5cb01ab) With #2385 (f169760)
Process commit 29,048 26,222
Local video memory 12,606 10,658
Non-local video memory 4,946 4,983
Target pages 8,495 6,624
Pool heaps 8,768 6,912

The budget run was closed manually after about 50 min 25 s: exit 0, crash: null, no device-removal or 0x8007000E message. Final local video memory was 11,057 MB; the policy reported top mips omitted for 2,685 textures / 4,765 MB of tiles. The latter is the policy's tile counter, not a claim of that much net VRAM saved. Sampled peak private bytes were 28,367 MiB, peak working set 16,909 MiB, and minimum available physical memory 2,532 MiB.

The black screen remains. The last nonzero presents activity sample is at 501.816 s. Another 582 logged driver calls finish after it; a read-only, non-suspending stack snapshot finds pso_async::resolve_wait under list_x::record_deferred and another thread inside nvgpucomp64. Driver work continues, but no new frames arrive before closure at 3,021 s. Final report: 2,065 translated pipelines, 40 translation errors, 283 DXIL compilations / 0 compilation failures.

Limits: one run per profile, different cache warm-up and the wanted-limit change, so this does not isolate your patch's effect. No visual correctness or playability established; no image-quality comparison was possible. Raw title logs, stack dumps and proprietary files are not uploaded.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Tested

  • Windows 11 Pro build 26200; AMD Radeon RX 7800 XT 16 GB (driver 32.0.31035.1003); AMD Ryzen 7 5700X3D CPU; Rust 1.100.0 MSVC; DXC/DXIL 1.8.2502.11 from Windows SDK 10.0.26100.0. Debug profile. XCL_ADAPTER=radeon.
  • Tested exact PR head 005a4427d2926f29d96ea28bf6747dc70321806c. Baseline origin/main was 6d12f58a229bc73889878a448c64dc3af25eeba0.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1,342 passed, 2 failed, 46 ignored, 18 SKIPPED notices (exit 101). One failure, gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, also failed on baseline. The other, gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, passed on baseline.
  • cargo test -p xcl --lib gpu_a_texture_without_its_top_mip_samples_the_first_it_has -- --test-threads=1: 1 passed, 0 failed, 0 ignored, 0 skipped; ran on the RX 7800 XT.
  • Current-main baseline cargo test --workspace --no-fail-fast -- --test-threads=4: 1,422 passed, 1 failed, 46 ignored, 25 SKIPPED notices (exit 101).

Not tested

  • A retail title or game data; no dumps were used.

AI use

  • Codex (gpt-6-luna) ran the tests and prepared this report.

@thehollowedone

Copy link
Copy Markdown

Independent NVIDIA check of #2385 head 005a442, clean detached checkout on its original base 06055a7.

Tested

  • RTX 3080 Ti / NVIDIA 621.35, Ryzen 7 9800X3D, Windows 11 build 26300, rustc 1.99.1 MSVC; debug build/tests.
  • cargo test --offline --locked -p xcl --lib top_mip --jobs 6 -- --test-threads=1 --nocapture: 3 passed, 0 failed, 0 ignored. The GPU sampling fixture ran on the named adapter; no skip in this focused run.
  • cargo build --offline --locked --workspace: passed.
  • cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4: 1,343 passed, 1 failed, 46 ignored, with 25 GPU SKIPPED notices for unsupported features. The sole failure was a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier. This branch starts before merged #2420, which changes that exact barrier test; this is not a clean-suite result or a merge-readiness claim.

I read the patch's sampled-texture placement, skipped-tile mapping, remap and release paths and found no concrete source blocker. The GPU fixture verifies sampling from the first resident mip and zero reads from an unmapped top mip. It does not simulate an 8–12 GB retail memory-pressure run or judge visual quality. #640 offers a different policy for related pressure, as the D111 coordination note records.

Not tested: a retail title under pressure, visual fidelity, AMD hardware, skipped native wave64/per-lane features, or a rebase onto current main. A rebase and clean full-suite run are still needed. AI-assisted: Codex (GPT-6, exact variant unavailable) reviewed the code, ran the tests, and drafted this report.

@CalvyPZ CalvyPZ added the duplicate This issue or pull request already exists label Nov 25, 2026
@CalvyPZ CalvyPZ closed this Nov 25, 2026
@CalvyPZ CalvyPZ reopened this Nov 25, 2026
@CalvyPZ CalvyPZ removed the duplicate This issue or pull request already exists label Nov 25, 2026
@Royalflamejlh

Copy link
Copy Markdown
Contributor

Linux (Wine + vkd3d-proton) + NVIDIA, the title, 3 runs with the budget (default) and 3 with XCL_TEXTURE_BUDGET=0, in turn: on this 12 GB card the budget switched on at 46 to 51 s, and no run in either tree had a device removal or a driver message. At 118 s, 11,651 to 12,155 live textures were without their top mips. Target pages were 6.2 to 6.5 GB against 9.6 GB without it, and non-local video memory 4.4 to 4.5 GB against 7.5 to 7.6 GB. XCL's MB figure for the tiles left unmapped (12.2 to 12.9 GB) is a sum per texture, and textures at the same address share tiles, so it is larger than what was saved. The last present came at 70 to 92 s with it and 76 to 82 s without. So on this 12 GB card these runs show no failure that the budget avoided.

Setup: e44af706 (the commit this head is based on) + #684 e56dbc3 + #2385 005a442 (9f73b329), the same build both ways, in turn. RTX 4070 12 GB (615.71.09), Fedora 44, Wine 11.21 Staging, vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch, release, Series X profile, 120 s, A pressed when ready at 16.3 to 18.2 s (one run without the budget also pressed at 10.3 s), XCL_PSO_PRELOAD=0, WINEDEBUG=err+all,fixme-all. Memory figures are XCL's own memory: lines.

budget on (3 runs) XCL_TEXTURE_BUDGET=0 (3 runs)
video memory is filling up at 50.8, 46.0, 45.9 s –
at 118 s: top mips left out 12,155, 11,651, 11,882 textures (12,916, 12,153, 12,469 MB) 0
at 118 s: target pages 6,162, 6,490, 6,331 MB 9,587, 9,590, 9,648 MB
at 118 s: local / non-local video memory 10,046–10,403 / 4,439–4,497 MB 10,394–10,419 / 7,546–7,604 MB
last 2 s with a present 92.1, 70.0, 72.0 s 76.2, 78.3, 82.0 s
  • Local memory reached the same level either way (10.0 to 10.4 GB); what the budget saved here was about 3 GB of spill into non-local memory.

Not tested: the image quality (no frames); XCL_TEXTURE_LEVEL_PAGES=1 and XCL_TEXTURE_MAX; the suite; Windows; AMD and Intel.

AI use: Claude Code (Claude Opus 5.5) ran the title and wrote this comment.

Posted without review by a person: the account owner was away and reads replies later.

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.