d3d12: hardware RT: no BLAS refit across a NaN vertex; name RT alloca… #3168
Open
Callimann8 wants to merge 6 commits from
upstream-pr/3168 into main
pull from: upstream-pr/3168
merge into: ProjectLeonida:main
ProjectLeonida:main
ProjectLeonida:claude/loop-total
ProjectLeonida:claude/pops-collision-seed
ProjectLeonida:claude/dstorage-hold-page-reads
ProjectLeonida:claude/host-image-copy-switch
ProjectLeonida:feat/gdk-lifecycle-window-hook
ProjectLeonida:claude/d16s8-uav-nvidia-fallback
ProjectLeonida:feat/mfplat-offline-shim
ProjectLeonida:claude/gameinput-slow-reader
ProjectLeonida:fix/rt-null-barrier-clear
ProjectLeonida:claude/depth-resolve-sample-positions
ProjectLeonida:integration/palmetto-parity
ProjectLeonida:claude/valu-literal-sext
ProjectLeonida:claude/slot74-pool-handle
ProjectLeonida:claude/rgb9e5-uint-alias-view
ProjectLeonida:claude/fssm-root-layout-tables
ProjectLeonida:feat/gdk-speech-display-lifecycle
ProjectLeonida:asset-audio-skip-current
ProjectLeonida:qemmhd/old-9940-rectangle-quad-lists
ProjectLeonida:feat/ws2-offline-shim
ProjectLeonida:qemmhd/rt-d16-unorm-uav
ProjectLeonida:feat/xs-device-stops-7-9
ProjectLeonida:qemmhd/rt-depth-same-base-shapes
ProjectLeonida:qemmhd/rt-lazy-attachment-variant
ProjectLeonida:feat/acphal-xma2-decoder
ProjectLeonida:asset-audio-skip
ProjectLeonida:codex/coord-claim-check-20261124-7e48
ProjectLeonida:feat/xs-frame-pacing-presentx
ProjectLeonida:feat/xs-device-vm-options
ProjectLeonida:old-pr/9844
ProjectLeonida:old-pr/9978
ProjectLeonida:old-pr/9815
ProjectLeonida:old-pr/10057
ProjectLeonida:old-pr/9874
ProjectLeonida:old-pr/9965
ProjectLeonida:old-pr/9863
ProjectLeonida:old-pr/10068
ProjectLeonida:old-pr/10066
ProjectLeonida:old-pr/10067
ProjectLeonida:old-pr/10007
ProjectLeonida:old-pr/10061
ProjectLeonida:old-pr/10065
ProjectLeonida:old-pr/10059
ProjectLeonida:old-pr/10063
ProjectLeonida:old-pr/10055
ProjectLeonida:old-pr/10062
ProjectLeonida:old-pr/10042
ProjectLeonida:old-pr/10041
ProjectLeonida:old-pr/10049
ProjectLeonida:old-pr/10047
ProjectLeonida:old-pr/10046
ProjectLeonida:old-pr/10045
ProjectLeonida:old-pr/10056
ProjectLeonida:old-pr/10043
ProjectLeonida:old-pr/10036
ProjectLeonida:old-pr/10034
ProjectLeonida:old-pr/9984
ProjectLeonida:old-pr/10052
ProjectLeonida:old-pr/10038
ProjectLeonida:old-pr/10033
ProjectLeonida:old-pr/10028
ProjectLeonida:old-pr/10050
ProjectLeonida:old-pr/9891
ProjectLeonida:old-pr/9889
ProjectLeonida:old-pr/10051
ProjectLeonida:old-pr/10019
ProjectLeonida:old-pr/10027
ProjectLeonida:old-pr/10029
ProjectLeonida:old-pr/10031
ProjectLeonida:old-pr/10026
ProjectLeonida:old-pr/9941
ProjectLeonida:old-pr/10030
ProjectLeonida:old-pr/10040
ProjectLeonida:old-pr/9990
ProjectLeonida:old-pr/10021
ProjectLeonida:old-pr/9962
ProjectLeonida:old-pr/10022
ProjectLeonida:old-pr/10020
ProjectLeonida:old-pr/10015
ProjectLeonida:old-pr/10025
ProjectLeonida:old-pr/9886
ProjectLeonida:old-pr/10048
ProjectLeonida:old-pr/10014
ProjectLeonida:old-pr/10011
ProjectLeonida:old-pr/9861
ProjectLeonida:old-pr/10010
ProjectLeonida:old-pr/10008
ProjectLeonida:old-pr/9860
ProjectLeonida:old-pr/10006
ProjectLeonida:old-pr/9920
ProjectLeonida:old-pr/9995
ProjectLeonida:old-pr/10000
ProjectLeonida:old-pr/10016
ProjectLeonida:old-pr/10004
ProjectLeonida:old-pr/10023
ProjectLeonida:old-pr/9982
ProjectLeonida:old-pr/9981
ProjectLeonida:old-pr/9983
ProjectLeonida:old-pr/9970
ProjectLeonida:old-pr/9969
ProjectLeonida:old-pr/9968
ProjectLeonida:old-pr/9971
ProjectLeonida:old-pr/9972
ProjectLeonida:old-pr/9942
ProjectLeonida:old-pr/9963
ProjectLeonida:old-pr/9960
ProjectLeonida:old-pr/9964
ProjectLeonida:old-pr/9985
ProjectLeonida:old-pr/9973
ProjectLeonida:old-pr/9862
ProjectLeonida:old-pr/9953
ProjectLeonida:old-pr/10017
ProjectLeonida:old-pr/9952
ProjectLeonida:old-pr/9955
ProjectLeonida:old-pr/9946
ProjectLeonida:old-pr/9954
ProjectLeonida:old-pr/9938
ProjectLeonida:old-pr/9956
ProjectLeonida:old-pr/9856
ProjectLeonida:old-pr/9947
ProjectLeonida:old-pr/9924
ProjectLeonida:old-pr/9961
ProjectLeonida:old-pr/9927
ProjectLeonida:old-pr/9979
ProjectLeonida:old-pr/10032
ProjectLeonida:old-pr/9926
ProjectLeonida:old-pr/5237
ProjectLeonida:old-pr/9951
ProjectLeonida:old-pr/9931
ProjectLeonida:old-pr/9902
ProjectLeonida:old-pr/9921
ProjectLeonida:old-pr/9994
ProjectLeonida:old-pr/9775
ProjectLeonida:old-pr/9768
ProjectLeonida:old-pr/9905
ProjectLeonida:old-pr/9936
ProjectLeonida:old-pr/9901
ProjectLeonida:old-pr/9904
ProjectLeonida:old-pr/9906
ProjectLeonida:old-pr/9988
ProjectLeonida:old-pr/9908
ProjectLeonida:old-pr/9909
ProjectLeonida:old-pr/9911
ProjectLeonida:old-pr/9912
ProjectLeonida:old-pr/9913
ProjectLeonida:old-pr/9887
ProjectLeonida:old-pr/9916
ProjectLeonida:old-pr/9919
ProjectLeonida:old-pr/9925
ProjectLeonida:old-pr/9933
ProjectLeonida:old-pr/9935
ProjectLeonida:old-pr/9918
ProjectLeonida:old-pr/9879
ProjectLeonida:old-pr/9880
ProjectLeonida:old-pr/9881
ProjectLeonida:old-pr/9996
ProjectLeonida:old-pr/9876
ProjectLeonida:old-pr/9892
ProjectLeonida:old-pr/9899
ProjectLeonida:old-pr/9915
ProjectLeonida:old-pr/9914
ProjectLeonida:old-pr/9872
ProjectLeonida:old-pr/9869
ProjectLeonida:old-pr/9866
ProjectLeonida:old-pr/9819
ProjectLeonida:old-pr/10012
ProjectLeonida:old-pr/9857
ProjectLeonida:old-pr/9893
ProjectLeonida:old-pr/9897
ProjectLeonida:old-pr/9928
ProjectLeonida:old-pr/9868
ProjectLeonida:old-pr/9917
ProjectLeonida:old-pr/9940
ProjectLeonida:old-pr/9873
ProjectLeonida:old-pr/9816
ProjectLeonida:old-pr/10009
ProjectLeonida:old-pr/9900
ProjectLeonida:old-pr/9966
ProjectLeonida:old-pr/9859
ProjectLeonida:old-pr/9843
ProjectLeonida:old-pr/9991
ProjectLeonida:old-pr/10058
ProjectLeonida:old-pr/9883
ProjectLeonida:old-pr/9838
ProjectLeonida:old-pr/9835
ProjectLeonida:old-pr/9959
ProjectLeonida:old-pr/9895
ProjectLeonida:old-pr/9837
ProjectLeonida:old-pr/9858
ProjectLeonida:old-pr/9865
ProjectLeonida:old-pr/9864
ProjectLeonida:old-pr/9840
ProjectLeonida:old-pr/9820
ProjectLeonida:old-pr/4669
ProjectLeonida:old-pr/9848
ProjectLeonida:old-pr/9850
ProjectLeonida:old-pr/9810
ProjectLeonida:old-pr/9799
ProjectLeonida:old-pr/9853
ProjectLeonida:old-pr/9875
ProjectLeonida:old-pr/9831
ProjectLeonida:old-pr/9796
ProjectLeonida:old-pr/9801
ProjectLeonida:old-pr/9813
ProjectLeonida:old-pr/9794
ProjectLeonida:old-pr/7417
ProjectLeonida:old-pr/9781
ProjectLeonida:old-pr/9806
ProjectLeonida:old-pr/9958
ProjectLeonida:old-pr/9809
ProjectLeonida:old-pr/9791
ProjectLeonida:old-pr/9792
ProjectLeonida:old-pr/10053
ProjectLeonida:old-pr/9784
ProjectLeonida:old-pr/9789
ProjectLeonida:old-pr/9849
ProjectLeonida:old-pr/9846
ProjectLeonida:old-pr/9773
ProjectLeonida:old-pr/9785
ProjectLeonida:old-pr/9803
ProjectLeonida:old-pr/9826
ProjectLeonida:old-pr/9839
ProjectLeonida:old-pr/9922
ProjectLeonida:old-pr/9948
ProjectLeonida:old-pr/7189
ProjectLeonida:old-pr/9957
ProjectLeonida:old-pr/9823
ProjectLeonida:old-pr/9807
ProjectLeonida:old-pr/9851
ProjectLeonida:old-pr/9774
ProjectLeonida:old-pr/9830
ProjectLeonida:old-pr/9836
ProjectLeonida:old-pr/9822
ProjectLeonida:old-pr/9783
ProjectLeonida:old-pr/9833
ProjectLeonida:old-pr/9890
ProjectLeonida:old-pr/9770
ProjectLeonida:old-pr/9769
ProjectLeonida:old-pr/9772
ProjectLeonida:old-pr/9787
ProjectLeonida:old-pr/9852
ProjectLeonida:old-pr/9834
ProjectLeonida:old-pr/9845
ProjectLeonida:old-pr/9871
ProjectLeonida:old-pr/9771
ProjectLeonida:old-pr/9776
ProjectLeonida:old-pr/10005
ProjectLeonida:old-pr/9949
ProjectLeonida:old-pr/9923
ProjectLeonida:old-pr/9805
ProjectLeonida:old-pr/9829
ProjectLeonida:old-pr/9790
ProjectLeonida:old-pr/9827
ProjectLeonida:old-pr/9929
ProjectLeonida:old-pr/9855
ProjectLeonida:old-pr/9934
ProjectLeonida:old-pr/9907
ProjectLeonida:old-pr/9910
ProjectLeonida:old-pr/9779
ProjectLeonida:old-pr/9780
ProjectLeonida:old-pr/9885
ProjectLeonida:old-pr/9882
ProjectLeonida:old-pr/9877
ProjectLeonida:old-pr/9998
ProjectLeonida:old-pr/4251
ProjectLeonida:old-pr/9987
ProjectLeonida:old-pr/9989
ProjectLeonida:old-pr/9950
ProjectLeonida:old-pr/9777
ProjectLeonida:old-pr/10044
ProjectLeonida:old-pr/9884
ProjectLeonida:old-pr/2906
ProjectLeonida:old-pr/5076
ProjectLeonida:old-pr/9937
ProjectLeonida:old-pr/9986
ProjectLeonida:old-pr/3014
ProjectLeonida:old-pr/9943
ProjectLeonida:old-pr/9939
ProjectLeonida:old-pr/4682
ProjectLeonida:old-pr/4765
No reviewers
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
ProjectLeonida/mandy!3168
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-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?
Imported from ubiquitarianism/leonida. Originally posted by Callimann8 on 2026-12-02T16:08:49Z.
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 %).Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T16:31:56Z.
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.
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-02T16:54:27Z.
Review: COMMENTED
Two gaps before this can be called "no refit across a NaN vertex":
copy_vbwrites the mark (hwrt.rs:754), but it only becomes CPU-visible at list reset (:3558), whileflush_blas_batchdecides the refit first (:3089-3099). So on the first clean→NaN frame for a BLAS, that build still takes aPERFORM_UPDATErefit that flips an active primitive inactive — exactly the update the spec leaves undefined. From the next frame it is blocked. That's 460k undefined refits reduced to one per BLAS per NaN onset, not zero (the CPU-decoded quant24 path is immediate,:3662). Either read the marks before the batch decision, or treat a newly-dirty vertex buffer as refit-unsafe for that frame.:4811prunes only ontitle_memory_freed), so one transient NaN permanently disables refits for that VA; andexecute_copyaliases the sharedHostAsunder a new key without copying the mark, so a clone/compaction of a marked BLAS (then a refit from the alias) bypassesrefit_unsafe. Keying the mark on the sharedHostAs/BlasMemoryfixes both the permanence and the alias hole.Coverage gaps:
dxr_vertex_alignacceptsR16G16_FLOATandR16G16B16A16_FLOAT(:363-378), butcopy_vb'smatches!skips them (:3862), so NaN in half-float vertex buffers is never marked — the "packed formats cannot hold such values" comment is wrong for those. AABBMinXNaN (the inactive-AABB rule) is also untracked.Mutation:
refit_unsafe → false && …passes all 24hwrttests, so the new test protects the mark plumbing, not the policy guard. Merge is clean (48b6bf2);hwrt24/24 and diagnostics compiles. The PR body also omits the second commit (postbuild size queries outside the frame budget), which is a separate behaviour change worth describing.Imported from ubiquitarianism/leonida. Originally posted by Callimann8 on 2026-12-02T17:10:46Z.
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.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T18:01:56Z.
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
Imported from ubiquitarianism/leonida. Originally posted by Callimann8 on 2026-12-02T18:49:22Z.
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)
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-02T19:31:48Z.
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).
Imported from ubiquitarianism/leonida. Originally posted by x2Tweek on 2026-12-02T19:44:55Z.
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.
Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T19:50:10Z.
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).
Imported from ubiquitarianism/leonida. Originally posted by Callimann8 on 2026-12-02T20:14:01Z.
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.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T22:00:49Z.
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).
Imported from ubiquitarianism/leonida. Originally posted by x2Tweek on 2026-12-02T22:38:54Z.
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.
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-03T00:00:33Z.
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.
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.