Shaders: a wave64 allocation idiom is taken in its barrier-free form when that has fewer group barriers (opt-in, no frame-time gain measured) #1182

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

@⁠wildheathen on GitHub · 2026-11-25 23:03 UTC · original
wildheathen:idiom-first → main · +297 −3 · 3 files · 1 commits · open

On a host with 32-lane waves, the retry ladder for a stuck wave64 compute program keeps the first of "without early-outs" / "without skips" that translates, and returns. The exact local-waves form of the allocation idiom (lower::wave_local) is only tried later, so a program that fits the idiom but also translates in one of those two forms never gets its barrier-free form. 14264103296aa43a is such a program: 64-thread groups, a ballot, the first lane's atomic add of the count, each lane storing at base + its rank. It was kept in "without skips" with 33 group barriers and 681 instructions (340 on a 64-lane host).

With VICTORY_WAVE_IDIOM_FIRST=1, before one of those two forms is kept, the idiom forms the exact pass would try are emitted too, and one is kept instead only if it has fewer group barriers and no more instructions. Otherwise the ladder's choice stands, byte for byte. Off by default; the build script reads the name, so it is part of the translation fingerprint.

This is a cleanup, not a speed-up. I expected the barriers to be what 14264103296aa43a costs on the card, and they are not: see "In game" below.

Measured offline

victory translate over the title's 2,682 compute programs, VICTORY_HOST_WAVE=32, emitted DXIL compared byte for byte (VICTORY_EMIT_DUMP), on 9c184b3:

programs
switch unset: identical to main 2,674 of 2,674
switch on: DXIL changes 26
of those, more barriers or more instructions 0
of those, validated (--validate, dxil.dll 10.0.26100) 26
  • Over the 26: group barriers 764 → 38, instructions 47,009 → 33,033. 14264103296aa43a: 33 → 1 barriers, 681 → 363 instructions.
  • The rule with barriers alone also took two programs that lose one barrier and get longer (03e3e26783a5799b 1,442 → 1,773 instructions, b96880482a17f632 1,326 → 2,503). The instruction condition leaves them as they are.
  • The 8 compute programs that don't translate are the same 8 with and without the switch.

In game

RTX 5080 (driver wave 32/32), one world run of 8 minutes per build with the card's time by pipeline (VICTORY_CARD_METER_PIPELINES=1), cold shader cache for the run with the switch:

14264103296aa43a, µs per binding, by 256-frame window
without the switch (two runs, nine windows) 5,138 to 5,329
with the switch (one run, two windows) 5,170 and 5,340
  • The run with the switch did use the new form: its cache holds the translation written during the run, with one dx.op.barrier call (dxc -dumpbin), against 33 in the earlier runs' entry.
  • So this pipeline's time on the card does not come from its barriers. I don't know where it comes from: the log has no dispatch size for it, and the meter counts from this pipeline's bind to the next.
  • No error and no device loss in the run; none of the 26 programs was refused. I did not compare the picture.
  • The two runs without the switch were on ca8829f plus local changes outside the shader crate; the compute translations are byte-identical between ca8829f and 9c184b3.

What "exact" means here

Nothing new: it is the form main already uses for the 27 programs that reach the idiom pass. Each 32-lane host wave reserves its own range with its own atomic, so the slots written and the final counter are the console's, and the order within a console wave is not.

Checks

  • New tests in wave64_tests.rs (hand-written GFX10 words): an allocation program the ladder keeps with 7 barriers is kept with 1 under the switch, with the slots and the counter of the 64-lane result on the device; a program without the idiom form is left as it is; the choice between candidates.
  • cargo test -p victory-shader on the RTX 5080: 219 passed, 0 failed, 3 ignored. That run was before the instruction condition went in; after it I ran the suite on WARP only (VICTORY_WARP=1): 215 passed, 4 failed, and the 4 are tests that need the device (three stop at "compute_pipeline failed", one reads a 32-lane mask) and are not touched here.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy fails on main too since 44bff61 (diagnostics/timing-run-2026-11-25.txt is over the size limit); nothing from this PR.
  • Overlap: #854 and #993 rework the same ladder and would need this re-placed if they land first; #558 touches the gate above it for native wave64 hosts and does not conflict.

