gpu: async zero-group culling for CS_RaytracingResolve indirect dispatches (fixes NVIDIA 0x887A0005 device removal) #187

Open
hingeowl wants to merge 2 commits from hingeowl/Darner:fix/rt-resolve-zero-cull into main
Contributor

Summary

Fixes recurring DXGI_ERROR_DEVICE_REMOVED (0x887A0005, no page fault, empty DRED breadcrumbs, no nvlddmkm 4101 TDR) crashes on NVIDIA GPUs when ray tracing (DARNER_HW_RT=1 or software RT with CS_RaytracingResolve enabled) is active — especially when entering interiors like the player's house.

Root Cause

Exhaustive bisection on an RTX 4090 (walking through the sliding door into the house) isolated the crash to a single D3D12 call:

  • Reproduces identically with DARNER_HW_RT=0, DARNER_RT_RESOLVE=1 (zero DXR/BVH/RayQuery).
  • Skipping tables(), root arguments, and ExecuteIndirect (so zero CS_RaytracingResolve threads execute on the GPU) while still calling SetPipelineState(&p.pso) on all ~220+ CS_RaytracingResolve pipelines still crashes with 0x887A0005 in seconds.
  • Stopping right before SetPipelineState(&p.pso) — with 100% of those PSOs still created and alive — eliminates the crash completely, and keeping any subset up to 15/16 of CS_RaytracingResolve also eliminates it.
  • The title issues ~687–1,168 CS_RaytracingResolve ExecuteIndirect calls per frame across ~220+ giant compute shaders (58–79 KiB each), even though only ~80–118 material buckets have non-zero ThreadGroupCount in any given scene. Binding all ~220+ giant resolve PSOs via SetPipelineState commits their compiled SASS into NVIDIA's ~512 MB per-device shader-code heap, which overflows when new interior PSOs are bound.

Fix (DARNER_RT_RESOLVE_CULL, on by default; 0 to disable)

  • Async zero-group culling (crates/darner-gpu/src/draw.rs): Copies each single-record CS_RaytracingResolve indirect dispatch's 12-byte [x, y, z] arguments into a 4-slot persistently mapped D3D12_HEAP_TYPE_READBACK ring, harvests completed slots after their GPU submission fence lands, tracks active resolve pipelines with a 60-frame keep-alive grace window, and skips host_pipeline() / SetPipelineState / ExecuteIndirect for idle (0, 0, 0) buckets.
  • Skip boot pre-warming (crates/darner-gpu/src/pipeline/make.rs): When culling is enabled, skips early_start for CS_RaytracingResolve so inactive permutations are never committed; active ones load from the mapped ID3D12PipelineLibrary (~4–5 ms) on first non-zero hit.
  • Helper (crates/darner-gpu/src/pipeline.rs): Adds is_rt_resolve.

Validation

  • cargo test -p darner-gpu --locked -- rt_resolve_cull_nonzero_and_keep_alive_window passes (1 passed; 0 failed).
  • cargo check --workspace --tests --locked passes cleanly on latest main.
  • 300s full Hardware RT walk-inside-house stress test on RTX 4090 (DARNER_HW_RT=1, DARNER_RELAY=2, DLSS Quality, 2x FG):
    • 0 crashes across 300s / 7,800+ frames / 113 walking steps inside the house (vs. 8.9–38s baseline crash).
    • 81–118 active resolve pipelines out of 687–1,168 probed/frame; 3.76M zero-group dispatches culled.
    • 30.3–33.4 base fps (~60–67 fps with 2x FG), 0.0 ms GPU stall, spotless interior Hardware RT lighting and reflections.
