shader, gpu: port 32-lane BVH builder lowering, structure views, and GPURT node answer #403

Merged
Kikoarl merged 1 commit from upstream-pr/403 into main 2026-11-29 00:24:48 +00:00
Kikoarl commented 2026-11-27 21:55:18 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Kikoarl on 2026-11-27T21:55:18Z.


Summary

Ports the portable 32-lane BVH builder lowering fixes, placed acceleration-structure view_address (Location), and GPURT [u32::MAX; 4] node answer from fxceless/victory-fork commits 17533c5, 1170216, 1320dfd, and 9a9091d (GPL-3.0-or-later), rebased onto main (df2daaf).

VICTORY_BVH_BUILDER remains opt-in (=1, off by default).

Changes

  • crates/victory-shader/src/emit/lower.rs, emit/wave64_tests.rs: Enables USER_DISPATCH_THREADS_X guarding (partial_active, effect_guard) for spilled 1D compute programs on 32-lane waves and programs with barriers instead of returning early; refines lane_uniform dword tracking, uniform ds_read checks, and v_readfirstlane_b32 masking when halves match or are guarded.
  • crates/victory-shader/src/bvh.rs, emit/intersect.rs: Returns [u32::MAX; 4] (-1 per AMD GPURT) for instance and procedural BVH nodes (kinds 6 and 7), and applies effect_guard to BVH intersection loads.
  • crates/victory-gpu/src/descriptor/host.rs: Extracts Location (words 4–5) for placed as well as shader acceleration-structure views in view_address, returning None when zero.
  • Adaptations for main: Omits 17533c5 (VICTORY_WAVE_PAIRS_SPILLED, paired.rs is absent on main) and omits 9a9091d written-page tracking because main uses Shadow::by_address sync (preserving PR #88 and PR #58).

Verification

Verified on Windows (x86_64-pc-windows-msvc) against main (df2daaf):

  • git diff --check main..HEAD — clean
  • cargo test -p xtask --locked — 6 passed, 0 failed (asset policy: 287 files ok)
  • cargo clippy -p victory-shader -p victory-gpu --all-targets --locked — exit 0, 0 warnings in changed files (main has pre-existing clippy warnings in untouched files)
  • cargo test -p victory-shader --locked emit::wave64_tests — 17 passed, 0 failed
  • cargo test -p victory-gpu --locked descriptor:: — 62 passed, 0 failed
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5533588410 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/403). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-11-27T21:55:18Z. --- ### Summary Ports the portable 32-lane BVH builder lowering fixes, placed acceleration-structure `view_address` (`Location`), and GPURT `[u32::MAX; 4]` node answer from `fxceless/victory-fork` commits `17533c5`, `1170216`, `1320dfd`, and `9a9091d` (`GPL-3.0-or-later`), rebased onto `main` (`df2daaf`). `VICTORY_BVH_BUILDER` remains opt-in (`=1`, off by default). ### Changes - **`crates/victory-shader/src/emit/lower.rs`, `emit/wave64_tests.rs`**: Enables `USER_DISPATCH_THREADS_X` guarding (`partial_active`, `effect_guard`) for spilled 1D compute programs on 32-lane waves and programs with barriers instead of returning early; refines `lane_uniform` dword tracking, uniform `ds_read` checks, and `v_readfirstlane_b32` masking when halves match or are guarded. - **`crates/victory-shader/src/bvh.rs`, `emit/intersect.rs`**: Returns `[u32::MAX; 4]` (`-1` per AMD GPURT) for instance and procedural BVH nodes (kinds 6 and 7), and applies `effect_guard` to BVH intersection loads. - **`crates/victory-gpu/src/descriptor/host.rs`**: Extracts `Location` (words 4–5) for placed as well as shader acceleration-structure views in `view_address`, returning `None` when zero. - **Adaptations for `main`**: Omits `17533c5` (`VICTORY_WAVE_PAIRS_SPILLED`, `paired.rs` is absent on `main`) and omits `9a9091d` written-page tracking because `main` uses `Shadow::by_address` sync (preserving PR #88 and PR #58). ### Verification Verified on Windows (`x86_64-pc-windows-msvc`) against `main` (`df2daaf`): - `git diff --check main..HEAD` — clean - `cargo test -p xtask --locked` — 6 passed, 0 failed (`asset policy: 287 files ok`) - `cargo clippy -p victory-shader -p victory-gpu --all-targets --locked` — exit 0, 0 warnings in changed files (`main` has pre-existing clippy warnings in untouched files) - `cargo test -p victory-shader --locked emit::wave64_tests` — 17 passed, 0 failed - `cargo test -p victory-gpu --locked descriptor::` — 62 passed, 0 failed
Castyan commented 2026-11-27 22:20:21 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Castyan on 2026-11-27T22:20:21Z.


i'm on it for testing

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7229243068 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/403#issuecomment-7229243068). Originally posted by [Castyan](https://github.com/Castyan) on 2026-11-27T22:20:21Z. --- i'm on it for testing
Castyan commented 2026-11-27 22:30:00 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Castyan on 2026-11-27T22:30:00Z.


