hwrt: avoid concurrent-THIN TLAS reallocation and mid-frame descriptor swap #279
Loading…
Reference in a new issue
No description provided.
Delete branch "hingeowl/Darner:fix/hwrt-tlas-concurrent-thin-race"
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 a Hardware RT
0x887A0006(DXGI_ERROR_DEVICE_HUNG) /nvlddmkmEvent ID 13 (Graphics SM Warp Exception: MMU Fault) race when twoDARNER_THIN=1worker threads record TLAS builds concurrently.Root Cause
In
crates/darner-gpu/src/hwrt.rs,alloc_or_reuse_as()gated in-place reuse onArc::strong_count(existing) == 1for both BLAS and TLAS so a build would not overwrite a buffer aliased byexecute_copy().However,
execute_tlas()holds its own localdest_as: Arc<HostAs>acrossBuildRaytracingAccelerationStructure,ResourceBarrier, andemit_postbuild()(~0.5 ms). When twoDARNER_THIN=1worker threads enterexecute_tlas()for the same TLASconsole_vawithin that window:dest_asraisesArc::strong_count(existing)from1to2.alloc_or_reuse_as(), seesArc::strong_count(existing) != 1, allocates a brand-new unbuilt 4 MiB TLAS buffer, overwritesas_map[console_va], and immediately callscrate::descriptor::refresh_tlas_views().refresh_tlas_views()overwrites live shader-visible SRV descriptors with the uninitialized TLAS GPU VA while earlier frames are still executingTraceRayon the GPU, causing an immediate SM Warp MMU Fault (nvlddmkmEvent ID 13) and0x887A0006.(Note:
execute_tlas'splane_uploadclosure already had a comment noting this exactArc::strong_counthazard underDARNER_THIN, butexecute_tlasitself still helddest_asacross the build.)Evidence
Observed in two independent 4K + Hardware RT playtest crashes with the exact same NVIDIA shader fault PC (
nvlddmkmEvent ID 13,ESR ...=0xf812b60 / 0x1104). In both crash logs, every preceding frame had a single worker thread recording TLAS builds until the final frame right before device removal, where two worker threads overlapped and recorded4 TLASbuilds within0.1 ms(Crash 1) and0.5 ms(Crash 2) of each other. IncreasingDARNER_THINworker thread count (e.g., PR #37) increases the overlap frequency and reproduces the fault sooner.Fix
copied: AtomicBoolonHostAs, set inexecute_copy()when aHostAsis aliased to a secondconsole_va.alloc_or_reuse_as(), forAsKind::Tlas(when!force_new && !tlas_fresh()), check!existing.copied.load(Ordering::Acquire)instead ofArc::strong_count(existing) == 1.as_map.write()lock before inserting a newly allocated TLAS so two threads racing on a first build/resize also avoid redundant reallocation and doublerefresh_tlas_views().Validation
cargo test -p darner-gpu --locked -- hwrt::— 26 passed, 0 failed.darnercleanly.MeshletCache/HostAsBLAS UAFs).PASS
Review of
353404b72.The TLAS reuse and in-flight descriptor handling changes were audited, including the interaction with the adjacent
#268work. 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— 25 passed, 0 failed.Not run in-game.
AI-assisted: yes (GitHub Copilot, Auto mode).
Code review only (read the diff at
353404b7), nothing built or run. I agree with lewis499: no blocking issue.copiedflag goes in before the alias does (under theas_mapwrite lock), and the second check under that lock drops the extra TLAS without arefresh_tlas_views. Looks right.DARNER_THINand more workers (#37), with and without this PR, would settle it.[pr-fix][RAYTRACING].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.