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

Manually merged
github merged 1 commit from gh-pr/2195/head into gh-pr/2195/base 2026-11-26 05:22:44 +00:00
Owner

@⁠mgrein on GitHub · 2026-11-25 08:57 UTC · original
mgrein:heap-index-bound → main · +42 −15 · 4 files · 1 commits · merged 2026-11-25 10:49 UTC

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

  • Whether the new retail game actually produces an index in that gap: I have not caught one; the change closes the gap whether or not it does. Its GPU hangs on this machine (#1452) were not shown to change with this alone.
  • GPUs whose view heap limit is above 1,000,000: their shared heap gets smaller (1,000,000 instead of up to 2^21). The view heaps XCL shares map pages lazily, and a full shared heap is logged.
  • AMD GPUs, Linux / Wine.

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

**@⁠mgrein** on GitHub · 2026-11-25 08:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/2195) `mgrein:heap-index-bound` → `main` · +42 −15 · 4 files · 1 commits · merged 2026-11-25 10:49 UTC 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** - Whether the new retail game actually produces an index in that gap: I have not caught one; the change closes the gap whether or not it does. Its GPU hangs on this machine (#1452) were not shown to change with this alone. - GPUs whose view heap limit is above 1,000,000: their shared heap gets smaller (1,000,000 instead of up to 2^21). The view heaps XCL shares map pages lazily, and a full shared heap is logged. - AMD GPUs, Linux / Wine. **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](https://claude.com/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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:22:42 +00:00
github manually merged commit 19bef421e6 into gh-pr/2195/base 2026-11-26 05:22:44 +00:00
Author
Owner

@⁠joeypercia on GitHub · 2026-11-25 10:39 UTC · original

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: #2057 f7e08e6 + 741cb5a (the video-memory budget from #1773).
  • With this PR: the same plus 19bef42, which applied cleanly.
  • Caches: compute and graphics pipelines were built ahead for each tree, so this one compiled 428 graphics pipelines in the title against 0 for the base.
  • Heap: the shared heap here is 1,000,000 descriptors, as on your 4070. Before this PR, the direct-DXIL guard accepted indices up to 2,097,150.
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.
**@⁠joeypercia** on GitHub · 2026-11-25 10:39 UTC · [original](https://github.com/xcl-dev/xcl/pull/2195#issuecomment-7159995534) **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:** #2057 `f7e08e6` + `741cb5a` (the video-memory budget from #1773). - **With this PR:** the same plus `19bef42`, which applied cleanly. - **Caches:** compute and graphics pipelines were built ahead for each tree, so this one compiled 428 graphics pipelines in the title against 0 for the base. - **Heap:** the shared heap here is 1,000,000 descriptors, as on your 4070. Before this PR, the direct-DXIL guard accepted indices up to 2,097,150. | | 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.
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 10:46 UTC · original

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** on GitHub · 2026-11-25 10:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/2195#issuecomment-7160147748) 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`.
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-25 09:30 UTC · original · edited 2026-11-25 19:31 UTC

Correction: the_shaders_t_sharp_index_bound_fits_the_shared_heap creates its device with D3D12CreateDevice(None, ..), so it runs on DXGI adapter 0, which on this machine is the RX 9070 XT, whatever XCL_ADAPTER says. Both runs of that test below were on the RX 9070 XT: the AMD result stands, but the RTX 3060 "heap tests 10 passed" line does not cover that test on the 3060. The per-card gpu:: counts are unaffected.


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:

  • RX 9070 XT (RDNA4, driver 32.0.32029.2010, native wave64):
    • cargo test -p xcl --lib -- console_heap heap_bounds: 10 passed, 0 failed, including the_shaders_t_sharp_index_bound_fits_the_shared_heap.
    • cargo test -p xcl --lib -- gpu::: 584 passed, 2 failed, 22 ignored, 6 SKIPPED, the same counts as on main. The 2 failures are the AMD fuzz seeds 722 and 1599 tracked in #2115.
  • RTX 3060 (driver 32.0.16.1088): heap tests 10 passed; gpu:: 586 passed, 0 failed, 22 ignored.

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.

**@⁠DarkPanda69** on GitHub · 2026-11-25 09:30 UTC · [original](https://github.com/xcl-dev/xcl/pull/2195#issuecomment-7158419775) · edited 2026-11-25 19:31 UTC **Correction:** `the_shaders_t_sharp_index_bound_fits_the_shared_heap` creates its device with `D3D12CreateDevice(None, ..)`, so it runs on DXGI adapter 0, which on this machine is the RX 9070 XT, whatever `XCL_ADAPTER` says. Both runs of that test below were on the RX 9070 XT: the AMD result stands, but the RTX 3060 "heap tests 10 passed" line does not cover that test on the 3060. The per-card `gpu::` counts are unaffected. --- 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: - **RX 9070 XT** (RDNA4, driver 32.0.32029.2010, native wave64): - `cargo test -p xcl --lib -- console_heap heap_bounds`: 10 passed, 0 failed, including `the_shaders_t_sharp_index_bound_fits_the_shared_heap`. - `cargo test -p xcl --lib -- gpu::`: 584 passed, 2 failed, 22 ignored, 6 SKIPPED, the same counts as on `main`. The 2 failures are the AMD fuzz seeds 722 and 1599 tracked in #2115. - **RTX 3060** (driver 32.0.16.1088): heap tests 10 passed; `gpu::` 586 passed, 0 failed, 22 ignored. 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.