#388 + #403 merged on main (df2daaf): no conflict, no new failure. Windows, RTX 5060, cargo test --workspace --no-fail-fast: 1070 passed (main 1064, the +6 are #403's new tests), 2 failed (victory-gpu indirect::tests, the same 2 on main). The clippy error at victory-formats/src/texture.rs:1346 is on main too. Not tested in game or with translate --list.

In game (RTX 5060 8 GB, 15 GB RAM, below the README's 32 GB): CS_CollectTriangles_Meshlets translates and gets its host pipeline. Series S + 2x frame gen ran 11 min, then device removed (0x887A0007). Series X runs out of memory after 2-3 min (E_OUTOFMEMORY), with main too (driver access violation in nvwgf2umx.dll). So the crashes look like this PC's memory, not these PRs. Not a like-for-like comparison.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7229378044 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/403#issuecomment-7229378044). Originally posted by [Castyan](https://github.com/Castyan) on 2026-11-27T22:30:00Z. --- **#388 + #403 merged on `main` (`df2daaf`): no conflict, no new failure.** Windows, RTX 5060, `cargo test --workspace --no-fail-fast`: 1070 passed (main 1064, the +6 are #403's new tests), 2 failed (`victory-gpu` `indirect::tests`, the same 2 on `main`). The clippy error at `victory-formats/src/texture.rs:1346` is on `main` too. Not tested in game or with `translate --list`. **In game** (RTX 5060 8 GB, 15 GB RAM, below the README's 32 GB): `CS_CollectTriangles_Meshlets` translates and gets its host pipeline. Series S + 2x frame gen ran 11 min, then device removed (`0x887A0007`). Series X runs out of memory after 2-3 min (`E_OUTOFMEMORY`), with `main` too (driver access violation in `nvwgf2umx.dll`). So the crashes look like this PC's memory, not these PRs. Not a like-for-like comparison.
CowboyBingus commented 2026-11-28 07:12:46 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by CowboyBingus on 2026-11-28T07:12:46Z.


A/B in game: with this PR, 1,626 of 1,635 static structures with header 0x80020006 are sound; without it, 138 of 1,332.

Setup: two builds that differ only by this PR's 5 files (git diff --stat between the arms):

  • base: main 8fc2254 + 2 window-focus test commits;
  • A: base + this PR's head a265798 merged + 3 diagnostics commits;
  • B: base + the same 3 diagnostics commits.

Each arm was one run with VICTORY_BVH_BUILDER=1, VICTORY_BVH_CALLS, VICTORY_MEMORY_DUMP, VICTORY_MEMORY_DUMP_BUFFERS=4 and VICTORY_NO_ACTIVATE=1, the same scripted key presses, and a dump of title memory (23 arenas) started at 104.3 s (A) and 104.1 s (B) after launch. Counted: static structures (packed entries last given at least 16 frames before the dump's first copy). "Sound" means every reachable node is in the dump and in bounds, no box child is of kind 6/7, and at least one triangle node is reached (walks capped at 200,000 nodes).

headers 0x80020006 sound triangle nodes still packed (0x81020006)
A, with this PR 1,635 1,626 1,715,219 14
B, without 1,332 138 276 51

Two earlier dumps, from different builds and runs, split the same way: with this PR 1,845 of 1,912 sound (2,222,662 triangle nodes); without it 140 of 1,437 (294).

This is one run per arm.

Still open with this PR (measured, not attributed to it):

  • Of the 14 still packed in run A, 2 were rehydrated once and 12 twice before their arena was copied; the 12 twice-rehydrated call pairs were 11-46 frames apart.
  • In an earlier with-PR dump, 596 of the 2,301 enabled instances (of 4,464) in one top-level structure name 184 bases that the dump lists as built (not packed), with no version-6 header.

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7235789065 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/403#issuecomment-7235789065). Originally posted by [CowboyBingus](https://github.com/CowboyBingus) on 2026-11-28T07:12:46Z. --- **A/B in game: with this PR, 1,626 of 1,635 static structures with header `0x80020006` are sound; without it, 138 of 1,332.** Setup: two builds that differ only by this PR's 5 files (`git diff --stat` between the arms): - base: main `8fc2254` + 2 window-focus test commits; - A: base + this PR's head `a265798` merged + 3 diagnostics commits; - B: base + the same 3 diagnostics commits. Each arm was one run with `VICTORY_BVH_BUILDER=1`, `VICTORY_BVH_CALLS`, `VICTORY_MEMORY_DUMP`, `VICTORY_MEMORY_DUMP_BUFFERS=4` and `VICTORY_NO_ACTIVATE=1`, the same scripted key presses, and a dump of title memory (23 arenas) started at 104.3 s (A) and 104.1 s (B) after launch. Counted: static structures (packed entries last given at least 16 frames before the dump's first copy). "Sound" means every reachable node is in the dump and in bounds, no box child is of kind 6/7, and at least one triangle node is reached (walks capped at 200,000 nodes). | | headers `0x80020006` | sound | triangle nodes | still packed (`0x81020006`) | |---|---|---|---|---| | A, with this PR | 1,635 | 1,626 | 1,715,219 | 14 | | B, without | 1,332 | 138 | 276 | 51 | Two earlier dumps, from different builds and runs, split the same way: with this PR 1,845 of 1,912 sound (2,222,662 triangle nodes); without it 140 of 1,437 (294). This is one run per arm. Still open with this PR (measured, not attributed to it): - Of the 14 still packed in run A, 2 were rehydrated once and 12 twice before their arena was copied; the 12 twice-rehydrated call pairs were 11-46 frames apart. - In an earlier with-PR dump, 596 of the 2,301 enabled instances (of 4,464) in one top-level structure name 184 bases that the dump lists as built (not packed), with no version-6 header. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ANDREANIADS commented 2026-11-28 08:13:41 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by ANDREANIADS on 2026-11-28T08:13:41Z.


I added a two-line regression check on a265798 that expects [u32::MAX; 4] directly for instance and procedural nodes (kinds 6 and 7), independently of the CPU reference. With the same test file on both revisions, all four D3D12 readback tests failed on df2daaf at the first kind-6 case and passed on this PR’s head using Windows WARP. The runner had no SM 6.6 hardware adapter. This check covers synthetic node readbacks only.

Two-line test · Windows job with before/after results

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7236446677 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/403#issuecomment-7236446677). Originally posted by [ANDREANIADS](https://github.com/ANDREANIADS) on 2026-11-28T08:13:41Z. --- I added a two-line regression check on `a265798` that expects `[u32::MAX; 4]` directly for instance and procedural nodes (kinds 6 and 7), independently of the CPU reference. With the same test file on both revisions, all four D3D12 readback tests failed on `df2daaf` at the first kind-6 case and passed on this PR’s head using Windows WARP. The runner had no SM 6.6 hardware adapter. This check covers synthetic node readbacks only. [Two-line test](https://github.com/ANDREANIADS/VIctory-NVIDIA/commit/a86b65eb9c919f9045d19612083edd6083dca38c) · [Windows job with before/after results](https://github.com/ANDREANIADS/VIctory-NVIDIA/actions/runs/46086555430/job/140797366889)
eleboucher commented 2026-11-28 16:45:07 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by eleboucher on 2026-11-28T16:45:07Z.


Measured on an RTX 4070 Ti SUPER (32-lane waves), with the title's own ray tracing (VICTORY_RT_NATIVE=1). This is a data point for the USER_DISPATCH_THREADS_X part of this PR.

Without it, the gate in counted_in_threads (!wave64 || host_max_wave() >= 64) leaves the wave64 builder stages caa78b8c and 28918b71 uncounted on NVIDIA. The last group of each DispatchX runs all 64 lanes. Those lanes store past the structure's end, and s_bcnt1_i32_b64 exec returns 64 instead of n, which moves every lane's read.

With a fix for that part alone, a card dump of the ray-tracing memory read with bvhwalk changes like this:

before after
packed (static) instances with a valid root 1 of 50 55 of 55
triangles reachable from the roots 43,458 102,624
ray misses whose first anomaly is an inverted box 2,318 100

In the prison-cell scene at the start, the room is no longer lit evenly by rays that pass through missing walls. Light now comes only through the window.

If it helps review, the fix for that one part is a single commit on top of main: github.com/eleboucher/VIctory-NVIDIA@ff74e1c0. It keeps the lanes past the count in the wave and outside EXEC on entry, so the two halves can still exchange through LDS. victory-shader --lib passes on the card: 295 passed. I'm not opening a separate PR, to avoid a duplicate of this one.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7242484081 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/403#issuecomment-7242484081). Originally posted by [eleboucher](https://github.com/eleboucher) on 2026-11-28T16:45:07Z. --- Measured on an RTX 4070 Ti SUPER (32-lane waves), with the title's own ray tracing (`VICTORY_RT_NATIVE=1`). This is a data point for the `USER_DISPATCH_THREADS_X` part of this PR. Without it, the gate in `counted_in_threads` (`!wave64 || host_max_wave() >= 64`) leaves the wave64 builder stages `caa78b8c` and `28918b71` uncounted on NVIDIA. The last group of each `DispatchX` runs all 64 lanes. Those lanes store past the structure's end, and `s_bcnt1_i32_b64 exec` returns 64 instead of n, which moves every lane's read. With a fix for that part alone, a card dump of the ray-tracing memory read with `bvhwalk` changes like this: | | before | after | |---|---:|---:| | packed (static) instances with a valid root | 1 of 50 | 55 of 55 | | triangles reachable from the roots | 43,458 | 102,624 | | ray misses whose first anomaly is an inverted box | 2,318 | 100 | In the prison-cell scene at the start, the room is no longer lit evenly by rays that pass through missing walls. Light now comes only through the window. If it helps review, the fix for that one part is a single commit on top of `main`: https://github.com/eleboucher/VIctory-NVIDIA/commit/ff74e1c0. It keeps the lanes past the count in the wave and outside EXEC on entry, so the two halves can still exchange through LDS. `victory-shader --lib` passes on the card: 295 passed. I'm not opening a separate PR, to avoid a duplicate of this one.
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
trustno1-coder/VIctory-NVIDIA!403
No description provided.