Shaders: count threads of wave64 builder programs on 32-lane hosts (NVIDIA) #66

Manually merged
github merged 1 commit from github-bot/gh-66 into main 2026-11-26 08:21:46 +00:00 AGit
Owner

@⁠Mumogg on GitHub · 2026-11-26 01:22 UTC · original
Mumogg:nvidia-partial-dispatch → main · +188 −16 · 2 files · 1 commits · merged 2026-11-26 08:17 UTC

Summary

On 32-lane hosts (NVIDIA), counted_in_threads skips the structure builder's one-dimensional wave64 programs (!parts.native.wave64 || host_max_wave() >= 64), because their console waves run as two host waves that exchange through group barriers, and lanes cannot leave at entry. The lanes past the dispatch's thread count (USER_DISPATCH_THREADS_X) therefore run: they count in wave ops (s_bcnt1 exec, reductions, ballots) and store.

This keeps those lanes alive for the barriers and leaves them out instead (partial_active): memory accesses (global, flat, buffer, image, LDS), EXEC ballots, wave reductions, scc tests and the halves' exchange. Shuffles (ds_swizzle, ds_(b)permute) keep the plain guard, because they read other lanes, not memory. AMD and other 64-lane hosts are unchanged (they still take the early return).

Together with the first-lane fix from fxceless/victory-fork#497 (54f3815, 3e36c41: the builder's prefix scans), this brings the ray-tracing structure builder to 53/53 host pipelines on an RTX 5070 Ti, and VICTORY_BVH_BUILDER=1 turns on in game. That fix is not part of this PR.

Test

partial_dispatch_with_a_cross_half_wave_op_runs_in_32_lane_waves (adapted from fxceless/victory-fork#646's test): a spilled 64-thread wave64 program reads s_bcnt1_i32_b64(exec) on entry, takes a whole-wave OR of 1 << (lane >> 1) (which crosses the halves), and stores both for every lane. It is lowered through lower::lower on a 32-lane host, so it goes through counted_in_threads as the game's programs do. It must take 32-lane waves and give exact results for counts 45, 1, 33 and 0.

  • Without the change: fails (USER_DISPATCH_THREADS_X is never read).
  • With it: passes on the hardware device.
  • Full victory-shader --features host suite on this branch: 278 passed, 1 failed (stub_pipeline_is_created, which also fails without this change: vkd3d-proton does not check the DXIL digest).

Tested on Linux only: RTX 5070 Ti, Wine 11.22 + vkd3d-proton, DXC 1.9.2609 validator. Not tested on Windows or AMD yet. In-game testing on NVIDIA/Linux is still in progress; I will post updates here.

No game data, code or assets are included.

AI-assisted: the change, the test and this text were made with Claude Code at my request.

🤖 Generated with Claude Code

**@⁠Mumogg** on GitHub · 2026-11-26 01:22 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/66) `Mumogg:nvidia-partial-dispatch` → `main` · +188 −16 · 2 files · 1 commits · merged 2026-11-26 08:17 UTC ## Summary On 32-lane hosts (NVIDIA), `counted_in_threads` skips the structure builder's one-dimensional wave64 programs (`!parts.native.wave64 || host_max_wave() >= 64`), because their console waves run as two host waves that exchange through group barriers, and lanes cannot leave at entry. The lanes past the dispatch's thread count (`USER_DISPATCH_THREADS_X`) therefore run: they count in wave ops (`s_bcnt1 exec`, reductions, ballots) and store. This keeps those lanes alive for the barriers and leaves them out instead (`partial_active`): memory accesses (global, flat, buffer, image, LDS), EXEC ballots, wave reductions, `scc` tests and the halves' exchange. Shuffles (`ds_swizzle`, `ds_(b)permute`) keep the plain guard, because they read other lanes, not memory. AMD and other 64-lane hosts are unchanged (they still take the early return). Together with the first-lane fix from fxceless/victory-fork#497 (`54f3815`, `3e36c41`: the builder's prefix scans), this brings the ray-tracing structure builder to **53/53 host pipelines on an RTX 5070 Ti**, and `VICTORY_BVH_BUILDER=1` turns on in game. That fix is not part of this PR. ## Test `partial_dispatch_with_a_cross_half_wave_op_runs_in_32_lane_waves` (adapted from fxceless/victory-fork#646's test): a spilled 64-thread wave64 program reads `s_bcnt1_i32_b64(exec)` on entry, takes a whole-wave OR of `1 << (lane >> 1)` (which crosses the halves), and stores both for every lane. It is lowered through `lower::lower` on a 32-lane host, so it goes through `counted_in_threads` as the game's programs do. It must take 32-lane waves and give exact results for counts 45, 1, 33 and 0. - Without the change: fails (`USER_DISPATCH_THREADS_X` is never read). - With it: passes on the hardware device. - Full `victory-shader --features host` suite on this branch: 278 passed, 1 failed (`stub_pipeline_is_created`, which also fails without this change: vkd3d-proton does not check the DXIL digest). Tested on Linux only: RTX 5070 Ti, Wine 11.22 + vkd3d-proton, DXC 1.9.2609 validator. **Not tested on Windows or AMD yet.** In-game testing on NVIDIA/Linux is still in progress; I will post updates here. No game data, code or assets are included. *AI-assisted: the change, the test and this text were made with Claude Code at my request.* 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The structure builder's one-dimensional programs are dispatched by a count
of threads whose last group may be partial (USER_DISPATCH_THREADS_X). On a
host of 32-lane waves (NVIDIA) a console wave64 program that crosses halves
runs as two host waves that exchange through group barriers, so the lanes
past the count cannot leave at entry. `counted_in_threads` therefore skipped
these programs on 32-lane hosts, and their lanes past the count ran: they
counted in wave ops and stored.

