Skip to content

D3D12.X: XCL_TEXTURE_DROP_LEVELS leaves large textures' top levels without video memory - #2968

Draft
Prime1997 wants to merge 1 commit into
xcl-dev:nvidia-devfrom
Prime1997:contrib/nv-texture-drop-levels
Draft

Prime1997 wants to merge 1 commit into
xcl-dev:nvidia-devfrom
Prime1997:contrib/nv-texture-drop-levels

Conversation

@Prime1997

@Prime1997 Prime1997 commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Requested by Prime · project thread

With XCL_TEXTURE_DROP_LEVELS=n (1 to 4; off by default) and XCL_TEXTURE_LEVEL_PAGES=1, a sampled texture with lazy levels whose largest level is XCL_TEXTURE_DROP_MIN texels or more on a side (1024 by default) leaves its n largest levels without video memory, and its views sample from the next level down (ResourceMinLODClamp). Textures look softer up close; each dropped level is about three quarters of such a texture's memory. Meant for cards whose video memory a title's world overruns, where the budget overrun costs more than the detail.

Part of #2688.

Why
In a retail title's world on an 8 GB card the title's textures held 3.2 GB of level pages and local video memory reached 10.2 GB on a 7.1 GB budget (Series S profile). In runs of the same length with the same settings, n = 1 brought the level pages to 2,286 MB and local video memory to 9,365 MB against 10,229 MB at about 400 s; n = 2 (with XCL_TWO_PASS_INDIRECT_MB=8, a local switch) peaked at about 9.0 GB. No view of such a texture was left unclamped, no crash (local branch of nvidia-dev with #1182, #2921 and #2815 merged in).

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs: drop_setting / dropped_levels_for (the switch and which textures it takes), Target::dropped set at placement, map_levels skips the dropped levels unless a GPU write asks for all of them, has_unmapped_levels ignores them, dropped_levels for the views.
  • crates/xcl/src/hle/d3d12x/real.rs: dev_create_srv_x clamps a 2D or 2D-array view of such a texture (clamp_view_to_level); default views are counted, not clamped.
  • Tests: a_view_of_a_texture_without_its_largest_level_samples_from_the_next (the clamp), and the level-pages GPU test places a texture with one level dropped: the smaller levels get pages with their texels, the largest none, it has no level still to map, and a GPU write gives it all of them.

Tested

  • NVIDIA GeForce RTX 3060 Ti 8 GB (driver 32.0.16.1714), Intel Core i5-10400, Windows 11 26200, rustc 1.100.0; debug tests, release smoke.
  • cargo test --locked --workspace --no-fail-fast -- --test-threads=4 with XCL_DXC_DIR set to DXC 1.9.2609.5: 1825 passed, 8 failed, 48 ignored. The 8 failures are the same tests that fail on nvidia-dev a5e2d851 itself (1820 passed, 12 failed, 48 ignored there, same command): async_compute_pso_registers_real_pso_and_not_standin, console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly, hle::d3d12x::texture_upload::tests::gpu_parts_of_a_texture_go_up_and_the_rest_stays, hle::d3d12x::texture_upload::tests::pieces_hold_the_texels_of_their_levels, split_compute_prefers_the_offline_whole_pipeline, two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs.
  • SKIPPED on this adapter: 28 (no wave64: 21, per-lane f16 form refused: 3, no dxc.exe: 1, no heap windows (opt-in: XCL_HEAP_WINDOWS=1): 1, cannot disable the driver cache (Windows Developer Mode is required): The application requested an operation that depend: 1, no heap windows: 1).
  • GitHub's Build and test (Windows, no GPU) has failed on other pull requests against nvidia-dev (kernelx: physical page homes in window 0 first, from the top, keeping 64 MB free (#2867) #2905, for one) on hle::d3d12x::sparse::tests::a_gpu_write_into_a_gpu_view_lands_in_its_cpu_view (the WARP device is removed, 0x887a0005). That test passes on the card above, on this branch and on a5e2d851.

Regression run
A commit of main (b49be183, the last one before the shader preparation screen of #2555, which prepares every record before the title and so does not fit a 60 s run):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 3060 Ti
title: 419239bf
seconds: 60
exit: 0x0
frames shown: 363 (PresentX 363)
presents per 2 s (last 3): 16 17 16
device removals: 0
crashes: 0
peak commit: 15320 MB

The base of this PR, nvidia-dev a5e2d851:

xcl-smoke v1
commit: a5e2d851a503fc0e04609f773ea53f2d2c4e3269
gpu: NVIDIA GeForce RTX 3060 Ti
title: 419239bf
seconds: 60
exit: 0x0
frames shown: 1356 (PresentX 1356)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15413 MB

This PR's head:

xcl-smoke v1
commit: 8c07f9abb06dddf2aaef505e6fc8e3e8c5b8b3bc
gpu: NVIDIA GeForce RTX 3060 Ti
title: 419239bf
seconds: 60
exit: 0x0
frames shown: 1364 (PresentX 1364)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15527 MB

Not tested

  • The picture: the hidden runs above have no screen to look at, so how much softer the textures look in the title is not checked here. The switch is off by default for that reason.
  • A shader that reads a dropped level with Load (no level of detail) reads zeros there; sampling is clamped.
  • AMD GPUs; tiled resources tier 1 (no level pages there).

AI use
Claude Code (Claude Opus 5.5) wrote the code, ran the suite and the regression runs on the hardware above, and wrote this description; Prime asked for it and owns the account. We coordinate the 8 GB work on the XCL Discord too: https://discord.gg/6B4TykyC4W

🤖 Generated with Claude Code

…thout video memory

Opt-in, off by default: with XCL_TEXTURE_LEVEL_PAGES=1, a sampled texture
with lazy levels of XCL_TEXTURE_DROP_MIN texels or more on a side (1024
by default) gives its n largest levels no pages (n = 1 to 4): map_levels
skips them unless a GPU write asks for all of them, and
has_unmapped_levels does not count them as levels still to map. Its 2D
and 2D-array views clamp their level of detail to level n
(ResourceMinLODClamp), so it is sampled from the next level down: softer
up close, for about three quarters of such a texture's memory a level.
Default views are counted, not clamped.

Measured in a retail title's world on an 8 GB card (420 s runs, same
settings otherwise): local video memory 9,365 MB against 10,229 MB at
~400 s with n = 1 (level pages 2,286 against 3,224 MB), and a peak of
about 9.0 GB with n = 2; no view was left unclamped, no crash.

Tests: a_view_of_a_texture_without_its_largest_level_samples_from_the_next
(the clamp), and the level-pages GPU test places a texture with one level
dropped: the smaller levels get pages with their texels, the largest none,
it has no level still to map, and a GPU write gives it all of them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Prime1997 Prime1997 self-assigned this Nov 27, 2026

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

An explicit 2D SRV can contain only a mip this option drops. For a valid view with MostDetailedMip=0 and MipLevels=1, the exact clamp_view_to_level helper returns the same one-mip view with ResourceMinLODClamp=1. Mip 1 is outside that view, so this cannot make sampling fall back to the next resident mip as described. The existing clamp test exposes the full chain and misses this case. Could the implementation keep the necessary level resident when the requested view has no intersection with the retained levels, or define and test an explicit fallback for that view? View clamp · D3D12 view fields

AI use: OpenAI Codex (GPT-6.2 Sol) reviewed the source, ran an isolated CPU harness around the exact descriptor helper, and drafted this comment. Shader sampling and retail impact were not measured.

@vibryxcx

Copy link
Copy Markdown

AMD data point for the "Not tested" side: on an RX 6800 (RDNA2, driver 32.0.21045.5002, Windows 11 Pro 26200, Rust 1.100.0, debug), this head adds no failure in the texture / vram / view tests.

cargo test -p xcl --lib -- --test-threads=1 title_textures vram dropped level view, run on the base (merge-base with nvidia-dev, a5e2d851) and on this head (8c07f9ab):

  • base: 129 passed, 1 failed, 2 ignored;
  • head: 130 passed, 1 failed, 2 ignored.

The one failure is the same on both, texture_upload::tests::pieces_hold_the_texels_of_their_levels, so it does not come from this PR. The extra pass is this PR's new test. I did not run the title on nvidia-dev: this card has 16 GB, so the over-budget case the switch is for does not happen here, and on this branch the shader cache is cold (about an hour of recompile).

Not tested: the switch on the title; RDNA3/4; 8 GB AMD cards.

AI use: Claude Code (Claude Opus 5.5) ran the tests through a local runner and wrote this comment.

@andrewDoing

Copy link
Copy Markdown

I checked the previously untested Load case on RTX 5070 / NVIDIA 616.92 at head 8c07f9abb06dddf2aaef505e6fc8e3e8c5b8b3bc. An instrumented test build extends the existing reserved-texture fixture with native shader readbacks and exposes the existing clamp helper to the test; its implementation is unchanged.

For 1024×1024 RGBA8 textures, mip 0 had red value 25 and mip 1 had red value 48. Each shader wrote one half of a 64×64 output:

View SampleLevel(0) Load at mip 0
All levels resident 25 25
Mip 0 dropped, min LOD clamped to 1 48 0

Each value above was observed in all 2,048 pixels of its half; the focused test passed without skips. This supports the stated risk that direct loads can see zero even though sampled reads use the next mip. It covers explicit 2D SRVs and this synthetic fixture; console descriptor dispatch, retail image quality, and actual memory savings were not tested.

AI use: OpenAI Codex with GPT-6.2 Astra built and ran the fixture; Codex reviewed and prepared this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants