Skip to content

D3D12.X: the T# index guard matches a 1,000,000-descriptor shared heap - #2195

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
mgrein:heap-index-bound
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
mgrein:heap-index-bound

Conversation

@mgrein

@mgrein mgrein commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

The translated shaders accept a T# SRV index below 2^21 − 1 (the paired UAV is at tw0 + 1), but the shared shader-visible view heap is min(device limit, 2^21) descriptors – 1,000,000 on an RTX 4070, which reports no larger limit. An accepted index between the two reads past the heap's end. XCL writes only indices it reserved, but a T# the title wrote itself as raw console words passes the type and BASE_ADDRESS_HI checks: its word 0 is the base address >> 8, so a texture at 256–512 MB gives 1–2 million. Another project running the same new retail game reports that reads past the heap's end hang NVIDIA GPUs (AMD forgives them).

The shared heap is now 1,000,000 descriptors on every GPU (resource binding tier 2 and up take that many) and the guard is tied to it.

What is in it

  • crates/xcl/src/hle/d3d12x/console_heap.rs: GLOBAL_MAX = 1,000,000 (was 2^21), public; the heap size computation moves into global_cap(), unchanged otherwise.
  • crates/xcl/src/gpu/dxil/lower_image.rs: VIEW_HEAP_MAX_SRV = GLOBAL_MAX − 1 (was (1 << 21) − 1); its tests compare against the constant.
  • crates/xcl/src/gpu/recomp/emit.rs: the HLSL path's guard uses the same constant (was a literal 2097151u).
  • Test the_shaders_t_sharp_index_bound_fits_the_shared_heap (GPU): the bound against the shared heap this GPU gets. It fails without the change on the RTX 4070: "shaders accept indices up to 2097151, the shared heap holds 1000000".

Tested

  • NVIDIA GeForce RTX 4070 12 GB (32-lane waves), AMD Ryzen 5 5600X, 32 GB RAM, Windows 11 25H2 (build 26200), Rust 1.94.1 MSVC, DXC 1.9.2602.17. Debug for the tests, release for the runs.
  • cargo test --workspace -- --test-threads=4 at 19bef42: 1155 passed, 0 failed, 46 ignored (21 test binaries). SKIPPED (25): 20 GPU subtests that need wave64, 3 wave32 per-lane f16 subtests of lower_dxil::tests (refused: unsupported f16 instructions), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows), pso_measurement_compiles_an_exact_synthetic_record (Windows Developer Mode is off).
  • The new test without the change: fails as quoted above.

Regression run

Same title for 100 s on each build, default settings, shader caches cold on both (the PR changes the translator).

main:

xcl-smoke v1
commit: 6020a33b16ba2de25b3aef5947552f2dc1831f09
gpu: NVIDIA GeForce RTX 4070
title: 5c412a26
seconds: 100
exit: 0x0
frames shown: 2529 (PresentX 2529)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15516 MB

This PR:

xcl-smoke v1
commit: 19bef421e6f974fec2aa8289b228c78ab92f3013
gpu: NVIDIA GeForce RTX 4070
title: 5c412a26
seconds: 100
exit: 0x0
frames shown: 2642 (PresentX 2642)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15705 MB

Not tested

AI use

  • Claude Code with Claude Opus 5.5: found the mismatch while investigating NVIDIA hangs, wrote the change, the test and this description, and ran the tests and the runs on the hardware above.

🤖 Generated with Claude Code

The translated shaders accept a T# SRV index below 2^21 - 1 (the UAV is at
tw0 + 1), while the shared shader-visible heap is min(device limit, 2^21)
descriptors: 1,000,000 on an RTX 4070. An index in between reads past the
heap's end, which hangs NVIDIA GPUs. XCL writes only indices it reserved,
but a T# the title wrote itself (raw console words: word 0 is the base
address >> 8, so a texture at 256-512 MB gives 1-2 million) passes the
type and BASE_ADDRESS_HI checks.

The shared heap is now 1,000,000 descriptors on every GPU (resource binding
tier 2+ takes that many) and the guard is tied to it: VIEW_HEAP_MAX_SRV =
GLOBAL_MAX - 1 in the direct DXIL translator, the same constant in the HLSL
path. global_cap() holds the heap size computation so a test can check it
against the bound; on the RTX 4070 it fails with the old values ("shaders
accept indices up to 2097151, the shared heap holds 1000000").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DarkPanda69

Copy link
Copy Markdown

AMD run (listed as untested) on an RDNA4 card, which is the Tier-3 case the guard's comment is about, plus the RTX 3060 for comparison. Nothing regresses with the lower bound compiled into the shaders.

Head 19bef42 applied on main 568e7db, debug, Windows 11 Pro 26200, XCL_ADAPTER set to each card:

Not tested: this card's actual view-heap limit (I did not read OPTIONS19, so I can't say whether the shared heap gets smaller here), a title, Linux / Wine.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@joeypercia

Copy link
Copy Markdown

In-title result on #2057, for the first point under Not tested: on an RTX 4070 Ti (12 GB) the world-load removal still happens with this PR. It came later in this run, but that's one run each.

Setup: RTX 4070 Ti 12 GB (driver 621.40), Ryzen 7 7800X3D, Windows 11 Pro 26200, release. Newer retail title 1.0.2.1, Series X profile. XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_DRED=1, A presses scripted with XCL_PRESS_AT from 42 s.

base + #2195
presents stop (30 fps → 1 per 2 s) ~100 s ~100 s
device removed 0x887a0005 at 304 s 0x887a0005 at 463.6 s
DRED page fault at VA 0x0, no allocations, none freed the same
running at the end CS 1b5466f261a70cde, 1,033 ms for one dispatch CS b78fa10b425b8e54 and CS 24de2aef6c31d55e, 1,581 ms and not finished
local video memory at the end 11.4 GB 12.0 GB

So on this tree the removal at world load isn't (only) a read past the heap. The guard doesn't change the signature: DRED names no allocation, and long compute dispatches are still running when it comes.

Not checked: whether the title produces an index in the gap at all. I didn't log the T# words, and I ran nothing without the budget commit.

AI use

  • Claude Code (Claude Opus 5.5) built the trees, ran them on my machine and wrote this comment.

@raylitebull

Copy link
Copy Markdown
Member

Code review on 19bef42:

  • Aligning console_heap::GLOBAL_MAX (1_000_000) and lower_image::VIEW_HEAP_MAX_SRV (GLOBAL_MAX - 1) across both direct DXIL (lower_image.rs) and HLSL (emit.rs) eliminates the OOB ResourceDescriptorHeap window (1_000_000..2_097_150) that caused hangs on 1M-descriptor GPUs, verified by the_shaders_t_sharp_index_bound_fits_the_shared_heap.
  • Note: updating GLOBAL_MAX also bounds global_cap() so every GPU's shared heap and shader guard share the exact same ceiling.
  • Diff audited and CI workflow approved (running).

Remaining before merge: Build and test finishing green plus dual-vendor (AMD + NVIDIA) verification on 19bef42.

@raylitebull
raylitebull merged commit 5b3c354 into xcl-dev:main Nov 25, 2026
2 checks passed
anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
Brings main to full parity with upstream/main (cdb0891), including:
- World rendering & gameplay: xcl-dev#1991, xcl-dev#1988, xcl-dev#1984, xcl-dev#2028, xcl-dev#2078
- Memory / VRAM / PSO: xcl-dev#1985, xcl-dev#2157, xcl-dev#2178, xcl-dev#2195, xcl-dev#2176, xcl-dev#1996, xcl-dev#1914
- Direct DXIL & shaders: xcl-dev#2120, xcl-dev#2174, xcl-dev#2194, xcl-dev#2207, xcl-dev#1951, xcl-dev#1973, xcl-dev#2156, xcl-dev#2064
- Preserves local Linux/Wine customizations: docs/linux.md, scripts/linux/*,
  in-process Wine XAsync (xgameruntime/api.rs), loader watchdog bypass, and
  Wine MEM_WRITE_WATCH bypass on coherent UMA windows (gpu/uma.rs).

Assisted-by: Antigravity (Gemini 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants