Skip to content

D3D12.X: a buffers-only heap gets a 64 KiB PC heap, not one of its full size - #3377

Draft
Prime1997 wants to merge 2 commits into
xcl-dev:mainfrom
Prime1997:contrib/small-buffer-heaps
Draft

Prime1997 wants to merge 2 commits into
xcl-dev:mainfrom
Prime1997:contrib/small-buffer-heaps

Conversation

@Prime1997

Copy link
Copy Markdown
Collaborator

Requested by Prime

Every heap the title makes gets a PC heap of its full size, and a heap that may hold buffers also gets a block of unified memory as large when its first buffer is placed: buffers go in the block (console code reads them at their addresses), textures in the PC heap. A heap made with ALLOW_ONLY_BUFFERS (both texture kinds denied) never holds a texture, so its PC heap was video memory of the heap's whole size that nothing was placed in, on top of the block.

Such a heap now takes its block at CreateHeap and gets a 64 KiB PC heap; GetDesc answers with the title's size rounded up to 64 KiB, and a title alignment above 64 KiB is promoted to 4 MiB, as dev_create_heap does for any heap description the PC refuses. A buffer that cannot go in the block (and does not fit in the 64 KiB) gets memory of its own of the heap's kind, as a texture past a heap's end already does. When unified memory is full the heap is made as before. XCL_SMALL_BUFFER_HEAPS=0 turns it off.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs (first commit): buffers-only heaps (ALLOW_ONLY_BUFFERS) get their block at CreateHeap and a 64 KiB PC heap, info line D3D12.X: buffers-only heap of ...; tests only_a_heap_that_denies_both_kinds_of_texture_is_buffers_only and a_small_buffer_heap_is_known_by_its_entry
  • crates/xcl/src/hle/d3d12x/real.rs (second commit): the small heap's GetDesc size and alignment follow dev_create_heap's normalisation (the first commit alone failed d3d12_create_heap's console_heap_descs_refused_by_host_are_normalized_by_xcl with 0x12345 where 0x20000 is expected); to be squashed into the first before review
  • README.md: XCL_SMALL_BUFFER_HEAPS

Tested

  • RTX 3060 Ti 8 GB (driver 32.0.16.1714), Intel Core i5-10400, 32 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0; the suite in debug, the smoke on a release build of the head commit
  • cargo test --workspace --no-fail-fast -- --test-threads=4 with the three uma_driver tests below skipped, on e8f6939: 2606 passed, 1 failed, 49 ignored; failing: hle::d3d12x::list_x::tests::mid_list_write64_wait64_split_avoids_cycle_and_reuses_spares (SKIPPED GPU tests: 28 lines: 21 no wave64 (this card runs wave32), 3 a wave32 per-lane form refused by the translator (gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426), 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1), 1 no dxc.exe, 1 cannot disable the driver cache (needs Windows Developer Mode))
  • the three skipped tests on their own (cargo test -p xcl --lib -- --test-threads=1 uma_driver::tests::a_refused_gpu_upload_segment_becomes_custom uma_driver::tests::mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment uma_driver::tests::failed_restore_stops_before_importing_an_unbacked_window): 3 passed, 0 failed. They are left out of the whole run because on this PC's driver they can end the library test process (exit 0x7c10003, "coherent window could not be restored"), on main too
  • the library harness twice more (cargo test -p xcl --lib -- --test-threads=4, same skips): 2468 passed, 0 failed; 2468 passed, 0 failed
  • the failure above: the test's D3D12 call returned E_OUTOFMEMORY (0x8007000E) while the run shared the 8 GB card with the other tests and the desktop; a list_x test failed the same way once on another branch of this set that changes no D3D12 code (DirectStorage only); it passed in the other runs here
  • the whole run again on the same head: 2607 passed, 0 failed, 49 ignored
  • the same whole run on main fa20459: 2605 passed, 0 failed, 49 ignored, 28 SKIPPED lines (own-prs-20261129 run, same command)
  • retail title (60 s scripts/smoke.ps1, no input, copied profile and shader cache): blocks below

