[pr-fix][RAYTRACING] hwrt: fix BLAS TDR bursts, ArenaSlot UAF on open thin lists, and in-flight HostAs reuse #268
Loading…
Reference in a new issue
No description provided.
Delete branch "hingeowl/Darner:fix/hwrt-blas-tdr-and-uaf"
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
DXGI_ERROR_DEVICE_HUNG(0x887A0006) insideBuildRaytracingAccelerationStructure(D3D12_AUTO_BREADCRUMB_OP_BUILDRAYTRACINGACCELERATIONSTRUCTURE, op 31) andnvlddmkmEvent ID 13Graphics SM Warp Exception: MMU Faultduring extended Hardware RT (DARNER_HW_RT=1) play sessions with large BLAS rehydrate/compaction streaming bursts.Crash evidence (RTX 4090, 4K + DLSS Quality + 2x FG + HW RT)
0x887A0006):nvlddmkmEvent ID 13Graphics SM Warp Exception: MMU Fault(Multiple Warp Errors) immediately following ~300+ BLAS rehydrates and ~100+ BLAS/TLAS builds recorded concurrently across worker threads with 26 submissions in flight.DARNER_D3D12_DRED=light,0x887A0006): DRED auto-breadcrumb stopped atcommand 503 of 1075 (op 31)(BuildRaytracingAccelerationStructure) after waiting2,288.4 ms(Windows 2 s TDR,nvlddmkmEvent ID 153), immediately following 60+mode 1compaction copies + 201 rehydrates + 21 builds packed into one command list.What it changes (
crates/darner-gpu/src/hwrt.rs)copy_waiting():HwRtOp::Copy(dest, src)whosesrcwas deferred inBacklogcalledq.budget.force(...)+execute_blas_batchsynchronously, bypassingBUILDS_PER_FRAMEand emitting a separate BLAS wave per copy into the same command list.execute_copyaliasesas_map[dest] = as_map[src](no GPU compaction copy),copy_waiting()now usesBacklog::copy_entryto re-key (mode == 1compaction) or clone (mode != 1) the waiting recipe todest(b.dest_va = dest), letting it build under the normal per-frame budget while TLAS masksdestuntil ready.64builds /16 MiBinputs, chunks32/8 MiB):256/64 MiB(chunks64/16 MiB) so 200–400 BLAS area-streaming/rehydrate bursts spread cleanly across several frames instead of packing 500–1,075 RT ops into a single submission and hitting Windows' 2 s TDR.MeshletCacheArenaSlotuse-after-free underDARNER_THIN=1(cached_meshlet_ib):cached_meshlet_ibpreviously calledlist.keep(&entry.buffer)(keeping the 32 MiBArenaBlockbuffer) without holdingArc<DecodedIb>(which ownsslot: Option<ArenaSlot>). IfMeshletCacheevictedentrywhile a thin worker-thread list was still open (not yet submitted),DecodedIb::dropcalledretire(slot)against an earlier fence, allowingArenaSlot::dropto free andarena_writeto overwrite those 4 KiB units before GPU execution.list.hold(Box::new(entry.clone()))on both cache-hit and cache-miss paths.HostAsoverwrite race (emit_blas_wave):emit_blas_wavepreviously kept only the COMID3D12Resource(list.keep(&r.dest_as.buffer)), lettingArc::strong_countdrop back to1while the list was still open or in flight soalloc_or_reuse_as/flush_blas_waves(Arc::strong_count == 1) could overwrite an in-flight BLAS buffer in place.list.hold(Box::new(r.dest_as.clone()))(andr.src_aswhen present), leavingAsKind::Tlasuntouched per the existing descriptor-view invariant.Verification
cargo test -p darner-gpu --locked -- hwrt::— 26 passed; 0 failed (including newbacklog_copy_entry_moves_compact_and_clones_other_without_forcing_build).bench-kitcam-city60(HW RT, RTX 4090,DARNER_D3D12_DRED=light): 100% clean (646frames,0.00 merror, zeronvlddmkmevents),10.27 fpsmedian (97.38 ms,p95 = 122.02 ms,p99 = 164.53 ms,>100 ms = 39.8%vs10.01 fps/128.36 msp95 /49.2% >100 mspre-fix even without DRED).bench-kitfull 172 scam-citystress test (HW RT, RTX 4090,DARNER_D3D12_DRED=light): 100% clean (1,629frames,0.00 merror, zeronvlddmkmevents), surviving26,796BLAS builds,55,295refits,10,586rehydrates,7,002copies,4,525evictions, and71,435meshlet IBs.PASS
Review of
75abcd65b.Audited
copy_waitingsource/destination bookkeeping, moved refit addresses, held-list lifetimes, and overlap with#279. No blocking correctness issue found.Windows validation: G1 PASS; G2 PASS;
cargo xtask policyPASS (555 files ok);cargo test --locked -p darner-gpu --lib hwrt— 26 passed, 0 failed.Not run in-game.
AI-assisted: yes (GitHub Copilot, Auto mode).
Code review only (read the diff at
75abcd65), nothing built or run. I agree with lewis499 that thecopy_waitingbookkeeping and the meshletholdare right. One point needs a measurement:HostAsholds is worth measuring. Blocking reuse while a list is in flight is the point of the holds. The side effect:list.holdkeeps theArcuntil the list is reset, andflush_blas_wavesrefits in place only whenArc::strong_count(src_entry) == 1(alloc_or_reuse_aslikewise). So a BLAS refit every frame (animated geometry) likely gets a new buffer per refit (RefitPlan::AllocDest,force_new) until its earlier list resets. That means more BLAS memory alive at once and more pressure on the BLAS budget and LRU. A comparison ofblas_heap_line()(heaps MB, in use) and the BLAS creation count on the same route, with and without this change, would show how much. If it is large, the hold could be limited to where lists are recorded out of order (DARNER_THIN).copy_waitingnow hidesdestuntil its build runs, so after a large rehydrate burst some objects may be missing from reflections and shadows for more frames. Worth a side-by-side look on a fast drive.mode != 1) of a waiting source now builds twice (source and copy), where before one build was aliased.Reviewed with Claude Code (AI-assisted); findings checked by a human before posting.
View 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.