Skip to content

Recompiler: send image heap indices that are no view to null views (#575) - #610

Draft
xstraok wants to merge 1 commit into
xcl-dev:mainfrom
xstraok:heap-index-clamp
Draft

xstraok wants to merge 1 commit into
xcl-dev:mainfrom
xstraok:heap-index-clamp

Conversation

@xstraok

@xstraok xstraok commented Nov 24, 2026 •

Copy link
Copy Markdown

Image instructions in recompiled shaders index ResourceDescriptorHeap with T# word 0. When a T# is still in the console encoding (word 0 = BASE_ADDRESS >> 8, not a heap index), the read lands far past the shared view heap. On RADV that is an SQC page fault and the device is removed during a retail game's world loading (details in #575). Such an index now goes to a null SRV / null UAV of the declared texture type, kept at the end of the heap: it reads 0 and its writes are dropped. Where the raw T# comes from is still open (#575). Fixes #575.

What is in it (one commit, 61df188)

  • gpu/desc.rs: VIEW_HEAP_SIZE = 1 000 000 (the least a resource binding tier 3 GPU has, which SM 6.6 dynamic resources need). The last 12 slots (from NULL_VIEWS = 999 988) are null views: an SRV of each texture type the emitter declares (1D, 2D, 3D, CubeArray, 1DArray, 2DArray, 2DMS) and a UAV of each (1D, 2D, 3D, 1DArray, 2DArray), because D3D12 needs a null view's dimension to match the declaration. null_srv(ty) / null_uav(ty) give their slots. Constants, so a translation does not depend on the device or on whether the heap existed yet, and cached translations stay valid.
  • hle/d3d12x/console_heap.rs: the shared heap is VIEW_HEAP_SIZE on every device (no OPTIONS19 size, no GLOBAL_MAX); write_null_views writes the 12 null views, each with its dimension (the PC methods on an adopted device); console heaps get slots below NULL_VIEWS only.
  • gpu/recomp/emit.rs: a T# is a view when tw0 < NULL_VIEWS - 1 and word 3's TYPE is an image type (≥ 8, the test console_heap::copy_words and desc::image use). MIMG sample / gather / resinfo / load then use tw0, otherwise null_srv(type); store and atomics tw0 + 1, otherwise null_uav(type), with the type of the declaration. The TYPE check covers the all-zero T# XCL writes for a null-resource CreateShaderResourceViewX / CreateUnorderedAccessViewX, whose word 0 would be the view at index 0. A 2DMS store or atomic is refused at translation (SM 6.6 has no RWTexture2DMS; DXC refused it before).
  • gpu/recomp/runner.rs: kernel test runs with textures get the same heap with its null views.
  • gpu/recomp/tests.rs: gpu_image_with_no_heap_index_reads_zero_and_drops_writes samples, loads, stores and runs an atomic through a T# whose word 0 is a console address: it expects 0, and a real UAV next to it holding only its own stores. It fails without the index check (the stray store lands in the real texture). It also samples 3D and cube, loads a 2D array and stores 3D through that T#, and loads through an all-zero T# (expects 0) and a real T# of view 0 (expects the texture); without the TYPE check the all-zero load returns the texture. image_declarations_fall_back_to_the_null_view_of_their_type checks the emitted null slot per type (fails when every type gets the 2D one).

Tested

Regression run

  • None: scripts/smoke.ps1 needs Windows (see Not tested).

Not tested

  • Windows: no Windows machine here, so no MSVC build and no scripts/smoke.ps1 blocks. Someone needs to run the regression on Windows before this can be merged.
  • The retail title on 61df188 itself (the null views replace the last-slot clamp the title runs had).
  • 61df188 on NVIDIA and Windows AMD drivers (d2fa766 passed the GPU test on both, see above). A device whose heap could hold more than 1 000 000 views now uses 1 000 000.
  • Whether the redirected T#s draw correctly: they now read 0.

AI use

  • Claude Code with Claude Opus 5.5: found the cause from the logs and bo_history, wrote the patch, the test, the review follow-up and this description, and ran the tests. I ran the title.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SobdMAZZmGnBr71QeZQsUz

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Some thoughts on c55352d, from reading the code (not run):

  1. The clamp target isn't reserved. VIEW_HEAP_LAST = cap - 1 is an ordinary slot: reserve_global / take_range can hand it to any heap. So a garbage T# lands on either a descriptor that was never written (still undefined behaviour; RADV may stop faulting there, other drivers needn't) or a live view of some unrelated resource. For image_store and atomics, that unrelated resource gets written to. Both the SRV (min(tw0, last)) and UAV (min(tw0 + 1, last)) paths also clamp to the same slot, so one of them always reads a descriptor of the wrong type. Reserving the last two slots at shared_heap creation, filled with a null SRV (last - 1) and a null UAV (last), and clamping SRV indices to last - 1, would make the fallback defined: reads return 0 and writes are dropped.
  2. The bound is baked into the HLSL text. It's read at translation time. A shader translated before shared_heap runs gets 2^21 − 1, which is larger than the heap (GLOBAL_MAX / MaxViewDescriptorHeapSize, default 1,000,000), so it isn't protected. If translated HLSL or DXIL is cached across runs (XCL_DXC_ARGS never reaches the cached compile path; the DXIL cache key also omits the optimisation level #559 / Recompiler: honor DXC overrides with warm translation caches #613 talk about warm translation caches), a value from another run or device is reused too. An alternative that avoids both: take the bound from a root constant or the heap size at bind time, or make the clamp constant independent of the device (GLOBAL_MAX - 1) and keep those slots null.
  3. The test checks text, not behaviour. image_heap_index_is_clamped_to_the_heap asserts the substring , {last}u))]. A GPU test that samples with word 0 = a large console address and expects 0 would cover the point of the fix.