Regression run

xcl-smoke v1
commit: fa204595a488c60c6c5f905244f0172072c9c2a9
gpu: NVIDIA GeForce RTX 3060 Ti
title: 419239bf
seconds: 60
exit: 0x0
frames shown: 1334 (PresentX 1334)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 15272 MB
xcl-smoke v1
commit: e8f6939359232ce5272d2ff3e01c109ede2bd192
gpu: NVIDIA GeForce RTX 3060 Ti
title: 419239bf
seconds: 60
exit: 0x0
frames shown: 1294 (PresentX 1294)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15303 MB

Not tested

  • AMD GPUs (this is an NVIDIA wave32 card)
  • the retail title's world: the 60 s runs end on the title's start-up screens
  • The retail title's 60 s smoke made no buffers-only heap (no buffers-only heap line in its log), so the smoke does not reach this code; the memory saved was not measured on a title that makes such heaps.

AI use

  • Claude Code wrote the change and its test, wrote this description, and ran the tests and the smoke runs on this PC. The model is not named here: this session cannot tell which model served each turn.

Optional temporary Discord for coordinating contributor work, testing and comparing results.

🤖 Generated with Claude Code

Prime1997 and others added 2 commits November 29, 2026 06:58
…ll size

Every heap the title makes gets a PC heap of its full size, and a heap that may hold buffers
also gets a block of unified memory as large when its first buffer is placed: buffers go in
the block (console code reads them at their addresses), textures in the PC heap. A heap made
with ALLOW_ONLY_BUFFERS (both texture kinds denied) never holds a texture, so its PC heap was
video memory of the heap's whole size that nothing was placed in, on top of the block.

Such a heap now takes its block at CreateHeap and gets a 64 KiB PC heap; GetDesc still
answers with the title's size. A buffer that cannot go in the block (and does not fit in the
64 KiB) gets memory of its own of the heap's kind, as a texture past a heap's end already does.
When unified memory is full the heap is made as before. XCL_SMALL_BUFFER_HEAPS=0 turns it off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DaZV7vMq866ni7pGnJC2Ew
A buffers-only heap with a 64 KiB PC heap answered GetDesc with the title's exact size, and
its PC heap was made with alignment 0 whatever the title asked. A heap made the usual way
from a description the PC refuses has its size rounded up to 64 KiB and an alignment above
64 KiB promoted to 4 MiB (dev_create_heap), and d3d12_create_heap's
console_heap_descs_refused_by_host_are_normalized_by_xcl checks exactly that: it failed on the
RTX 3060 Ti with 0x12345 where 0x20000 was expected. The small heap now does the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DaZV7vMq866ni7pGnJC2Ew
@Prime1997 Prime1997 self-assigned this Nov 29, 2026
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@saintwolf

Copy link
Copy Markdown
Contributor

Reviewed and tested at e8f69393.

Code review findings

  1. Eager UMA allocation on CreateHeap (small_buffer_heap, crates/xcl/src/hle/d3d12x/real.rs): Previously note_heap_uma left block: None and heap_block() allocated unified memory lazily on the first placed buffer. small_buffer_heap now calls heap_block(heap) eagerly during CreateHeap / CreateHeap1. Any buffers-only heap created ahead of time (or never populated, or a READBACK heap <= COHERENT_READBACK_MAX) now consumes sparse/coherent UMA immediately. Also, if UMA_BUFFER is empty, small_buffer_heap still creates and immediately Release()s a 64 KiB PC heap before falling back to dev_create_heap_pc. Checking UMA_BUFFER before calling create(&d) would avoid the wasted round-trip.
  2. CreatePlacedResource1 bypass: Only placed_in_heap_x received the is_small_buffer_heap(heap) committed-resource fallback (hr3). Any CreatePlacedResource1 call on a small-buffer heap with offset + size > 64 KiB will fail with E_INVALIDARG.
  3. Alignment > 64 KiB rejected by D3D12: small_buffer_heap sets d.Alignment = D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT (4 MiB) when title.Alignment > 0x1_0000 while setting d.SizeInBytes = SMALL_BUFFER_HEAP (64 KiB). D3D12 rejects SizeInBytes < Alignment, wasting a failed CreateHeap call before falling back. Since buffers_only forbids textures, d.Alignment = 0 is always valid for the 64 KiB PC heap.
  4. Missing test coverage for mem_heap_get_desc and >64 KiB placement: The new tests cover buffers_only() and a direct HEAP_UMA map lookup, but nothing exercises the adopted ID3D12Heap::GetDesc hook (ABI + rounded SizeInBytes) or placing a >64 KiB buffer in a small-buffer heap on D3D12.

