Repository navigation
Conversation
Translated shaders index the shared shader-visible heap with T# word 0 and the sampler heap with S# word 3 [11:0], both read from console memory. A T# from memory the GPU never wrote (a retail game's cutscene, after skipped dispatches) gives an index anywhere: past the heap's end NVIDIA is reported to wrap onto an unrelated slot, and a descriptor of the wrong kind there hangs the GPU without a DRED page fault (device removal 0x887a0005). The shared heap's last 14 descriptors become guard slots, never given to a console heap: per kind of view a translated shader declares (Texture1D, 2D, 3D, CubeArray, 1DArray, 2DArray, 2DMS) a null SRV and next to it a null UAV, written when the heap is made. The heap's size depends on the GPU (OPTIONS19, at most 2^21), so the first guard slot goes to the shaders in io[IO_VIEW_LIMIT] (113, in the trap-temp range next to IO_UMA_BASE_HI) for every translated draw and dispatch that binds the shared heap; 0 otherwise (a view heap of its own when the shared heap could not be made) and with XCL_HEAP_CLAMP=0. Shader-visible PC sampler heaps get all 2048 samplers D3D12 allows, the ones past the title's slots the zero S#'s point sampler, so a sampler index bounded to 2047 always names a sampler. Nothing reads the io slot yet: the recompiler uses it in the next commit. Idea from VIctory (GPL-3.0), reimplemented; no code taken. Assisted-by: Claude Code (Claude Opus 5.5)
Every ResourceDescriptorHeap index a translated shader takes from T# word 0 (image sample / get_lod / get_resinfo / load / store / atomics) is now one select: below io[IO_VIEW_LIMIT] it is itself, else the guard slot of its view kind there (a null SRV, the UAV one next to it), so a garbage T# reads zeros and its stores go nowhere instead of indexing past the heap. The UAV index is taken after the bound: word 0 0xFFFFFFFF used to make it 0 (wrapped), the shared heap's first SRV, as an RWTexture. The bound is loaded once in main (xcl_vlast = io - 1, so an io slot of 0 leaves the indices as they were). Sampler heap indices are min(S# word 3 & 0xFFF, 2047): 4095 was past any shader-visible sampler heap. Only shaders that index a heap change; the others' HLSL stays byte for byte the same. emit.rs and mod.rs are translator sources, so the translation caches' identity changes with them. The kernel test runner puts the guard slots after the test textures and fills its sampler heap like the runtime's. Assisted-by: Claude Code (Claude Opus 5.5)
|
Ran the new heap-bound tests on an NVIDIA Blackwell part at 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.
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. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Note: the full |
Translated 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