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
Callimann8 commented 2026-12-02 16:08:49 +00:00 (Migrated from github.com)

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) in d3d12/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.

  1. No BLAS refit that changes which triangles are inactive. The sanitising copies (copy_vb, and sane_position for 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's copy_vb reads 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. Because execute_copy shares the HostAs between source and copy, a copy keeps what its source held. copy_vb also covers R16G16_FLOAT and R16G16B16A16_FLOAT vertices (f16tof32), and a BLAS with procedural boxes is never refitted, since a box is inactive where the title's own MinX is 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 whose Transform3x4 has 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.
  2. No read past a vertex through a root view. copy_vb read 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.
  3. Hardware RT allocations are named. BLAS/TLAS buffers, lease pieces, readbacks and decoded meshlet index buffers now get names through 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_HUNG with a DRED page fault at 0xd63da2000. That address is inside a host title-memory copy (0xdbb800000+0x800000 at 0xd63800000) 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 and LEONIDA_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 --tests and --features diagnostics) and cargo clippy with no new warnings. On Windows (x2Tweek, at e7558c4d merged onto main): cargo test -p leonida-gpu --lib hwrt, 26 passed, 0 failed, including the FXC compile of SANITIZE_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.
  • New unit tests: 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_inactive and the_nan_set_of_decoded_vertices_tells_which_vertices_are_nan. the_card_copies_follow_the_cpu_rules_and_compile now 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.
  • NVIDIA run (x2Tweek, RTX 5090, 4K, -HardwareRT, about 6 minutes): no device loss, lighting as expected, about 21 fps as before. 152 refits built whole against 140,418 held. Again at e7558c4d in game (340 s, on foot and driving): no device loss, no lighting fault, 205 built whole against 85,481 held (0.24 %).
  • TODO: an AMD run (lighting and the device loss).
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5610262356 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3168). Originally posted by [Callimann8](https://github.com/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`) in `d3d12/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. 1. **No BLAS refit that changes which triangles are inactive.** The sanitising copies (`copy_vb`, and `sane_position` for 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"](https://github.com/microsoft/DirectX-Specs/blob/master/d3d/Raytracing.md#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's `copy_vb` reads 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. Because `execute_copy` shares the `HostAs` between source and copy, a copy keeps what its source held. `copy_vb` also covers `R16G16_FLOAT` and `R16G16B16A16_FLOAT` vertices (`f16tof32`), and a BLAS with procedural boxes is never refitted, since a box is inactive where the title's own `MinX` is 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 whose `Transform3x4` has 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. 2. **No read past a vertex through a root view.** `copy_vb` read 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. 3. **Hardware RT allocations are named.** BLAS/TLAS buffers, lease pieces, readbacks and decoded meshlet index buffers now get names through `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_HUNG` with a DRED page fault at `0xd63da2000`. That address is inside a host title-memory copy (`0xdbb800000+0x800000` at `0xd63800000`) 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 and `LEONIDA_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 `--tests` and `--features diagnostics`) and `cargo clippy` with no new warnings. On Windows (x2Tweek, at `e7558c4d` merged onto `main`): `cargo test -p leonida-gpu --lib hwrt`, 26 passed, 0 failed, including the FXC compile of `SANITIZE_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. - New unit tests: `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_inactive` and `the_nan_set_of_decoded_vertices_tells_which_vertices_are_nan`. `the_card_copies_follow_the_cpu_rules_and_compile` now 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. - NVIDIA run (x2Tweek, RTX 5090, 4K, `-HardwareRT`, about 6 minutes): no device loss, lighting as expected, about 21 fps as before. 152 refits built whole against 140,418 held. Again at `e7558c4d` in game (340 s, on foot and driving): no device loss, no lighting fault, 205 built whole against 85,481 held (0.24 %). - TODO: an AMD run (lighting and the device loss).
fiestorra commented 2026-12-02 16:31:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T16:31:56Z.


Verified here: it applies on the current main and the hwrt group passes - 23 tests, 0 failed, including the new one.

merge base 3c106eb2f (current main), head 6115d0340
git apply on main   (1 file: d3d12/crates/leonida-gpu/src/hwrt.rs)

cargo test -p leonida-gpu --lib -- --test-threads=1 hwrt
  test result: ok. 23 passed; 0 failed; 0 ignored
  hwrt::tests::a_blas_with_a_vertex_made_nan_is_found_by_its_marks_and_its_staged_vertices ... ok

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=1 on a run and two images to compare, which this machine cannot do (no title).

One thing for the merge: the pull request currently shows UNSTABLE in 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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7352081433 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3168#issuecomment-7352081433). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-02T16:31:56Z. --- **Verified here: it applies on the current `main` and the `hwrt` group passes - 23 tests, 0 failed, including the new one.** ``` merge base 3c106eb2f (current main), head 6115d0340 git apply on main (1 file: d3d12/crates/leonida-gpu/src/hwrt.rs) cargo test -p leonida-gpu --lib -- --test-threads=1 hwrt test result: ok. 23 passed; 0 failed; 0 ignored hwrt::tests::a_blas_with_a_vertex_made_nan_is_found_by_its_marks_and_its_staged_vertices ... ok ``` **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=1` on a run and two images to compare**, which this machine cannot do (no title). **One thing for the merge**: the pull request currently shows **`UNSTABLE`** in 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.
KelboLive commented 2026-12-02 16:54:27 +00:00 (Migrated from github.com)

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":

  1. The GPU-copy path is one frame late. copy_vb writes the mark (hwrt.rs:754), but it only becomes CPU-visible at list reset (:3558), while flush_blas_batch decides the refit first (:3089-3099). So on the first clean→NaN frame for a BLAS, that build still takes a PERFORM_UPDATE refit 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.
  2. The mark is keyed by console VA and never cleared. A later clean full build does not unmark it (:4811 prunes only on title_memory_freed), so one transient NaN permanently disables refits for that VA; and execute_copy aliases the shared HostAs under a new key without copying the mark, so a clone/compaction of a marked BLAS (then a refit from the alias) bypasses refit_unsafe. Keying the mark on the shared HostAs/BlasMemory fixes both the permanence and the alias hole.

Coverage gaps: dxr_vertex_align accepts R16G16_FLOAT and R16G16B16A16_FLOAT (:363-378), but copy_vb's matches! 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. AABB MinX NaN (the inactive-AABB rule) is also untracked.

Mutation: refit_unsafe → false && … passes all 24 hwrt tests, so the new test protects the mark plumbing, not the policy guard. Merge is clean (48b6bf2); hwrt 24/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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6155307412 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3168#pullrequestreview-6155307412). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-02T16:54:27Z. **Review:** COMMENTED --- Two gaps before this can be called "no refit across a NaN vertex": 1. **The GPU-copy path is one frame late.** `copy_vb` writes the mark (`hwrt.rs:754`), but it only becomes CPU-visible at list reset (`:3558`), while `flush_blas_batch` decides the refit first (`:3089-3099`). So on the **first** clean→NaN frame for a BLAS, that build still takes a `PERFORM_UPDATE` refit 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. 2. **The mark is keyed by console VA and never cleared.** A later clean full build does not unmark it (`:4811` prunes only on `title_memory_freed`), so one transient NaN permanently disables refits for that VA; and `execute_copy` aliases the shared `HostAs` under a new key without copying the mark, so a clone/compaction of a marked BLAS (then a refit from the alias) bypasses `refit_unsafe`. Keying the mark on the shared `HostAs`/`BlasMemory` fixes both the permanence and the alias hole. Coverage gaps: `dxr_vertex_align` accepts `R16G16_FLOAT` and `R16G16B16A16_FLOAT` (`:363-378`), but `copy_vb`'s `matches!` 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. AABB `MinX` NaN (the inactive-AABB rule) is also untracked. Mutation: `refit_unsafe → false && …` passes all **24** `hwrt` tests, so the new test protects the mark plumbing, not the policy guard. Merge is clean (`48b6bf2`); `hwrt` 24/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.
Callimann8 commented 2026-12-02 17:10:46 +00:00 (Migrated from github.com)

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 HostAs now 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's copy_vb reads those positions as g_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 HostAs itself. It's replaced on every build or refit of that structure, goes away with it, and execute_copy's alias shares it because it's the same Arc. The title_memory_freed pruning is gone. The flush also checks that the source it refits is the same HostAs the copies were made against.

Coverage. You're right that the comment was wrong. copy_vb now handles R16G16_FLOAT and R16G16B16A16_FLOAT (f16tof32), and the comment is fixed. BLASes with AABBs are never refitted, since MinX NaN is the title's own and we can't hold it.

Mutation. New a_refit_is_refused_unless_every_geometry_keeps_its_inactive_triangles covers 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 if refit_keeps_activity is 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 in flush_blas_waves itself 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/clippy for the Windows target (also --tests and --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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7353012064 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3168#issuecomment-7353012064). Originally posted by [Callimann8](https://github.com/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 `HostAs` now 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's `copy_vb` reads those positions as `g_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 `HostAs` itself. It's replaced on every build or refit of that structure, goes away with it, and `execute_copy`'s alias shares it because it's the same `Arc`. The `title_memory_freed` pruning is gone. The flush also checks that the source it refits is the same `HostAs` the copies were made against. **Coverage.** You're right that the comment was wrong. `copy_vb` now handles `R16G16_FLOAT` and `R16G16B16A16_FLOAT` (`f16tof32`), and the comment is fixed. BLASes with AABBs are never refitted, since `MinX` NaN is the title's own and we can't hold it. **Mutation.** New `a_refit_is_refused_unless_every_geometry_keeps_its_inactive_triangles` covers 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 if `refit_keeps_activity` is 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 in `flush_blas_waves` itself 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`/`clippy` for the Windows target (also `--tests` and `--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.
MoonEyes commented 2026-12-02 18:01:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T18:01:56Z.


Code review only, not built: leonida-gpu is Windows-only and the HLSL in hwrt.rs compiles with FXC at test time. Not ready to merge yet: the current head has not been run anywhere.

  • Head: 2ab4e92bf, merge base 3c106eb2f, 21 behind current main 45dc41f95. A trial merge is clean.
  • CI: no workflow run exists for this head yet.
  • Earlier verification (fiestorra, 16:31) covered 6115d0340 only. Since then two commits changed the design: 02706e17 (budget) and 2ab4e92b, which replaced the readback marks with per-HostAs Held state, g_old and f16 positions. By the author's own note, 2ab4e92b has only had cargo check/clippy.

What reads right (d3d12/crates/leonida-gpu/src/hwrt.rs):

  • refit_keeps_activity decides 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 without g_old. That respects the DXR rule on inactive primitives at the root, instead of detecting the problem a frame late.
  • Keeping held on the HostAs behind its Arc makes it follow copies and be freed with the structure. The old VA-keyed map with title_memory_freed pruning is gone.
  • create_default_buffer rounds the width to 256 bytes, so the reuse check in hold_activity (*b >= bytes against the rounded size) cannot copy past the end.

Concerns:

  1. Scope. 02706e17 changes the BLAS budget: postbuild sizes are answered with told_for prebuild sizes while the build waits, and copy_waiting queues clones and compactions as builds of dest. 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 by told_for. Please split it out, or show that the compacted-size contract still holds with a test.
  2. copy_vb with mode & 256 checks only old.x for 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.
  3. Tests. a_refit_is_refused_unless_every_geometry_keeps_its_inactive_triangles pins the policy function. Nothing exercises the flush_blas_waves guard (held_from against Arc::as_ptr(src_entry)) or the held_read barrier bookkeeping. The author acknowledges this.

Needed before merge: cargo test -p leonida-gpu hwrt on 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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7353877294 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3168#issuecomment-7353877294). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T18:01:56Z. --- **Code review only, not built: `leonida-gpu` is Windows-only and the HLSL in `hwrt.rs` compiles with FXC at test time. Not ready to merge yet: the current head has not been run anywhere.** - Head: `2ab4e92bf`, merge base `3c106eb2f`, 21 behind current `main` `45dc41f95`. A trial merge is clean. - CI: no workflow run exists for this head yet. - Earlier verification (fiestorra, 16:31) covered `6115d0340` only. Since then two commits changed the design: `02706e17` (budget) and `2ab4e92b`, which replaced the readback marks with per-`HostAs` `Held` state, `g_old` and f16 positions. By the author's own note, `2ab4e92b` has only had `cargo check`/`clippy`. **What reads right (`d3d12/crates/leonida-gpu/src/hwrt.rs`):** - `refit_keeps_activity` decides 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 without `g_old`. That respects the DXR rule on inactive primitives at the root, instead of detecting the problem a frame late. - Keeping `held` on the `HostAs` behind its `Arc` makes it follow copies and be freed with the structure. The old VA-keyed map with `title_memory_freed` pruning is gone. - `create_default_buffer` rounds the width to 256 bytes, so the reuse check in `hold_activity` (`*b >= bytes` against the rounded size) cannot copy past the end. **Concerns:** 1. **Scope.** `02706e17` changes the BLAS budget: postbuild sizes are answered with `told_for` prebuild sizes while the build waits, and `copy_waiting` queues clones and compactions as builds of `dest`. 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 by `told_for`. Please split it out, or show that the compacted-size contract still holds with a test. 2. **`copy_vb` with `mode & 256`** checks only `old.x` for 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. 3. **Tests.** `a_refit_is_refused_unless_every_geometry_keeps_its_inactive_triangles` pins the policy function. Nothing exercises the `flush_blas_waves` guard (`held_from` against `Arc::as_ptr(src_entry)`) or the `held_read` barrier bookkeeping. The author acknowledges this. **Needed before merge:** `cargo test -p leonida-gpu hwrt` on 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](https://claude.ai/code)_
Callimann8 commented 2026-12-02 18:49:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Callimann8 on 2026-12-02T18:49:22Z.


Code review only, not built: leonida-gpu is Windows-only and the HLSL in hwrt.rs compiles with FXC at test time. Not ready to merge yet: the current head has not been run anywhere.

  • Head: 2ab4e92bf, merge base 3c106eb2f, 21 behind current main 45dc41f95. A trial merge is clean.
  • CI: no workflow run exists for this head yet.
  • Earlier verification (fiestorra, 16:31) covered 6115d0340 only. Since then two commits changed the design: 02706e17 (budget) and 2ab4e92b, which replaced the readback marks with per-HostAs Held state, g_old and f16 positions. By the author's own note, 2ab4e92b has only had cargo check/clippy.

What reads right (d3d12/crates/leonida-gpu/src/hwrt.rs):

  • refit_keeps_activity decides 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 without g_old. That respects the DXR rule on inactive primitives at the root, instead of detecting the problem a frame late.
  • Keeping held on the HostAs behind its Arc makes it follow copies and be freed with the structure. The old VA-keyed map with title_memory_freed pruning is gone.
  • create_default_buffer rounds the width to 256 bytes, so the reuse check in hold_activity (*b >= bytes against the rounded size) cannot copy past the end.

Concerns:

  1. Scope. 02706e17 changes the BLAS budget: postbuild sizes are answered with told_for prebuild sizes while the build waits, and copy_waiting queues clones and compactions as builds of dest. 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 by told_for. Please split it out, or show that the compacted-size contract still holds with a test.
  2. copy_vb with mode & 256 checks only old.x for 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.
  3. Tests. a_refit_is_refused_unless_every_geometry_keeps_its_inactive_triangles pins the policy function. Nothing exercises the flush_blas_waves guard (held_from against Arc::as_ptr(src_entry)) or the held_read barrier bookkeeping. The author acknowledges this.

Needed before merge: cargo test -p leonida-gpu hwrt on 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)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7355205340 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3168#issuecomment-7355205340). Originally posted by [Callimann8](https://github.com/Callimann8) on 2026-12-02T18:49:22Z. --- > **Code review only, not built: `leonida-gpu` is Windows-only and the HLSL in `hwrt.rs` compiles with FXC at test time. Not ready to merge yet: the current head has not been run anywhere.** > > * Head: `2ab4e92bf`, merge base `3c106eb2f`, 21 behind current `main` `45dc41f95`. A trial merge is clean. > * CI: no workflow run exists for this head yet. > * Earlier verification (fiestorra, 16:31) covered `6115d0340` only. Since then two commits changed the design: `02706e17` (budget) and `2ab4e92b`, which replaced the readback marks with per-`HostAs` `Held` state, `g_old` and f16 positions. By the author's own note, `2ab4e92b` has only had `cargo check`/`clippy`. > > **What reads right (`d3d12/crates/leonida-gpu/src/hwrt.rs`):** > > * `refit_keeps_activity` decides 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 without `g_old`. That respects the DXR rule on inactive primitives at the root, instead of detecting the problem a frame late. > * Keeping `held` on the `HostAs` behind its `Arc` makes it follow copies and be freed with the structure. The old VA-keyed map with `title_memory_freed` pruning is gone. > * `create_default_buffer` rounds the width to 256 bytes, so the reuse check in `hold_activity` (`*b >= bytes` against the rounded size) cannot copy past the end. > > **Concerns:** > > 1. **Scope.** `02706e17` changes the BLAS budget: postbuild sizes are answered with `told_for` prebuild sizes while the build waits, and `copy_waiting` queues clones and compactions as builds of `dest`. 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 by `told_for`. Please split it out, or show that the compacted-size contract still holds with a test. > 2. **`copy_vb` with `mode & 256`** checks only `old.x` for 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. > 3. **Tests.** `a_refit_is_refused_unless_every_geometry_keeps_its_inactive_triangles` pins the policy function. Nothing exercises the `flush_blas_waves` guard (`held_from` against `Arc::as_ptr(src_entry)`) or the `held_read` barrier bookkeeping. The author acknowledges this. > > **Needed before merge:** `cargo test -p leonida-gpu hwrt` on 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](https://claude.ai/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)
lixonik commented 2026-12-02 19:31:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-02T19:31:48Z.


RUN (in game) -- Windows hwrt debug-layer unit tests + 300 s -HardwareRT render-path gate run for PR #3168:

  • PR head SHA: 337388052
  • Merged onto main SHA: f1a559851 (git merge --no-ff, clean merge)
  • Clean-room check: python -I scripts/check_no_game_data.py PASS
  • Unit tests (Windows 10 x64, Rust 1.98.1, D3D12 debug layer enabled):
    • LEONIDA_D3D12_DEBUG=1 cargo test -p leonida-gpu --features diagnostics --lib --locked hwrt -- 24 passed, 0 failed
  • Build & profile: diag profile (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 snapshot
  • GPU / Driver / OS: NVIDIA GeForce RTX 5070 (12 GB), driver 595.79, Windows 10 x64
Run Profile Time in world World samples Device lost / crashes / errors Median rendered FPS (ms) Slowest / fastest tenth (fps) Median draws
PR #3168 (337388052 on f1a559851) Series S + DLSS + Hardware RT 315 s (475.0 s total) 64 0 / 0 / 0 24.8 fps (40.3 ms) 17.9 / 25.8 4,412
main alone (f1a559851, ref) Series S + DLSS (RT off) 303.2 s (480.0 s total) 62 0 / 0 / 0 27.2 fps (36.8 ms) 21.8 / 28.7 4,385

Loaded cleanly into the world with DXR Hardware RT active, stayed up past 300 s in-world with 0 device lost / 0 crashes / 0 ERROR lines, and closed cleanly.

Verdict: PASS.

AI-assisted: yes (Antigravity).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7356319664 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3168#issuecomment-7356319664). Originally posted by [lixonik](https://github.com/lixonik) on 2026-12-02T19:31:48Z. --- RUN (in game) -- Windows `hwrt` debug-layer unit tests + 300 s `-HardwareRT` render-path gate run for PR #3168: - **PR head SHA:** `337388052` - **Merged onto `main` SHA:** `f1a559851` (`git merge --no-ff`, clean merge) - **Clean-room check:** `python -I scripts/check_no_game_data.py` PASS - **Unit tests (Windows 10 x64, Rust 1.98.1, D3D12 debug layer enabled):** - `LEONIDA_D3D12_DEBUG=1 cargo test -p leonida-gpu --features diagnostics --lib --locked hwrt` -- **24 passed, 0 failed** - **Build & profile:** `diag` profile (`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 snapshot - **GPU / Driver / OS:** NVIDIA GeForce RTX 5070 (12 GB), driver 595.79, Windows 10 x64 | Run | Profile | Time in world | World samples | Device lost / crashes / errors | Median rendered FPS (ms) | Slowest / fastest tenth (fps) | Median draws | | --- | --- | ---: | ---: | --- | ---: | ---: | ---: | | **PR #3168 (`337388052` on `f1a559851`)** | Series S + DLSS + **Hardware RT** | 315 s (475.0 s total) | 64 | **0 / 0 / 0** | **24.8 fps** (40.3 ms) | 17.9 / 25.8 | 4,412 | | **`main` alone (`f1a559851`, ref)** | Series S + DLSS (RT off) | 303.2 s (480.0 s total) | 62 | **0 / 0 / 0** | **27.2 fps** (36.8 ms) | 21.8 / 28.7 | 4,385 | Loaded cleanly into the world with DXR Hardware RT active, stayed up past 300 s in-world with 0 device lost / 0 crashes / 0 `ERROR` lines, and closed cleanly. Verdict: **PASS**. AI-assisted: yes (Antigravity).
x2Tweek commented 2026-12-02 19:44:55 +00:00 (Migrated from github.com)

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
0d7a451ab plus #3113 and #3182, diag build. This PR merged on top at 337388052. Series X profile, 3840x2160
output, render scale 0.6667, the title's upscaler, -HardwareRT -SmoothMotion -PrecompileAll -Log, borderless
window. About 6 minutes of play from a save, then city driving at night.

Windows tests: cargo test -p leonida-gpu --lib hwrt gives 25 passed and 0 failed, including
the_card_copies_follow_the_cpu_rules_and_compile (the FXC compile of SANITIZE_HLSL).

The run's frame log, at the end:

hardware RT inputs: index buffers clamped on the card 46528, vertex buffers sanitised 834814, geometries given
inactive in their place 0, with indices past their vertex count 0; build memory pieces made 147 (255 MB), spare
240 MB; refits built whole as their inactive triangles could not be held 152, refits whose vertex copies held them 140418
hardware RT: BLAS live 15146 (built 40707, refit 140418, refit->rebuild 513, rehydrated 15059), TLAS live 5 ...
  • 152 refits were built whole because their inactive triangles could not be held, against 140,418 that
    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.
  • No device loss, and no device-removed lines in the log.
  • Frame rate: 20.9 fps median over the last 3 minutes of driving. That is in line with the base on the same
    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.
  • Picture: lighting looked as expected at night (headlights, street lights, the car's own lights).
    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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7356659566 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3168#issuecomment-7356659566). Originally posted by [x2Tweek](https://github.com/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 `0d7a451ab` plus #3113 and #3182, diag build. This PR merged on top at `337388052`. Series X profile, 3840x2160 output, render scale 0.6667, the title's upscaler, `-HardwareRT -SmoothMotion -PrecompileAll -Log`, borderless window. About 6 minutes of play from a save, then city driving at night. **Windows tests:** `cargo test -p leonida-gpu --lib hwrt` gives 25 passed and 0 failed, including `the_card_copies_follow_the_cpu_rules_and_compile` (the FXC compile of `SANITIZE_HLSL`). **The run's frame log, at the end:** ``` hardware RT inputs: index buffers clamped on the card 46528, vertex buffers sanitised 834814, geometries given inactive in their place 0, with indices past their vertex count 0; build memory pieces made 147 (255 MB), spare 240 MB; refits built whole as their inactive triangles could not be held 152, refits whose vertex copies held them 140418 hardware RT: BLAS live 15146 (built 40707, refit 140418, refit->rebuild 513, rehydrated 15059), TLAS live 5 ... ``` - **152 refits were built whole** because their inactive triangles could not be held, against **140,418** that 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. - **No device loss**, and no device-removed lines in the log. - **Frame rate:** 20.9 fps median over the last 3 minutes of driving. That is in line with the base on the same 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. - **Picture:** lighting looked as expected at night (headlights, street lights, the car's own lights). 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.
Kal0s-design commented 2026-12-02 19:50:10 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T19:50:10Z.


Ran natively on Windows 11, head 337388052 merged into current main (b41763227, clean merge).

lixonik already ran hwrt on this head, over an older main. This adds the full crate on current main, 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.

run main merge
card 703 passed, 0 failed, 59 ignored 705 passed, 0 failed, 59 ignored
--features diagnostics 784 passed 786 passed
same, with LEONIDA_D3D12_WARP=1 - 786 passed
same, with LEONIDA_D3D12_DEBUG=1 - 786 passed

The 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 hwrt tests never create a device through host.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_activity always return true fails a_refit_is_refused_unless_every_geometry_keeps_its_inactive_triangles (23/24). Replacing both guards in flush_blas_waves (&& !unheld and the held_from pointer check) with true still passes all 24 hwrt tests. So MoonEyes' point 3 still applies. cargo clippy -p leonida-gpu --all-targets --features diagnostics reports nothing in hwrt.rs.

copy_vb on the card (measured)

I dispatched the PR's copy_vb directly and compared the output with sane_position. The card and WARP gave identical results. All 12 f32 cases matched the CPU rule bit for bit.

input output
NaN in x, NaN only in z, signalling NaN, negative NaN all three components 0x7FC00000
+Inf, -Inf, 1 ulp past 1e10, -1e11 NaN
exactly 1e10, -0.0, denormals unchanged
R32G32 where the next vertex's x is NaN z = 0, the next vertex isn't read
R16G16B16A16_FLOAT with NaN or Inf in w unchanged, w is ignored
half NaN or Inf in x, half -Inf in y (R16G16) NaN
half 65504, -0, half denormal converted exactly

The refit merge (mode | 256 against g_old) behaved like this.

held now output
NaN finite NaN, stays inactive
finite NaN or Inf the old position
finite finite the new position
NaN only in y finite the new position, since only old.x is 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 COMMON is read as root SRV t1, then NON_PIXEL_SHADER_RESOURCE → COMMON. Next COMMON → COPY_DEST, the copy, then back to COMMON. The piece goes UNORDERED_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_UPDATE and 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_activity stores each refit's output as the next g_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_UPDATE BLAS adds a CopyBufferRegion of vertices * 12 bytes, and the touched pieces get an extra transition to COPY_SOURCE. The held buffers (vertices * 12, rounded to 256) come from create_default_buffer and are never charged to the BLAS LEDGER, so that VRAM falls outside the budget. They are freed together with the HostAs.

Not covered by either PR (read)

A NaN in a geometry's own Transform3x4 makes the whole geometry inactive in the build. Activity doesn't look at the transform, so a refit across a transform turning NaN, or recovering, still changes activity. #3107 guards instance transforms in REMAP_HLSL (TLAS), not this.

Other open PRs touching hwrt.rs

I filtered open PRs by changed files.

PR git merge-tree with this one
#3107 (WriteBufferImmediate, 65535-group cap, NaN/Inf instance transforms) conflict in hwrt.rs, two hunks in sanitize(): #3107's dispatch_1d_grid against this PR's 4th root view. Keep both. The shader merges on its own, and g_old.Load3(v * 12) uses #3107's 2D v. The NaN handling doesn't overlap (instances vs vertices).
#3113 (write-watch walk) clean

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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7356800775 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3168#issuecomment-7356800775). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-12-02T19:50:10Z. --- Ran natively on Windows 11, head `337388052` merged into current `main` (`b41763227`, clean merge). lixonik already ran `hwrt` on this head, over an older `main`. This adds the full crate on current `main`, 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. | run | main | merge | | --- | ---: | ---: | | card | 703 passed, 0 failed, 59 ignored | 705 passed, 0 failed, 59 ignored | | `--features diagnostics` | 784 passed | 786 passed | | same, with `LEONIDA_D3D12_WARP=1` | - | 786 passed | | same, with `LEONIDA_D3D12_DEBUG=1` | - | 786 passed | The 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 `hwrt` tests never create a device through `host.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_activity` always return `true` fails `a_refit_is_refused_unless_every_geometry_keeps_its_inactive_triangles` (23/24). Replacing both guards in `flush_blas_waves` (`&& !unheld` and the `held_from` pointer check) with `true` still passes all 24 `hwrt` tests. So MoonEyes' point 3 still applies. `cargo clippy -p leonida-gpu --all-targets --features diagnostics` reports nothing in `hwrt.rs`. **`copy_vb` on the card (measured)** I dispatched the PR's `copy_vb` directly and compared the output with `sane_position`. The card and WARP gave identical results. All 12 f32 cases matched the CPU rule bit for bit. | input | output | | --- | --- | | NaN in x, NaN only in z, signalling NaN, negative NaN | all three components `0x7FC00000` | | +Inf, -Inf, 1 ulp past 1e10, -1e11 | NaN | | exactly 1e10, -0.0, denormals | unchanged | | `R32G32` where the next vertex's x is NaN | z = 0, the next vertex isn't read | | `R16G16B16A16_FLOAT` with NaN or Inf in w | unchanged, w is ignored | | half NaN or Inf in x, half -Inf in y (`R16G16`) | NaN | | half 65504, -0, half denormal | converted exactly | The refit merge (`mode | 256` against `g_old`) behaved like this. | held | now | output | | --- | --- | --- | | NaN | finite | NaN, stays inactive | | finite | NaN or Inf | the old position | | finite | finite | the new position | | NaN only in y | finite | the new position, since only `old.x` is 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 `COMMON` is read as root SRV `t1`, then `NON_PIXEL_SHADER_RESOURCE` → `COMMON`. Next `COMMON` → `COPY_DEST`, the copy, then back to `COMMON`. The piece goes `UNORDERED_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_UPDATE` and 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_activity` stores each refit's output as the next `g_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_UPDATE` BLAS adds a `CopyBufferRegion` of `vertices * 12` bytes, and the touched pieces get an extra transition to `COPY_SOURCE`. The held buffers (`vertices * 12`, rounded to 256) come from `create_default_buffer` and are never charged to the BLAS `LEDGER`, so that VRAM falls outside the budget. They are freed together with the `HostAs`. **Not covered by either PR (read)** A NaN in a geometry's own `Transform3x4` makes the whole geometry inactive in the build. `Activity` doesn't look at the transform, so a refit across a transform turning NaN, or recovering, still changes activity. #3107 guards instance transforms in `REMAP_HLSL` (TLAS), not this. **Other open PRs touching `hwrt.rs`** I filtered open PRs by changed files. | PR | `git merge-tree` with this one | | --- | --- | | #3107 (WriteBufferImmediate, 65535-group cap, NaN/Inf instance transforms) | conflict in `hwrt.rs`, two hunks in `sanitize()`: #3107's `dispatch_1d_grid` against this PR's 4th root view. Keep both. The shader merges on its own, and `g_old.Load3(v * 12)` uses #3107's 2D `v`. The NaN handling doesn't overlap (instances vs vertices). | | #3113 (write-watch walk) | clean | 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).
Callimann8 commented 2026-12-02 20:14:01 +00:00 (Migrated from github.com)

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:

  • Guard mutation. The flush's source check is now 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 !unheld term only counts and short-circuits, because held_from == 0 already makes refit_from_held false.
  • Transform3x4. Covered now. A NaN in the row giving X (t[0..4]) makes the geometry Inactive. A NaN anywhere else, or a transform we can't read, makes it Unknown, which is never held, so that BLAS is built whole.
  • staged_nan_hash cost. It now runs only when a refit can follow (ALLOW_UPDATE or PERFORM_UPDATE, or a refit asked for). Otherwise the activity is Unknown, and nothing is stored for it anyway.
  • Held buffers outside the budget. They're now charged to the BLAS LEDGER (BlasMemory, rounded size) and released with the buffer.
  • Card path vs CPU path after a NaN. That difference is deliberate. Rebuilding on the card path would need a readback, which is the one-frame-late design the first review rejected. Freezing the vertex at its last good position stays within DXR's rules until the title rebuilds. I've noted it in the PR body.
  • #3107. Agreed that both should be kept. Whichever lands second rebases and resolves the two sanitize() hunks the way you described.

cargo check/clippy for the Windows target are clean (also with --tests and --features diagnostics). The new tests haven't run on Windows yet.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7357422772 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3168#issuecomment-7357422772). Originally posted by [Callimann8](https://github.com/Callimann8) on 2026-12-02T20:14:01Z. --- Thanks for the thorough run, especially the copy_vb table and the debug-layer replay. Pushed e7558c4d: - **Guard mutation.** The flush's source check is now `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 `!unheld` term only counts and short-circuits, because `held_from == 0` already makes `refit_from_held` false. - **Transform3x4.** Covered now. A NaN in the row giving X (`t[0..4]`) makes the geometry `Inactive`. A NaN anywhere else, or a transform we can't read, makes it `Unknown`, which is never held, so that BLAS is built whole. - **staged_nan_hash cost.** It now runs only when a refit can follow (`ALLOW_UPDATE` or `PERFORM_UPDATE`, or a refit asked for). Otherwise the activity is `Unknown`, and nothing is stored for it anyway. - **Held buffers outside the budget.** They're now charged to the BLAS `LEDGER` (`BlasMemory`, rounded size) and released with the buffer. - **Card path vs CPU path after a NaN.** That difference is deliberate. Rebuilding on the card path would need a readback, which is the one-frame-late design the first review rejected. Freezing the vertex at its last good position stays within DXR's rules until the title rebuilds. I've noted it in the PR body. - **#3107.** Agreed that both should be kept. Whichever lands second rebases and resolves the two `sanitize()` hunks the way you described. `cargo check`/`clippy` for the Windows target are clean (also with `--tests` and `--features diagnostics`). The new tests haven't run on Windows yet.
MoonEyes commented 2026-12-02 22:00:49 +00:00 (Migrated from github.com)

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:

  • the head SHA and the main SHA it was merged onto;
  • GPU, driver and OS;
  • at least 300 s in the world after loading;
  • device lost / crashes (count), and rendered fps (median) if you have them;
  • the same run on main alone 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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7360100380 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3168#issuecomment-7360100380). Originally posted by [MoonEyes](https://github.com/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`: - the head SHA and the `main` SHA it was merged onto; - GPU, driver and OS; - at least 300 s in the world after loading; - device lost / crashes (count), and rendered fps (median) if you have them; - the same run on `main` alone 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).
x2Tweek commented 2026-12-02 22:38:54 +00:00 (Migrated from github.com)

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.

  • Head / main: head e7558c4df merged with git merge --no-ff onto main f3865cae8 (merge 82c4f1660,
    clean). No other changes: no local patches and no other PRs.
  • GPU / driver / OS: NVIDIA GeForce RTX 5090 32 GB, driver 621.40, i9-14900KS, 64 GB DDR5, Windows 11 (build
    26300).
  • Build: diag profile, features diagnostics,dlss,mimalloc. cargo test -p leonida-gpu --lib hwrt gives 26
    passed and 0 failed.
  • Settings: Series X profile, 3840x2160 output, render scale 0.6667, the title's upscaler,
    -HardwareRT -SmoothMotion -PrecompileAll -Log, fullscreen.
  • Time in the world: 340 s (22:32:13 to 22:37:53 UTC). From a save, on foot, then walking and driving.
  • Device lost / crashes: 0. No device removed line in the log.
  • Rendered fps: 13.6 median, 8.9 p10 and 20.0 p90 (the 5 s frame-log lines). 5 frames over 1 s and 1 over
    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 BLAS
    cap (#3135 / #3225) and cold masked-pipeline compiles (#3200 / #3105).
  • This PR's counters (the last "hardware RT inputs" line): "refits built whole as their inactive triangles
    could not be held 205, refits whose vertex copies held them 85481", so the guard rebuilds about 0.24 % of the
    refits.
  • Picture: no visible lighting fault noticed.

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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7360974823 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3168#issuecomment-7360974823). Originally posted by [x2Tweek](https://github.com/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. - **Head / main:** head `e7558c4df` merged with `git merge --no-ff` onto `main` `f3865cae8` (merge `82c4f1660`, clean). No other changes: no local patches and no other PRs. - **GPU / driver / OS:** NVIDIA GeForce RTX 5090 32 GB, driver 621.40, i9-14900KS, 64 GB DDR5, Windows 11 (build 26300). - **Build:** diag profile, features `diagnostics,dlss,mimalloc`. `cargo test -p leonida-gpu --lib hwrt` gives 26 passed and 0 failed. - **Settings:** Series X profile, 3840x2160 output, render scale 0.6667, the title's upscaler, `-HardwareRT -SmoothMotion -PrecompileAll -Log`, fullscreen. - **Time in the world:** 340 s (22:32:13 to 22:37:53 UTC). From a save, on foot, then walking and driving. - **Device lost / crashes:** **0.** No `device removed` line in the log. - **Rendered fps:** 13.6 median, 8.9 p10 and 20.0 p90 (the 5 s frame-log lines). 5 frames over 1 s and 1 over 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 BLAS cap (#3135 / #3225) and cold masked-pipeline compiles (#3200 / #3105). - **This PR's counters** (the last "hardware RT inputs" line): "refits built whole as their inactive triangles could not be held 205, refits whose vertex copies held them 85481", so the guard rebuilds about 0.24 % of the refits. - **Picture:** no visible lighting fault noticed. 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.
fiestorra commented 2026-12-03 00:00:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-03T00:00:33Z.


VERIFY-3168 — Windows nativo: red then green en el guardián del refit

Own commit e7558c4df — hwrt.rs, +89/−9

Ran at the head

cargo test -p leonida-gpu --lib hwrt     26 passed; 0 failed
  hwrt::tests::a_refit_is_recorded_only_from_the_structure_its_copies_held ... ok
  hwrt::tests::a_nan_in_the_transform_row_giving_x_makes_the_geometry_inactive ... ok

Negative control (synthetic): I weakened the guard from held_from != 0 && held_from == source to ||, rebuilt and ran:

FAILED: a_refit_is_recorded_only_from_the_structure_its_copies_held

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_activity refuses a refit whose geometries changed which triangles are inactive (DXR: none may become active, none inactive) with boxes never refitted; and a NaN in the transform row that gives x makes the geometry inactive.

Why the second test is the interesting one: a NaN in 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

  • A real DXR refit: no ray-traced title run here; the tests drive the predicates the refit path uses.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7362687698 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3168#issuecomment-7362687698). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-03T00:00:33Z. --- ## VERIFY-3168 — Windows nativo: `red then green` en el guardián del refit | | | |---|---| | Own commit | `e7558c4df` — `hwrt.rs`, +89/−9 | **Ran at the head** ``` cargo test -p leonida-gpu --lib hwrt 26 passed; 0 failed hwrt::tests::a_refit_is_recorded_only_from_the_structure_its_copies_held ... ok hwrt::tests::a_nan_in_the_transform_row_giving_x_makes_the_geometry_inactive ... ok ``` **Negative control (synthetic)**: I weakened the guard from `held_from != 0 && held_from == source` to `||`, rebuilt and ran: ``` FAILED: a_refit_is_recorded_only_from_the_structure_its_copies_held ``` **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_activity` **refuses a refit whose geometries changed which triangles are inactive** (DXR: none may become active, none inactive) **with boxes never refitted**; and **a `NaN` in the transform row that gives `x` makes the geometry inactive.** **Why the second test is the interesting one**: **a `NaN` in 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 - **A real DXR refit**: no ray-traced title run here; the tests drive the predicates the refit path uses. Written with an AI assistant.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3168:upstream-pr/3168'
git switch 'upstream-pr/3168'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3168'
git switch 'upstream-pr/3168'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3168'
git switch 'upstream-pr/3168'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3168'
git switch 'main'
git merge --squash 'upstream-pr/3168'
git switch 'main'
git merge --ff-only 'upstream-pr/3168'
git switch 'main'
git merge 'upstream-pr/3168'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
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
No description provided.