Tested locally

  • Windows 11 (build 26300), NVIDIA GeForce RTX 4070 SUPER (driver 32.0.16.2140), AMD Ryzen 7 7800X3D, rustc 1.100.0.
  • cargo test -p xcl --lib hle::d3d12x::real::heap_release_order_tests:: -- --test-threads=1: 5 passed, 0 failed.

AI use

  • Antigravity (Gemini 4 Neon) assisted with code review and drafting; all builds and tests were executed locally on the hardware above.

@Aniseto

Aniseto commented Nov 29, 2026

Copy link
Copy Markdown

Ran the buffers-only heap tests at e8f69393 on an NVIDIA Blackwell desktop part:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

XCL_ADAPTER=NVIDIA cargo test -p xcl --lib only_a_heap_that_denies_both_kinds_of_texture_is_buffers_only -- --test-threads=1
1 passed; 0 failed; 0 ignored; 0 measured; 2499 filtered out      (exit 0)

XCL_ADAPTER=NVIDIA cargo test -p xcl --lib a_small_buffer_heap_is_known_by_its_entry -- --test-threads=1
1 passed; 0 failed; 0 ignored; 0 measured; 2499 filtered out      (exit 0)

Both new tests pass: only a heap that denies both texture kinds is classified as buffers-only, and a small buffer heap is known by its entry with the 64 KiB PC heap size. The PR is a draft and has no comments yet, so this is the first datapoint in the thread and the first from an RTX 5070 Ti. These are CPU-side classification tests, not a title memory comparison.

Not tested: a retail title, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

@minimalhipster990

Copy link
Copy Markdown

RTX 4090, a retail title through world loading: it never makes a buffers-only heap, so this PR has nothing to act on there. This covers the "retail title's world" case in the description's Not tested.

Setup

Results

  • One 220 s run of the tree as it is: 0 buffers-only heap of … lines.
  • Two more runs, 220 s and 300 s (the 300 s one was cut short by a device removal at 295.6 s, 1.0 GB of system commit left), with a local probe at the top of dev_create_heap / dev_create_heap1. It logged each heap kind (is_own_work(), flags, type, size) when its count reached a power of two. Both runs logged the same kinds; the counts below are from the 300 s run:
made by flags type size count
XCL (own_work, sparse pools) 0xC0 DEFAULT 4 MiB 2,048 or more by 90 s
XCL (own_work) 0x0 DEFAULT 64 MiB 64 or more by 45 s
the title 0x0 DEFAULT 128 KiB – 63.75 MiB, alignment 64 KiB 11 sizes; 16–21 heaps (330–490 MB) by the last line at 18.0 s
  • Every kind is logged at its first heap, so a buffers-only heap made by the title would have shown up at once; none did. The title's heaps all allow textures. After 18 s no new kind appeared and no count reached its next power of two. The only buffers-only heaps are XCL's sparse pools, which small_buffer_heap rightly leaves alone (is_own_work).
  • The probe was a local diagnostic only (24 lines in real.rs, not part of any PR).