### Summary Fixes recurring `DXGI_ERROR_DEVICE_REMOVED` (`0x887A0005`, no page fault, empty DRED breadcrumbs, no `nvlddmkm` 4101 TDR) crashes on NVIDIA GPUs when ray tracing (`DARNER_HW_RT=1` or software RT with `CS_RaytracingResolve` enabled) is active — especially when entering interiors like the player's house. ### Root Cause Exhaustive bisection on an RTX 4090 (walking through the sliding door into the house) isolated the crash to a single D3D12 call: - Reproduces identically with `DARNER_HW_RT=0, DARNER_RT_RESOLVE=1` (zero DXR/BVH/RayQuery). - Skipping `tables()`, root arguments, and `ExecuteIndirect` (so zero `CS_RaytracingResolve` threads execute on the GPU) while still calling `SetPipelineState(&p.pso)` on all ~220+ `CS_RaytracingResolve` pipelines still crashes with `0x887A0005` in seconds. - Stopping right before `SetPipelineState(&p.pso)` — with 100% of those PSOs still created and alive — eliminates the crash completely, and keeping any subset up to 15/16 of `CS_RaytracingResolve` also eliminates it. - The title issues ~687–1,168 `CS_RaytracingResolve` `ExecuteIndirect` calls per frame across ~220+ giant compute shaders (58–79 KiB each), even though only ~80–118 material buckets have non-zero `ThreadGroupCount` in any given scene. Binding all ~220+ giant resolve PSOs via `SetPipelineState` commits their compiled SASS into NVIDIA's ~512 MB per-device shader-code heap, which overflows when new interior PSOs are bound. ### Fix (`DARNER_RT_RESOLVE_CULL`, on by default; `0` to disable) - **Async zero-group culling (`crates/darner-gpu/src/draw.rs`):** Copies each single-record `CS_RaytracingResolve` indirect dispatch's 12-byte `[x, y, z]` arguments into a 4-slot persistently mapped `D3D12_HEAP_TYPE_READBACK` ring, harvests completed slots after their GPU submission fence lands, tracks active resolve pipelines with a 60-frame keep-alive grace window, and skips `host_pipeline()` / `SetPipelineState` / `ExecuteIndirect` for idle `(0, 0, 0)` buckets. - **Skip boot pre-warming (`crates/darner-gpu/src/pipeline/make.rs`):** When culling is enabled, skips `early_start` for `CS_RaytracingResolve` so inactive permutations are never committed; active ones load from the mapped `ID3D12PipelineLibrary` (~4–5 ms) on first non-zero hit. - **Helper (`crates/darner-gpu/src/pipeline.rs`):** Adds `is_rt_resolve`. ### Validation - `cargo test -p darner-gpu --locked -- rt_resolve_cull_nonzero_and_keep_alive_window` passes (`1 passed; 0 failed`). - `cargo check --workspace --tests --locked` passes cleanly on latest `main`. - **300s full Hardware RT walk-inside-house stress test** on RTX 4090 (`DARNER_HW_RT=1`, `DARNER_RELAY=2`, DLSS Quality, 2x FG): - **0 crashes** across 300s / 7,800+ frames / 113 walking steps inside the house (vs. 8.9–38s baseline crash). - **81–118** active resolve pipelines out of **687–1,168** probed/frame; **3.76M** zero-group dispatches culled. - **30.3–33.4 base fps** (~60–67 fps with 2x FG), `0.0 ms` GPU stall, spotless interior Hardware RT lighting and reflections.
Owner

