Skip to content

D3D12.X: look for superseded targets in every declared table range - #3443

Open
Lakanya wants to merge 1 commit into
xcl-dev:mainfrom
Lakanya:fix/superseded-declared-table-ranges
Open

Lakanya wants to merge 1 commit into
xcl-dev:mainfrom
Lakanya:fix/superseded-declared-table-ranges

Conversation

@Lakanya

@Lakanya Lakanya commented Nov 29, 2026

Copy link
Copy Markdown

A superseded target bound through a descriptor table is remapped when a draw or dispatch binds the table (#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, so that target kept no tiles: its writes were dropped and its reads returned zeros. This reads the SRV and UAV ranges each table's root signature declares instead, wherever they lie in the table, and only those. Follow-up to #3179.

What is in it (one commit)

  • crates/xcl/src/hle/d3d12x/console_list.rs: Layout::table_ranges, the SRV / UAV ranges of each descriptor-table parameter (RTS0 1.0 and 1.1 range layouts, OFFSET_APPEND and unbounded ranges). CBV and sampler ranges cannot name a placed target and are left out.
  • crates/xcl/src/hle/d3d12x/bind.rs: note_superseded_in_tables scans those ranges in chunks of 256 slots. An unbounded range ends with the view heap the table lies in; outside any view heap it has no known extent and is not read. The scan is scan_superseded_in_tables_with, with the memory and heap lookups passed in so it can be tested without a device.
  • crates/xcl/src/hle/d3d12x/console_heap.rs: view_heap_remaining_slots, the slots from an address to the end of its view heap (no shared-heap page is allocated by asking).
  • Tests: descriptor_tables_keep_their_srv_and_uav_ranges (both RTS0 versions: appended, unbounded and explicit-offset ranges, CBV / sampler ranges skipped) and superseded_targets_are_found_in_every_declared_table_range (a target at slot 300 is found – the old 256-slot scan never read it –, slots between declared ranges are not read, unbounded ranges stop at the view heap's end, and are not read outside one).

Tested

  • NVIDIA GeForce RTX 5070 Laptop GPU 8 GB (driver 617.71), AMD Ryzen AI 7 350, Windows 11 Pro build 26300, Rust 1.100.0; tests and runs in release.
  • cargo test --release --workspace --no-fail-fast -- --test-threads=4 on 7afecf84: the integration harnesses 139 passed, 0 failed, 20 ignored (4 e2e tests first failed only because xcl_testtitle.exe was not built; after cargo build --release --workspace, cargo test --release -p xcl --test e2e: 5 passed, 0 failed).
  • The library harness ends early on this PR and on main 0fe06eb0 alike: two tests end the process (0x80004005): gpu::recomp::dxc::private_heap_tests::failed_private_heap_compiler_falls_back_to_dxc_create_instance, and one whose title reaches end_title ("sparse upload preparation still failed after bounded retries"). Counts before they do:
    • --test-threads=1: 962 passed, 0 failed, 24 ignored, on this PR and on main;
    • --test-threads=4 --skip failed_private_heap_compiler_falls_back_to_dxc_create_instance: 1078 passed, 0 failed on this PR, 1070 passed, 0 failed on main.
  • The modules this PR changes, on their own: cargo test --release -p xcl --lib -- hle::d3d12x::console_list:: hle::d3d12x::console_heap:: hle::d3d12x::placements:: hle::d3d12x::bind::: 166 passed, 0 failed, 0 ignored, the two new tests among them.
  • SKIPPED on this adapter: 25 lines, the same on both: 22 "no wave64", 3 per-lane f16 / f32 forms refused (gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics). None is a test of this PR.

Regression run

scripts/smoke.ps1 -Game <retail title> -Seconds 600, each tree's own script and release build, the same environment for both (the title's Series S profile, XCL_DIRECT_DXIL=1, XCL_SPARSE_LAZY=1, XCL_TEXTURE_LEVEL_PAGES=1, XCL_PREPARE=1 with a warm cache, scripted A presses). A run of this PR's head came first to fill the translation cache (cold); not pasted.

main:

xcl-smoke v1
commit: 0fe06eb0f05459007ebfffc67bb9983acb3a832d
gpu: NVIDIA GeForce RTX 5070 Laptop GPU
title: 2c508222
seconds: 600
exit: 0x0
frames shown: 2031 (PresentX 2031)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 29889 MB

this PR's head:

xcl-smoke v1
commit: 7afecf845184279013bac99796d4d5b0417d6e4e
gpu: NVIDIA GeForce RTX 5070 Laptop GPU
title: 2c508222
seconds: 600
exit: 0x0
frames shown: 17866 (PresentX 17866)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 13060 MB

Not tested

  • Whether the retail title binds a superseded target past slot 256 of a table: its logs show superseded targets being used again, but not where in a table their views are.
  • The two smoke runs do not reach the draws this PR changes, and did not take the same path: on this 8 GB card the main run stopped presenting at world loading (frame ~2,000, video memory over budget) until its time ran out; this PR's run stayed in the intro video and menus at 30 fps for its 600 s. Both ended without a crash or device removal. They check that nothing breaks, not the change itself.
  • AMD, other NVIDIA cards, wave64 GPUs.

AI use

  • Claude Code (Claude Opus 5.5): wrote the change and its tests, ran the test suite and the regression runs, and wrote this description.

🤖 Generated with Claude Code

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 Nov 29, 2026
@Lakanya
Lakanya marked this pull request as ready for review November 29, 2026 18:16
@andrewDoing

andrewDoing commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

I tested the descriptor scan on 7afecf845184279013bac99796d4d5b0417d6e4e with an RTX 5070 12 GB (616.92), Ryzen 7 5700X3D, Windows 11 26300.10075 and Rust 1.100.0, debug. The synthetic fixture registered a real sparse-backed 73,727-slot view heap, created console SRVs through the production writer, and overlapped two R32_FLOAT render targets by one 64 KiB page.

  • With the unmapped target's SRV at zero-based slot 73,726, the scan from main 0fe06eb0 left it unmapped. On the PR, a declared one-slot range at offset 73,726 and an unbounded range from slot zero each remapped it in fresh processes. A 256-slot range on the PR left it unmapped. After remapping, native compute readback returned 0.25 and 0.75 through the two real descriptors after distinct clears.
  • There is a CPU cost case worth checking in release. While the same superseded target remained live but had no descriptor in the table, the first 512 slots held valid SRVs of the other target. The remaining slots were empty. Over 240 interleaved samples per case in each of three processes, the main 256-slot scan took 69.0–69.2 µs median, the PR's 256-slot range took 69.1–69.6 µs, and the PR's unbounded range took 3.49–3.53 ms. Unbounded p95 was 3.80–4.10 ms. This is time inside the production scan, with main's scan body copied into the same test executable for comparison. The unbounded path visits about 2.25 MiB of descriptor shadow per call while an unrelated target keeps the superseded gate open.

I repeated the CPU comparison in three fresh processes with the XCL crate compiled at opt-level=2 (cargo --config profile.test.package.xcl.opt-level=2 test …). Main and the PR's 256-slot range took 8.2–8.4 µs median. The PR's unbounded miss took 382–387 µs median and 440–532 µs p95. All three processes reproduced the same native readback.

I ran cargo test --offline --locked -p xcl --lib -- hle::d3d12x::bind::probe3443::native_wide_table hle::d3d12x::bind::tests::superseded_targets_are_found_in_every_declared_table_range hle::d3d12x::console_list::tests::descriptor_tables_keep_their_srv_and_uav_ranges --exact --test-threads=1 --nocapture with XCL_ADAPTER=5070 XCL_COHERENT_CAP_MB=512. Each process passed all three selected tests with zero skips. The full release profile, frequency of wide misses in a title, preservation of pre-eviction contents, and gameplay impact remain unmeasured. A release capture of scan count and scanned slots while the gate is open would tell whether to optimize this before shipping. Codex with GPT-6.2 Sol adapted the test-only fixture and ran the controls.

lnqigr added a commit to lnqigr/xcl that referenced this pull request Nov 29, 2026
Keep XCL_LAZY_TARGETS opt-in. Defer shared video-memory tiles for
GPU-owned placed targets and map them before command-list or upload
use. Track copied RTV and DSV handles while mapping is pending.

Reject a command list if first use cannot allocate its tiles.
Unmapped targets remain eligible for a retry after reset.
Cover deferred allocation, first use, and submission refusal.

Views bound through descriptor tables are looked for in every SRV/UAV
range the root signature declares, with the range walk of xcl-dev#3443 (now
for_each_declared_table_slot), not only in the first 64 slots of each
table: a target bound further in would otherwise keep no tiles.

