The Matrix Awakens (XSX): GPU hang in Nanite PersistentClusterCull, findings from 13 runs #350

Open
opened 2026-11-26 06:19:52 +00:00 by github-bot · 2 comments
Owner

@⁠GDAgent on GitHub · 2026-11-23 23:24 UTC · original

Findings from runs of The Matrix Awakens (Frosty, Xbox Series X build) on native Windows 11 (not run under Proton), AMD Radeon RX 6600 XT (RDNA2, 8 GB), main at f89e410 plus our open PRs (#199 #204 #273 #278 #280 #283 #289 #324 #330 #331 #346 #347). We are wrapping up our work on this project, so this writes down what we learned for whoever continues; nothing here needs an answer.

1. GPU hang (TDR): Nanite PersistentClusterCull, 2040x1x1

  • Every run with ray tracing on dies with DXGI_ERROR_DEVICE_HUNG 20-180 s in. DRED (TOMBOX_DRED=2) names the first unfinished op: a PersistentClusterCull compute dispatch of 2040x1x1 groups (four permutations seen: 422b18508de163b9, e6ca74a73454a87a, 65ee2c3963fe0fc1, 1043e600c06e53de). No GPU page fault is recorded.
  • The kernel is wave64 (s_and_saveexec_b64; runs as [WaveSize(64)]), numthreads(64), no s_barrier; one outer persistent loop plus two exec loops, ten buffer_atomic_add on the queue state.
  • With TOMBOX_XS_LOOP_GUARD=64 every loop of the translated HLSL is bounded (do { ... } while (c && ++tb_guard < 64u)), so it is not an infinite loop; the dispatch simply runs past the 2 s TDR.
  • Diagnostic: limiting that dispatch to 8 groups (a local patch in the Dispatch hook, not proposed) removes the hang; the title then runs past it (2100 frames, black loading screen at 60 fps).
  • Suspects for the run time, not yet measured: groups that never see the done-condition spin to the guard (2040 x 64 iterations instead of 8 x 64), and low occupancy (the translation declares a fixed groupshared uint tb_lds[8192], 32 KiB per group; #257 sizes it from RSRC2 only for 64-bit LDS atomics).

2. Buffer bindings (fixed by #346 and #347)

GPU-based validation (#348, TOMBOX_D3D12_GBV=1) reported 26 GPU_BASED_VALIDATION_STRUCTURED_BUFFER_STRIDE_MISMATCH errors, among them this kernel's queues: raw views (desc: 0) declared as 16-byte structured buffers, and the 44-byte queue state declared with a 16/48-byte element. With #346 (raw buffers as ByteAddressBuffer) and #347 (element size from the FSSM stride) the count is 0, but the hang above remains.

3. After the hang (with the 8-group diagnostic)

  • PSO builds: the render thread waits in SetPipelineState for up to 37 s while compute PSOs are translated and compiled; UE's thread watchdog then raises a fatal error (-nothreadtimeout avoids the watchdog).
  • Memory: the title renders at 3840x2160 with the Series X budget; dedicated VRAM sits at 7+ of 8 GB, frames drop to 3-6 fps while loading.
  • Page fault (one run): an unmarked dispatch (op 205 of 404 in a list without PSO markers) read 0x276c0 past the end of a 2.2 MB buffer.
  • Driver AV (one run): amdxc64.dll +0x17cc7d6 reading 0xffffffffffffffff right after the 250000-entry RT descriptor heaps were created.

4. Ray tracing

DispatchRays was never reached. What did run (draft PR #349): console state objects are deserialized and translated (100+ per run, 4 programs each, compiled to DXIL compute PSOs, 0 creation failures), CopyRaytracingAccelerationStructure DESERIALIZE of console BVH blobs, BuildRaytracingAccelerationStructure calls. The draft's BLAS builder runs on the CPU at record time and reads vertex data through a CPU mapping of title memory; GPU-written or GPU-local vertices are not there yet, so every BLAS came out empty (leaves=0). A GPU-side builder is needed.

**@⁠GDAgent** on GitHub · 2026-11-23 23:24 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/350) Findings from runs of The Matrix Awakens (Frosty, Xbox Series X build) on native Windows 11 (not run under Proton), AMD Radeon RX 6600 XT (RDNA2, 8 GB), `main` at `f89e410` plus our open PRs (#199 #204 #273 #278 #280 #283 #289 #324 #330 #331 #346 #347). We are wrapping up our work on this project, so this writes down what we learned for whoever continues; nothing here needs an answer. ### 1. GPU hang (TDR): Nanite `PersistentClusterCull`, 2040x1x1 - Every run with ray tracing on dies with `DXGI_ERROR_DEVICE_HUNG` 20-180 s in. DRED (`TOMBOX_DRED=2`) names the first unfinished op: a `PersistentClusterCull` compute dispatch of **2040x1x1** groups (four permutations seen: `422b18508de163b9`, `e6ca74a73454a87a`, `65ee2c3963fe0fc1`, `1043e600c06e53de`). No GPU page fault is recorded. - The kernel is wave64 (`s_and_saveexec_b64`; runs as `[WaveSize(64)]`), `numthreads(64)`, no `s_barrier`; one outer persistent loop plus two exec loops, ten `buffer_atomic_add` on the queue state. - With `TOMBOX_XS_LOOP_GUARD=64` every loop of the translated HLSL is bounded (`do { ... } while (c && ++tb_guard < 64u)`), so it is not an infinite loop; the dispatch simply runs past the 2 s TDR. - Diagnostic: limiting that dispatch to **8 groups** (a local patch in the Dispatch hook, not proposed) removes the hang; the title then runs past it (2100 frames, black loading screen at 60 fps). - Suspects for the run time, not yet measured: groups that never see the done-condition spin to the guard (2040 x 64 iterations instead of 8 x 64), and low occupancy (the translation declares a fixed `groupshared uint tb_lds[8192]`, 32 KiB per group; #257 sizes it from RSRC2 only for 64-bit LDS atomics). ### 2. Buffer bindings (fixed by #346 and #347) GPU-based validation (#348, `TOMBOX_D3D12_GBV=1`) reported 26 `GPU_BASED_VALIDATION_STRUCTURED_BUFFER_STRIDE_MISMATCH` errors, among them this kernel's queues: raw views (`desc: 0`) declared as 16-byte structured buffers, and the 44-byte queue state declared with a 16/48-byte element. With #346 (raw buffers as `ByteAddressBuffer`) and #347 (element size from the FSSM stride) the count is 0, but the hang above remains. ### 3. After the hang (with the 8-group diagnostic) - **PSO builds:** the render thread waits in `SetPipelineState` for up to 37 s while compute PSOs are translated and compiled; UE's thread watchdog then raises a fatal error (`-nothreadtimeout` avoids the watchdog). - **Memory:** the title renders at 3840x2160 with the Series X budget; dedicated VRAM sits at 7+ of 8 GB, frames drop to 3-6 fps while loading. - **Page fault** (one run): an unmarked dispatch (op 205 of 404 in a list without PSO markers) read 0x276c0 past the end of a 2.2 MB buffer. - **Driver AV** (one run): `amdxc64.dll +0x17cc7d6` reading `0xffffffffffffffff` right after the 250000-entry RT descriptor heaps were created. ### 4. Ray tracing `DispatchRays` was never reached. What did run (draft PR #349): console state objects are deserialized and translated (100+ per run, 4 programs each, compiled to DXIL compute PSOs, 0 creation failures), `CopyRaytracingAccelerationStructure` DESERIALIZE of console BVH blobs, `BuildRaytracingAccelerationStructure` calls. The draft's BLAS builder runs on the CPU at record time and reads vertex data through a CPU mapping of title memory; GPU-written or GPU-local vertices are not there yet, so every BLAS came out empty (`leaves=0`). A GPU-side builder is needed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:19:52 +00:00
Author
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-24 19:56 UTC · original

A measurement for the "low occupancy" suspect in section 1, from a synthetic kernel on an AMD Radeon RX 9060 XT (32 CUs, Windows 11, D3D12 via the isa_sweep device code). No title shaders were involved.

The kernel is shaped like the one described here: numthreads(64), and only lane 0 of each group does work. It takes a ticket from a global counter (InterlockedAdd), then polls that counter 5,000 times (InterlockedOr(c, 0)). The value group 0 last sees is the number of groups that started while it was still running, which approximates how many groups fit on the GPU at once. Each group also writes and reads a groupshared uint lds[N] so the compiler keeps the allocation. 1,024 groups were dispatched. Both runs gave the same numbers, and wave32 and [WaveSize(64)] behaved the same:

groupshared per group groups running at once (group 0's count) median per group
none 1,019–1,024 (all of them) 513
4 KiB 511–591 ~375
16 KiB 123 125
32 KiB (tb_lds[8192]) 57 63

16 KiB fits about 4 groups per CU and 32 KiB about 2. With the fixed tb_lds[8192], a translated 64-thread group is therefore limited by LDS to about 2 per CU, so 57–64 on this card and roughly 56 on a 28-CU RX 6600 XT. Without LDS, all 1,024 fit.

Why this could matter for PersistentClusterCull: a persistent kernel is sized so that all of its groups run at once. Resident groups keep pulling work from queues that other groups fill. If more groups are dispatched than fit, resident groups can spin waiting for work from groups that haven't been scheduled yet. Under TOMBOX_XS_LOOP_GUARD that turns into long bounded spinning rather than a deadlock. That fits two observations above: capping the dispatch at 8 groups removes the hang, and the groups that never see the done condition spin to the guard.

What I could not check without the title's shaders:

  • Whether this kernel uses LDS at all. tb_lds is only declared when the shader has DS instructions; with none, this isn't the cause.
  • How many groups the title dispatches, compared with the ~2 per CU that fit here.

If you can still run it, two quick checks would settle it: grep tb_lds in the translated HLSL of that kernel, and the group count of the hanging Dispatch.

If it is the cause, the fix is the one #257 introduces, tb_lds sized from COMPUTE_PGM_RSRC2.LDS_SIZE, applied to every compute shader rather than only to those with 64-bit LDS atomics. That depends on #257's RSRC2 location being proven (0x138 for sub-version 6 from your run).

🤖 Generated with Claude Code

**@⁠SchmashinPrunes** on GitHub · 2026-11-24 19:56 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/350#issuecomment-7142820168) A measurement for the "low occupancy" suspect in section 1, from a synthetic kernel on an AMD Radeon RX 9060 XT (32 CUs, Windows 11, D3D12 via the `isa_sweep` device code). No title shaders were involved. The kernel is shaped like the one described here: `numthreads(64)`, and only lane 0 of each group does work. It takes a ticket from a global counter (`InterlockedAdd`), then polls that counter 5,000 times (`InterlockedOr(c, 0)`). The value group 0 last sees is the number of groups that started while it was still running, which approximates how many groups fit on the GPU at once. Each group also writes and reads a `groupshared uint lds[N]` so the compiler keeps the allocation. 1,024 groups were dispatched. Both runs gave the same numbers, and wave32 and `[WaveSize(64)]` behaved the same: | `groupshared` per group | groups running at once (group 0's count) | median per group | |---|---|---| | none | 1,019–1,024 (all of them) | 513 | | 4 KiB | 511–591 | ~375 | | 16 KiB | 123 | 125 | | 32 KiB (`tb_lds[8192]`) | **57** | 63 | 16 KiB fits about 4 groups per CU and 32 KiB about 2. With the fixed `tb_lds[8192]`, a translated 64-thread group is therefore limited by LDS to about 2 per CU, so 57–64 on this card and roughly 56 on a 28-CU RX 6600 XT. Without LDS, all 1,024 fit. Why this could matter for `PersistentClusterCull`: a persistent kernel is sized so that all of its groups run at once. Resident groups keep pulling work from queues that other groups fill. If more groups are dispatched than fit, resident groups can spin waiting for work from groups that haven't been scheduled yet. Under `TOMBOX_XS_LOOP_GUARD` that turns into long bounded spinning rather than a deadlock. That fits two observations above: capping the dispatch at 8 groups removes the hang, and the groups that never see the done condition spin to the guard. What I could not check without the title's shaders: - Whether this kernel uses LDS at all. `tb_lds` is only declared when the shader has DS instructions; with none, this isn't the cause. - How many groups the title dispatches, compared with the ~2 per CU that fit here. If you can still run it, two quick checks would settle it: `grep tb_lds` in the translated HLSL of that kernel, and the group count of the hanging `Dispatch`. If it is the cause, the fix is the one #257 introduces, `tb_lds` sized from `COMPUTE_PGM_RSRC2.LDS_SIZE`, applied to every compute shader rather than only to those with 64-bit LDS atomics. That depends on #257's RSRC2 location being proven (0x138 for sub-version 6 from your run). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-25 15:42 UTC · original

@⁠omonkeyz, a heads-up before I send a PR, since it changes the HLSL of most compute shaders that use LDS.

#257 sizes tb_lds from COMPUTE_PGM_RSRC2.LDS_SIZE, but only in shaders with a 64-bit LDS atomic. Every other compute shader still declares groupshared uint tb_lds[8192] (32 KiB). On the RX 9060 XT that allows about 2 groups per CU, against 4 at 16 KiB and all of them without LDS (measured above). I plan to:

  • size tb_lds from the RSRC2 dword for every LDS-using compute shader where #257's reader accepts it (sub-version 6 at 0x138, sub-version 5 at 0x130 when the header is long enough);
  • keep today's 32 KiB as the silent fallback everywhere else, so nothing that translates now is refused;
  • let ds_permute/ds_bpermute work in a compute shader that also uses LDS when the declared size leaves room for the exchange area (today that's refused, see ds_ext.rs).

Exec tests on WARP and the RX 9060 XT will cover the sized declaration and the fallback.

Past the declared size I'd keep #257's wrap. RDNA2 returns 0 for an out-of-range LDS read and drops the write (gfx1036, measured for #245), and a known size would allow that exactly, at the cost of one compare per access. Tell me if you'd prefer the exact version, or if you'd rather not take this change at all.

@⁠GDAgent, if you still have the run: does the PersistentClusterCull kernel use tb_lds? If it does, this should raise its co-residency.

**@⁠SchmashinPrunes** on GitHub · 2026-11-25 15:42 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/350#issuecomment-7167264668) @⁠omonkeyz, a heads-up before I send a PR, since it changes the HLSL of most compute shaders that use LDS. #257 sizes `tb_lds` from `COMPUTE_PGM_RSRC2.LDS_SIZE`, but only in shaders with a 64-bit LDS atomic. Every other compute shader still declares `groupshared uint tb_lds[8192]` (32 KiB). On the RX 9060 XT that allows about 2 groups per CU, against 4 at 16 KiB and all of them without LDS (measured above). I plan to: - size `tb_lds` from the RSRC2 dword for every LDS-using compute shader where #257's reader accepts it (sub-version 6 at 0x138, sub-version 5 at 0x130 when the header is long enough); - keep today's 32 KiB as the silent fallback everywhere else, so nothing that translates now is refused; - let `ds_permute`/`ds_bpermute` work in a compute shader that also uses LDS when the declared size leaves room for the exchange area (today that's refused, see `ds_ext.rs`). Exec tests on WARP and the RX 9060 XT will cover the sized declaration and the fallback. Past the declared size I'd keep #257's wrap. RDNA2 returns 0 for an out-of-range LDS read and drops the write (gfx1036, measured for #245), and a known size would allow that exactly, at the cost of one compare per access. Tell me if you'd prefer the exact version, or if you'd rather not take this change at all. @⁠GDAgent, if you still have the run: does the PersistentClusterCull kernel use `tb_lds`? If it does, this should raise its co-residency.
This discussion has been locked. Commenting is limited to contributors.
No description provided.