Thanks for the bisection. Seeing the crash with HW_RT=0 just from SetPipelineState on the ~220 resolve pipelines is an independent confirmation of the shader heap mechanism behind #164. On the 4090, darner nv-profile (1 GiB heap) already turned a 2-minute 0x887A0005 into 39 minutes with no loss. So main has one fix, and this PR is a second, complementary one. Review of ac4cca96; it can't go in on by default as it is:

  1. Missing work for one or more frames (flicker). A resolve bucket only counts as active after a readback from an earlier frame has been harvested. The first time a bucket gets non-zero groups (entering a room, turning toward a reflective surface), its dispatch is skipped until the harvest lands, at least a frame or two. At start, every bucket is skipped until the first harvest. The 60-frame keep-alive only helps after the first hit. Flicker counts as a regression here, so this needs an in-game A/B with recordings at the door you bisected.
  2. CPU cost of is_rt_resolve. It runs container.windows(20) over the whole shader container (58-79 KiB) on every single-record indirect dispatch, about 700-1,100 a frame. That's tens of MB scanned per frame. It needs to be computed once per pipeline and cached on the pipeline.
  3. Readback timing. done_at = started + queued + 2 at the next frame's first resolve dispatch is a guess. The list holding the copy may be submitted later than that number, for example with the relay or thin lists, and then the harvest reads the slot before the card wrote it. Tie done_at to the submission number of the list that actually carries the copy.
  4. Key reuse. active is keyed by the title pipeline's address. A released pipeline's address can be reused by another, which then inherits its active state. Small, but cheap to avoid: clear the entry when the pipeline is released.
  5. AMD. It changes behaviour on every vendor, and only NVIDIA has the heap limit. Limit it to NVIDIA unless AMD gains something.

Suggested path: make it opt-in (DARNER_RT_RESOLVE_CULL=1), fix 2 and 3, then an A/B on the 4090 spot with and without nv-profile: device losses, fps, and a recording checked for missing reflections or lighting. If the cull lets a stock 512 MiB heap survive with no visible loss, that's the case for turning it on by default.

Thanks for the bisection. Seeing the crash with HW_RT=0 just from SetPipelineState on the ~220 resolve pipelines is an independent confirmation of the shader heap mechanism behind #164. On the 4090, `darner nv-profile` (1 GiB heap) already turned a 2-minute 0x887A0005 into 39 minutes with no loss. So main has one fix, and this PR is a second, complementary one. Review of ac4cca96; it can't go in on by default as it is: 1. **Missing work for one or more frames (flicker).** A resolve bucket only counts as active after a readback from an earlier frame has been harvested. The first time a bucket gets non-zero groups (entering a room, turning toward a reflective surface), its dispatch is skipped until the harvest lands, at least a frame or two. At start, every bucket is skipped until the first harvest. The 60-frame keep-alive only helps after the first hit. Flicker counts as a regression here, so this needs an in-game A/B with recordings at the door you bisected. 2. **CPU cost of `is_rt_resolve`.** It runs `container.windows(20)` over the whole shader container (58-79 KiB) on every single-record indirect dispatch, about 700-1,100 a frame. That's tens of MB scanned per frame. It needs to be computed once per pipeline and cached on the pipeline. 3. **Readback timing.** `done_at = started + queued + 2` at the next frame's first resolve dispatch is a guess. The list holding the copy may be submitted later than that number, for example with the relay or thin lists, and then the harvest reads the slot before the card wrote it. Tie `done_at` to the submission number of the list that actually carries the copy. 4. **Key reuse.** `active` is keyed by the title pipeline's address. A released pipeline's address can be reused by another, which then inherits its active state. Small, but cheap to avoid: clear the entry when the pipeline is released. 5. **AMD.** It changes behaviour on every vendor, and only NVIDIA has the heap limit. Limit it to NVIDIA unless AMD gains something. Suggested path: make it opt-in (`DARNER_RT_RESOLVE_CULL=1`), fix 2 and 3, then an A/B on the 4090 spot with and without `nv-profile`: device losses, fps, and a recording checked for missing reflections or lighting. If the cull lets a stock 512 MiB heap survive with no visible loss, that's the case for turning it on by default.
Author
Contributor

Thanks for the thorough review! Updated fix/rt-resolve-zero-cull to address all 5 points:

  1. Opt-in: DARNER_RT_RESOLVE_CULL=1 is now opt-in (off by default) so it does not change default behavior ahead of flicker/A-B verification.
  2. Cached rt_resolve flag: Computed once on Pipeline creation in pipeline.rs (hand_out) alongside builder, so is_rt_resolve is an O(1) bool read with zero per-dispatch container scanning.
  3. Exact readback timing: Replaced the guessed done_at watermark with SlotInFlight(Arc<AtomicUsize>) guards attached to each HostList via list.hold(...) (at most once per (slot, list)). Sealed slots are harvested only when in_flight == 0, tying readback directly to the GPU completion of the exact list(s) carrying the copies across relay, thin lists, and cut lists.
  4. Key reuse cleanup: pipeline::release now calls rt_resolve_cull_release(this as usize) when a title pipeline's refcount drops to 0.
  5. NVIDIA-only: Gated on host.is_nvidia() (VendorId == 0x10DE).

