D3D12.X: read a view heap's slots in place when scanning for superseded targets #3592
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3592"
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 Royalflamejlh on 2026-12-01T17:30:09Z.
Stacked on #3443; only the top commit (
00ce5644c) belongs here. (Edited: rebased ontomain1c8b5514; #3443's commit is carried asc7eccd9d9, its author kept, so the branch builds on today'smain.)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 asksVirtualQueryregion 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
x86_64-pc-windows-gnu, release, head6ccc2f80c(Foniass's review points fixed; the results below that name662209739were taken there) on #3443's7afecf845:cargo test -p xcl --release --lib -- bind::: 115 passed, 1 failed (gpu_two_pass_indirect_commands_keep_their_own_records, which fails onmain6bfb5c515here too), 1 SKIPPED.6ccc2f80c, under Wine on CPU Vulkan (no card),cargo test -p xcl --release --lib -- --test-threads=4: 2578 passed, 13 failed, 29 ignored; the parent7afecf845fails the same 13;main6bfb5c51: 2735 passed, 11 failed (the 2 extra here are theindirect_guardtests, fixed onmainafter 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 theuma_drivertests (over 12 GB).XCL_LOOK_STATS=2, from another fork), 1 run each, 900 s: theVirtualQuerycall site inread_committed_intomade 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 inread_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
RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, Windows 11 Pro 26200, release builds by
scripts/smoke.ps1, the same retail title for 60 s each.main:this PR's head:
Not tested
read_committed_intomakes oneReadProcessMemoryfor the range, so the gain is expected to be small), AMD, the whole suite.AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T20:45:36Z.
Review (head
66220973, diff read, not a merge-check; draft, checks red):view_heap_remaining_slots(console_heap.rs~1088) dropsHEAPSbefore it returns, andscan_superseded_in_tables_withthen copies the slots straight from the heap's memory (bind.rs~1341, ~1358) with no lock or lease. Ifunregisterruns on another thread in that gap,freegives the memory back (sparse::freedecommits it; title-memory heaps go back throughXMemFree), and the raw copy faults whereread_committed_intoreturned zeros. The module's other in-place readers (view_slot_words,exact_view_slot_words, ~1464) keepHEAPSheld while they copy for this reason; doing the copy under that lock would close the gap.xcl-smokeblocks (the reasonPR descriptionis red), and Tested reports onlycargo 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.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-01T21:37:10Z.
@Foniass thanks; fixed at
6ccc2f80c(one commit on #3443's7afecf845).copy_view_heap_slots(console_heap.rs) copies underHEAPS, asview_slot_wordsdoes; if the heap is gone, the range goes throughread_committed_into. The bind test fails without the change, andview_heap_slots_are_copied_only_while_the_heap_is_registeredchecks the lock.7afecf845fails the same 13.main6bfb5c51: 2735 passed, 11 failed; the 2 extra here are theindirect_guardtests, fixed onmainafter 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 theuma_drivertests (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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T21:41:55Z.
Follow-up review (head
6ccc2f80, since66220973, diff read, not a merge-check; draft, checks red):copy_view_heap_slots(console_heap.rs~1097), which holdsHEAPSwhile 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 fromHEAPSbeforefree, and a heap that went away falls back toread_committed_into(bind.rs~1361). Both new tests cover the unregistered case.xcl-smokeblocks (the reasonPR descriptionis red); the whole-suite counts are only in a reply comment, from a--librun under Wine, and Tested still lists onlybind::.New: none.
Fine: the in-place copy now runs under
HEAPSlikeview_slot_words, the lock is taken whereview_heap_remaining_slotsalready took it so there is no new lock order, and ranges outside a registered heap still go throughread_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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T02:44:58Z.
Follow-up review (head
00ce5644, since6ccc2f80, diff read, not a merge-check; checks red):git range-diffshows both commits (#3443's, carried asc7eccd9d9, and this PR's00ce5644) identical to7afecf845/6ccc2f80; this push only rebases ontomain1c8b5514. The use-after-free fix still holds; thexcl-smokeblocks are still owed (the reasonPR descriptionis red), and the suite results are from6ccc2f80under Wine.New: none.
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 Decodere on 2026-12-02T09:32:40Z.
CI triage (#3041, log read only — not a merge-check) for head
00ce5644ca0e:The failing
Build and test (Windows, no GPU)run (46797214033, merged ontomain1c8b5514) looks unrelated to this PR:hle::d3d12x::pso_async::used_tests::retained_failed_demand_observes_another_binds_successful_retrypanicked atcrates/xcl/src/hle/d3d12x/pso_async.rs:6957:9(successful retry was not reconciled), followed immediately byhle::d3d12x::pso_async::used_tests::retained_native_deferred_is_fail_closed_then_observes_exact_publicationaborting inwindows-core-0.62.2(null reference produced, non-unwinding panic, exit0xc0000409STATUS_STACK_BUFFER_OVERRUN).bind.rs,console_heap.rs, andconsole_list.rs(nopso_async.rsoverlap), and all three new tests passed before the abort:bind::tests::superseded_targets_are_found_in_every_declared_table_range,console_heap::tests::view_heap_slots_are_copied_only_while_the_heap_is_registered, andconsole_list::tests::descriptor_tables_keep_their_srv_and_uav_ranges.Now that
PR descriptionis green, a maintainer CI rerun should clear this flake.AI use: Antigravity (Gemini 4 Neon) read the CI log and PR diff and drafted this triage note (no local build or test run).
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:24:05Z.
Code review location:
crates/xcl/src/hle/d3d12x/console_heap.rs; line 1102High: Not certain about this one:
copy_view_heap_slotsreads a heap's memory directly on the assumption that it stays readable while registered, but for Memory::Title heaps the memory belongs to the title and was only checked as readable once, atregister().read_committed_into, which this path now bypasses, skipped no-access and guard pages. If window 0 is sparse (soin_committedis false), the heap is Memory::Title, and the title's allocator later changes protection on part of that pool (a guard page for tracking, a VirtualProtect to NOACCESS) or decommits it, the next bind while any target is superseded runscopy_nonoverlappingover those pages. That's an access violation in the title, or it consumes the title's guard page, where the old path zero-filled those regions. Keeping the direct copy for UMA/sparse heaps and usingread_committed_intofor Memory::Title would avoid it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:24:05Z.
Review: COMMENTED
Review of
00ce5644: 1 finding(s) (1 high), most severe first.crates/xcl/src/hle/d3d12x/console_heap.rs:1102: Not certain about this one:copy_view_heap_slotsreads a heap's memory directly on the assumption that it stays readable while registered, but for Memory::Title heaps the memory belongs to the title and was only checked as readable onc.... (inline)These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:24:06Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T20:32:16Z.
Code review location:
crates/xcl/src/hle/d3d12x/console_heap.rs; line 1102Not changed: the pages copied here are the heap's own, not memory the title uses for anything else. A
Memory::Titleheap's slots are what the title's allocation hook returned for this heap (runtime_alloc(bytes, D3D_DESCRIPTOR_HEAP),console_heap.rs:815), checked readable there (:816), and given back only byfree(:962), afterunregister(:907) has taken the heap out ofHEAPS; the copy holdsHEAPS(:1098). The title writes its descriptors into those pages, so it has no reason to guard or decommit them while the heap lives.mainalready reads the same pages in place under the same lock:view_slot_words(:1488) andexact_view_slot_words(:1501), called fromvram.rs:524, :593 and :690. A page made unreadable there would fault in those first.AI use: Claude Code (Claude Opus 5.5) checked the code and wrote this reply.
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.