Skip to content

D3D12.X: a texture level that lost its texels gives its pages back - #2927

Draft
Prime1997 wants to merge 2 commits into
xcl-dev:nvidia-devfrom
Prime1997:contrib/nv-level-pages-given-back
Draft

Prime1997 wants to merge 2 commits into
xcl-dev:nvidia-devfrom
Prime1997:contrib/nv-level-pages-given-back

Conversation

@Prime1997

@Prime1997 Prime1997 commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Requested by Prime · project thread

With XCL_TEXTURE_LEVEL_PAGES=1 a streamed texture's level gets video memory pages at the first upload with texels for it, and kept them as long as the texture lived. A streaming title takes the memory from under the large levels of textures it no longer shows at that size, and the texture is uploaded again with those levels all zeros: the pages stayed, holding zeros. Before such an upload, a group of levels that has pages and is all zeros now gives them back (unmapped on the mapping queue, released as a released texture's pages are). Tiles without memory read as zeros (tiled resources tier 2), as the zeros the upload would have written; the level gets pages again with its next texels.

Part of #2688.

Why
In a retail title's world (RTX 3060 Ti 8 GB, Series S profile, XCL_TEXTURE_LEVEL_PAGES=1; a local branch of nvidia-dev with #1182 and #2921 merged in, 420 s runs with the title driven to its world) the target pages grew from 2.7 GB to 4.2 GB in four minutes with 0 MB idle, more than the title's whole texture pool (63,632 pages, 3.98 GB), and video memory reached 10.2 GB on a 7.1 GB budget. With this change, in a run of the same length with the same settings, levels gave their pages back 16,384 times and the target pages stood at 3,549 MB at the end against 4,189 MB (at 391 s: 3,577 MB against 4,196 MB), while the run got further into the world (134,493 draws with translated pipelines against 17,816). Video memory as a whole was still over the budget there (10.4 GB): the sparse windows and the GPU views hold the rest.

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs: unmap_levels (the groups of levels in zero that have pages: their tiles unmapped with Pages::unmap_range, their page keys out of the texture's, release_tiles), Pages::unmap_range (unmap for a range of tiles from a subresource on), a line at powers of two, mapped_level_tiles for the test.
  • crates/xcl/src/hle/d3d12x/title_textures.rs: map_levels_with_texels calls unmap_levels for the levels that are all zeros before mapping those with texels.
  • Second commit (review note): the keys a level gives back leave the texture's list in one pass (remove_once_each, with a unit test) instead of a search per key under the pages lock.
  • The GPU test title_textures::tests::a_placed_texture_gets_the_pages_of_a_level_with_its_texels goes on: the title decommits mip 0 again, the next upload gives back mip 0's pages (86 -> 22 tiles with pages; still 86 without this change), mip 0 reads zeros while the other levels keep their texels, the other texture on the same pages keeps them, and mip 0 gets them back with its texels.

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: 1823 passed, 9 failed, 48 ignored. The 9 failures are the same tests that fail on nvidia-dev eff3bcab itself (1822 passed, 9 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, gpu::recomp::tests::gpu_compute_thread_limits_leave_the_lanes_past_them_out, 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 eff3bcab.

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 eff3bcab:

xcl-smoke v1
commit: eff3bcabf1b6f99223796ece166948003a53e0bc
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: 15372 MB

This PR's head:

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

Not tested

  • XCL_TEXTURE_LEVEL_PAGES unset (the default): nothing changes, as no texture has lazy levels.
  • A texture the GPU wrote and whose memory the title then unmapped: its level now reads zeros where the GPU's texels stayed before (the console shows the unmapped memory there too).
  • 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/gK3y7WRRY

🤖 Generated with Claude Code

With XCL_TEXTURE_LEVEL_PAGES=1 a streamed texture's level gets video
memory pages at the first upload with texels for it, and kept them for
as long as the texture lived. A streaming title takes the memory from
under the large levels of textures it no longer shows at that size (its
GPU-view pages unmapped), and the texture is uploaded again with those
levels all zeros: the pages stayed, holding zeros. In a retail title's
world on an 8 GB card the target pages grew from 2.7 GB to 4.2 GB in
four minutes with 0 MB idle, more than the title's whole texture pool
(63,632 pages, 3.98 GB), and video memory reached 10.2 GB on a 7.1 GB
budget.

Before such an upload a group of levels that has pages and is all zeros
now gives them back (vram::unmap_levels: its tiles unmapped on the
mapping queue, its pages released as a released texture's are, idle and
then back to the pools when no other texture uses them). Tiles without
memory read as zeros (tiled resources tier 2), as the zero texels the
upload would have written; the level gets pages again with its next
texels (map_levels).

Test: the level-pages GPU test goes on: the title decommits mip 0 again,
the next upload gives back mip 0's pages (86 -> 22 tiles with pages; 86
without this change), mip 0 reads zeros and the other levels keep their
texels, the other texture on the same pages keeps them, and mip 0 gets
them back with its texels.

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

Copy link
Copy Markdown

I checked unmap_levels bookkeeping at head db0780c3. Each removed page searches and swap_removes from t.used while the shared pages lock is held. In an optimized synthetic comparison with 16,384 removals from 21,845 entries, that loop made 104,397,938 comparisons (30.96 ms); a local count-based single retain pass took 1.01 ms. These are CPU-only measurements of this bookkeeping loop, not a GTA VI frame-time measurement.

The local candidate counts removals by key and consumes one count per retained-vector occurrence, rather than filtering by set membership. An exhaustive test of 14,641 ordered input pairs confirmed identical surviving multisets, including duplicates. Survivors become stable-ordered; the original swap_remove already made their order unstable. The existing native texture test for mip release, zero readback, other-mip preservation and reacquisition also passed (1/1, no reported skips). I have not run a full suite or retail test for this candidate.

AI use: OpenAI Codex with GPT-6.2 Astra investigated, wrote the synthetic comparisons and local candidate, and ran the tests; Codex coordinated and prepared this report.

@ettehn

ettehn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Independent Windows GPU check on db0780c3c96ba5f7bc0bfd1d08ce5f9c40492b82: the stock a_placed_texture_gets_the_pages_of_a_level_with_its_texels test passed (1/1, no skips) on the RTX 5070 Ti Laptop test host (621.24, Windows 11 26200.9974, Rust 1.97.1 MSVC, debug).

I also extended the fixture locally to cover the packed mip group rather than only mip 0. The adapter put levels 4–10 in one tile. Feeding the mapping helper one zero mip and six nonzero ones retained the tile. Feeding it seven zero mips removed exactly one mapping: all seven levels read back as zeros, mip 0 stayed intact, and the other texture sharing those pages still read the original bytes. Feeding the original texels back remapped the tile and restored the original GPU readbacks. This test-only variant passed 3/3 in fresh processes, with no skip. It covers mapping and readback of a packed group, not a title run or frame-time measurement. OpenAI Codex (6.2sol) assisted with verification.

@andrewDoing

Copy link
Copy Markdown

Follow-up to my bookkeeping review: on head db0780c3c96ba5f7bc0bfd1d08ce5f9c40492b82 plus a test-only overlay, an RTX 5070 test wrote a known pixel to mip 0 on the GPU, decommitted that guest mip, and called the production mapping function. Mip 0 read back as zero; all ten lower mips retained their expected data, and an alias retaining the physical pages still contained the GPU-written pixel. Remapping restored the pixel. The texture's mapped count went 86 → 22 → 86 tiles.

The single test passed without reported skips. It invokes the mapping function directly and does not test production scheduling, total physical VRAM savings or GTA VI.

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

Review note on xcl-dev#2927: unmap_levels searched the texture's page keys and
swap_removed one for each key given back, under PAGES: quadratic in the
pages of a large level. remove_once_each counts the keys to drop and
takes one occurrence of each in a single retain.

Test: remove_once_each_takes_one_occurrence_for_each_naming (duplicates,
keys not named, nothing to take); the level-pages GPU test still passes.

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

Copy link
Copy Markdown

Tested — Wine/RTX4060 Laptop, exact production head 0c8378463f04ae17b4070f1fe96e528ef57adcdb, with local test-only fail-closed guards (require NVIDIA hardware, D3D12, tiled support and an actual lazy-level texture) and mapped-tile prints. No production edits.

a_placed_texture_gets_the_pages_of_a_level_with_its_texels and remove_once_each_takes_one_occurrence_for_each_naming: 2 passed /0 failed /0 ignored,1.28s. Fresh intended-worktree compilation34.04s; total guarded command36.43s. Actual GPU readback confirms mip0 zero after decommit/unmap, all ten lower mips preserved, another texture retaining the same pages preserved, and reacquisition restores original mip0 data. Mapped count 86→22→86. This is64 tiles unmapped from one resource, not4MiB proven physical VRAM returned: the other texture still holds those pages. The CPU fixture checks multiplicity-preserving key removal.

Linux6.17, Wine11.0, i7-13620H/16GiB RAM, RTX4060 Laptop8GiB/NVIDIA590.48.01, Rust1.98.1 Windows-MSVC target; DXVK_CONFIG='dxgi.hideNvidiaGpu = False'. Diagnostic-relaxed vkd3d-proton 2576c0b4adfae4a+, not stock Wine certification. No silent adapter skip or WARP fallback. Unchanged9GiB/512MiB scope and global2048MiB available-RAM/6000MiB GPU/10GiB disk cutoffs; sampled GPUpeak282MiB, minimum availableRAM9721MiB.

Command (under the local guarded Wine Cargo wrapper):

cargo test --locked --target x86_64-pc-windows-msvc -p xcl --lib -- --nocapture --test-threads=1 --exact hle::d3d12x::vram::tests::remove_once_each_takes_one_occurrence_for_each_naming hle::d3d12x::title_textures::tests::a_placed_texture_gets_the_pages_of_a_level_with_its_texels

Evidence: .compat-runtime/logs/verify-pr2927-level-retirement-20261127T025231Z/ (console, provenance, command/environment, resources and result JSON).

Not tested: matched parent on this machine, packed-tail or GPU-written-mip extension, outstanding cross-queue GPU work during retirement, full suite, title/world loading, FPS or aggregate RAM/VRAM saving. The reclaim/reacquire portion directly calls the production mapping helper; this does not certify end-to-end upload scheduling or fix our separate Game-Init stalled-fence blocker. A useful additional lifetime gate would keep an old GPU use pending while requesting retirement/reuse, then check both readback and fence ordering without skipping required work.

AI-assisted verification and report: omp/OpenAI GPT-6 Astra. No assets or imagery published.

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