Note from extended playtesting on the 4090 (stock 512 MiB heap): DARNER_RT_RESOLVE_CULL=1 extended a ~9 s doorway crash to 13m 28s before hitting 0x887A0005 again as newly visited areas accumulated unique CS_RaytracingResolve PSOs in Pending::made's OnceLock. Pairing this with darner nv-profile (1 GiB heap) and/or evicting idle culled resolve PSOs is the logical next step to test in the A/B.

Thanks for the thorough review! Updated `fix/rt-resolve-zero-cull` to address all 5 points: 1. **Opt-in:** `DARNER_RT_RESOLVE_CULL=1` is now opt-in (off by default) so it does not change default behavior ahead of flicker/A-B verification. 2. **Cached `rt_resolve` flag:** Computed once on `Pipeline` creation in `pipeline.rs` (`hand_out`) alongside `builder`, so `is_rt_resolve` is an O(1) bool read with zero per-dispatch container scanning. 3. **Exact readback timing:** Replaced the guessed `done_at` watermark with `SlotInFlight(Arc<AtomicUsize>)` guards attached to each `HostList` via `list.hold(...)` (at most once per `(slot, list)`). Sealed slots are harvested only when `in_flight == 0`, tying readback directly to the GPU completion of the exact list(s) carrying the copies across relay, thin lists, and cut lists. 4. **Key reuse cleanup:** `pipeline::release` now calls `rt_resolve_cull_release(this as usize)` when a title pipeline's refcount drops to 0. 5. **NVIDIA-only:** Gated on `host.is_nvidia()` (`VendorId == 0x10DE`). Note from extended playtesting on the 4090 (stock 512 MiB heap): `DARNER_RT_RESOLVE_CULL=1` extended a ~9 s doorway crash to 13m 28s before hitting `0x887A0005` again as newly visited areas accumulated unique `CS_RaytracingResolve` PSOs in `Pending::made`'s `OnceLock`. Pairing this with `darner nv-profile` (1 GiB heap) and/or evicting idle culled resolve PSOs is the logical next step to test in the A/B.
Author
Contributor

Follow-up A/B benchmarks using bench-kit (cam-city60 65 s city camera flight, Series X, Hardware RT DARNER_HW_RT=1, play.rs default tuning, warm pipeline library, RTX 4090) on the same --release --features bench-remote build rebased onto main (34b0ba7), toggling only DARNER_RT_RESOLVE_CULL=0 vs 1:

1. Stock NVIDIA shader heap (512 MiB, no nv-profile)

Metric (segment 1 — fast) DARNER_RT_RESOLVE_CULL=0 DARNER_RT_RESOLVE_CULL=1
Route completion Crashed at +2.33 s (frame 1215) (0x887A0005, no page fault, 5.8 ms after binding compute 503cf21ee3992b39) 100% clean (556 frames, 0.00 m readback error)
Median FPS / frame time 9.18 fps / 108.88 ms (21 pre-crash frames) 10.25 fps / 97.52 ms (9.28 overall, 8.06 slowest 10%)
P95 / P99 frame time 125.37 / 161.81 ms (pre-crash) 135.54 / 185.88 ms (full 556 frames)
Zero-group dispatches culled 0 554,279 (active_pipelines=85–129)

2. Raised NVIDIA shader heap (2048 MiB via darner nv-profile)

Both runs completed the full cam-city60 route 100% clean (rendered director = D 100.0%, body 100.0%, 0.00 m readback error):

