Shaders: the ray-tracing structure builder's three wave64 programs on 32-lane hosts (exact, no write-only shortcut) #1700

Manually merged
github merged 1 commit from github-bot/gh-1700 into main 2026-11-29 08:21:35 +00:00 AGit
Owner

@⁠L-696 on GitHub · 2026-11-28 23:35 UTC · original
L-696:wave32-structure-builder → main · +354 −33 · 3 files · 1 commits · merged 2026-11-29 08:16 UTC

Fixes #1475

What it changes

On a 32-lane host (NVIDIA), three of the ray-tracing structure builder's 53 compute programs are refused ("no wave32 lowering for this wave64 program"). The builder's stages run all or none, so the builder stays off (missing=3 of=53). This PR translates the three with exact forms. It does not use the LDS write-only shortcut, so no approximation is involved.

  • 28918b7150a7aad5, caa78b8ca62bc3d6 (groups of 64): their per-lane loops write LDS that other lanes read, inside per-lane skips (s_cbranch_execz). Only widen() translates them, with 3 branches taken wave-wide in each. Each group is a single console wave, so the group barriers meet exactly its two host waves. Both shaders join the programs that are widened by default.
    • Those defaults now live in wide_by_default(digest, threads), keyed by group size: 64, 128 or 512.
    • The existing entries are unchanged, including CS_CollisionRaytraced. water_portals and the DefragHeap with_half_meets path are untouched.
  • e63d22c4def9ba6a (groups of 512, eight console waves): 8 rounds of a 4-bit ballot. Each console wave's first lane counts the ballot with s_bcnt1 inside a skip.
    • The mask's halves have to be exchanged at the tail of a block that has already been lowered. With pair meetings that was refused, because the meeting would split the block.
    • The new once_per_thread marks the blocks that every thread of the group runs exactly once: blocks that post-dominate the entry and are on no cycle. They are combined with all_lane_blocks_of(st, true).
    • In such a block, the exchange takes the existing group-barrier path, so every console wave reaches the barrier exactly once. Everywhere else the exchange is still refused with its own message.

Synthetic regression tests (wave64_tests.rs, no game code):

  • lds_exchange_in_a_loop_inside_a_lane_skip_needs_the_skip_wave_wide: the 28918b71/caa78b8c shape. Run on the card, the result matches the console model.
  • a_ballot_before_a_first_lane_skip_is_exchanged_with_the_whole_group: the e63d shape, in a group of 128 (two console waves).
    • Run on the card, every tested s0 (0, 1, 31, 32, 37, 64, 65, 100, 127, 128) gives [min(s0,64), min(s0-64,64)], the console's counts.
    • With the new path disabled, this test fails with e63d's error.
  • a_ballot_inside_a_wave_wide_branch_of_several_console_waves_stays_refused: the same code inside a branch that console waves may take differently is still refused, with the exact message.
  • the_structure_builders_programs_are_widened_by_default: each digest is enabled only at its own group size.

How it was tested

  • GPU and profile: RTX 4060 8 GB, driver 621.40, Windows 11 26100. Series S profile, DLSS and frame generation (MFG), ray tracing with VICTORY_BVH_BUILDER=1, cold shader cache.
  • Before (main 32ecacfa):
    WARN victory_gpu::pipeline: the ray-tracing structure builder stays off: not all of its programs have a host pipeline, and its stages run all or none missing=3 of=53 which=["e63d22c4def9ba6a", "caa78b8ca62bc3d6", "28918b7150a7aad5"]
    
  • After (the same change on 32ecacfa; this rebase onto d4b5d517 has not been run in-game):
    INFO victory_gpu::pipeline: shader translated stage="compute" hash=e63d22c4def9ba6a user_data=16 samplers=0
    INFO victory_gpu::pipeline: shader translated stage="compute" hash=caa78b8ca62bc3d6 user_data=9 samplers=0
    INFO victory_gpu::pipeline: shader translated stage="compute" hash=28918b7150a7aad5 user_data=9 samplers=0
    INFO victory_gpu::pipeline: the ray-tracing structure builder runs: all of its programs have host pipelines pipelines=53
    
    About 13 minutes of play followed. The log has no ERROR, TDR or device-removed lines, and the run ended with a normal exit.
  • Offline, on this branch (d4b5d517 + this commit):
    • Before the patch, all three are refused here too. After it, all three translate (31608 / 41148 / 67776 bytes of DXIL), and the driver creates a compute pipeline for each.
    • Census of all 2,734 compute programs, with and without the patch: 2,692 → 2,695 translate. Only these three change; the other 2,731 have identical results and byte-identical DXIL.
  • Wave sizes tested: 32-lane host. On 64-lane hosts nothing changes: the new paths apply only when the host's maximum wave is 32.
  • cargo test: yes. victory-shader --lib 352 passed, 0 failed, 9 ignored; victory-gpu --lib 550 passed, 43 ignored; cargo build --release -p victory succeeds.
  • cargo clippy --workspace --all-targets -- -D warnings: fails on two findings that are already on main and not in this diff: lower.rs spare / per (manual checked division) and the unused colour. It reports nothing for this diff.