The clamp is a reasonable stopgap while the source of the raw T# (#575) stays open; these are about making its fallback safe.

AI-assisted (Claude Code), read-only review.

@xstraok

xstraok commented Nov 24, 2026

Copy link
Copy Markdown
Author

Thanks – all three check out. take_range could hand out cap - 1, so the clamp could land on a live view, and SRV and UAV shared it; the bound was read at translation time, and since #762 the translated DXIL cache doesn't key on it. Pushed d2fa766: the shared heap is now 1,000,000 views on every device (the tier-3 minimum that SM 6.6 dynamic resources need), its last two slots are a null SRV (999,998) and a null UAV (999,999) that no heap gets, and image instructions send any index that is not a view's to those constants – so nothing depends on the device or on when a shader was translated. The text test is replaced by a GPU test that samples, loads, stores and runs an atomic through a T# whose word 0 is a console address and expects 0, with a real UAV next to it untouched; it fails without the clamp (the stray store lands in the real texture). Linux / RX 9060 XT / RADV / Proton: cargo test --release --target x86_64-pc-windows-gnu -p xcl --lib -- --test-threads=4: 642 passed, 4 failed (known under Wine: gpu_f64_roots, gpu_f64_math_random, gpu_nonfused_mad_and_mac_prevent_fma_contraction, xma2_source_voice_decodes_and_manages_lifetime), 21 ignored. Windows regression still open.

(Drafted with Claude Code, Claude Opus 5.5.)