Now the lanes stay for the barriers and `partial_active` leaves them out of
memory accesses, EXEC's ballots and the wave's reductions. Shuffles keep the
plain guard (they read other lanes, not memory).

Test: a spilled 64-thread wave64 program with s_bcnt1(exec) and a whole-wave
OR across halves, lowered through `lower::lower` on a 32-lane host; it must
take 32-lane waves and give the console's results for counts 45, 1, 33, 0.
It fails without the change (no USER_DISPATCH_THREADS_X) and passes with it
on an RTX 5070 Ti (Wine + vkd3d-proton).

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:31:42 +00:00
Author
Owner

@⁠MoonYueya on GitHub · 2026-11-26 05:28 UTC · original

Tested on an RTX 3080 10 GB, driver 32.0.16.1742, Ryzen 7 7700, 31.1 GB RAM, Windows 11 26300, merged into MoonYueya/VIctory-Kira a3de053 on top of e2a28ec together with the other open NVIDIA PRs (#47 #48 #24 #23 #78 #42 #66 #18 #10 #4 #58 #17).

  • cargo test --workspace --locked --no-fail-fast -- --test-threads=1: 925 passed, 0 failed, 45 ignored after this PR was merged (never below the count before it; the branch started at 923).
  • The RTX 3080 reports 32-lane waves, so counted_in_threads used to skip the structure builder's programs outright. Its spill test passes here.
  • With everything merged, three unattended runs reached the world with no device removal, panic or untranslated shader.

What this does not show: the PR was not run in the game on its own, so this is unit tests plus a combined run, not an in-game verification of this PR by itself; nothing here is about picture quality.

AI-assisted.

**@⁠MoonYueya** on GitHub · 2026-11-26 05:28 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/66#issuecomment-7183517897) Tested on an RTX 3080 10 GB, driver 32.0.16.1742, Ryzen 7 7700, 31.1 GB RAM, Windows 11 26300, merged into [MoonYueya/VIctory-Kira](https://github.com/MoonYueya/VIctory-Kira) `a3de053` on top of `e2a28ec` together with the other open NVIDIA PRs (#47 #48 #24 #23 #78 #42 #66 #18 #10 #4 #58 #17). - `cargo test --workspace --locked --no-fail-fast -- --test-threads=1`: **925 passed, 0 failed, 45 ignored** after this PR was merged (never below the count before it; the branch started at 923). - The RTX 3080 reports 32-lane waves, so `counted_in_threads` used to skip the structure builder's programs outright. Its spill test passes here. - With everything merged, three unattended runs reached the world with no device removal, panic or untranslated shader. What this does **not** show: the PR was not run in the game on its own, so this is unit tests plus a combined run, not an in-game verification of this PR by itself; nothing here is about picture quality. *AI-assisted.*
Author
Owner

@⁠avatarmanz on GitHub · 2026-11-26 07:56 UTC · original

Merged into main in the next push (tests pass); thanks.

**@⁠avatarmanz** on GitHub · 2026-11-26 07:56 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/66#issuecomment-7185998453) Merged into main in the next push (tests pass); thanks.
github manually merged commit 29c6429592 into main 2026-11-26 08:21:46 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.