Not verified, and help is welcome

  • Whether the traced image is fully correct with the builder on. Lighting, reflections, foliage and materials were not compared frame by frame against a reference.
  • Other NVIDIA cards, especially the RTX 30 series. Marvisak/VIctory#3330 reports a 3060 hanging on 64-thread programs of this kind under a different split. These kernels use group barriers and per-console-wave meetings, so review of the synchronisation reasoning (once_per_thread, and the exchange in exchange_halves) is welcome.
  • The performance and VRAM cost of running the builder.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related:
    • #1504 (exact folding) leaves these three refused ("3 with XboxBvhBuilder.dll"). It is complementary, but it also edits emit/lower.rs.
    • #1575 and #1590 re-enable the LDS write-only shortcut (approximate). By #1575's own measurement the three BVH kernels stay refused there; #1590 reports two XboxBvhBuilder.dll kernels.
    • #1450 adds a scoped write-only retry for known kernels.
    • This PR uses only exact forms and leaves the write-only policy alone.

AI assistance: written and tested with Claude (Anthropic); the in-game run was done by hand on the card above.

🤖 Generated with Claude Code

**@⁠L-696** on GitHub · 2026-11-28 23:35 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1700) `L-696:wave32-structure-builder` → `main` · +354 −33 · 3 files · 1 commits · merged 2026-11-29 08:16 UTC Fixes #1475 ## What it changes On a 32-lane host (NVIDIA), three of the ray-tracing structure builder's 53 compute programs are refused ("no wave32 lowering for this wave64 program"). The builder's stages run all or none, so the builder stays off (`missing=3 of=53`). This PR translates the three with exact forms. It does not use the LDS write-only shortcut, so no approximation is involved. - **`28918b7150a7aad5`, `caa78b8ca62bc3d6`** (groups of 64): their per-lane loops write LDS that other lanes read, inside per-lane skips (`s_cbranch_execz`). Only `widen()` translates them, with 3 branches taken wave-wide in each. Each group is a single console wave, so the group barriers meet exactly its two host waves. Both shaders join the programs that are widened by default. - Those defaults now live in `wide_by_default(digest, threads)`, keyed by group size: 64, 128 or 512. - The existing entries are unchanged, including `CS_CollisionRaytraced`. `water_portals` and the DefragHeap `with_half_meets` path are untouched. - **`e63d22c4def9ba6a`** (groups of 512, eight console waves): 8 rounds of a 4-bit ballot. Each console wave's first lane counts the ballot with `s_bcnt1` inside a skip. - The mask's halves have to be exchanged at the tail of a block that has already been lowered. With pair meetings that was refused, because the meeting would split the block. - The new `once_per_thread` marks the blocks that every thread of the group runs exactly once: blocks that post-dominate the entry and are on no cycle. They are combined with `all_lane_blocks_of(st, true)`. - In such a block, the exchange takes the existing group-barrier path, so every console wave reaches the barrier exactly once. Everywhere else the exchange is still refused with its own message. Synthetic regression tests (`wave64_tests.rs`, no game code): - `lds_exchange_in_a_loop_inside_a_lane_skip_needs_the_skip_wave_wide`: the 28918b71/caa78b8c shape. Run on the card, the result matches the console model. - `a_ballot_before_a_first_lane_skip_is_exchanged_with_the_whole_group`: the e63d shape, in a group of 128 (two console waves). - Run on the card, every tested s0 (0, 1, 31, 32, 37, 64, 65, 100, 127, 128) gives `[min(s0,64), min(s0-64,64)]`, the console's counts. - With the new path disabled, this test fails with e63d's error. - `a_ballot_inside_a_wave_wide_branch_of_several_console_waves_stays_refused`: the same code inside a branch that console waves may take differently is still refused, with the exact message. - `the_structure_builders_programs_are_widened_by_default`: each digest is enabled only at its own group size. ## How it was tested - **GPU and profile:** RTX 4060 8 GB, driver 621.40, Windows 11 26100. Series S profile, DLSS and frame generation (MFG), ray tracing with `VICTORY_BVH_BUILDER=1`, cold shader cache. - **Before** (main 32ecacfa): ``` WARN victory_gpu::pipeline: the ray-tracing structure builder stays off: not all of its programs have a host pipeline, and its stages run all or none missing=3 of=53 which=["e63d22c4def9ba6a", "caa78b8ca62bc3d6", "28918b7150a7aad5"] ``` - **After** (the same change on 32ecacfa; this rebase onto d4b5d517 has not been run in-game): ``` INFO victory_gpu::pipeline: shader translated stage="compute" hash=e63d22c4def9ba6a user_data=16 samplers=0 INFO victory_gpu::pipeline: shader translated stage="compute" hash=caa78b8ca62bc3d6 user_data=9 samplers=0 INFO victory_gpu::pipeline: shader translated stage="compute" hash=28918b7150a7aad5 user_data=9 samplers=0 INFO victory_gpu::pipeline: the ray-tracing structure builder runs: all of its programs have host pipelines pipelines=53 ``` About 13 minutes of play followed. The log has no ERROR, TDR or device-removed lines, and the run ended with a normal exit. - **Offline, on this branch** (d4b5d517 + this commit): - Before the patch, all three are refused here too. After it, all three translate (31608 / 41148 / 67776 bytes of DXIL), and the driver creates a compute pipeline for each. - Census of all 2,734 compute programs, with and without the patch: 2,692 → 2,695 translate. Only these three change; the other 2,731 have identical results and byte-identical DXIL. - **Wave sizes tested:** 32-lane host. On 64-lane hosts nothing changes: the new paths apply only when the host's maximum wave is 32. - **`cargo test`:** yes. `victory-shader --lib` 352 passed, 0 failed, 9 ignored; `victory-gpu --lib` 550 passed, 43 ignored; `cargo build --release -p victory` succeeds. - **`cargo clippy --workspace --all-targets -- -D warnings`:** fails on two findings that are already on main and not in this diff: `lower.rs` `spare / per` (manual checked division) and the unused `colour`. It reports nothing for this diff. **Not verified, and help is welcome** - Whether the traced image is fully correct with the builder on. Lighting, reflections, foliage and materials were not compared frame by frame against a reference. - Other NVIDIA cards, especially the RTX 30 series. Marvisak/VIctory#3330 reports a 3060 hanging on 64-thread programs of this kind under a different split. These kernels use group barriers and per-console-wave meetings, so review of the synchronisation reasoning (`once_per_thread`, and the exchange in `exchange_halves`) is welcome. - The performance and VRAM cost of running the builder. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: - #1504 (exact folding) leaves these three refused ("3 with XboxBvhBuilder.dll"). It is complementary, but it also edits `emit/lower.rs`. - #1575 and #1590 re-enable the LDS write-only shortcut (approximate). By #1575's own measurement the three BVH kernels stay refused there; #1590 reports two XboxBvhBuilder.dll kernels. - #1450 adds a scoped write-only retry for known kernels. - This PR uses only exact forms and leaves the write-only policy alone. AI assistance: written and tested with Claude (Anthropic); the in-game run was done by hand on the card above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Three of the builder's 53 compute programs were refused on NVIDIA ("no wave32
lowering for this wave64 program"), so the builder stayed off (missing=3).

