Skip to content

D3D12.X: XCL_TEXTURE_LEVEL_PAGES=1 gives a sampled texture's levels their pages with their texels - #2306

Open
imnicho wants to merge 1 commit into
xcl-dev:mainfrom
imnicho:texture-level-pages
Open

imnicho wants to merge 1 commit into
xcl-dev:mainfrom
imnicho:texture-level-pages

Conversation

@imnicho

@imnicho imnicho commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

With XCL_TEXTURE_LEVEL_PAGES=1 (off by default) a sampled texture's levels get their video memory pages when an upload first has texels for them, not all at once when the title places the texture. Part of #1773 (point 2 there, the sampled textures' half of the "target pages").

A retail title places its streamed textures at full size and has memory behind their levels only as it loads them, the small ones first. vram::place_pages gives a sampled texture a 64 KiB page of video memory for every tile at once, so most of those pages hold nothing: when that title's world is set up, 80 690 pages lie under such textures and 6 809 of them (8 %) are committed, on my card. @shortside measured the same on a Mac and has a branch for native hosts, where each texture is a reserved resource of its own (#1773 (comment)); this is the idea for the shared-pages path Windows uses, which that comment left open. Measurements and the plan: #1773 (comment).

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs: with the switch on, place_pages places a sampled 2D texture of one slice with no tile mapped. Levels keeps its tiling (GetResourceTiling) as groups of tiles: one for each level with tiles of its own, one for the packed levels. map_levels gives a group its pages - the same pages by address as before (bind_range, what bind does for a range of the tiles; map takes the subresource the range starts at), so textures placed at one address still share them. A texture unmapped as a whole (unmap_superseded) starts again with no level mapped. A tiling that does not add up to the resource's tiles, arrays, volumes, multisampled and GPU-owned textures are placed as before.
  • crates/xcl/src/hle/d3d12x/title_textures.rs: before an upload's copies, the levels of the texture that have texels (a byte that is not zero in what goes up) get their pages; the upload queue waits for the mapping (vram::before_execute, already called there). A level of zeros keeps none: it reads as zeros either way, and its copy goes to tiles that are not mapped, which drops it (tiled resources tier 2, the tier the shared pages already need). A texture the GPU writes (note_gpu_write: CopyTextureRegion, CopyResource, the resolves) gets all its pages at that call, and so does one of those when it is uncovered again.
  • Tests: the_tiles_of_a_texture_are_grouped_by_its_levels (the grouping; tilings that do not add up), and a_placed_texture_gets_the_pages_of_a_level_with_its_texels on the GPU: a 1024x1024 texture of 11 levels whose memory has every level but the largest - no page before the first upload, then pages for those levels only (counted against the driver's tiling), their texels right, zeros read from the level without pages; with memory under the largest level a texture placed there again gets that level's pages, the others shared, and holds all of it; a texture the GPU writes gets the pages of all its levels.
  • 405 lines added, 12 changed; 162 of them are the tests. Without the switch: one cached check where a sampled texture is placed, one per uploaded texture and one per GPU write into one.
  • Not done: a level the title unloads keeps its pages until the texture goes. A level that gets its pages for a GPU write holds what the pages' last user left where the GPU does not write (as a texture's pages do today before its first upload).

Tested