The branch is rebased on 6d20eed; main has no change in crates/victory-shader between 9c184b3, where the numbers above were taken, and there.

Windows 11, RTX 5080. No game data included; programs are named by hash only.

**@⁠wildheathen** on GitHub · 2026-11-25 23:03 UTC · [original](https://github.com/fxceless/victory-fork/pull/1182) `wildheathen:idiom-first` → `main` · +297 −3 · 3 files · 1 commits · open On a host with 32-lane waves, the retry ladder for a stuck wave64 compute program keeps the first of "without early-outs" / "without skips" that translates, and returns. The exact local-waves form of the allocation idiom (`lower::wave_local`) is only tried later, so a program that fits the idiom but also translates in one of those two forms never gets its barrier-free form. `14264103296aa43a` is such a program: 64-thread groups, a ballot, the first lane's atomic add of the count, each lane storing at base + its rank. It was kept in "without skips" with 33 group barriers and 681 instructions (340 on a 64-lane host). With `VICTORY_WAVE_IDIOM_FIRST=1`, before one of those two forms is kept, the idiom forms the exact pass would try are emitted too, and one is kept instead only if it has **fewer group barriers and no more instructions**. Otherwise the ladder's choice stands, byte for byte. Off by default; the build script reads the name, so it is part of the translation fingerprint. **This is a cleanup, not a speed-up.** I expected the barriers to be what `14264103296aa43a` costs on the card, and they are not: see "In game" below. ## Measured offline `victory translate` over the title's 2,682 compute programs, `VICTORY_HOST_WAVE=32`, emitted DXIL compared byte for byte (`VICTORY_EMIT_DUMP`), on `9c184b3`: | | programs | |---|---:| | switch unset: identical to `main` | 2,674 of 2,674 | | switch on: DXIL changes | 26 | | of those, more barriers or more instructions | 0 | | of those, validated (`--validate`, dxil.dll 10.0.26100) | 26 | - Over the 26: group barriers 764 → 38, instructions 47,009 → 33,033. `14264103296aa43a`: 33 → 1 barriers, 681 → 363 instructions. - The rule with barriers alone also took two programs that lose one barrier and get longer (`03e3e26783a5799b` 1,442 → 1,773 instructions, `b96880482a17f632` 1,326 → 2,503). The instruction condition leaves them as they are. - The 8 compute programs that don't translate are the same 8 with and without the switch. ## In game RTX 5080 (driver wave 32/32), one world run of 8 minutes per build with the card's time by pipeline (`VICTORY_CARD_METER_PIPELINES=1`), cold shader cache for the run with the switch: | `14264103296aa43a`, µs per binding, by 256-frame window | | |---|---| | without the switch (two runs, nine windows) | 5,138 to 5,329 | | with the switch (one run, two windows) | 5,170 and 5,340 | - The run with the switch did use the new form: its cache holds the translation written during the run, with one `dx.op.barrier` call (`dxc -dumpbin`), against 33 in the earlier runs' entry. - So this pipeline's time on the card does not come from its barriers. I don't know where it comes from: the log has no dispatch size for it, and the meter counts from this pipeline's bind to the next. - No error and no device loss in the run; none of the 26 programs was refused. I did not compare the picture. - The two runs without the switch were on `ca8829f` plus local changes outside the shader crate; the compute translations are byte-identical between `ca8829f` and `9c184b3`. ## What "exact" means here Nothing new: it is the form `main` already uses for the 27 programs that reach the idiom pass. Each 32-lane host wave reserves its own range with its own atomic, so the slots written and the final counter are the console's, and the order within a console wave is not. ## Checks - New tests in `wave64_tests.rs` (hand-written GFX10 words): an allocation program the ladder keeps with 7 barriers is kept with 1 under the switch, with the slots and the counter of the 64-lane result on the device; a program without the idiom form is left as it is; the choice between candidates. - `cargo test -p victory-shader` on the RTX 5080: 219 passed, 0 failed, 3 ignored. That run was before the instruction condition went in; after it I ran the suite on WARP only (`VICTORY_WARP=1`): 215 passed, 4 failed, and the 4 are tests that need the device (three stop at "compute_pipeline failed", one reads a 32-lane mask) and are not touched here. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy` fails on `main` too since `44bff61` (`diagnostics/timing-run-2026-11-25.txt` is over the size limit); nothing from this PR. - Overlap: #854 and #993 rework the same ladder and would need this re-placed if they land first; #558 touches the gate above it for native wave64 hosts and does not conflict. The branch is rebased on `6d20eed`; `main` has no change in `crates/victory-shader` between `9c184b3`, where the numbers above were taken, and there. Windows 11, RTX 5080. No game data included; programs are named by hash only.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:59:02 +00:00
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 23:20 UTC · original · edited 2026-11-25 23:38 UTC

Independent correctness check on RTX 3050 Laptop (native wave32), head 18b1a2f. I ran both translations of the PR's synthetic allocation fixture, with the option off and on, for every threshold from 0 through 64. The fixture's barrier count went from 7 to 1. All 130 hardware dispatches matched an independent CPU expectation for the counter, the set of allocated lane IDs, and the untouched tail of the 66-dword output. This includes the empty/full cases and both sides of the 32-lane boundary. Slot order was intentionally unconstrained.

The host's local Series S baseline log records a successful bind for 14264103296aa43a before this change. This is a potential performance comparison, not a missing pipeline on this machine. No per-pipeline speedup measured on the 3050 in this test. AI-assisted.

Additional RTX 3050 Laptop 4 GB, Series S baseline (local tree fccb160). In the last two consecutive 256-frame windows, the meter attributed 2,420.4 and 2,375.0 microseconds per bind to 14264103296aa43a (2.42 and 2.37 ms/frame). Total attributed pipeline time was 124.9 and 122.9 ms/frame respectively. These are bind-to-next-bind intervals. Only the baseline was timed on this adapter, so this does not establish a performance delta for the PR.

**@⁠Dathinel** on GitHub · 2026-11-25 23:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/1182#issuecomment-7177423747) · edited 2026-11-25 23:38 UTC Independent correctness check on RTX 3050 Laptop (native wave32), head 18b1a2f. I ran both translations of the PR's synthetic allocation fixture, with the option off and on, for every threshold from 0 through 64. The fixture's barrier count went from 7 to 1. All 130 hardware dispatches matched an independent CPU expectation for the counter, the set of allocated lane IDs, and the untouched tail of the 66-dword output. This includes the empty/full cases and both sides of the 32-lane boundary. Slot order was intentionally unconstrained. The host's local Series S baseline log records a successful bind for 14264103296aa43a before this change. This is a potential performance comparison, not a missing pipeline on this machine. No per-pipeline speedup measured on the 3050 in this test. AI-assisted. Additional RTX 3050 Laptop 4 GB, Series S baseline (local tree fccb160). In the last two consecutive 256-frame windows, the meter attributed 2,420.4 and 2,375.0 microseconds per bind to 14264103296aa43a (2.42 and 2.37 ms/frame). Total attributed pipeline time was 124.9 and 122.9 ms/frame respectively. These are bind-to-next-bind intervals. Only the baseline was timed on this adapter, so this does not establish a performance delta for the PR.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/wave64_tests.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/1182/head:github-bot/gh-1182'
git switch 'github-bot/gh-1182'

Merge

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