Recompiler: send image heap indices that are no view to null views (#575) #610
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!610
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-610"
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?
@xstraok on GitHub · 2026-11-24 02:27 UTC · original
xstraok:heap-index-clamp→main· +212 −22 · 5 files · 1 commits · draftImage instructions in recompiled shaders index
ResourceDescriptorHeapwith 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 (fromNULL_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 isVIEW_HEAP_SIZEon every device (no OPTIONS19 size, noGLOBAL_MAX);write_null_viewswrites the 12 null views, each with its dimension (the PC methods on an adopted device); console heaps get slots belowNULL_VIEWSonly.gpu/recomp/emit.rs: a T# is a view whentw0 < NULL_VIEWS - 1and word 3's TYPE is an image type (≥ 8, the testconsole_heap::copy_wordsanddesc::imageuse). MIMG sample / gather / resinfo / load then usetw0, otherwisenull_srv(type); store and atomicstw0 + 1, otherwisenull_uav(type), with the type of the declaration. The TYPE check covers the all-zero T# XCL writes for a null-resourceCreateShaderResourceViewX/CreateUnorderedAccessViewX, whose word 0 would be the view at index 0. A 2DMS store or atomic is refused at translation (SM 6.6 has noRWTexture2DMS; 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_writessamples, 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_typechecks the emitted null slot per type (fails when every type gets the 2D one).Tested
x86_64-pc-windows-gnu, release.maincb868b2+61df188), withXCL_DXC_DIR:cargo test --release --target x86_64-pc-windows-gnu -p xcl --lib -- --test-threads=4: 643 passed, 4 failed, 21 ignored, noSKIPPED. The failures aregpu_f64_math_random,gpu_f64_roots,gpu_nonfused_mad_and_mac_prevent_fma_contractionandhle::xaudio2::tests::xma2_source_voice_decodes_and_manages_lifetime; all 4 fail the same way onmainon this machine.gpu_image_with_no_heap_index_reads_zero_and_drops_writes: passes; fails with the rawtw0index (and that run faulted the GPU, as in #575). RADV accepts a null view of the wrong dimension, so the per-type part is covered by the text test, not by this GPU run.d2fa766: RTX 3070 / Windows 11 (upipibi) and RX 7900 XT / Windows (crosettiremi): the GPU test passes. Not rerun on61df188.maina6f5f7a+ #257 + #458 + #496 + #484, with the first version of this PR (c55352d, clamp to the heap's last slot):f4ce27c+ #257 + #496 + #172 with it had none either. They stop later for other reasons (the title's watchdog during long first-bind shader compiles).Regression run
scripts/smoke.ps1needs Windows (see Not tested).Not tested
scripts/smoke.ps1blocks. Someone needs to run the regression on Windows before this can be merged.61df188itself (the null views replace the last-slot clamp the title runs had).61df188on NVIDIA and Windows AMD drivers (d2fa766passed the GPU test on both, see above). A device whose heap could hold more than 1 000 000 views now uses 1 000 000.AI use
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 on GitHub · 2026-11-24 04:56 UTC · original
Some thoughts on
c55352d, from reading the code (not run):VIEW_HEAP_LAST = cap - 1is an ordinary slot:reserve_global/take_rangecan 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. Forimage_storeand 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 atshared_heapcreation, filled with a null SRV (last - 1) and a null UAV (last), and clamping SRV indices tolast - 1, would make the fallback defined: reads return 0 and writes are dropped.shared_heapruns 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 (#559 / #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.image_heap_index_is_clamped_to_the_heapasserts 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 on GitHub · 2026-11-24 05:23 UTC · original
Thanks – all three check out.
take_rangecould hand outcap - 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. Pushedd2fa766: 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.)
@upipibi on GitHub · 2026-11-24 05:56 UTC · original
Windows NVIDIA run of
d2fa766, since the description lists Windows as open (not the retail regression run; we have no title).Tested
cargo test -p xcl --lib -- --test-threads=4:cb868b2: 645 passed, 0 failed, 21 ignored (the difference is the new test).gpu_image_with_no_heap_index_reads_zero_and_drops_writespasses. So doesgpu_typed_buffer_loads_and_storesalone, 3 of 3, on both trees.For completeness: in a first full
cargo test --workspacerun of this head, the device was removed (0x887a0006) duringgpu_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 seesDEVICE_HUNGwith 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).
@xstraok on GitHub · 2026-11-24 06:16 UTC · original
Thanks to both.
@crosettiremi – right:
write_null_viewsmade only Texture2D null views, while the emitter also declares 1D, 3D, CubeArray, 1DArray, 2DArray and 2DMS. Pushed550bcd0: 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_uavgive 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 noRWTexture2DMS; DXC refused it before). New text testimage_declarations_fall_back_to_the_null_view_of_their_typechecks 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 yourDEVICE_HUNGat0xd000happens 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 testline 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, noSKIPPED. 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 on GitHub · 2026-11-24 06:02 UTC · original · edited 2026-11-24 06:26 UTC
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
https://github.com/Marvisak/VIctory/pull/205#issuecomment-7122711762
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.
@crosettiremi on GitHub · 2026-11-24 06:33 UTC · original · edited 2026-11-24 06:37 UTC
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.
@xstraok on GitHub · 2026-11-24 06:39 UTC · original
@crosettiremi – confirmed: the null-resource
CreateShaderResourceViewX/CreateUnorderedAccessViewXpaths write[0; 8], and word 0 = 0 passed the bound. Pushed61df188: 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 testconsole_heap::copy_wordsanddesc::imageuse); 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 the0xd000fault 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, noSKIPPED.(Drafted with Claude Code, Claude Opus 5.5.)
@ClosetPie107 on GitHub · 2026-11-24 11:45 UTC · original · edited 2026-11-24 12:31 UTC
Retail-title test of
61df188on 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
experimental-11.0-20261112), vkd3d-proton v3.1 + #257's patch (-Db_ndebug=true, dxil-spirv53aac418, so #611 is out of the way), DXC 1.9.2609.5. Rust 1.96.0,x86_64-pc-windows-gnu, release.main384f7f7against384f7f7+ this PR (clean merge). Retail 1.0.2.1, first-run setup done earlier,XCL_PRESS_AT=30.6:A,XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_PSO_WAIT_MS=50 XCL_COHERENT_MB=512 VKD3D_CONFIG=ignore_shared_fence.384f7f7384f7f7+ #610#101journalctl -k)SQC (data)TCP (0x8)0x00008000befff000: RADV's 32-bit range, past the end of the 1 000 000-slot view heap, as in #5750x0000c00100000000PERMISSION_FAULTS/MAPPING_ERROR0x3/0x00x3/0x0comp_1.1.0timeout, ring reset succeededgfx_0.0.0timeout, ring reset succeededD3D12 device removed: 0x887a00050x80000003at+0x24746060.1 s later)mainit came ~30 s after#101in both runs I made (the other on6efdabc+ #905, in my #846 comment).0xffffc001_00000000: 64 TiB into the high VA range, beyond anything allocated here. I have not found which descriptor or address produces it. It is not the0xd000fault @crosettiremi reported on Windows / RX 7900 XT.main47efa2e, withoutXCL_PSO_WAIT_MS(0 skipped draws or dispatches), with RADV's cache warmed (#1035): 1 of 4 runs took the same fault (TCP (0x8),0x0000c00100000000, ~10 s after the first#101), thendevice removedand the watchdog at 114.8 s. The other 3 ended in the watchdog at 108.6–110.6 s (~30 s after#101) with no GPU fault. So with #610 the #575 fault is gone and this one, already inmain, is what is left.mainalone; details on #1035.Not tested: a second run reaching the new fault, without
XCL_PSO_WAIT_MS,RADV_DEBUG=bo_history/XCL_LIST_TRACEfor 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 on GitHub · 2026-11-25 02:58 UTC · original
Regression run of
61df188fon the retail title, for this PR's Regression run section. Both blocks are fromscripts/smoke.ps1as printed, not edited:mainon4178e888, this PR on its head commit with no uncommitted changes, same title and time.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.@DavidM1911 on GitHub · 2026-11-25 12:55 UTC · original
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
main— needs a rebase before it can be tested.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.