Recompiler: bound descriptor heap indices from T# and S# words to the heap #1215
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!1215
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1215"
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?
@duudiis on GitHub · 2026-11-24 13:18 UTC · original
duudiis:pr/heap-index-bound→main· +303 −18 · 9 files · 2 commits · openTranslated shaders index
ResourceDescriptorHeapwith T# word 0 andSamplerDescriptorHeapwith S# word 3 [11:0], and both come from console memory. If a T# was read from memory the GPU never wrote, the index can be anything. On NVIDIA an index past the heap wraps onto an unrelated slot, and if that slot holds a descriptor of the wrong kind the GPU hangs with no DRED page fault (device removal 0x887a0005). A retail title's cutscene reads T#s from memory that skipped GPU work was meant to write. This PR keeps those indices inside the heap. The shared heap now ends in null-view guard slots, and every data-derived heap index in a translated shader is bounded to them, so a garbage T# reads zeros and its stores are dropped.Idea from VIctory (GPL-3.0), reimplemented; no code taken.
Overlaps #610 (draft): it also puts null views at the end of the heap and sends T# indices that are not views to them. The approaches differ. #610 fixes the heap at 1 000 000 views, checks word 0 against a compile-time constant and also checks word 3's TYPE. This PR keeps the heap at its OPTIONS19 size and passes the bound at run time in an io slot. It also bounds S# indices and fills shader-visible sampler heaps to 2048. The two conflict in
console_heap.rs,emit.rsandrunner.rs, so only one of them should land.What is in it
D3D12.X: reserve null-view guard slots at the end of the shared heap:hle/d3d12x/console_heap.rs: the last 14 descriptors of the shared heap are guard slots. For each view kind the emitter declares (1D, 2D, 3D, CubeArray, 1DArray, 2DArray, 2DMS) there is a null SRV with a null UAV next to it, and no console heap is ever given these slots.view_limitreturns the first guard slot when the shared heap is bound, and 0 otherwise or withXCL_HEAP_CLAMP=0.gpu/recomp/mod.rs:IO_VIEW_LIMIT= io slot 113. Slot 112 is alreadyIO_UMA_BASE_HI, so the new one goes next to it in the trap-temp range. Also addsVIEW_GUARD_KINDSandSAMPLER_HEAP_SLOTS.bind.rs,console_list.rsandlist_x.rswrite the io slot for each translated draw and dispatch, from the heaps the list has bound.real.rs: shader-visible PC sampler heaps get 2048 samplers. The slots past the title's are the zero S#'s point sampler.Recompiler: bound heap indices from T# and S# words to the heap(gpu/recomp/emit.rs):xcl_vlast = io[IO_VIEW_LIMIT] - 1.+ 1is applied after the bound. Before, word 0 0xFFFFFFFF wrapped the UAV index to 0.min(s & 0xFFF, 2047).gpu/recomp/runner.rs: the kernel test runner puts the guard slots after the test textures and fills its sampler heap the same way the runtime does.Tested
cargo build --workspace --release: ok.cargo test --workspace --release -- --test-threads=4on757ece9: 744 passed, 0 failed, 41 ignored (lib: 701 passed, 0 failed, 21 ignored).gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware.shared_heap_guard_slots(console_heap.rs): passes.heap_indices_are_bounded(gpu/recomp/tests.rs): passes, and fails with this head'semit.rsreverted.gpu_heap_index_past_the_views_reads_the_guard(GPU): passes. On this NVIDIA GPU it also passes withemit.rsreverted, because the out-of-range reads there returned 0 and the stores were dropped. It shows that the guard path reads zeros and drops stores. It does not reproduce the hang.Regression run
main (
47efa2e):This PR (
757ece9):The main run went first with a cold shader and driver cache (both builds share the cache folder), so most of the frame difference is the cache, not this change. Both runs cover boot and the intro, not the cutscene that reads garbage T#s.
Not tested
AI use
@Aniseto on GitHub · 2026-11-24 13:25 UTC · original
Ran the new heap-bound tests on an NVIDIA Blackwell part at
757ece9:Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC 14.44.35207, DXC 1.9.2609.5, debug build.
gpu_heap_index_past_the_views_reads_the_guardruns on the GPU here and reads the guard slot as expected;heap_indices_are_boundedand the console-heap unit set are unaffected. This is a debug build on a Blackwell part with driver 32.0.16.2124 (the author's run was release on an RTX 5070).Not tested: retail titles, RDNA2/RDNA4 and Intel GPUs, Wine, native wave64.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash 1017 - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified.
@DavidM1911 on GitHub · 2026-11-24 13:47 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:Note: the full
d3d12xlib filter currently aborts with 0xc0000005 on unmodifiedmaintoo (pre-existing, unrelated to this PR); the PR's own tests were run by name and pass.@jessenic on GitHub · 2026-11-25 09:59 UTC · original
A measurement that supports this PR's explanation of the
0x887a0005removal, from a retail title on an RTX 5070 Ti, on a tree without this PR. I'm now testing the PR on the same setup and will add the result here.Setup: RTX 5070 Ti 16 GB (driver 610.88), Windows 11 Pro 26300, release, Series S profile. A local integration branch on
main8f5fca5with #1323, #1405, #1464, #1291, #1342, #1156, #2009, #1993 and others.XCL_HEAP_WINDOWS=1 XCL_COHERENT_HEAPS=sparse:256. The title reaches the intro cutscene's title card and then loses the device 7–9 s after its first#101, in every run (about 10 so far). DRED shows no list in progress and no page fault, and Windows logs no TDR event (nvlddmkm) for it.Where the removal comes from: cdb attached to the game at
#101, with breakpoints onD3D12Core!*RemoveDevice*(public Microsoft symbols):ExecuteCommandLists, in two runs one of XCL's own sparse uploads (sparse::State::submit_slot). The chain isnvwgf2umx→D3D12Core!CDevice::UMSetError_→CDevice::ProcessDriverErrors→NDXGI::CDevice::RemoveDevice.UMSetError_is0x88760870(D3DDDIERR_DEVICEREMOVED). So the list submitted then is not the cause. The kernel had already marked the device lost, and the next submission found out.CD3D12TelemetryHelper::LogRemoveDeviceEvent, is 6,D3DKMT_DEVICEEXECUTION_ERROR_DMAFAULT. It is not a page fault (7), a hang (3) or out of memory (5).A DMA fault with no page fault and no TDR fits what this PR describes: the GPU stops on a heap index that lands on a descriptor of the wrong kind. Two more things about
main's guard, seen while applying this PR on top of it:main's MIMG guard (5195e27) passes any word 0 below 2 097 151. The shared heap is smaller than that, so an index between its end and 2M still runs past it.XCL_HEAP_WINDOWS=1, slot 0 is memory window 0's raw buffer UAV, so a T# that fails the check samples a buffer UAV as a texture.When I combined this PR with
main's guard, I sent the invalid-T# fallback toxcl_vlast + 1u(the guard slot when the heap is bounded, 0 when it is not), not to 0. That may be worth doing in the PR if it gets rebased ontomain.AI use: Claude Code (Claude Opus 5.5) ran the debugger sessions on the machine above and wrote this note.
@jessenic on GitHub · 2026-11-25 14:12 UTC · original
Follow-up to my note above: with this PR, the removal 7–9 s after the title's first
#101is gone in 3 of 3 runs on the RTX 5070 Ti. Without the PR it happened in every run (about 10).Same tree and setup as the note: the PR's two commits were cherry-picked onto the integration branch, with the conflicts against
main's5195e27guard resolved as described there. Every compute pipeline was precompiled for the new translation first (12 threads, 3.8 h). Pixel and vertex programs were not precompiled.#101#101+ 2 s#101+ 2 s0x887a0005at 284 s,#101+ 94 s#101is not a hang on the GPU. A thread dump (cdb attached 20 s after#101, then detached) shows the title's render thread inbind::graphics_bound→pso_async::resolve_wait, waiting for a graphics pipeline that is still being built. One thread is in DXC and the other pipeline workers are idle. This PR changes the HLSL of every pixel and vertex program that reads an image, so on a cold cache the world's first draws wait for DXC and the driver. Graphics pipelines of 0.74 MB of DXIL took about 9 s each in the driver. #1798 (a draw does not wait for a graphics pipeline still being built), or precompiling--only ps/--only vs, should cover this.huge, wanted at once). So it is a later and different fault, probably the world's own mesh and pixel programs. The textured-world report on #505 explains why those read garbage descriptors without #1803 (the heaps' addresses in the user SGPRs). I'm testing a tree with #1803 next.Not tested: AMD; Series X; more than 3 runs; a
scripts/smoke.ps1regression run; this PR alone onmain.AI use: Claude Code (Claude Opus 5.5) ran the runs and the debugger on the machine above and wrote this comment.
@jessenic on GitHub · 2026-11-25 15:28 UTC · original
Correction to my comment above: "gone in 3 of 3" was wrong. With a warm cache, this PR delays the removal; it does not prevent it.
In those three runs the world drew almost nothing after
#101. Draws waited for the graphics pipelines this PR's changed HLSL had made cold, and run 3's removal came as soon as drawing resumed. So those runs could not tell "fixed" from "delayed".Run 4 had the graphics driver blobs from runs 1–3 already cached. Same tree and switches, cdb attached at
#101with a breakpoint onCD3D12TelemetryHelper::LogRemoveDeviceEvent:#101on (up to about 980 draws every 2 s, 1–2 presents every 2 s);#101+ 18.7 s, with execution state 6 (D3DKMT_DEVICEEXECUTION_ERROR_DMAFAULT) and0x887a0005, as without the PR.Without the PR this removal came at
#101+ 7–9 s. With it, it came at + 18.7 s in this one warm run, so the PR may move it, but one run is not enough to say. The fault itself is still there on this tree. My guess in the earlier comment, "a later and different fault", is not supported: the kernel's reason is the same.I'm next checking whether the page budget's evictions take part (a run without
XCL_PAGE_BUDGET_MB), and testing a tree with #1803.AI use: Claude Code (Claude Opus 5.5) ran the run and the debugger and wrote this correction.
@DavidM1911 on GitHub · 2026-11-26 04:05 UTC · original
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current
mainon the new head — needs another 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.