- 28918b7150a7aad5 and caa78b8ca62bc3d6: groups of 64 whose per-lane loops write
  LDS inside execz skips. Only widen() translates them; they join the programs
  widened by default (now `wide_by_default`, keyed by group size).
- e63d22c4def9ba6a: groups of 512 (eight console waves). A 4-bit ballot is counted
  by each console wave's first lane inside a skip, so the mask halves must be
  exchanged at the tail of a block already lowered, which pair meetings refused.
  Where that block is one every thread of the group runs exactly once
  (post-dominates the entry, on no cycle: `once_per_thread`), the exchange now
  uses the group-barrier path; everywhere else it stays refused.

Synthetic tests: an LDS exchange in a loop inside a lane skip needs the skip
wave-wide; a ballot before a first-lane skip in a group of two console waves
is exchanged with the whole group (matches the console on the card); the same
ballot inside a wave-wide branch stays refused; the default widening policy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 23:41:06 +00:00
Author
Owner

@⁠eleboucher on GitHub · 2026-11-29 00:53 UTC · original

On an RTX 4070 Ti SUPER (32 lanes) this PR gets the builder running. The runs that died ran out of memory; nothing points at this change.

Setup: Ryzen 7 9800X3D, 16 GB RAM, Windows 11 build 26300. Native 1440p, VICTORY_BVH_BUILDER=1 VICTORY_ACTIVATE_RAYS=1, diagnostics build. Base is main f9dfb76f + #1640 + this PR. Conflict with main: emit/mod.rs, where main had added the four CS_Tree_BatchCull digests to the inline list. I kept your wide_by_default and added those four to GROUPS_OF_64.

  • Builder: e63d22c4, caa78b8c and 28918b71 translate, and the builder runs: structure builder lines throughout, no TDR line.
  • Dropped dispatches: "dropped without a host pipeline" falls from ~350 a frame (builder kept off on main) to 2-10.
  • Tests: 1388 passed. The same 2 tests fail on plain main (crash::tests::memory_at_names_what_an_access_hit, policy::tests::repository_passes_policy).
  • Start 1: ran through the unpack burst (0.4-2.6 fps at 120-180 s), then 14.4 / 14.4 / 13.7 fps at 240 / 300 / 420 s. It died between 420 and 600 s with device removed (0x887A0004). Shared GPU memory rose 6540 → 6994 MB against Windows' 7224 MB cap on a 16 GB PC, with 0.2-0.4 GB of RAM free.
  • Start 2: died at ~120 s in the burst, device removed (relay fence not reached, 0x887A0005).
  • Without this PR: the builder stays off, and the same base runs 10 minutes at ~25 fps.