Metric (segment 1 — fast) DARNER_RT_RESOLVE_CULL=0 DARNER_RT_RESOLVE_CULL=1 Delta
Frames rendered (60.0 s) 327 591 +80.7%
Overall FPS 5.44 fps 9.84 fps +80.9%
Median FPS 8.82 fps 10.01 fps +13.5%
Slowest tenth FPS 6.46 fps 8.30 fps +28.5%
Median frame time 113.32 ms 99.90 ms -13.4 ms (-11.8%)
P95 frame time 183.63 ms 128.36 ms -55.3 ms (-30.1%)
P99 frame time 3,199.48 ms 168.00 ms -3,031.5 ms (-94.7%)
Worst frame time 4,867.50 ms 217.54 ms -4,650.0 ms (-95.5%)
Frames > 100 ms 78.0% 49.2% -28.8 pp
worked_ms (median / p95) 105.26 / 151.85 ms 91.36 / 116.67 ms -13.2% / -23.2%
prep_ms (median / p95) 100.85 / 157.38 ms 88.51 / 123.26 ms -12.2% / -21.7%
pipe_wait_ms (total / max) 126,623 ms / 29,416 ms (14 made) 552 ms / 70 ms (17 made) -99.6%
Draws / frame (mean) 5,292 5,922 (+11.9%) —
Zero-group dispatches culled 0 543,253 (active_pipelines=88–122) —

Summary

Even alongside darner nv-profile (2048 MiB), culling zero-group CS_RaytracingResolve dispatches provides two complementary benefits on Hardware RT:

  1. Steady-state CPU/submission speedup (-11.8% median frame time, +13.5% median FPS, -13.2% worked_ms): skipping ~543k zero-group indirect dispatches and avoiding unused resolve-PSO churn reduces per-frame work even with ~12% more draws/frame.
  2. Eliminates multi-second resolve-PSO compile stalls (p99: 3,199 ms → 168 ms, worst: 4,868 ms → 218 ms): both 2 GiB runs compiled a similar number of city pipelines (14 vs 17), but off stalled 126.6 s compiling unused giant CS_RaytracingResolve variants, whereas on spent only 0.55 s total in pipe_wait_ms.
  3. Zero-setup crash prevention on stock 512 MiB: prevents the 0x887A0005 DXGI_ERROR_DEVICE_REMOVED crash on default driver setups without requiring elevated nv-profile.