@xstraok xstraok changed the title Recompiler: clamp image heap indices to the shared view heap (#575) Recompiler: send image heap indices that are no view to null views (#575) Nov 24, 2026
@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Windows NVIDIA run of d2fa766, since the description lists Windows as open (not the retail regression run; we have no title).

Tested

  • NVIDIA GeForce RTX 3070 (driver 616.56, wave32), Ryzen 9 5950X, Windows 11 Pro 26100, rustc 1.100.0 MSVC, debug
  • cargo test -p xcl --lib -- --test-threads=4:
    • this head: 646 passed, 0 failed, 21 ignored;
    • its merge base cb868b2: 645 passed, 0 failed, 21 ignored (the difference is the new test).
  • gpu_image_with_no_heap_index_reads_zero_and_drops_writes passes. So does gpu_typed_buffer_loads_and_stores alone, 3 of 3, on both trees.

For completeness: in a first full cargo test --workspace run of this head, the device was removed (0x887a0006) during gpu_typed_buffer_loads_and_stores, and 9 more GPU tests failed after it. That didn't reproduce in the reruns above (0 device removals), and other GPU jobs on this machine may have overlapped that run, so I'm not attributing it to the PR. If anyone sees DEVICE_HUNG with this head, the runner's per-dispatch 1,000,000-view heap (runner.rs) would be the first thing I'd look at.

AI-assisted (Claude Code).

@crosettiremi

crosettiremi commented Nov 24, 2026 •

Copy link
Copy Markdown

I tested head d2fa766 on Windows / RX 7900 XT in a local integration. The targeted gpu_image_with_no_heap_index_reads_zero_and_drops_writes test ran on the adapter and passed.

For the title test I used the same saved player profile (anaconda), initial application caches, compact PSO preloading and 28 GiB job cap as the baseline. I regenerated both opt-in compute packages against this emitter. Both runs reached world-loading artwork. The baseline exited with DXGI_ERROR_DEVICE_HUNG and a DRED page fault at 0xd000 at 196.172 s. With this PR the same status and GPU VA returned at 166.311 s. Player selection happened at different times. The absolute timings do not establish a speed difference. Neither compact lighting shader had a recorded bind before either failure.

The second run traced matching sequences of seven recorded dispatches on two partially completed command lists (6 of 20 operations, next breadcrumb Dispatch). Two of the six distinct programs in that sequence lower to 2D texture loads/samples. Four have no ResourceDescriptorHeap references in their conventional four-window translation. This narrows the inspection set; it does not identify which descriptor caused the fault or contradict the separate RADV result.

One independent coverage issue: write_null_views currently creates only Texture2D null SRV/UAV descriptors, while the emitter can select those same indices for Texture3D or TextureCubeArray. Microsoft's null-descriptor rules require compatible view types. VIctory's review also found that descriptor creation and even a zero read on one GPU can pass with the wrong dimension. A test of the emitted slot selection plus a non-2D access under GPU-based validation would cover that path. The two textured candidates above use 2D views, so I am not attributing this particular crash to that dimension mismatch.

https://learn.microsoft.com/en-us/windows/win32/direct3d12/descriptors-overview#null-descriptors
Marvisak/VIctory#205 (comment)
Follow-up on the same Radeon with #610 still applied and a lower-memory pipeline queue. At 165.301 s the 0xd000 fault repeated. Full DRED histories put all three partially executed lists at the third of seven dispatches. Two had one Texture2D shader there and one had the other, with the same two shaders swapped between positions three and four. Both also read the guest memory windows. This locates the incomplete dispatches and leaves both binding classes under investigation.

@xstraok

xstraok commented Nov 24, 2026

Copy link
Copy Markdown
Author

Thanks to both.

@crosettiremi – right: write_null_views made only Texture2D null views, while the emitter also declares 1D, 3D, CubeArray, 1DArray, 2DArray and 2DMS. Pushed 550bcd0: the heap's last 12 slots are a null SRV per declared type (1D, 2D, 3D, CubeArray, 1DArray, 2DArray, 2DMS) and a null UAV per type (1D, 2D, 3D, 1DArray, 2DArray). desc::null_srv / null_uav give the slot, and each declaration falls back to the one of its own type. A 2DMS store or atomic is now refused at translation (SM 6.6 has no RWTexture2DMS; DXC refused it before). New text test image_declarations_fall_back_to_the_null_view_of_their_type checks the emitted index per type. It fails when every type gets the 2D slot. The GPU test now also samples 3D and cube, loads a 2D array and stores 3D through the bad T#. Since your DEVICE_HUNG at 0xd000 happens with and without the PR, I'm not treating it as caused by this PR.

@upipibi – thanks for the NVIDIA run. Your comment's cargo test line came through without counts; could you add them? Noted on the runner: it makes a 1,000,000-view heap only for tests that bind textures, one per run.

Linux / RX 9060 XT / Mesa 26.2.6 RADV / Proton Experimental, 550bcd0: cargo test --release --target x86_64-pc-windows-gnu -p xcl --lib -- --test-threads=4: 643 passed, 4 failed (known under Wine: gpu_f64_roots, gpu_f64_math_random, gpu_nonfused_mad_and_mac_prevent_fma_contraction, xma2_source_voice_decodes_and_manages_lifetime), 21 ignored, no SKIPPED. RADV takes a null view of the wrong dimension, so on Linux only the text test covers the per-type choice. Windows still open.

(Drafted with Claude Code, Claude Opus 5.5.)

@crosettiremi

crosettiremi commented Nov 24, 2026 •

Copy link
Copy Markdown

Follow-up on 550bcd0, Windows / RX 7900 XT. The expanded dimension-specific null-view GPU test passes on my local integration.

There is also a separate in-range case. XCL's null-resource CreateShaderResourceViewX and CreateUnorderedAccessViewX paths write an all-zero guest texture descriptor. The upper-bound check interprets its word 0 as PC heap index zero. In the synthetic compute test I installed an ordinary Texture2D with red=1.25 at slot zero, then loaded through a zero T# and through a valid typed T# for the same index. With the upper-bound check alone the zero T# read 1.25 on lane 0. With a check for zero index and zero texture-type word, the zero T# reads 0 and the valid T# still reads 1.25. Both variants used the same 2D native view, so this is a deterministic alias test without an invalid native access.

I am running the corrected emitter with freshly generated packages against the retail load. The isolated test establishes an aliasing defect; the recurring 0xd000 page fault is still under investigation.
Retail result: the corrected emitter rebuilt with the same Series X profile, 28 GiB cap and observed A press at 63 s. It reproduced the DRED page fault at GPU VA 0xd000 at 167.997 s. The surviving third-dispatch breadcrumb maps to the same Texture2D shader and 72-group launch as the comparison. Peak sampled process commit was 25,893 MB. The all-zero descriptor regression is fixed in the synthetic test; the title crash requires a separate fix.

…vall#575)

A T# that is still in the console encoding (word 0 = BASE_ADDRESS >> 8,
not an XCL heap index) made ResourceDescriptorHeap[tw0] read gigabytes
past the shader-visible view heap. On RADV that is an SQC page fault and
the device is removed during a retail game's world loading: the faulting
VAs were never covered by a BO (RADV_DEBUG=bo_history) and lie past the
1 000 000 x 32 B heap; as T# word 0 they are addresses in the title's own
mappings.