So on 16 GB the builder fits only briefly. Trying the windows-in-card-memory / texture-room trade next.

**@⁠eleboucher** on GitHub · 2026-11-29 00:53 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1700#issuecomment-7248425581) On an RTX 4070 Ti SUPER (32 lanes) this PR gets the builder running. The runs that died ran out of memory; nothing points at this change. Setup: Ryzen 7 9800X3D, 16 GB RAM, Windows 11 build 26300. Native 1440p, `VICTORY_BVH_BUILDER=1 VICTORY_ACTIVATE_RAYS=1`, diagnostics build. Base is main f9dfb76f + #1640 + this PR. Conflict with main: `emit/mod.rs`, where main had added the four `CS_Tree_BatchCull` digests to the inline list. I kept your `wide_by_default` and added those four to `GROUPS_OF_64`. - **Builder:** e63d22c4, caa78b8c and 28918b71 translate, and the builder runs: `structure builder` lines throughout, no TDR line. - **Dropped dispatches:** "dropped without a host pipeline" falls from ~350 a frame (builder kept off on main) to 2-10. - **Tests:** 1388 passed. The same 2 tests fail on plain main (`crash::tests::memory_at_names_what_an_access_hit`, `policy::tests::repository_passes_policy`). - **Start 1:** ran through the unpack burst (0.4-2.6 fps at 120-180 s), then 14.4 / 14.4 / 13.7 fps at 240 / 300 / 420 s. It died between 420 and 600 s with device removed (0x887A0004). Shared GPU memory rose 6540 → 6994 MB against Windows' 7224 MB cap on a 16 GB PC, with 0.2-0.4 GB of RAM free. - **Start 2:** died at ~120 s in the burst, device removed (relay fence not reached, 0x887A0005). - **Without this PR:** the builder stays off, and the same base runs 10 minutes at ~25 fps. So on 16 GB the builder fits only briefly. Trying the windows-in-card-memory / texture-room trade next.
github manually merged commit e19b4cabb8 into main 2026-11-29 08:21:35 +00:00
Author
Owner

@⁠NotADonky43 on GitHub · 2026-11-29 08:34 UTC · original

RTX 5070 Ti / Series X: on a cumulative descendant with the reflection fold scoped separately, asking for RT left the builder off, missing 1 of 53 stages (the 512-thread ballot). With the shader changes from this PR integrated, both ballot tests passed and the real game explicitly activated all 53 stages. In an exact-executable warmed release with #1878 and BVH_SIZE_COPY also enabled, six settled heavy reports ranged from 0.5 to 15.1 rendered FPS. This verifies builder activation, not visual parity or sustained performance. Static-sampler and GPU wait safeguards retained.

**@⁠NotADonky43** on GitHub · 2026-11-29 08:34 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1700#issuecomment-7253193054) RTX 5070 Ti / Series X: on a cumulative descendant with the reflection fold scoped separately, asking for RT left the builder off, missing 1 of 53 stages (the 512-thread ballot). With the shader changes from this PR integrated, both ballot tests passed and the real game explicitly activated all 53 stages. In an exact-executable warmed release with #1878 and BVH_SIZE_COPY also enabled, six settled heavy reports ranged from 0.5 to 15.1 rendered FPS. This verifies builder activation, not visual parity or sustained performance. Static-sampler and GPU wait safeguards retained.
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!1700
No description provided.