Skip to content

D3D12.X: tiny sampled textures take 4 KiB heap slots, not 64 KiB tiles - #1248

Open
AmYisael wants to merge 1 commit into
xcl-dev:mainfrom
AmYisael:small-textures-4k
Open

AmYisael wants to merge 1 commit into
xcl-dev:mainfrom
AmYisael:small-textures-4k

Conversation

@AmYisael

Copy link
Copy Markdown

A sampled texture of at most 4 KiB that sits inside one 64 KiB page of the title's address (no page boundary within it) gets a whole 64 KiB "extra" tile on the title-texture pages (vram::Pages, keyed by its address). While a retail game loads its world it makes ~12 000 views by address of 16x4 R16G16B16A16_FLOAT textures of 1–2.5 KB each: 768 MiB of tiles for 20 MiB of textures (counted with a local log line, not in this PR). Part of #320.

What is in it

  • vram.rs: place_pages first tries place_small. A texture of ≤ 4 KiB on the console, single-sample, with no page boundary inside it, that the PC places in 4 KiB (GetResourceAllocationInfo with Alignment = 4096 says so) becomes a placed resource in 4 MiB heaps (DENY_BUFFERS | DENY_RT_DS_TEXTURES), one 4 KiB slot per title address. Anything else takes the pages as before.
  • Same sharing as the pages: textures at one address share the slot as they shared the extra tile, and they stay in PLACED_TEXTURES, so title_textures treats them as before. A slot no texture uses any more is reused after COOL (2 s).
  • The XCL_ACTIVITY "target pages N MB (pools M MB)" figure includes the small slots and heaps.
  • Tests: small_texture_slots_are_per_address_and_come_back_cooled (no GPU) and small_sampled_textures_take_slots_not_pages (GPU: 64 such textures take slots and no pages, a second one at an address shares its slot, two neighbours keep their own texels after a copy in and a read back, one over a page boundary still goes on the pages, released slots come back). It fails with place_small taken out ("small textures took pages").

Tested

  • Linux, not Windows: Manjaro, kernel 7.3, xcl.exe cross-built for x86_64-pc-windows-msvc (rustc 1.100.0) and run under GE-Proton11-12's Wine with a vkd3d-proton v3.1 build carrying Linux: docs/linux.md, scripts/linux and Wine start-up checks for vkd3d-proton and DXVK (#154, #241) #257's patch, DXVK's dxgi, DXC 1.9.2609. NVIDIA GeForce RTX 2060 SUPER 8 GB (driver 620.70; main's full-suite run below was on 615.71), Ryzen 5 3600, 16 GB RAM.
  • cargo test -p xcl --lib vram:: title_textures::: 24 passed, 0 failed on 620.70 (includes placed_title_textures_share_vram_and_preserve_pixels).
  • cargo test --workspace -- --test-threads=4 (debug), this branch (same tree as 7877001, driver 620.70): lib 643 passed, 57 failed, 21 ignored; e2e 2/1 failed; pls_quota 0/1; predication_e2e 0/1; the rest passed. main (47efa2e), same setup on driver 615.71: lib 642 passed, 56 failed. Same failures apart from the new GPU test, which fails there only on a poisoned VRAM_TEST_LOCK, as d32s8_targets_take_their_own_size_of_video_memory does on main. Most failures follow gpu_more_atomics_sub_dword_scratch_valu, which hangs the GPU on this stack and leaves the shared device removed.
  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64), gpu_console_textures_upload_every_mip_and_slice, gpu_upload_batches_reuse_the_queues_upload_buffer (no GPU).
  • Retail title, 300 s, A pressed from 100 s (XCL_PRESS_AT) into its world load, XCL_ACTIVITY=1. Title-texture pages / non-local video memory at the end: main 6963 / 7521 MB (300 s), this PR 4876 / 5381 MB (299 s). Local video memory is full (~7.6 GB) in both, so what the pages save is what spills into system memory. At ~240 s: main 4754 / 5204, PR 4055 / 4609 MB. The runs reach the world load at different times, so single runs vary: another run of the same tree ended at 5645 / 6211 MB. Earlier pairs on 615.71: 6025 → 4424 MB of pages (47efa2e), 5646 → 4500 MB (beaa245).