Not tested: other titles, a run past 300 s that reaches the world with this PR (the one 300 s run did not; my #3318 runs with the same setup reached it in 5 of 6, at 169–320 s), AMD, and any memory or frame-time effect: with no heap to act on, there is none to measure on this title.

AI use: Claude Code (Claude Opus 5.5) built the tree, wrote the probe, ran the tests and the replays, and wrote this report. The person running these tests asked for it.

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

Static review of e8f69393 for the stack in the #3041 comparison.

I confirmed the CreatePlacedResource1 bypass reported by saintwolf. For example, CreateHeap1 can return a 64 KiB native heap while reporting the requested 4 MiB. Placing a 64 KiB buffer at offset 64 KiB fits that reported heap, but CreatePlacedResource1 passes the operation straight to the native driver and it fails against the actual heap. A regression test using those two entry points would cover the gap. Heap creation ?? Placement wrapper

Review assisted by Codex (GPT-6, exact variant unavailable). No new build or GPU run for this review.

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

Critical review of current head e8f69393 (source and existing Windows reports; I did not run Windows tests here). Changes needed: The small native heap reports the title's full size, but CreatePlacedResource1 still bypasses placed_in_heap_x; a legal buffer placement beyond 64 KiB can therefore fail against the real 64 KiB heap. Please route all placed-resource entry points through the same UMA/committed fallback and add a CreateHeap1 + CreatePlacedResource1 regression. Also account for the new eager UMA reservation at CreateHeap: unused buffers-only heaps now consume the full block. The existing review describes that lifetime cost. A retail-world run in this thread observed no buffers-only heaps, so the claimed FPS/memory benefit needs a workload that exercises this path.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head e8f6939, diff read, not a merge-check; draft, so not built or run):

  • Title tile mappings into a buffers-only heap. I found no XCL hook on the queue's UpdateTileMappings / CopyTileMappings (the hooked queue slots start at QUEUE_FIRST = 14), so a title's call reaches the PC with the title heap as it is. If a title maps a reserved buffer into a buffers-only heap past 64 KiB, that offset is now out of range of the 64 KiB PC heap; on main the PC heap is full size. I don't know whether any title does this, but it's worth ruling out (or refusing the small heap once a heap is used for tile mappings).
  • Fallback (real.rs ~4461). When placement in the block fails, a buffer that doesn't fit in the 64 KiB becomes its own committed resource. On main it was placed in the PC heap at its offset, so such buffers still aliased each other; now they don't. Any hr2 failure (bad description or state) also turns into a committed resource instead of an error.
  • The block is taken at CreateHeap (~4765), not on the first placed buffer, which reverses the lazy rule documented in main's note_heap_uma (~4697-4707, unified memory filling up and the image flickering). An unused buffers-only heap now holds unified memory.
  • The tests don't test the claim: they cover the flag check and a map lookup, but nothing creates a buffers-only heap and checks the 64 KiB PC heap, GetDesc, a placement past 64 KiB, or the fallback. The smoke run doesn't reach this code, and the memory saved isn't measured.
  • Minor: mem_heap_get_desc (~4787) assumes the (this, out) argument order, while the descriptor-heap GetDesc hook handles both. The second commit is a fixup to squash, CI is red on 2 lib tests that look unrelated, and AI use names no model.

Fine: the buffers-only check is conservative, failure paths release the heap and fall back to the old path, Release frees the block, the GetDesc size matches dev_create_heap's rounding, XCL_SMALL_BUFFER_HEAPS=0 turns it off, and the README is updated.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Foniass

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Test report (not a merge-check: draft)
base: b2b1f10
head: e8f6939
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2902 passed, 2 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: hle::d3d12x::uma_driver::tests::a_refused_gpu_upload_segment_becomes_custom, hle::d3d12x::uma_driver::tests::mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment
review: not repeated here; my review of this same head is at #3377 (comment), and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: no smoke run.
assessment: 2 tests failed in both runs of this merge: uma_driver::tests::a_refused_gpu_upload_segment_becomes_custom and mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment, both "Map gave

, wanted " when remaking a mixed window (uma_driver.rs ~756 / ~810). Correction to an earlier version of this comment: the same failure also hit #2991 and, once, #3318 (which doesn't touch heaps), while two full runs of main passed them. So it is intermittent on this machine, not clearly caused by this PR, though it hit this PR in both of its runs. A local run of cargo test -p xcl --lib uma_driver a few times on this head would settle it. The rest of the suite passes, and the findings in my review stand.
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

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

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants