Assign unique compute thread IDs on tiled wave32 GPUs #18

Open
github-bot wants to merge 1 commit from github-bot/gh-18 into main AGit
Owner

@⁠gomeaw on GitHub · 2026-11-25 23:37 UTC · original
gomeaw:fix/compute-wave32-thread-ids → main · +366 −92 · 3 files · 1 commits · open

Fix

Native wave32 compute shaders that use lane operations currently derive a logical wave base by rounding the first hardware thread ID down. NVIDIA can tile a wave across rows. In a 32 × 2 group, for example, the two waves can start at 0 and 16, so both get logical IDs 0–31. Stores from the second logical wave are lost.

This adapts the wave ticket from Marvisak/VIctory#2126 by 0xkn0wh3r3 to this fork’s existing wave64-to-wave32 lowering. One physical thread initializes the shared counter and one lane of each full wave increments it. A partial wave takes the last range regardless of arrival order. The XYZ components share one remapped flat ID. Native one-dimensional and single-wave groups keep the fast path. Native wave32 shaders already using all 32 KiB of group-shared memory keep their existing lowering.

Verification

  • The Windows SDK validator accepted the translated wave32 and split-wave64 fixtures. The same ticket prologue wrote exactly one value to every ID in three WARP dispatches, including full and partial waves. The tests also ran with shader optimization enabled. Windows validation

  • The original PR measured the tiled layout on RTX hardware. To test this port on a 32-lane GPU, run cargo test --locked -p victory-shader --lib wave_ticket_counters_cover_every_id_on_wave32_hardware -- --nocapture. It runs 11 synthetic shapes and checks both ID coverage and the console lane value at each ID. Gameplay and frame-time impact are still open.

  • A separate Windows 11 test on a physical RTX 3080 Ti 12 GB at preview bfd9ef8 passed all 11 translated group shapes. The test checked the console lane value and exact ID coverage. Independent Ampere result

AI-assisted with Codex. The fixtures are synthetic.

**@⁠gomeaw** on GitHub · 2026-11-25 23:37 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/18) `gomeaw:fix/compute-wave32-thread-ids` → `main` · +366 −92 · 3 files · 1 commits · open ## Fix Native wave32 compute shaders that use lane operations currently derive a logical wave base by rounding the first hardware thread ID down. NVIDIA can tile a wave across rows. In a 32 × 2 group, for example, the two waves can start at 0 and 16, so both get logical IDs 0–31. Stores from the second logical wave are lost. This adapts the wave ticket from [Marvisak/VIctory#2126](https://github.com/Marvisak/VIctory/pull/2126) by 0xkn0wh3r3 to this fork’s existing wave64-to-wave32 lowering. One physical thread initializes the shared counter and one lane of each full wave increments it. A partial wave takes the last range regardless of arrival order. The XYZ components share one remapped flat ID. Native one-dimensional and single-wave groups keep the fast path. Native wave32 shaders already using all 32 KiB of group-shared memory keep their existing lowering. ## Verification - The Windows SDK validator accepted the translated wave32 and split-wave64 fixtures. The same ticket prologue wrote exactly one value to every ID in three WARP dispatches, including full and partial waves. The tests also ran with shader optimization enabled. [Windows validation](https://github.com/gomeaw/VIctory-7900XTX/actions/runs/45722491679) - The original PR measured the tiled layout on RTX hardware. To test this port on a 32-lane GPU, run `cargo test --locked -p victory-shader --lib wave_ticket_counters_cover_every_id_on_wave32_hardware -- --nocapture`. It runs 11 synthetic shapes and checks both ID coverage and the console lane value at each ID. Gameplay and frame-time impact are still open. - A separate Windows 11 test on a physical RTX 3080 Ti 12 GB at preview `bfd9ef8` passed all 11 translated group shapes. The test checked the console lane value and exact ID coverage. [Independent Ampere result](https://git.gtahub.st/github/avatarmanz--VIctory-7900XTX/issues/3) AI-assisted with Codex. The fixtures are synthetic.
Adapt the wave ticket from Marvisak/VIctory#2126 (411ed48) to this fork’s split-wave lowering. Reserve the final logical wave for the partial hardware wave and use one initializing thread and one atomic per full wave.

Co-authored-by: 0xkn0wh3r3 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:31:22 +00:00
Author
Owner

@⁠spook40 on GitHub · 2026-11-26 00:15 UTC · original

Tested PR #18 on NVIDIA GeForce RTX 3060 Ti (8 GB VRAM) (pr-18 branch, diag profile with --features diagnostics, VICTORY_TEXTURE_MAX=512):

  • Unit test: cargo test --locked -p victory-shader --lib wave_ticket_counters_cover_every_id_on_wave32_hardware -- --nocapture passed (all 11 translated group shapes wrote each console ID once on 32-lane hardware).
  • In-game & pacing: Ran past frame 1798 to at least frame 3665 without crashing, saving a 273560526-byte host pipeline library (early=2567, made=271, loaded=1361, started_early=2291). Frame pacing in this diag run was ~1.0 fps (1013.2 ms/frame, 3899 draws/frame, GPU ~26% busy), mostly limited by CPU list/pipeline/memory-tracking overhead rather than the wave ticket change itself.

AI-assisted with Gemini.