The shared view heap is now 1 000 000 descriptors on every device (the
least a resource binding tier 3 GPU has, which SM 6.6 dynamic resources
need), and its last 12 slots are null views that no console heap gets:
a null SRV of each texture type recompiled shaders declare (1D, 2D, 3D,
CubeArray, 1DArray, 2DArray, 2DMS) and a null UAV of each (1D, 2D, 3D,
1DArray, 2DArray), since D3D12 needs a null view's dimension to match
the declaration. Image instructions use word 0 as the view index only
below them and when word 3's TYPE is an image type (>= 8); otherwise the
null view of the type they declare: such a T# reads 0 and its stores and
atomics are dropped. The TYPE check covers the all-zero T# XCL writes
for a null-resource CreateShaderResourceViewX / CreateUnorderedAccessViewX,
whose word 0 would otherwise be the view at index 0. A 2DMS store or
atomic is refused at translation (SM 6.6 has no RWTexture2DMS; DXC
refused it before). The bound is a constant (gpu::desc::NULL_VIEWS), so
a translation does not depend on the device or on whether the heap
existed when it was made, and cached translations stay valid. Test runs
with textures get the same heap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SobdMAZZmGnBr71QeZQsUz
@xstraok

xstraok commented Nov 24, 2026

Copy link
Copy Markdown
Author

@crosettiremi – confirmed: the null-resource CreateShaderResourceViewX / CreateUnorderedAccessViewX paths write [0; 8], and word 0 = 0 passed the bound. Pushed 61df188: a T# is used as a view only when word 0 is below the null views and word 3's TYPE is an image type (≥ 8, the same test console_heap::copy_words and desc::image use); anything else goes to the null view of its declared type. The GPU test now loads through an all-zero T# (expects 0) and through a real T# of view 0 (expects the texture). Without the TYPE check, the zero-T# load returns the texture's data. Thanks for the retail run: agreed the 0xd000 fault is separate.

Linux / RX 9060 XT / Mesa 26.2.6 RADV / Proton Experimental, 61df188: cargo test --release --target x86_64-pc-windows-gnu -p xcl --lib -- --test-threads=4: 643 passed, 4 failed (the same known Wine failures), 21 ignored, no SKIPPED.

(Drafted with Claude Code, Claude Opus 5.5.)

@ClosetPie107

ClosetPie107 commented Nov 24, 2026 •

Copy link
Copy Markdown

Retail-title test of 61df188 on RDNA4 under Linux: the #575 fault is gone; the run ends on a different GPU page fault about 25 s after the first #101.

Tested

384f7f7 384f7f7 + #610
first ListX #101 84.6 s 84.9 s
GPU page fault (journalctl -k) ~114 s (+29.6 s) ~110 s (+25.3 s)
UTCL2 client SQC (data) TCP (0x8)
faulting page 0x00008000befff000: RADV's 32-bit range, past the end of the 1 000 000-slot view heap, as in #575 0x0000c00100000000
PERMISSION_FAULTS / MAPPING_ERROR 0x3 / 0x0 0x3 / 0x0
driver comp_1.1.0 timeout, ring reset succeeded gfx_0.0.0 timeout, ring reset succeeded
D3D12 device removed: 0x887a0005 118.408 s 112.069 s (title's 0x80000003 at +0x2474606 0.1 s later)
skipped draws / dispatches 4 208 / 663 1 362 / 831

Not tested: a second run reaching the new fault, without XCL_PSO_WAIT_MS, RADV_DEBUG=bo_history / XCL_LIST_TRACE for the new fault, the lib suite on this head, Windows.

AI use: T3 Code (Claude Opus 5.5) built both trees, ran the title and wrote this comment from XCL's logs and the kernel log; I checked it before posting.

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of 61df188f on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 61df188f76cf842d6ba070bf6acd7db50a2baa8e
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1544 (PresentX 1544)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14860 MB

Against the limits in CONTRIBUTING.md: 95 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

6 participants