D3D12.X: a buffers-only heap gets a 64 KiB PC heap, not one of its full size #3377
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3377"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-29T11:17:54Z.
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
CreateHeapand gets a 64 KiB PC heap;GetDescanswers with the title's size rounded up to 64 KiB, and a title alignment above 64 KiB is promoted to 4 MiB, asdev_create_heapdoes 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=0turns it off.What is in it
crates/xcl/src/hle/d3d12x/real.rs(first commit): buffers-only heaps (ALLOW_ONLY_BUFFERS) get their block atCreateHeapand a 64 KiB PC heap, info lineD3D12.X: buffers-only heap of ...; testsonly_a_heap_that_denies_both_kinds_of_texture_is_buffers_onlyanda_small_buffer_heap_is_known_by_its_entrycrates/xcl/src/hle/d3d12x/real.rs(second commit): the small heap'sGetDescsize and alignment followdev_create_heap's normalisation (the first commit alone failedd3d12_create_heap'sconsole_heap_descs_refused_by_host_are_normalized_by_xclwith 0x12345 where 0x20000 is expected); to be squashed into the first before reviewREADME.md:XCL_SMALL_BUFFER_HEAPSTested
cargo test --workspace --no-fail-fast -- --test-threads=4with the threeuma_drivertests below skipped, one8f6939359: 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: 21no wave64(this card runs wave32), 3 a wave32 per-lane form refused by the translator (#1426), 2no heap windows(opt-inXCL_HEAP_WINDOWS=1), 1no dxc.exe, 1cannot disable the driver cache(needs Windows Developer Mode))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"), onmaintoocargo test -p xcl --lib -- --test-threads=4, same skips): 2468 passed, 0 failed; 2468 passed, 0 failedE_OUTOFMEMORY(0x8007000E) while the run shared the 8 GB card with the other tests and the desktop; alist_xtest failed the same way once on another branch of this set that changes no D3D12 code (DirectStorage only); it passed in the other runs heremainfa204595a4: 2605 passed, 0 failed, 49 ignored, 28SKIPPEDlines (own-prs-20261129 run, same command)scripts/smoke.ps1, no input, copied profile and shader cache): blocks belowRegression run
Not tested
buffers-only heapline 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
Optional temporary Discord for coordinating contributor work, testing and comparing results.
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-29T13:47:45Z.
Reviewed and tested at
e8f69393.Code review findings
CreateHeap(small_buffer_heap,crates/xcl/src/hle/d3d12x/real.rs): Previouslynote_heap_umaleftblock: Noneandheap_block()allocated unified memory lazily on the first placed buffer.small_buffer_heapnow callsheap_block(heap)eagerly duringCreateHeap/CreateHeap1. Any buffers-only heap created ahead of time (or never populated, or aREADBACKheap<= COHERENT_READBACK_MAX) now consumes sparse/coherent UMA immediately. Also, ifUMA_BUFFERis empty,small_buffer_heapstill creates and immediatelyRelease()s a 64 KiB PC heap before falling back todev_create_heap_pc. CheckingUMA_BUFFERbefore callingcreate(&d)would avoid the wasted round-trip.CreatePlacedResource1bypass: Onlyplaced_in_heap_xreceived theis_small_buffer_heap(heap)committed-resource fallback (hr3). AnyCreatePlacedResource1call on a small-buffer heap withoffset + size > 64 KiBwill fail withE_INVALIDARG.small_buffer_heapsetsd.Alignment = D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT(4 MiB) whentitle.Alignment > 0x1_0000while settingd.SizeInBytes = SMALL_BUFFER_HEAP(64 KiB). D3D12 rejectsSizeInBytes < Alignment, wasting a failedCreateHeapcall before falling back. Sincebuffers_onlyforbids textures,d.Alignment = 0is always valid for the 64 KiB PC heap.mem_heap_get_descand >64 KiB placement: The new tests coverbuffers_only()and a directHEAP_UMAmap lookup, but nothing exercises the adoptedID3D12Heap::GetDeschook (ABI + roundedSizeInBytes) or placing a >64 KiB buffer in a small-buffer heap on D3D12.Tested locally
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
Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-29T14:00:02Z.
Ran the buffers-only heap tests at
e8f69393on 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.
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.
Imported from ivall/xcl. Originally posted by minimalhipster990 on 2026-11-29T18:08:14Z.
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
--locked.main7a649b0e+ #3318 headf5496479(so the title gets past its load stall) + #3344 head0f0cc342+ this PR's heade8f69393. Clean merges, local commit9ff5fe40.cargo test --release --locked -p xcl --lib -- only_a_heap_that_denies_both_kinds_of_texture_is_buffers_only a_small_buffer_heap_is_known_by_its_entry --test-threads=1: 2 passed, 0 failed.XCL_ACTIVITY=1 XCL_GFX_PSO_WAIT_MS=50 XCL_CS_PSO_WAIT_MS=200 XCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16 XCL_COHERENT_HEAPS=sparse XCL_TEXTURE_LEVEL_PAGES=1 XCL_COHERENT_MB=3990 XCL_TWO_PASS_MB=3072,XCL_PREPARE=0,XCL_SMALL_BUFFER_HEAPSunset.Results
buffers-only heap of …lines.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:own_work, sparse pools)0xC0own_work)0x00x0small_buffer_heaprightly leaves alone (is_own_work).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.
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-29T22:39:38Z.
Review: COMMENTED
Static review of
e8f69393for the stack in the #3041 comparison.I confirmed the
CreatePlacedResource1bypass reported by saintwolf. For example,CreateHeap1can 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, butCreatePlacedResource1passes 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 wrapperReview assisted by Codex (GPT-6, exact variant unavailable). No new build or GPU run for this review.
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-29T22:43:23Z.
Review: COMMENTED
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, butCreatePlacedResource1still bypassesplaced_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 aCreateHeap1+CreatePlacedResource1regression. Also account for the new eager UMA reservation atCreateHeap: 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.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:35:48Z.
Review (head
e8f69393, diff read, not a merge-check; draft, so not built or run):UpdateTileMappings/CopyTileMappings(the hooked queue slots start atQUEUE_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).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. Anyhr2failure (bad description or state) also turns into a committed resource instead of an error.CreateHeap(~4765), not on the first placed buffer, which reverses the lazy rule documented in main'snote_heap_uma(~4697-4707, unified memory filling up and the image flickering). An unused buffers-only heap now holds unified memory.GetDesc, a placement past 64 KiB, or the fallback. The smoke run doesn't reach this code, and the memory saved isn't measured.mem_heap_get_desc(~4787) assumes the (this, out) argument order, while the descriptor-heapGetDeschook 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
GetDescsize matchesdev_create_heap's rounding,XCL_SMALL_BUFFER_HEAPS=0turns 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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T15:54:12Z.
Test report (not a merge-check: draft)
, wanted " when remaking a mixed window (base:
b2b1f109d2head:
e8f6939359merge: 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 https://github.com/xcl-dev/xcl/pull/3377#issuecomment-7299868751, 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_customandmixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment, both "Map gaveuma_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 ofcargo test -p xcl --lib uma_drivera 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.