**@⁠spook40** on GitHub · 2026-11-26 00:15 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/18#issuecomment-7178570068) Tested PR #18 on **NVIDIA GeForce RTX 3060 Ti (8 GB VRAM)** (`pr-18` branch, `diag` profile with `--features diagnostics`, `VICTORY_TEXTURE_MAX=512`): * **Unit test:** `cargo test --locked -p victory-shader --lib wave_ticket_counters_cover_every_id_on_wave32_hardware -- --nocapture` passed (`all 11 translated group shapes wrote each console ID once on 32-lane hardware`). * **In-game & pacing:** Ran past frame 1798 to at least frame 3665 without crashing, saving a `273560526`-byte host pipeline library (`early=2567`, `made=271`, `loaded=1361`, `started_early=2291`). Frame pacing in this `diag` run was ~`1.0 fps` (`1013.2 ms/frame`, `3899 draws/frame`, GPU ~26% busy), mostly limited by CPU list/pipeline/memory-tracking overhead rather than the wave ticket change itself. AI-assisted with Gemini.
Author
Owner

@⁠j-fuxa on GitHub · 2026-11-26 01:40 UTC · original

Results from before the change, in case they help judge where the prologue is needed. RTX 4060 Laptop 8 GB and Radeon 780M iGPU, both 32-lane, Windows 11. Small compute programs storing each thread's console id with the old rounding (waveReadLaneFirst(flat id) rounded down to the wave size, plus the lane). Ids stored of total, the same on both GPUs:

group stored / total
32x2 32 / 64
32x8 128 / 256
64x4 128 / 256
32x32 512 / 1024
32x2x2 64 / 128
10x10 68 / 100

12x12 and 24x8 did not create a pipeline on the RTX 4060 in our harness ("Not enough memory resources"); on the 780M they stored 96 / 144 and 128 / 192. So this is not NVIDIA-only: both GPUs fill 2-D groups from 16x2 tiles, and a host wave is not an aligned run of flat ids.

The ticket here is the design we ended up with too (zeroed counter, barrier, each full wave's first lane takes a block of wave-size ids, the partial wave takes the last block). In the title's shader archive 221 compute programs take it in our tree; three were wrong without it (all 32x2, ambient-map sky). The visible gain is small and the cost, a barrier and an LDS dword, falls on the other 218, so the single-wave and 1-D fast path matters.

Both versions assume at most one partial host wave per group. We have not seen more, and did not try to prove there cannot be. A form without that assumption: each wave's first lane does atomicAdd(counter, WaveActiveCountBits(true)) and lanes use base + WavePrefixCountBits(true). Ids stay unique but are no longer wave-aligned, so code using id & 63 as the console lane would still need it.

Caveat: synthetic programs on two GPUs, not the title; the 221 / 3 counts come from translating the archive, not running it.

**@⁠j-fuxa** on GitHub · 2026-11-26 01:40 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/18#issuecomment-7180018218) Results from before the change, in case they help judge where the prologue is needed. RTX 4060 Laptop 8 GB and Radeon 780M iGPU, both 32-lane, Windows 11. Small compute programs storing each thread's console id with the old rounding (`waveReadLaneFirst(flat id)` rounded down to the wave size, plus the lane). Ids stored of total, the same on both GPUs: | group | stored / total | |---|---| | 32x2 | 32 / 64 | | 32x8 | 128 / 256 | | 64x4 | 128 / 256 | | 32x32 | 512 / 1024 | | 32x2x2 | 64 / 128 | | 10x10 | 68 / 100 | 12x12 and 24x8 did not create a pipeline on the RTX 4060 in our harness ("Not enough memory resources"); on the 780M they stored 96 / 144 and 128 / 192. So this is not NVIDIA-only: both GPUs fill 2-D groups from 16x2 tiles, and a host wave is not an aligned run of flat ids. The ticket here is the design we ended up with too (zeroed counter, barrier, each full wave's first lane takes a block of wave-size ids, the partial wave takes the last block). In the title's shader archive 221 compute programs take it in our tree; three were wrong without it (all 32x2, ambient-map sky). The visible gain is small and the cost, a barrier and an LDS dword, falls on the other 218, so the single-wave and 1-D fast path matters. Both versions assume at most one partial host wave per group. We have not seen more, and did not try to prove there cannot be. A form without that assumption: each wave's first lane does `atomicAdd(counter, WaveActiveCountBits(true))` and lanes use `base + WavePrefixCountBits(true)`. Ids stay unique but are no longer wave-aligned, so code using `id & 63` as the console lane would still need it. Caveat: synthetic programs on two GPUs, not the title; the 221 / 3 counts come from translating the archive, not running it.
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: 928 passed, 0 failed, 45 ignored after this PR was merged (never below the count before it; the branch started at 923).
  • NVIDIA's 8x8 groups are the case this is about; lane_order_tests passes on this adapter. It conflicted with #66 (self.halves.is_some() became self.split_wave, the same rename this PR makes elsewhere).
  • 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/18#issuecomment-7183518604) 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`: **928 passed, 0 failed, 45 ignored** after this PR was merged (never below the count before it; the branch started at 923). - NVIDIA's 8x8 groups are the case this is about; `lane_order_tests` passes on this adapter. It conflicted with #66 (`self.halves.is_some()` became `self.split_wave`, the same rename this PR makes elsewhere). - 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:36 UTC · original

Left open: rewrites the thread-ID relabelling outside the 32-lane path too; needs a shader check and an in-game check on AMD and NVIDIA first.

**@⁠avatarmanz** on GitHub · 2026-11-26 07:36 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/18#issuecomment-7185639005) Left open: rewrites the thread-ID relabelling outside the 32-lane path too; needs a shader check and an in-game check on AMD and NVIDIA first.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/18/head:github-bot/gh-18'
git switch 'github-bot/gh-18'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-18'
git switch 'github-bot/gh-18'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-18'
git switch 'github-bot/gh-18'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-18'
git switch 'main'
git merge --squash 'github-bot/gh-18'
git switch 'main'
git merge --ff-only 'github-bot/gh-18'
git switch 'main'
git merge 'github-bot/gh-18'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.