Follow-up A/B benchmarks using `bench-kit` (`cam-city60` 65 s city camera flight, Series X, Hardware RT `DARNER_HW_RT=1`, `play.rs` default tuning, warm pipeline library, RTX 4090) on the same `--release --features bench-remote` build rebased onto `main` (`34b0ba7`), toggling only `DARNER_RT_RESOLVE_CULL=0` vs `1`: ### 1. Stock NVIDIA shader heap (512 MiB, no `nv-profile`) | Metric (`segment 1 — fast`) | `DARNER_RT_RESOLVE_CULL=0` | `DARNER_RT_RESOLVE_CULL=1` | |---|---:|---:| | **Route completion** | **Crashed at +2.33 s (frame 1215)** (`0x887A0005`, no page fault, 5.8 ms after binding compute `503cf21ee3992b39`) | **100% clean** (`556 frames`, `0.00 m` readback error) | | **Median FPS / frame time** | 9.18 fps / 108.88 ms *(21 pre-crash frames)* | **10.25 fps / 97.52 ms** *(9.28 overall, 8.06 slowest 10%)* | | **P95 / P99 frame time** | 125.37 / 161.81 ms *(pre-crash)* | **135.54 / 185.88 ms** *(full 556 frames)* | | **Zero-group dispatches culled** | 0 | **554,279** (`active_pipelines=85–129`) | ### 2. Raised NVIDIA shader heap (2048 MiB via `darner nv-profile`) Both runs completed the full `cam-city60` route **100% clean** (`rendered director = D 100.0%`, `body 100.0%`, `0.00 m` readback error): | Metric (`segment 1 — fast`) | `DARNER_RT_RESOLVE_CULL=0` | `DARNER_RT_RESOLVE_CULL=1` | Delta | |---|---:|---:|---:| | **Frames rendered (60.0 s)** | 327 | **591** | **+80.7%** | | **Overall FPS** | 5.44 fps | **9.84 fps** | **+80.9%** | | **Median FPS** | 8.82 fps | **10.01 fps** | **+13.5%** | | **Slowest tenth FPS** | 6.46 fps | **8.30 fps** | **+28.5%** | | **Median frame time** | 113.32 ms | **99.90 ms** | **-13.4 ms (-11.8%)** | | **P95 frame time** | 183.63 ms | **128.36 ms** | **-55.3 ms (-30.1%)** | | **P99 frame time** | 3,199.48 ms | **168.00 ms** | **-3,031.5 ms (-94.7%)** | | **Worst frame time** | 4,867.50 ms | **217.54 ms** | **-4,650.0 ms (-95.5%)** | | **Frames > 100 ms** | 78.0% | **49.2%** | **-28.8 pp** | | **`worked_ms` (median / p95)** | 105.26 / 151.85 ms | **91.36 / 116.67 ms** | **-13.2% / -23.2%** | | **`prep_ms` (median / p95)** | 100.85 / 157.38 ms | **88.51 / 123.26 ms** | **-12.2% / -21.7%** | | **`pipe_wait_ms` (total / max)** | 126,623 ms / 29,416 ms *(14 made)* | **552 ms / 70 ms** *(17 made)* | **-99.6%** | | **Draws / frame (mean)** | 5,292 | **5,922** *(+11.9%)* | — | | **Zero-group dispatches culled** | 0 | **543,253** (`active_pipelines=88–122`) | — | ### Summary Even alongside `darner nv-profile` (2048 MiB), culling zero-group `CS_RaytracingResolve` dispatches provides two complementary benefits on Hardware RT: 1. **Steady-state CPU/submission speedup (`-11.8%` median frame time, `+13.5%` median FPS, `-13.2%` `worked_ms`):** skipping ~543k zero-group indirect dispatches and avoiding unused resolve-PSO churn reduces per-frame work even with ~12% more draws/frame. 2. **Eliminates multi-second resolve-PSO compile stalls (`p99: 3,199 ms → 168 ms`, `worst: 4,868 ms → 218 ms`):** both 2 GiB runs compiled a similar number of city pipelines (`14` vs `17`), but `off` stalled `126.6 s` compiling unused giant `CS_RaytracingResolve` variants, whereas `on` spent only `0.55 s` total in `pipe_wait_ms`. 3. **Zero-setup crash prevention on stock 512 MiB:** prevents the `0x887A0005` `DXGI_ERROR_DEVICE_REMOVED` crash on default driver setups without requiring elevated `nv-profile`.
hingeowl force-pushed fix/rt-resolve-zero-cull from d0b48384ee to 82b66bf0c7 2026-12-04 04:33:47 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'fix/rt-resolve-zero-cull:hingeowl-fix/rt-resolve-zero-cull'
git switch 'hingeowl-fix/rt-resolve-zero-cull'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'hingeowl-fix/rt-resolve-zero-cull'
git switch 'hingeowl-fix/rt-resolve-zero-cull'
git rebase 'main'
git switch 'main'
git merge --ff-only 'hingeowl-fix/rt-resolve-zero-cull'
git switch 'hingeowl-fix/rt-resolve-zero-cull'
git rebase 'main'
git switch 'main'
git merge --no-ff 'hingeowl-fix/rt-resolve-zero-cull'
git switch 'main'
git merge --squash 'hingeowl-fix/rt-resolve-zero-cull'
git switch 'main'
git merge --ff-only 'hingeowl-fix/rt-resolve-zero-cull'
git switch 'main'
git merge 'hingeowl-fix/rt-resolve-zero-cull'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!187
No description provided.