d3d12: hardware RT: no BLAS refit across a NaN vertex; name RT alloca… #3168
Code
Clone this repository
Checkout
From your project repository, check out a new branch and test the changes.
git fetch -u origin "github-pr/3168:github-pr/3168" git switch "github-pr/3168"
Open
leonida/mandy
Callimann8 wants to merge 6 commits from
github-pr/3168 into main
pull from: github-pr/3168
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!3168
Loading…
Reference in a new issue
No description provided.
Delete branch "github-pr/3168"
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?
This branch is out-of-date with the base branch
Reviewers 0 approvals
Details
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Claimed in the coordination issue as: d3d12 hardware RT on AMD: lighting differs (BLAS refits across NaN vertices)
What and why
Two fixes and a diagnostics change for hardware ray tracing (
LEONIDA_HW_RT=1) ind3d12/crates/leonida-gpu/src/hwrt.rs, after a run on an AMD card (20 GB, Series X profile, 2560x1440) whose lighting differed from an RTX 4070's and that lost the device after about 6 minutes.copy_vb, andsane_positionfor vertices decoded on the CPU) make a triangle with a vertex that is not finite or past 1e10 inactive (NaN). They do it per frame. DXR leaves an update undefined if a primitive that was inactive at the first build becomes active, or the reverse (Raytracing spec, "Inactive primitives and instances"). A title's dynamic vertices that are NaN only in some frames therefore went through refits (PERFORM_UPDATE) that DXR does not define. The AMD run made about 460,000 refits in 345 s. Now each refittable structure (HostAs) holds, per geometry, how its build left the triangles inactive (Held). For a copy on the card, that is the positions it was built with, copied into a buffer of its own after the build. For vertices decoded on the CPU, it is a hash of which vertices are NaN. A refit'scopy_vbreads those positions (g_old): it writes NaN where the structure has NaN, and the old position where a vertex turned bad, so the set never changes. The refit goes ahead only when every geometry holds (refit_keeps_activity). That is decided in the same frame, before the build is recorded, with no readback. Otherwise the BLAS is built whole. Becauseexecute_copyshares theHostAsbetween source and copy, a copy keeps what its source held.copy_vbalso coversR16G16_FLOATandR16G16B16A16_FLOATvertices (f16tof32), and a BLAS with procedural boxes is never refitted, since a box is inactive where the title's ownMinXis NaN. The frame log's "hardware RT inputs" line counts "refits built whole as their inactive triangles could not be held" and "refits whose vertex copies held them". The held buffers stay common between uses, as buffers are after every submission. They are charged to the BLAS memory ledger, so the budget sees them. A geometry whoseTransform3x4has a NaN in the row giving X counts as wholly inactive, and one whose transform cannot be read is never refitted. The NaN-set hash runs only for structures a refit may follow. One difference stays by design: on the card path, a vertex that goes bad during refits keeps its last good position until the title asks for a full build, while on the CPU path the change forces a full build at once. Both are within DXR's rules.copy_vbread the third component of a two-component vertex (mode >= 3 ? g_src.Load(at + 8) : 0u, and HLSL's?:evaluates both sides) through a root SRV, which has no bounds. It now uses an explicit branch.crate::host::name. A device-removed report then names them when a page fault lands in one, and a diagnostics build's book records them. In the AMD run, the fault was inside a freed allocation listed as"unnamed (type 34)", and the book had no entry for it.The per-frame build budget change that was here (postbuild size queries and copies of waiting builds) is now its own PR.
Not settled by this PR
The AMD run's device loss was
DXGI_ERROR_DEVICE_HUNGwith a DRED page fault at0xd63da2000. That address is inside a host title-memory copy (0xdbb800000+0x800000at0xd63800000) that the 1 s sweep freed at 328.2 s (a "host copies of windows of title memory let go" entry 6.06 s before the loss). After that, an allocation with no name took the same address and was also freed. The log does not say which command read it. The report's "1 slots reach it: slot 10151" does not point at the culprit. That slot is a 1728x960 texture whose metadata sits 18.6 MB below the fault, and the book's heuristic counts any texture with metadata within 32 MB as reaching it. The "view heap / sampler heap past its end" parts only say the address is in neither heap. A repro with this branch andLEONIDA_D3D12_DRED=light(or=1) should name the command and the allocation.Tests
cargo check -p leonida-gpu --target x86_64-pc-windows-msvc(also--testsand--features diagnostics) andcargo clippywith no new warnings. On Windows (x2Tweek, ate7558c4dmerged ontomain):cargo test -p leonida-gpu --lib hwrt, 26 passed, 0 failed, including the FXC compile ofSANITIZE_HLSL. Debug layer and GPU-based validation (Kal0s-design, NVIDIA and WARP, a test replaying the held-buffer barriers and NaN refits): no state errors.a_refit_is_refused_unless_every_geometry_keeps_its_inactive_triangles(the refit policy: it fails if the guard is made to allow everything),a_refit_is_recorded_only_from_the_structure_its_copies_held(the flush's check),a_nan_in_the_transform_row_giving_x_makes_the_geometry_inactiveandthe_nan_set_of_decoded_vertices_tells_which_vertices_are_nan.the_card_copies_follow_the_cpu_rules_and_compilenow also checks that there is no load on either side of a?:, that copy_vb merges against the held positions, and that it reads half floats.-HardwareRT, about 6 minutes): no device loss, lighting as expected, about 21 fps as before. 152 refits built whole against 140,418 held. Again ate7558c4din game (340 s, on foot and driving): no device loss, no lighting fault, 205 built whole against 85,481 held (0.24 %).Verified here: it applies on the current
mainand thehwrtgroup passes - 23 tests, 0 failed, including the new one.The new test is the right one for the change: a BLAS whose vertex became NaN is found by its marks and its staged vertices - that is what "do not refit across a NaN vertex" has to look like from the outside, and it is the case that would otherwise be a silent lighting difference rather than a crash.
Why it may matter to a thread you already have: #3135 is a report of hardware RT on a 5090 asking whether the lights differ - and this is a correctness fix in the same path (the AMD refit-across-NaN one). Two different bugs in one feature are worth merging independently, and this one has a test.
What it does not cover: the lighting. The test checks the bookkeeping around the BLAS, not what the rays produce - that needs
LEONIDA_HW_RT=1on a run and two images to compare, which this machine cannot do (no title).One thing for the merge: the pull request currently shows
UNSTABLEin the checks - with a green suite locally, that is worth a look before asking for a review.AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.
Thanks, all good points. Pushed 2ab4e92b, which replaces the marks entirely instead of patching them.
1. One frame late. Agreed, and there's no readback any more. Each refittable
HostAsnow holds, per geometry, how its last build left the triangles inactive (Held). For card copies, that's the positions it was built with, copied into a buffer of its own after the build. For CPU-decoded vertices, it's a hash of which vertices are NaN. A refit'scopy_vbreads those positions asg_old. It writes NaN where the structure has NaN, and the old position where a vertex has just turned bad, so the inactive set can't change. The refit is allowed only if every geometry holds (refit_keeps_activity), which is decided before the build is recorded, in the same frame. Otherwise the BLAS is built whole. So the first clean→NaN frame refits with the vertex frozen at its last good position rather than going inactive.2. VA-keyed, never cleared, lost through copies. The state now lives on the
HostAsitself. It's replaced on every build or refit of that structure, goes away with it, andexecute_copy's alias shares it because it's the sameArc. Thetitle_memory_freedpruning is gone. The flush also checks that the source it refits is the sameHostAsthe copies were made against.Coverage. You're right that the comment was wrong.
copy_vbnow handlesR16G16_FLOATandR16G16B16A16_FLOAT(f16tof32), and the comment is fixed. BLASes with AABBs are never refitted, sinceMinXNaN is the title's own and we can't hold it.Mutation. New
a_refit_is_refused_unless_every_geometry_keeps_its_inactive_trianglescovers the policy (an unmerged card copy, a changed CPU NaN set, a changed vertex count, boxes, and mismatched geometry lists are all refused). It fails ifrefit_keeps_activityis made to return true. There's also a test for the NaN-set hash, and string checks on the shader's merge rule. The guard inflush_blas_wavesitself is still only covered through that function, since it sits in command recording.PR body. Updated: it now describes the new design and the budget commit (postbuild size queries and copies of waiting builds now wait under the frame budget).
Caveat: I've only checked this with
cargo check/clippyfor the Windows target (also--testsand--features diagnostics).cargo test -p leonida-gpu hwrt, which compiles the HLSL with FXC, still needs a Windows run, and the AMD retest is pending.Code review only, not built:
leonida-gpuis Windows-only and the HLSL inhwrt.rscompiles with FXC at test time. Not ready to merge yet: the current head has not been run anywhere.2ab4e92bf, merge base3c106eb2f, 21 behind currentmain45dc41f95. A trial merge is clean.6115d0340only. Since then two commits changed the design:02706e17(budget) and2ab4e92b, which replaced the readback marks with per-HostAsHeldstate,g_oldand f16 positions. By the author's own note,2ab4e92bhas only hadcargo check/clippy.What reads right (
d3d12/crates/leonida-gpu/src/hwrt.rs):refit_keeps_activitydecides before recording, in the same frame, whether a refit is allowed, and refuses whenever activity cannot be held: AABB geometry, a changed count, a CPU NaN set that differs, or a card copy withoutg_old. That respects the DXR rule on inactive primitives at the root, instead of detecting the problem a frame late.heldon theHostAsbehind itsArcmakes it follow copies and be freed with the structure. The old VA-keyed map withtitle_memory_freedpruning is gone.create_default_bufferrounds the width to 256 bytes, so the reuse check inhold_activity(*b >= bytesagainst the rounded size) cannot copy past the end.Concerns:
02706e17changes the BLAS budget: postbuild sizes are answered withtold_forprebuild sizes while the build waits, andcopy_waitingqueues clones and compactions as builds ofdest. That is a separate behaviour change to queueing and sizing, not part of "no BLAS refit across a NaN vertex". CONTRIBUTING.md asks for one topic per pull request, with follow-ups in a new one. It also carries most of the risk: a compaction destination now becomes a whole build from the source request, sized bytold_for. Please split it out, or show that the compacted-size contract still holds with a test.copy_vbwithmode & 256checks onlyold.xfor NaN. That is correct as long as every writer stores all three components as NaN, which the shader does. A one-line comment would stop a future writer from breaking this.a_refit_is_refused_unless_every_geometry_keeps_its_inactive_trianglespins the policy function. Nothing exercises theflush_blas_wavesguard (held_fromagainstArc::as_ptr(src_entry)) or theheld_readbarrier bookkeeping. The author acknowledges this.Needed before merge:
cargo test -p leonida-gpu hwrton Windows at this head, a debug-layer run (the new COMMON, COPY_DEST, COMMON and SRV-promotion transitions on held buffers are what it would catch), and the in-game render-path gate with-RayTracing.Verdict: not ready (no test run on this head, and two topics). No concrete defect found in the refit logic.
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
Split as asked: the budget change is reverted here and parked on its own branch. It'll come as a separate PR once this one lands (I can only have one open at a time)
RUN (in game) -- Windows
hwrtdebug-layer unit tests + 300 s-HardwareRTrender-path gate run for PR #3168:337388052mainSHA:f1a559851(git merge --no-ff, clean merge)python -I scripts/check_no_game_data.pyPASSLEONIDA_D3D12_DEBUG=1 cargo test -p leonida-gpu --features diagnostics --lib --locked hwrt-- 24 passed, 0 faileddiagprofile (diagnostics,dlss,mimalloc), Series S profile, DLSS on, Hardware RT enabled (LEONIDA_HW_RT=1,LEONIDA_AMBIENT=0,LEONIDA_RT_RESOLVE=1,LEONIDA_ACTIVATE_RAYS=1), Frame Gen off, same restored save snapshot337388052onf1a559851)mainalone (f1a559851, ref)Loaded cleanly into the world with DXR Hardware RT active, stayed up past 300 s in-world with 0 device lost / 0 crashes / 0
ERRORlines, and closed cleanly.Verdict: PASS.
AI-assisted: yes (Antigravity).
NVIDIA run and the Windows tests, the two TODOs above.
Setup: RTX 5090 32 GB, driver 621.40, i9-14900KS, 64 GB DDR5, Windows 11 (26300). Base: upstream main
0d7a451abplus #3113 and #3182, diag build. This PR merged on top at337388052. Series X profile, 3840x2160output, render scale 0.6667, the title's upscaler,
-HardwareRT -SmoothMotion -PrecompileAll -Log, borderlesswindow. About 6 minutes of play from a save, then city driving at night.
Windows tests:
cargo test -p leonida-gpu --lib hwrtgives 25 passed and 0 failed, includingthe_card_copies_follow_the_cpu_rules_and_compile(the FXC compile ofSANITIZE_HLSL).The run's frame log, at the end:
went ahead. So on this title and card, a dynamic vertex turning NaN between frames is rare (about 0.1 % of
refits), and the guard costs next to nothing in rebuilds.
kind of drive (about 20 to 21 fps on earlier runs), so I see no measurable cost; the runs were not on the same route.
Screenshots are available.
AI-assisted: the build, the test run, the log reading and the write-up were done with Claude Opus 5.5 (Claude
Code); the numbers are the runtime's own log lines from the run above.
Ran natively on Windows 11, head
337388052merged into currentmain(b41763227, clean merge).lixonik already ran
hwrton this head, over an oldermain. This adds the full crate on currentmain, the copy shader and the refit rule run directly on the card and WARP, the held-buffer barriers under the debug layer, and two mutations.Suite
cargo test -p leonida-gpu --lib --test-threads=4. The card supports raytracing tier 1.2.--features diagnosticsLEONIDA_D3D12_WARP=1LEONIDA_D3D12_DEBUG=1The last two rows had the switch set, but nothing in the output confirms it took effect. No "host device" line shows up in the test output. From reading the code, the
hwrttests never create a device throughhost.rs, so the switches don't reach them anyway. For the WARP and debug-layer checks I wrote a throwaway test that creates its own device on the card or on WARP (tier 1.1), with the debug layer and optionally GPU-based validation turned on. Results are below.Red/green check, measured. Making
refit_keeps_activityalways returntruefailsa_refit_is_refused_unless_every_geometry_keeps_its_inactive_triangles(23/24). Replacing both guards inflush_blas_waves(&& !unheldand theheld_frompointer check) withtruestill passes all 24hwrttests. So MoonEyes' point 3 still applies.cargo clippy -p leonida-gpu --all-targets --features diagnosticsreports nothing inhwrt.rs.copy_vbon the card (measured)I dispatched the PR's
copy_vbdirectly and compared the output withsane_position. The card and WARP gave identical results. All 12 f32 cases matched the CPU rule bit for bit.0x7FC00000R32G32where the next vertex's x is NaNR16G16B16A16_FLOATwith NaN or Inf in wR16G16)The refit merge (
mode | 256againstg_old) behaved like this.old.xis checked (as the new comment says)Debug layer (measured)
The held-buffer sequence was replayed in one list as the PR records it. A default buffer created
COMMONis read as root SRVt1, thenNON_PIXEL_SHADER_RESOURCE→COMMON. NextCOMMON→COPY_DEST, the copy, then back toCOMMON. The piece goesUNORDERED_ACCESS→NON_PIXEL_SHADER_RESOURCE→COPY_SOURCE→UNORDERED_ACCESS. That ran twice in one list, then once more in a second list after decay. On the card and on WARP, with the debug layer and GPU-based validation on, there were no errors or warnings about states. The only messages came from my own buffer creation and the GBV startup notice.Then a BLAS with
ALLOW_UPDATEand two triangles, one with a NaN vertex. I ran a build, then three refits in one list: NaN held, inactive to active, and active to inactive (out of place). Neither the card nor WARP raised anything, GBV included. The debug layer doesn't check this rule, so the same-frame guard in this PR is the only thing that does. A debug-layer run can't answer the AMD lighting question.After the NaN goes away (read, with the shader part measured above)
On the card path, a vertex that was NaN when the structure was built stays NaN on every later refit, because
hold_activitystores each refit's output as the nextg_old. The triangle comes back only when the title asks for a full build. A vertex that goes bad during refits stays frozen at its last good position and doesn't vanish. That's within DXR's rules. Until the title rebuilds, though, the result differs from a full build, and I can't tell how often the title rebuilds.Vertices decoded on the CPU work differently. Any change in the NaN set, either way, makes that frame a whole build, and refits continue once the set is stable. So here the triangle comes back immediately. The two paths treat the same situation in different ways.
The CPU hash covers every decoded vertex, including ones no triangle references. A NaN that flickers in an unused vertex forces whole builds that aren't needed. That's conservative, not wrong. On the card path, unreferenced vertices change nothing.
Cost
staged_nan_hash, measured in a debug test build only (no release build here), takes about 22 ms per 1M vertices and 90 ms per 4M. NaN or not makes no difference, and it scales linearly. I didn't time the release build or the decode it runs next to. It runs for every CPU-decoded geometry, even when no refit is asked for.On the card path (read), every build or refit of an
ALLOW_UPDATEBLAS adds aCopyBufferRegionofvertices * 12bytes, and the touched pieces get an extra transition toCOPY_SOURCE. The held buffers (vertices * 12, rounded to 256) come fromcreate_default_bufferand are never charged to the BLASLEDGER, so that VRAM falls outside the budget. They are freed together with theHostAs.Not covered by either PR (read)
A NaN in a geometry's own
Transform3x4makes the whole geometry inactive in the build.Activitydoesn't look at the transform, so a refit across a transform turning NaN, or recovering, still changes activity. #3107 guards instance transforms inREMAP_HLSL(TLAS), not this.Other open PRs touching
hwrt.rsI filtered open PRs by changed files.
git merge-treewith this onehwrt.rs, two hunks insanitize(): #3107'sdispatch_1d_gridagainst this PR's 4th root view. Keep both. The shader merges on its own, andg_old.Load3(v * 12)uses #3107's 2Dv. The NaN handling doesn't overlap (instances vs vertices).Not checked: in-game runs (no title here), AMD hardware, a release build or release timing, GPU time of the extra held copies, #3107 + #3168 built and tested together after resolving the conflict, and ray tracing through the refitted BLAS (my BLAS test only looks at validation).
GPUs tested: one NVIDIA desktop card + WARP
AI-assisted: yes (Claude Code).
Thanks for the thorough run, especially the copy_vb table and the debug-layer replay. Pushed e7558c4d:
refit_from_held(held_from, source), and it has its own test (a_refit_is_recorded_only_from_the_structure_its_copies_held). Making it always return true now fails. The!unheldterm only counts and short-circuits, becauseheld_from == 0already makesrefit_from_heldfalse.t[0..4]) makes the geometryInactive. A NaN anywhere else, or a transform we can't read, makes itUnknown, which is never held, so that BLAS is built whole.ALLOW_UPDATEorPERFORM_UPDATE, or a refit asked for). Otherwise the activity isUnknown, and nothing is stored for it anyway.LEDGER(BlasMemory, rounded size) and released with the buffer.sanitize()hunks the way you described.cargo check/clippyfor the Windows target are clean (also with--testsand--features diagnostics). The new tests haven't run on Windows yet.This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists).
Could you, or anyone with a working setup, post a run report on the current head merged onto current
main:mainSHA it was merged onto;mainalone for comparison, if you can.Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough.
AI-assisted (Claude Code).
RUN (in game, RTX 5090 32 GB, hardware RT, 340 s in the world): PASS, 0 device losses on the current head.
e7558c4dfmerged withgit merge --no-ffontomainf3865cae8(merge82c4f1660,clean). No other changes: no local patches and no other PRs.
26300).
diagnostics,dlss,mimalloc.cargo test -p leonida-gpu --lib hwrtgives 26passed and 0 failed.
-HardwareRT -SmoothMotion -PrecompileAll -Log, fullscreen.device removedline in the log.250 ms in the 5 s lines. I put these down to
main's known costs on this card, not to this PR: the 1.5 GB BLAScap (#3135 / #3225) and cold masked-pipeline compiles (#3200 / #3105).
could not be held 205, refits whose vertex copies held them 85481", so the guard rebuilds about 0.24 % of the
refits.
AI-assisted: the build, the run, the log reading and the write-up were done with Claude Opus 5.5 (Claude Code);
the numbers are the runtime's own log lines.
VERIFY-3168 — Windows nativo:
red then greenen el guardián del refite7558c4df—hwrt.rs, +89/−9Ran at the head
Negative control (synthetic): I weakened the guard from
held_from != 0 && held_from == sourceto||, rebuilt and ran:It bites, and the mutation is exactly the bug the guard exists for: a refit recorded against a structure nobody's copies were made from.
&&and||differ by one character and by a corrupted BLAS.What the change is:
refit_from_held(held_from, source)records a refit only from the structure the copies were actually made from;refit_keeps_activityrefuses a refit whose geometries changed which triangles are inactive (DXR: none may become active, none inactive) with boxes never refitted; and aNaNin the transform row that givesxmakes the geometry inactive.Why the second test is the interesting one: a
NaNin a transform does not fail on the GPU — it silently produces a geometry whose tests never pass, which reads as "the ray missed" for every ray of that instance. Turning it into "inactive" is turning an invisible failure into a stated one.What I could not test
Written with an AI assistant.