Skip to content

D3D12.X: read a view heap's slots in place when scanning for superseded targets - #3592

Open
Royalflamejlh wants to merge 2 commits into
xcl-dev:mainfrom
Royalflamejlh:d3d12x/superseded-scan-in-heap
Open

Royalflamejlh wants to merge 2 commits into
xcl-dev:mainfrom
Royalflamejlh:d3d12x/superseded-scan-in-heap

Conversation

@Royalflamejlh

@Royalflamejlh Royalflamejlh commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #3443; only the top commit (662209739) belongs here.

With #3443, once any render target is superseded, every draw and dispatch bound on XCL's ABI reads each descriptor range its layout declares, one 32-byte slot at a time (about 41 reads a bind), through title_textures::read_committed_into. Under Wine that function asks VirtualQuery region by region (its whole-range read is skipped there, #2844), each call under Wine's one virtual-memory lock. A range inside a registered view heap is now copied where it is: its slots stay committed while the heap is registered. Ranges outside every heap are read as before.

What is in it

  • hle/d3d12x/bind.rs (scan_superseded_in_tables_with): a range inside a registered view heap is read in place; a test that the scan reads such ranges where they are (5 against 0 without the change).

Tested

  • RTX 4060 Ti 16 GB, NVIDIA 615.71.09, AMD Ryzen 9 9950X3D, Linux, Wine 11.21 Staging, Rust 1.98.0, x86_64-pc-windows-gnu, release, head 6ccc2f80c (Foniass's review points fixed; the results below that name 662209739 were taken there) on D3D12.X: look for superseded targets in every declared table range #3443's 7afecf845: cargo test -p xcl --release --lib -- bind::: 115 passed, 1 failed (gpu_two_pass_indirect_commands_keep_their_own_records, which fails on main 6bfb5c515 here too), 1 SKIPPED.
  • Whole lib suite at 6ccc2f80c, under Wine on CPU Vulkan (no card), cargo test -p xcl --release --lib -- --test-threads=4: 2578 passed, 13 failed, 29 ignored; the parent 7afecf845 fails the same 13; main 6bfb5c51: 2735 passed, 11 failed (the 2 extra here are the indirect_guard tests, fixed on main after this branch's base). Skipped on all three trees: a test that crashes the binary under Wine, the D32S8 test that hangs under Wine, and the uma_driver tests (over 12 GB).
  • In a retail title on a tree that carries D3D12.X: look for superseded targets in every declared table range #3443 and other unmerged pull requests, with XCL's own memory-call counters (XCL_LOOK_STATS=2, from another fork), 1 run each, 900 s: the VirtualQuery call site in read_committed_into made 150,000 to 195,000 calls a second, 1.12 s of thread time a second on average; frames a second in the world 1.19. With this change and two others of ours together (a cheaper Wine read in read_committed_into, and reusing the memory report's commit sum): that call site was not in the top list, and 3.70 frames a second. The gain from this change alone was not measured.

Regression run

  • None yet: no Windows machine of ours was reachable. The two xcl-smoke blocks are owed.

Not tested

  • Native Windows (there read_committed_into makes one ReadProcessMemory for the range, so the gain is expected to be small), AMD, the whole suite.

AI use

  • Claude Code. Claude Opus 5.5 found the caller, wrote the change and the test, and wrote this description; the title runs were made on the same machine.

A superseded target bound through a descriptor table is remapped when a draw
or dispatch binds the table (xcl-dev#3179), but only the first 256 slots of each
table were read. A view further in – a bindless SRV range, or a range at an
explicit offset past slot 256 – was never seen: the target kept no tiles,
its writes were dropped and its reads returned zeros.

The root signature's SRV and UAV ranges of each descriptor table (RTS0 1.0
and 1.1, appended and unbounded ones included) are now kept in the layout,
and the scan reads those ranges and nothing else. An unbounded range ends
with the view heap the table lies in (console_heap::view_heap_remaining_slots);
outside any view heap it has no known extent and is not read. CBV and sampler
ranges cannot name a placed target and are skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 1, 2026
Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head 6622097, diff read, not a merge-check; draft, checks red):

  • The heap can be freed between the lookup and the in-place copy. view_heap_remaining_slots (console_heap.rs ~1088) drops HEAPS before it returns, and scan_superseded_in_tables_with then copies the slots straight from the heap's memory (bind.rs ~1341, ~1358) with no lock or lease. If unregister runs on another thread in that gap, free gives the memory back (sparse::free decommits it; title-memory heaps go back through XMemFree), and the raw copy faults where read_committed_into returned zeros. The module's other in-place readers (view_slot_words, exact_view_slot_words, ~1464) keep HEAPS held while they copy for this reason; doing the copy under that lock would close the gap.
  • Regression run and whole-suite counts missing. Regression run has no xcl-smoke blocks (the reason PR description is red), and Tested reports only cargo test -p xcl --release --lib -- bind::.

Fine: the fast path only applies when the table lies in a registered view heap, each range is cut to that heap's end, ranges outside any heap still go through read_committed_into, and the new test would fail without the change. The diff also carries #3443's commit, as the description says.

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

…ed targets

While any target is superseded, every draw and dispatch bound on XCL's ABI
scans the descriptor ranges its layout declares for views of superseded
targets (note_superseded_in_tables, xcl-dev#3443). A table outside the committed
window, such as the title's view heaps in sparse window 0, was read with
read_committed_into, one read for each declared range (about 41 a bind
in that run), and under Wine each read asks VirtualQuery first (Windows
reads it with one ReadProcessMemory). In a run in the title's world that
VirtualQuery was the first call site of all, about 17 µs a call for a
32-byte slot.

A range inside a registered view heap is already cut to the heap's end,
and the heap's slots are committed while it is registered (XCL commits a
heap it places in the sparse windows; one in the title's memory was
committed when it was made): such a range is now copied where it is,
under HEAPS as view_slot_words copies, so a heap unregistered on another
thread since its lookup is not freed under the copy; it is then read
with read_committed_into, as a range outside any view heap is.

Measured with two other changes (one read of a few resident pages in
read_committed_into under Wine, and the memory report reusing its commit
sum) on a tree carrying other unmerged work, RTX 4060 Ti, Wine 11.21,
1 run each with the same options, the title in its world: 1.19 -> 3.70
frames a second. What each change gives on its own was not measured.

Test: in-heap ranges are found without read_committed (red without the
change); a bounded range outside any heap, or in one unregistered since
its lookup, is read through it; a view heap's slots are copied only
while it is registered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Royalflamejlh
Royalflamejlh force-pushed the d3d12x/superseded-scan-in-heap branch from 6622097 to 6ccc2f8 Compare December 1, 2026 21:36
@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

@Foniass thanks; fixed at 6ccc2f80c (one commit on #3443's 7afecf845).

  • copy_view_heap_slots (console_heap.rs) copies under HEAPS, as view_slot_words does; if the heap is gone, the range goes through read_committed_into. The bind test fails without the change, and view_heap_slots_are_copied_only_while_the_heap_is_registered checks the lock.
  • Whole lib suite under Wine 11.21 (CPU Vulkan, 4 threads): 2578 passed, 13 failed, 29 ignored. The parent 7afecf845 fails the same 13. main 6bfb5c51: 2735 passed, 11 failed; the 2 extra here are the indirect_guard tests, fixed on main after this branch's base. Skipped on all three trees: one test that crashes the binary under Wine, the D32S8 test that hangs under Wine, and the uma_driver tests (over 12 GB). The smoke pair is still owed.

AI use: Claude Code (Claude Opus 5.5) made the change, ran the tests and drafted this reply.

@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Follow-up review (head 6ccc2f8, since 6622097, diff read, not a merge-check; draft, checks red):

  • The heap can be freed between the lookup and the in-place copy: fixed. The copy now goes through copy_view_heap_slots (console_heap.rs ~1097), which holds HEAPS while it checks that the range lies in one registered view heap and while it copies; every path that frees a heap (unregister, take, take_after_release, ~907-940) removes it from HEAPS before free, and a heap that went away falls back to read_committed_into (bind.rs ~1361). Both new tests cover the unregistered case.
  • Regression run and whole-suite counts missing: still open. Regression run has no xcl-smoke blocks (the reason PR description is red); the whole-suite counts are only in a reply comment, from a --lib run under Wine, and Tested still lists only bind::.

New: none.

Fine: the in-place copy now runs under HEAPS like view_slot_words, the lock is taken where view_heap_remaining_slots already took it so there is no new lock order, and ranges outside a registered heap still go through read_committed_into. Still carries #3443's commit, as the description says.

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

Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Dec 1, 2026
The merge of 6ccc2f8 kept the stack's older line, which copied a view heap's slots without HEAPS; the
reviewed head copies them under it (copy_view_heap_slots) and its test failed here without this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@Royalflamejlh
Royalflamejlh marked this pull request as ready for review December 2, 2026 02:18
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:memory Virtual/physical memory, arenas, VRAM budget, UMA 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.

3 participants