Regression run

Made by a line-for-line bash port of scripts/smoke.ps1 (no PowerShell here), A pressed from 100 s in both runs. peak commit is 0 because Wine reports no private bytes. Not every run here gets to 300 s: on this commit 3 of 4 runs ended with status 0x3 from an abort inside winevulkan / d3d12core (no xcl.exe frame on the stack), the same abort as in earlier runs of main (cedf8ce); on main 47efa2e one of three runs was killed at the 13 GB memory cap and one crashed in ucrtbase (read in a GPU view of CPU memory).

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 2060 SUPER
title: Xbox
seconds: 300
exit: 0x0
frames shown: 7578 (PresentX 7578)
presents per 2 s (last 3): 52 52 24
device removals: 0
crashes: 0
peak commit: 0 MB

PR:

xcl-smoke v1
commit: 78770017450281836c811b760a07ffb0401d40d6
gpu: NVIDIA GeForce RTX 2060 SUPER
title: Xbox
seconds: 300
exit: 0x0
frames shown: 7807 (PresentX 7807)
presents per 2 s (last 3): 57 5 52
device removals: 0
crashes: 0
peak commit: 0 MB

Not tested

  • Windows and any AMD GPU. Where the driver refuses 4 KiB placement for these textures, nothing changes.

AI use

  • Claude Code (Claude Opus 5.5): found the waste with local instrumentation, wrote the code, the tests and this description, and made the runs above; the account owner reviewed the diff before opening this PR.

A sampled texture of at most 4 KiB inside one 64 KiB page of the title's
address (no page boundary within it) got an extra 64 KiB tile on the
title-texture pages, keyed by its address. A retail game makes ~12 000 views
of 16x4 textures of 1-2.5 KB while it loads its world: 768 MiB of tiles for
20 MiB. Such a texture is now a 4 KiB-aligned placed resource in 4 MiB heaps
(when the PC places it with 4 KiB alignment), one slot per address: textures
at one address share it as they shared the tile, and it stays a placed texture
for title_textures. A slot no texture uses any more is reused after COOL.

Assisted-by: Claude Code (Claude Opus 5.5)
@AmYisael
AmYisael marked this pull request as ready for review November 24, 2026 13:47
@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib vram new tests (small_texture_slots, small_sampled_textures): 2 passed, 0 failed.

Thanks!

@Chrysana

Copy link
Copy Markdown

First native Windows / AMD run of 7877001. The memory saving holds, but the stretch after the first A press runs at about two-thirds of main's frame rate on this card.

Setup: AMD Radeon RX 9070 XT 16 GB (RDNA4), driver 32.0.32015.2008, Ryzen 7 9800X3D, 31 GB RAM, Windows 11 26200.9974, rustc 1.100.0 MSVC, release. Retail title 1.0.2.1, the same saved state for every run. main 47efa2e against this PR's head 7877001, which sits directly on 47efa2e. Runs alternate main / PR. Every run: XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_PRESS_A_AT=20,25,30.

Memory (does what it says): 240 s runs into the world load, two each.

target pages, peak local video memory, peak title's stop at +0x23cf683
main 9781 / 9778 MB 14176 / 14111 MB 146.9 / 133.9 s
this PR 9031 / 9067 MB 13476 / 13409 MB 140.8 / 137.9 s

