gpu: async zero-group culling for CS_RaytracingResolve indirect dispatches (fixes NVIDIA 0x887A0005 device removal) #187
Loading…
Reference in a new issue
No description provided.
Delete branch "hingeowl/Darner:fix/rt-resolve-zero-cull"
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?
Summary
Fixes recurring
DXGI_ERROR_DEVICE_REMOVED(0x887A0005, no page fault, empty DRED breadcrumbs, nonvlddmkm4101 TDR) crashes on NVIDIA GPUs when ray tracing (DARNER_HW_RT=1or software RT withCS_RaytracingResolveenabled) 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:
DARNER_HW_RT=0, DARNER_RT_RESOLVE=1(zero DXR/BVH/RayQuery).tables(), root arguments, andExecuteIndirect(so zeroCS_RaytracingResolvethreads execute on the GPU) while still callingSetPipelineState(&p.pso)on all ~220+CS_RaytracingResolvepipelines still crashes with0x887A0005in seconds.SetPipelineState(&p.pso)— with 100% of those PSOs still created and alive — eliminates the crash completely, and keeping any subset up to 15/16 ofCS_RaytracingResolvealso eliminates it.CS_RaytracingResolveExecuteIndirectcalls per frame across ~220+ giant compute shaders (58–79 KiB each), even though only ~80–118 material buckets have non-zeroThreadGroupCountin any given scene. Binding all ~220+ giant resolve PSOs viaSetPipelineStatecommits 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;0to disable)crates/darner-gpu/src/draw.rs): Copies each single-recordCS_RaytracingResolveindirect dispatch's 12-byte[x, y, z]arguments into a 4-slot persistently mappedD3D12_HEAP_TYPE_READBACKring, harvests completed slots after their GPU submission fence lands, tracks active resolve pipelines with a 60-frame keep-alive grace window, and skipshost_pipeline()/SetPipelineState/ExecuteIndirectfor idle(0, 0, 0)buckets.crates/darner-gpu/src/pipeline/make.rs): When culling is enabled, skipsearly_startforCS_RaytracingResolveso inactive permutations are never committed; active ones load from the mappedID3D12PipelineLibrary(~4–5 ms) on first non-zero hit.crates/darner-gpu/src/pipeline.rs): Addsis_rt_resolve.Validation
cargo test -p darner-gpu --locked -- rt_resolve_cull_nonzero_and_keep_alive_windowpasses (1 passed; 0 failed).cargo check --workspace --tests --lockedpasses cleanly on latestmain.DARNER_HW_RT=1,DARNER_RELAY=2, DLSS Quality, 2x FG):0.0 msGPU stall, spotless interior Hardware RT lighting and reflections.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 ofac4cca96; it can't go in on by default as it is:is_rt_resolve. It runscontainer.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.done_at = started + queued + 2at 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. Tiedone_atto the submission number of the list that actually carries the copy.activeis 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.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 withoutnv-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 thorough review! Updated
fix/rt-resolve-zero-cullto address all 5 points:DARNER_RT_RESOLVE_CULL=1is now opt-in (off by default) so it does not change default behavior ahead of flicker/A-B verification.rt_resolveflag: Computed once onPipelinecreation inpipeline.rs(hand_out) alongsidebuilder, sois_rt_resolveis an O(1) bool read with zero per-dispatch container scanning.done_atwatermark withSlotInFlight(Arc<AtomicUsize>)guards attached to eachHostListvialist.hold(...)(at most once per(slot, list)). Sealed slots are harvested only whenin_flight == 0, tying readback directly to the GPU completion of the exact list(s) carrying the copies across relay, thin lists, and cut lists.pipeline::releasenow callsrt_resolve_cull_release(this as usize)when a title pipeline's refcount drops to 0.host.is_nvidia()(VendorId == 0x10DE).Note from extended playtesting on the 4090 (stock 512 MiB heap):
DARNER_RT_RESOLVE_CULL=1extended a ~9 s doorway crash to 13m 28s before hitting0x887A0005again as newly visited areas accumulated uniqueCS_RaytracingResolvePSOs inPending::made'sOnceLock. Pairing this withdarner nv-profile(1 GiB heap) and/or evicting idle culled resolve PSOs is the logical next step to test in the A/B.Follow-up A/B benchmarks using
bench-kit(cam-city6065 s city camera flight, Series X, Hardware RTDARNER_HW_RT=1,play.rsdefault tuning, warm pipeline library, RTX 4090) on the same--release --features bench-remotebuild rebased ontomain(34b0ba7), toggling onlyDARNER_RT_RESOLVE_CULL=0vs1:1. Stock NVIDIA shader heap (512 MiB, no
nv-profile)segment 1 — fast)DARNER_RT_RESOLVE_CULL=0DARNER_RT_RESOLVE_CULL=10x887A0005, no page fault, 5.8 ms after binding compute503cf21ee3992b39)556 frames,0.00 mreadback error)active_pipelines=85–129)2. Raised NVIDIA shader heap (2048 MiB via
darner nv-profile)Both runs completed the full
cam-city60route 100% clean (rendered director = D 100.0%,body 100.0%,0.00 mreadback error):segment 1 — fast)DARNER_RT_RESOLVE_CULL=0DARNER_RT_RESOLVE_CULL=1worked_ms(median / p95)prep_ms(median / p95)pipe_wait_ms(total / max)active_pipelines=88–122)Summary
Even alongside
darner nv-profile(2048 MiB), culling zero-groupCS_RaytracingResolvedispatches provides two complementary benefits on Hardware RT:-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.p99: 3,199 ms → 168 ms,worst: 4,868 ms → 218 ms): both 2 GiB runs compiled a similar number of city pipelines (14vs17), butoffstalled126.6 scompiling unused giantCS_RaytracingResolvevariants, whereasonspent only0.55 stotal inpipe_wait_ms.0x887A0005DXGI_ERROR_DEVICE_REMOVEDcrash on default driver setups without requiring elevatednv-profile.d0b48384eeto82b66bf0c7View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.