Related to xcl-dev#3211 and xcl-dev#1773.

Assisted-by: Antigravity (Gemini 4 Neon)
Assisted-by: Codex (GPT-6)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 7d86c5d
head: 7afecf8
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2898 passed, 0 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: none
review: read the whole diff (+192/-23). Findings: (1) Per-bind cost has no bound. An unbounded range (the usual bindless SRV table) is now read to the end of its view heap (bind.rs ~1346-1350, heap_rem - start), on every draw and dispatch bind while any target is superseded (XCL_PLACE_RETIRE is on by default). Main reads 256 slots (8 KB) per table. A heap of 1M descriptors is 32 MB read per bind, and every T# found takes note_use's registry lock. Nothing measures this. Capping it, or keeping a per-heap index of the slots that name superseded targets, would bound it. (2) More stale views get remapped. Every T# in the range counts as a use, including views the title left in the heap for an aliased transient target it no longer samples. Those targets are mapped again (note_use -> map_again), which brings back the tile sharing that supersession removes. The 256-slot scan had the same weakness on a smaller window. Reasoned only. (3) Nothing shows a case that needs it: no issue is linked, the description says it is unknown whether the title binds a superseded target past slot 256, and its smoke runs don't reach the draws it changes. (4) Minor: view_heap_remaining_slots has no test of its own (the bind.rs test passes a closure), and overlapping declared ranges are read twice. Fine: RTS0 1.0 / 1.1 range layouts (20 / 24 bytes, offset at +16 / +20) and OFFSET_APPEND are parsed correctly, CBV and sampler ranges are skipped, clipping at the heap end is right, the 8 KB stack buffer is reused (no allocation per bind), and the ranges are parsed once per root signature.
performance: 60 s smoke of a retail title, main 7d86c5d vs this merge (7cd8991a): 1663 -> 1668 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 17153 -> 17480 MB, 0 device removals, 0 crashes. This run's log has no supersession at all in 60 s, so it doesn't reach the changed scan; it's a boot regression check only.
verdict: not yet: an unbounded range is now read to the end of its view heap on every bind while any target is superseded (finding 1), with nothing measuring that cost or showing a title that needs it; bound the scan, or show the cost on a run that reaches superseded targets
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.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 7afecf8

No open or merged PR makes the same change. #3395 shares most of these lines because it is stacked on this PR (its description says only its top commit bdf38bf4 belongs to it), so it is not a duplicate.
One thing to measure: scan_superseded_in_tables_with now reads an unbounded SRV/UAV range up to the end of its view heap on every draw/dispatch while placements::any_superseded() is true, and console_heap::view_heap_remaining_slots takes the HEAPS lock per table. With a bindless table over a large heap that is far more than the old fixed 8 KiB per table; a frame-time number with superseded targets live would settle it.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Dec 1, 2026
Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Dec 1, 2026
…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>
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.

4 participants