without with without with
texture pages (target pages) at the end 9 227 MB 4 949 MB 9 483 MB 4 835 MB
local video memory, peak (budget 15.1 GB) 20 382 MB 19 156 MB 22 003 MB 19 382 MB
draws after the world's set-up 26 535 114 436 42 677 215 154
end 300 s reached 0x887a0006 136 s after the set-up 0x887a0005 58 s after it 0x887a0006 160 s after it
  • In the minute the world is set up local video memory was 17.3 GB without and 12.9 GB with (one run each).
  • The logo and the loading artwork are right with the switch (frame captures); the world is grey on that tree either way (Memory: more than 4 memory windows once #680 lands, so title memory stops falling back to plain memory #697). No upload failed and no texture warning in five runs with the switch.
  • It does not keep this card's device: the texture pages are halved, the rest of the video memory is other things (the issue comment has the parts), and the runs still end over the budget.

Regression run (default settings: the switch is off)

main:

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: NVIDIA GeForce RTX 5080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1323 (PresentX 1324)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14064 MB

PR (this PR's head commit):

xcl-smoke v1
commit: 3ea5edc1c941be6350d66b45e1e5c91f72158c18
gpu: NVIDIA GeForce RTX 5080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1341 (PresentX 1341)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14105 MB

A second round of the same two binaries: main 1134 frames, PR 1323.

Not tested

  • The title's world on this head itself: not run. The world runs above are on the local tree named, whose upload path differs as said.
  • Whether a world's textures look right with the switch: the world is grey on that tree for another reason.
  • AMD and Intel GPUs, native 64-lane waves, Linux / Wine; a driver whose tiling does not group this way (the texture is then placed as before).
  • Other titles.

AI use

  • Claude Code with Claude Fable 5.2: wrote the change and its tests, ran the suite and the title runs on the machine named, and wrote this description.

🤖 Generated with Claude Code

…heir pages with their texels

A retail title places its streamed textures at full size and has memory behind
their levels only as it loads them, the small ones first. vram::place_pages
gives a sampled texture a 64 KiB page of video memory for every tile at once:
when that title's world is set up about 92 % of those pages have nothing behind
them (80 690 pages, 6 809 committed, on one card).

With the switch (off by default) a sampled 2D texture of one slice is placed
with no tile mapped. Its tiling is kept as groups of tiles, one for each level
with tiles of its own and one for the packed levels, and a group gets its pages
before the first upload that has texels for it - the same pages by address as
before, so textures placed at one address still share them. A texture the GPU
writes gets all its pages.

Part of xcl-dev#1773.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@thehollowedone

Copy link
Copy Markdown

Independent Windows check of 3ea5edc. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, DXC 1.8.2502.11.

  • On the clean head, cargo build --offline --locked --workspace -j 6 passed. cargo test --offline --locked --workspace -j 6 --no-fail-fast -- --test-threads=4 --nocapture finished with 1,252 passed, 0 failed, 46 ignored. The pass count includes 25 runtime skips. The two new tests also passed in isolation with zero skips.
  • I reran the stock 11-mip texture fixture twice with test-only instrumentation, using standard D3D12 validation and then GPU-based validation. Each run passed 1/1 with zero skips, zero D3D12 errors or warnings, and a healthy device. The unmapped top mip read back as zero, it read back the expected texels after mapping, and the two resources at the same address shared the expected pages. The production code was unchanged in these runs.

Synthetic fixtures only. Retail world-load timing and visual output were outside these runs.

AI-assisted. Codex (GPT-6, exact variant unavailable) added the temporary test instrumentation, ran the tests, and drafted this report.

@SlopTart

Copy link
Copy Markdown

Linux/RADV (RDNA3) verification over Wine: green with the switch on and off, one single-shot flake to note.

Tested: origin/main 379725ae + PR head 3ea5edc1 (merge 4fc3b501, no conflicts). Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, official MS DXC (binaries 2026-09-29). gpu_ suite = cargo test --release --locked --target x86_64-pc-windows-gnu -p xcl --lib -- gpu_.

  • Switch off (default), --test-threads=2: 142 passed / 3 failed / 1 ignored. The 3 are this rig's known baseline (fuzz seed 1003 of DXIL fuzz tests: fuzz_validate_and_gpu_1 fails on AMD (seed 722 and others, RDNA2-4), so the default suite is red there #2115, gpu_nonfused_mad_and_mac_prevent_fma_contraction, gpu_depth_buffer_created_for_unordered_access_is_placed). Both tests the PR adds pass.
  • XCL_TEXTURE_LEVEL_PAGES=1, run 1, --test-threads=2: 141 / 4: one extra, gpu_geometry_wave32_prefix_count_over_a_mask.
  • Same flag, run 2, --test-threads=2: 142 / 3, the extra one gone.
  • Same flag, --test-threads=1: 142 / 3.
  • That test solo, --exact --test-threads=1 with the flag set: green 3 of 3.

So on this rig the change is clean: no deterministic failure with the switch on. The one gpu_geometry_wave32_prefix_count_over_a_mask red appears once in three full-suite runs at --test-threads=2 with the flag on and never again; on a rig where geometry/wave tests are a known flake family, I would not read that as caused by this change, but the count is reported so the record is complete.

Not tested: Windows hosts; the streamed-texture retail measurements in the PR body (no title data run here, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

@nnonno91

Copy link
Copy Markdown

Independent native Windows Radeon iGPU check of 3ea5edc1c941be6350d66b45e1e5c91f72158c18.

Tested

  • AMD Radeon(TM) Graphics, driver 32.0.21042.62, Ryzen 7 9800X3D, Windows 11 25H2 build 26200.9974, Rust 1.100.0 MSVC, unoptimized test profile.
  • cargo test --locked -p xcl --lib the_tiles_of_a_texture_are_grouped_by_its_levels -- --nocapture --test-threads=1 gave 1 passed, 0 failed on the unchanged head.
  • The GPU fixture normally uses DXGI adapter index 0. I temporarily changed only its adapter lookup and printed the selected Radeon. cargo test --locked -p xcl --lib a_placed_texture_gets_the_pages_of_a_level_with_its_texels -- --nocapture --test-threads=1 gave 1 passed, 0 failed per run, with XCL_TEXTURE_LEVEL_PAGES=1 and 0 in separate processes. The fixture explicitly enables lazy pages internally, so both runs exercise that path.
  • The fixture verified the level page counts, uploaded texels, zeros from the unmapped top level, shared pages after re-placement, and allocation for a GPU-written texture. No ignores or skips in any run. The test-only adapter edit was restored.

Not tested

A forced eager-page GPU control, retail gameplay, memory savings in a title, and the full workspace suite.

AI use

OpenAI Codex (GPT-6.2 Sol) adapted the adapter selection for the test, ran the checks and wrote this report.

@minimalhipster990

Copy link
Copy Markdown

RTX 4090, clean PR head 3ea5edc1c941be6350d66b45e1e5c91f72158c18. With XCL_TEXTURE_LEVEL_PAGES=1, target pages fell by 50.8% at the same loading artwork. Neither run reached a visible gameplay HUD or recognizable 3D world within 300 s.

Measurement Default (off) On
Target pages at the matched artwork 8,828 MiB 4,342 MiB
Local video memory at that artwork 12,918 MiB 8,660 MiB
Process commit at that artwork 26,618 MiB 23,701 MiB
Target pages at 120 s, after presentations had stopped 9,816 MiB 4,458 MiB
Local video memory at 120 s 14,431 MiB 8,797 MiB
Available Windows system commit near 120 s 10.47 GiB 14.61 GiB
Last 2 s activity interval with any presents ended at 100.061 s 90.039 s
Total PresentX calls at cutoff 1,336 1,239
Peak sampled process private memory 30.00 GiB 25.41 GiB

The matched images were frames 1247 at 86.623 s (off) and 1223 at 86.963 s (on). Memory comes from the nearest XCL activity samples at 86.054 and 86.037 s. Their artwork looks consistent in both readbacks. With the switch on, XCL explicitly logged 17,299 textures representing 2,135 MiB with 940 MiB backed at 65.389 s.

End of run. Both reached the configured cutoff with exit code 0, a null crash field and no logged D3D12 device removal. After the last interval with any presents, the logs recorded 52 large compute PSO builds finishing with the switch off, and 63 compute plus 2 graphics builds with it on. Pipeline builds were still progressing near cutoff. The logs do not identify which build, if any, held up the presenter.

Setup. RTX 4090 24 GB, NVIDIA 621.40, Ryzen 7 5800X3D, 32 GB RAM, Windows 11 build 26300. Retail 1.0.2.1, Series X. Built once with cargo build --locked --release -p xcl --bin xcl, Rust 1.99.1 MSVC. Ran xcl run <title> with XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_ACTIVITY=1 XCL_NETWORK=0 XCL_FRAME_DUMP=12 XCL_RUN_SECONDS=300. Identical scripted input and separate, identical starting copies of an already configured title profile and a 6,432-file XCL cache from earlier #2057 runs. Some large pipeline builds still lacked driver blobs on this head. Default ran first. NVIDIA’s internal cache was uncontrolled. An initial setup-only attempt with a blank profile was excluded from the pair.

Not tested: post-HUD stability, texture correctness in the rendered world, or behavior after 300 s. One run per setting. AI use: OpenAI Codex (GPT-6) built the PR, ran the pair, inspected the frame captures and logs, and drafted 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.

5 participants