That's about 0.7 GB less in both columns. The world load stalls the same way in all four runs: presents fall to 0 at 110–120 s, memory goes flat, then the title's own stop (#534). So the saving doesn't change how far the load gets here.

Regression: fewer frames after the first A press. scripts/smoke.ps1 -Seconds 60 from each tree, two rounds:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: AMD Radeon RX 9070 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1139 (PresentX 1139)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17259 MB
xcl-smoke v1
commit: 78770017450281836c811b760a07ffb0401d40d6
gpu: AMD Radeon RX 9070 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 708 (PresentX 709)
presents per 2 s (last 3): 35 25 27
device removals: 0
crashes: 0
peak commit: 16328 MB

Second round: main 1139 frames, PR 832 frames.

  • Where the frames go (XCL_ACTIVITY, the 240 s runs). From the first A press (~28 s) to ~56 s, the PR shows 25–42 presents per 2 s in both runs; main shows 60 in both. Draws per frame are the same (6), so it's the same content drawn more slowly. The stretch lasts ~28 s on the PR against ~19 s on main, which fits the same frames played slower. In earlier runs with frame captures on this machine, this stretch is the title's intro video. From ~58 s on, both are back at 60.
  • A lead, not checked further: the title textures: N uploads left out so far counter grows more slowly in that stretch on the PR. It reaches 1024 at 41–46 s and 2048 at 57 s, against main's ~30 s and ~34 s, about 2.5× fewer skipped uploads per frame even allowing for the lower frame rate. It may be that the small textures in 4 KiB slots no longer get the unchanged-content skip and are uploaded again.

Tests on this card: TESTS_PLACEHOLDER

Not tested

  • Where exactly the time goes. No profiler; the counters above are all from XCL's own log.
  • Other GPUs on Windows, and the full test suite.

AI use

  • Claude Code (Claude Opus 5.5) built both trees, ran the runs and tests, read the logs and drafted this comment. I checked it before posting.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…all#1248, ivall#1250, ivall#1265, ivall#1273, ivall#1277, ivall#1278

Fix sudden RAM OOM during world loading under XCL_PSO_WAIT_MS and integrate 6 new upstream PRs:
- pso_async.rs: track active waiters via WantGuard so build_is_wanted() drops back to false once resolve_within times out, preventing all background workers from bypassing BIG_COMPILES and commit-memory guards simultaneously (adds unit test a_timed_out_bind_clears_wanted_demand).
- ivall#1248: pack <= 4 KiB sampled textures into 4 KiB heap slots instead of 64 KiB tiles (~768 MiB VRAM saved).
- ivall#1250: late_release seals/waits only when nothing is in flight.
- ivall#1265: default SRVs of multisampled depth buffers use Texture2DMS/Texture2DMSArray.
- ivall#1273: skip budgeted bind waits when all workers are busy / build is queued behind others.
- ivall#1277: exit sparse::upload_dirty cleanly if staging ring fence wait times out.
- ivall#1278: isolate >= 4 MiB DXIL compute driver compiles in a dedicated GIANT_COMPILES queue.

Assisted-by: Antigravity (Google DeepMind)
@crosettiremi

Copy link
Copy Markdown

RDNA3 data point on Windows, RX 7900 XT, driver 32.0.32029.2010. I applied 7877001 to main 930e8b4 and ran the exact hardware test hle::d3d12x::vram::tests::small_sampled_textures_take_slots_not_pages. It passed in 0.26 s with no skip reported, including the 64 distinct addresses, reuse at the same address, and page-boundary fallback. This confirms 4 KiB placement support on this machine. I have no retail frame-time measurement for this PR on RDNA3 yet.

@grahamster2

Copy link
Copy Markdown
Collaborator

Test report on the retail title, on a 10 GB card. #1182 and #1248 were tested together, in one build. The savings below are for both combined, not split between them.

Builds

Setup: RTX 3080 10 GB (driver 610.88), Ryzen 5 7600X, 32 GB RAM, Windows 11 26200. Settings: XCL_NETWORK=0, XCL_PSO_PRELOAD=0, XCL_PSO_WAIT_MS=50. A pressed at 14, 17, 21, 25 and 31 s. Warm DXIL and driver blob caches. One run each. Both runs were stopped at about 100 s by my free-RAM guard (under 0.5 GB of RAM available).

Tested

From the XCL_ACTIVITY memory line. RAM available is GlobalMemoryStatusEx ullAvailPhys.

without with
target pages at 58 s 8641 MB (pools 8960) 6733 MB (pools 6924)
target pages at 74 s 9672 MB (pools 10176) 7081 MB (pools 7628)
video memory local at 74 s 14340 MB 11971 MB
video memory non-local at 74 s 4904 MB 4911 MB
physical RAM available at ~75 s 1994 MB 3175 MB
physical RAM available at ~66 s 4285 MB 3782 MB
device removals / crashes 0 / 0 0 / 0
  • What was saved: about 2.6 GB of target pages, 2.5 GB of pools and 2.4 GB of local video memory, after world start. That matches the 1.85 GB + 768 MiB estimated in the two PRs.
  • Physical RAM: the curves cross. The build with the PRs dips earlier (66 s), then levels off higher (3.2 GB vs 2.0 GB at 75 s).
  • The frame:
    • In the last frame I dumped (about 92 s), two 2560x1440 targets that were all zero in the runs without the PRs now have data: an R32G32 target (172 088 of 230 400 sampled texels non-zero) and an R16G16 target (230 332 of 230 400).
    • The frame had 2228 draws and dispatches, against 1293 in an earlier run without the PRs. That earlier run had 3 workers (XCL_DXC_THREADS=3) and preload on, so this comparison is loose.
    • The world is still black on this card. The G-buffer colour targets stay zero for a reason outside these PRs: large uncached pipeline builds that never finish.

Not tested

  • Each PR on its own: the savings are not split between them.
  • More than one run per build.
  • Cards with more or less than 10 GB, AMD and Wine.
  • Whether the aliased render targets now hold what the title wrote through the other alias. I only counted memory and non-zero texels.

Test report written with Claude Code (Claude Opus 5.5) from my own runs; the extra logging is local only.

@Royalflamejlh

Royalflamejlh commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Linux (Wine + vkd3d-proton) + NVIDIA test of 7877001 on main b7aa9f3 + #684, 5 alternated runs each way of a retail title on a 12 GB card: 38 s in, after the title has made its small textures, the title-texture pages were about 845 MB smaller and local video memory 836 MB lower with it, in 5 of 5 runs. The frame rate after the A press did not drop here.

Setup: Fedora 44 (kernel 7.2.9), Wine 11.21 Staging (Wayland driver), vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch, VKD3D_CONFIG=ignore_shared_fence. RTX 4070 12 GB (driver 615.71.09, 32-lane waves; the desktop is on it too), Ryzen 9 9950X3D, 64 GB RAM. Release, cross-compiled to x86_64-pc-windows-gnu (rustc 1.98.0), DXC 1.9.2609.5, XCL_NETWORK=0, XCL_PSO_PRELOAD=0, XCL_ACTIVITY=1. Retail title 1.0.2.1, the first-run screens completed once and no story progress, one A press on the account screen at 16 to 18 s. 7877001 merged onto main b7aa9f3 + #684 (e56dbc3) without conflicts. The first two runs of each tree were asked for 125 s and ended at the title's watchdog; the other three were 100 s runs. main is 9e3831e now.

Tested

  • cargo test --release -p xcl --lib for small_texture_slots and small_sampled_textures under Wine, on the merge: 2 passed, 0 failed, none skipped. So vkd3d-proton on this card places these textures at 4 KiB.
5 runs each b7aa9f3 + #684 the same + 7877001
at 30 s: target pages / local video memory 3581 to 3583 MB / 6659 MB 3575 to 3577 MB / 6663 MB
at 38 s: target pages (pools) 4533 to 4537 MB (4608) 3684 to 3693 MB (3772)
at 38 s: local video memory 7683 MB in 5 of 5 6847 MB in 5 of 5
at 80 s: target pages 9609, 9590, 9596, 9323, 9642 MB 8925, 8848, 8891, 8811, 8841 MB
at 80 s: local video memory 9502 to 9536 MB 9506 to 9547 MB
at 80 s: non-local video memory 8857, 8707, 8869, 8191, 8877 MB 8132, 8082, 8109, 7958, 7966 MB
presents in the 2 s activity lines from 2 s after the press to the line at 60 s 776, 797, 820, 843, 831 837, 828, 832, 856, 844
last 2 s with a present 72.2, 72.1, 72.3, 85.2, 80.1 s 70.2, 72.2, 70.1, 72.0, 76.2 s
the title's null write at game+0x23cf683 (the runs that went that far) 101.5, 102.5 s 98.5, 100.5, 98.5 s
DirectStorage requests failed (0x89240009) 0, 95, 96, 0, 1917 2101, 2047, 11, 71, 235

The readings are those of the memory: line nearest each time. Between 30 and 38 s the pages grow by about 950 MB without the change and by about 110 MB with it. By 80 s this card is full with or without the change (9.5 GB local; my guess is that this is what the title gets on a card that also holds the desktop), so later the saving shows elsewhere: the pages were 400 to 800 MB smaller, and non-local video memory was 7958 to 8132 MB against 8191 to 8877 MB. The runs end at the stall of #662 either way; a few hundred MB do not move it here.

The failed DirectStorage requests are the ones #549 is about. Their count swings between runs of one tree, on both sides, so I do not put the two high first runs with the change down to it.

Read

  • vram.rs:765 (place_small) and :782: a texture only takes a slot when the driver itself answers 4 KiB alignment and at most 4 KiB for it, and otherwise goes to the pages as before (:683). The test's pass above is that path under vkd3d-proton.
  • vram.rs:800: when a slot's new heap cannot be made, the slot is handed back by next -= 1. That is right while SMALL stays locked from take to here, which it does. A comment there would save the next reader the check.
  • vram.rs:831 (small_bytes): the memory: line's "target pages" now includes the slots in use and "pools" their 4 MiB heaps, so the numbers in the table are like for like.

Not tested: past the stall, where the description's 300 s numbers are; a card with free video memory at that point; the preload of #690 on; the rest of the test suite; AMD and Intel.

AI use: Claude Code (Claude Fable 5.2) read the diff, built the trees, ran the tests and the ten runs, compared the logs and wrote this report.

Edited 2026-11-24: removed a paragraph that said three runs without the change logged NVIDIA kernel messages and the runs with it did not. Every run logs the same 12 lines (_threadNodeCheckTimeout) about 12 s after XCL's process has ended; our harness caught them in some runs only. Also: the third Read point named the wrong log line, and the 9.5 GB remark is now marked as a guess.

@madaraXor

Copy link
Copy Markdown

Measured together with #1182 on a 12 GB RDNA2 card and the retail title (head 787700174 of this PR): local video memory at 280 s 6.7 GB instead of 8.6 GB, and under the card from there on, see #1182 (comment). I did not run the two apart.

AI use: Claude Code, Claude Opus 5.5 ran the runs and wrote this note.

@thiagocalile

Copy link
Copy Markdown

Tested commit 78770017450281836c811b760a07ffb0401d40d6 on an AMD Radeon RX 6600 (8 GB VRAM, RDNA2, native 64-lane waves) with targeted/workspace tests and a 60 s scripts/smoke.ps1 regression run (comparing against main 62265d3).

Tested

  • Hardware: AMD Radeon RX 6600 (8146 MiB VRAM, RDNA2, native wave64 + mesh shaders, driver 32.0.21045.29003; XCL_ADAPTER=radeon), AMD Ryzen 7 5700X3D, 47.9 GB RAM, Windows 11 (10.0.26200.0), Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.8.2502.11.
  • XCL_ADAPTER=radeon cargo test -p xcl --lib vram::tests -- --test-threads=4: 11 passed, 0 failed, 0 ignored (42.81s).
  • XCL_ADAPTER=radeon cargo test --workspace --no-fail-fast -- --test-threads=4: 739 passed, 4 failed, 41 ignored (54.32s).
    • Failures: the 3 pre-existing RX 6600 main failures (placed_title_textures_share_vram_and_preserve_pixels + 2 mutex-poison cascades; D3D12.X: map and unmap 3D texture mips separately #1028), plus small_sampled_textures_take_slots_not_pages hitting the same VRAM_TEST_LOCK poison cascade in the workspace run (it passed in targeted vram::tests: 11/0).

Regression run (scripts/smoke.ps1, 60 s, release build, XCL_ADAPTER=radeon)

Base (main 62265d3):

xcl-smoke v1
commit: 62265d3bbde2255f849fb650cc29872df91a4cf0
gpu: AMD Radeon RX 6600
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1517 (PresentX 1517)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13034 MB

PR (7877001):

xcl-smoke v1
commit: 78770017450281836c811b760a07ffb0401d40d6
gpu: AMD Radeon RX 6600
title: GTA6.Xbox.v1.0.2.1-CYBERLEEK
seconds: 60
exit: 0x0
frames shown: 1519 (PresentX 1519)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19948 MB

Not tested

  • D3D12 debug layer, NVIDIA / Intel GPUs, Linux / Wine.

AI use

  • Antigravity (Gemini 4 Neon) ran the test suites and scripts/smoke.ps1 runs on my RX 6600 and drafted this report; I checked the output before posting.

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.

9 participants