shader: masks with lanes elsewhere in one host wave, for the wave-wide form refused at them #146

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

@⁠Flezzonkeys on GitHub · 2026-12-01 21:35 UTC · original
Flezzonkeys:wavewide-mask-numbers → main · +208 −5 · 5 files · 1 commits · open

What

Part of the TASKS item "Wave-wide regions with per-path descriptors": one of the five game shaders that keep per-lane branches the console runs wave-wide, CS_RaytracingResolve 52ab310c, now translates wave-wide.

Its wave-wide form was refused at a lane mask with lanes outside EXEC read as data (MASK_ELSEWHERE). Two things were missing:

  1. emit never gave the wave-wide form the second try that translate already gives a per-lane form refused this way (with_mask_ops_on_numbers). Two other store variants of CS_RaytracingResolve (4b4661fd, ecd67a43) only needed that.
  2. 52ab310c reads a real mask (s_cselect_b32 s0, exec_lo, 0 ANDed with a compare, around 0x5b0c). mask_dword takes such a mask as the ballot of every lane only with two exchanging host waves. With one host wave that is the console wave, all_lanes is always true and says nothing, so it refused, and it named no block, so widen stopped with "a branch around it cannot be".

The change, only for a wave-wide form refused with MASK_ELSEWHERE, as two more tries in this order:

  • numbers only (with_mask_ops_on_numbers), so a program the per-lane second try already handles comes out as before;
  • then also lower::with_one_wave_masks: where one host wave is the console wave (no exchange, no halves, a fixed wave of the console's size, a compute group of whole waves, no thread count), a mask made in a block every lane runs (all_lane_blocks, branches taken wave-wide count) is the ballot of every lane, if every lane computes its bit from what every lane ran: the mask's atoms are Uniform, Opaque, Constant, or Lane compares in such blocks. Not a phi, as the mask or inside it. Where it doesn't hold, the block is named for widen.

The reference

No vkd3d-proton counterpart (it doesn't translate console ISA). The reference inside the translator is the existing two-host-wave case in mask_dword (exchange, all_lanes), and how the wave sum and a fetch-inactive v_permlane already decide "every lane runs this block" for one host wave (all_lane_blocks). The order of tries follows translate / emit_with_retries: each second try only for programs refused for it, "so no program that translated without it changes".

Evidence

  • Whole-store DXIL diff on my store (19,154 containers, translate-dir before/after): 3 compute programs change (52ab310c, 4b4661fd, ecd67a43), 0 of the other 16,391. 7007ec7e keeps its per-lane form, now refused for "a descriptor's address or format read as data". 18 store programs keep per-lane branches (21 before).
  • A first version was wrong, and the diff and a test caught it: without the order and the atom check it also changed five CS_TraceShadowRays programs that translated fine before, and a test with the mask read after a per-lane join translated where it must not. Details in docs/learnings/distshadow.md.
  • Card tests (victory-shader under Proton, RX 9070 XT, RADV 26.3.1): two new tests in wave64_tests.rs, a mask of the lanes outside EXEC made in a branch, counted there and after the join. Refused per lane and wave-wide without the second try; with it, the console's counts on the card. Whole crate: 345 passed, 15 card runs, none skipped. Linux tests and clippy (Linux and xwin) clean. TRANSLATOR_VERSION 14.
  • In game (my build: 31c20c7 + this commit + my local stuff that doesn't touch the translator, Series X, free roam, 193+ stats windows): "pipeline with a program whose lane branches stayed per lane" lists 4 shaders (0ae69044, 2da4beb3, aab1b3c7, e4a9f58e). The run before on the same PC listed 5, with 52ab310c. No device loss, no new loud errors.
  • Cost: 52ab310c on RADV goes from 144 to 168 VGPRs and 38,484 to 42,160 instructions; 4b4661fd and ecd67a43 from 120 to 192 VGPRs. Not measured in a gpuprof A/B.
  • Not shown: a visible difference. The picture looked a bit nicer to me, but I didn't compare the same spot and time, so I'm not claiming it. No validation run.

Checklist (docs/AGENTS.md)

  • One topic (rule 31); docs/TASKS.md not edited, the related item named above (rule 29)
  • "Allow edits by maintainers" on; after review, no force-push and no close-and-reopen
  • No fallback or second path for a case that can't happen (rule 33); unexpected input fails loudly (rule 9): where the conditions don't hold it stays refused and counted, as before
  • Constants come from the console, the hardware or the title's data (rule 9b): no new constants
  • Every switch is listed, read in one place, and a bad value stops the start (rule 2): no new switches (the second try is a thread-local like with_mask_ops_on_numbers, not an environment switch)
  • Queues and other externally synchronized Vulkan objects are used under their lock (rule 35): not touched
  • Every unsafe block has a // SAFETY: comment (rule 36): no new unsafe
  • Clippy clean; tests call the production code; TRANSLATOR_VERSION bumped (rule 27)
  • Comments say what is true now and name functions, not line numbers (rule 3)
  • Nothing from the title, and no pointers to where non-free data can be found
**@⁠Flezzonkeys** on GitHub · 2026-12-01 21:35 UTC · [original](https://github.com/vktory6/VKtory/pull/146) `Flezzonkeys:wavewide-mask-numbers` → `main` · +208 −5 · 5 files · 1 commits · open ## What Part of the TASKS item "Wave-wide regions with per-path descriptors": one of the five game shaders that keep per-lane branches the console runs wave-wide, `CS_RaytracingResolve` 52ab310c, now translates wave-wide. Its wave-wide form was refused at a lane mask with lanes outside EXEC read as data (`MASK_ELSEWHERE`). Two things were missing: 1. `emit` never gave the wave-wide form the second try that `translate` already gives a per-lane form refused this way (`with_mask_ops_on_numbers`). Two other store variants of `CS_RaytracingResolve` (4b4661fd, ecd67a43) only needed that. 2. 52ab310c reads a real mask (`s_cselect_b32 s0, exec_lo, 0` ANDed with a compare, around 0x5b0c). `mask_dword` takes such a mask as the ballot of every lane only with two exchanging host waves. With one host wave that is the console wave, `all_lanes` is always true and says nothing, so it refused, and it named no block, so `widen` stopped with "a branch around it cannot be". The change, only for a wave-wide form refused with `MASK_ELSEWHERE`, as two more tries in this order: - numbers only (`with_mask_ops_on_numbers`), so a program the per-lane second try already handles comes out as before; - then also `lower::with_one_wave_masks`: where one host wave is the console wave (no exchange, no halves, a fixed wave of the console's size, a compute group of whole waves, no thread count), a mask made in a block every lane runs (`all_lane_blocks`, branches taken wave-wide count) is the ballot of every lane, if every lane computes its bit from what every lane ran: the mask's atoms are `Uniform`, `Opaque`, `Constant`, or `Lane` compares in such blocks. Not a phi, as the mask or inside it. Where it doesn't hold, the block is named for `widen`. ## The reference No vkd3d-proton counterpart (it doesn't translate console ISA). The reference inside the translator is the existing two-host-wave case in `mask_dword` (`exchange`, `all_lanes`), and how the wave sum and a fetch-inactive `v_permlane` already decide "every lane runs this block" for one host wave (`all_lane_blocks`). The order of tries follows `translate` / `emit_with_retries`: each second try only for programs refused for it, "so no program that translated without it changes". ## Evidence - **Whole-store DXIL diff** on my store (19,154 containers, translate-dir before/after): 3 compute programs change (52ab310c, 4b4661fd, ecd67a43), 0 of the other 16,391. 7007ec7e keeps its per-lane form, now refused for "a descriptor's address or format read as data". 18 store programs keep per-lane branches (21 before). - **A first version was wrong, and the diff and a test caught it:** without the order and the atom check it also changed five `CS_TraceShadowRays` programs that translated fine before, and a test with the mask read after a per-lane join translated where it must not. Details in `docs/learnings/distshadow.md`. - **Card tests** (victory-shader under Proton, RX 9070 XT, RADV 26.3.1): two new tests in `wave64_tests.rs`, a mask of the lanes outside EXEC made in a branch, counted there and after the join. Refused per lane and wave-wide without the second try; with it, the console's counts on the card. Whole crate: 345 passed, 15 card runs, none skipped. Linux tests and clippy (Linux and xwin) clean. `TRANSLATOR_VERSION` 14. - **In game** (my build: 31c20c7 + this commit + my local stuff that doesn't touch the translator, Series X, free roam, 193+ stats windows): "pipeline with a program whose lane branches stayed per lane" lists 4 shaders (0ae69044, 2da4beb3, aab1b3c7, e4a9f58e). The run before on the same PC listed 5, with 52ab310c. No device loss, no new loud errors. - **Cost:** 52ab310c on RADV goes from 144 to 168 VGPRs and 38,484 to 42,160 instructions; 4b4661fd and ecd67a43 from 120 to 192 VGPRs. Not measured in a gpuprof A/B. - **Not shown:** a visible difference. The picture looked a bit nicer to me, but I didn't compare the same spot and time, so I'm not claiming it. No validation run. ## Checklist (docs/AGENTS.md) - [x] One topic (rule 31); `docs/TASKS.md` not edited, the related item named above (rule 29) - [x] "Allow edits by maintainers" on; after review, no force-push and no close-and-reopen - [x] No fallback or second path for a case that can't happen (rule 33); unexpected input fails loudly (rule 9): where the conditions don't hold it stays refused and counted, as before - [x] Constants come from the console, the hardware or the title's data (rule 9b): no new constants - [x] Every switch is listed, read in one place, and a bad value stops the start (rule 2): no new switches (the second try is a thread-local like `with_mask_ops_on_numbers`, not an environment switch) - [x] Queues and other externally synchronized Vulkan objects are used under their lock (rule 35): not touched - [x] Every `unsafe` block has a `// SAFETY:` comment (rule 36): no new `unsafe` - [x] Clippy clean; tests call the production code; `TRANSLATOR_VERSION` bumped (rule 27) - [x] Comments say what is true now and name functions, not line numbers (rule 3) - [x] Nothing from the title, and no pointers to where non-free data can be found
The wave-wide form of a program refused at a lane mask with lanes outside EXEC read as data
(MASK_ELSEWHERE) gets the second tries the per-lane form already gets, in this order:

1. mask operations on numbers read as the numbers they compute (`with_mask_ops_on_numbers`),
   which `translate` gives a per-lane form refused so but `emit` never gave the wave-wide form;
2. then also `with_one_wave_masks`: where one host wave is the console wave (no exchange, no
   halves, a fixed wave of the console's size, a compute group of whole waves, no thread count),
   a mask made in a block every lane runs (`all_lane_blocks`, branches taken wave-wide included)
   whose bits every lane computes from what every lane ran (atoms: wave scalars, or compares in
   such blocks; no phi, as the mask or inside it) is the ballot of every lane, as `mask_dword`
   already takes it with two exchanging host waves. Where not, its block is named for `widen`.

Only programs refused so change: whole-store DXIL diff on the reference card's store (19,154
containers), 3 compute programs change (CS_RaytracingResolve 52ab310c, wanted by the game, and
4b4661fd, ecd67a43), 0 of the other 16,391; 18 store programs keep per-lane branches (21 before).
A first version without the order and the atom check changed five CS_TraceShadowRays programs
that translated before; see docs/learnings/distshadow.md.

Tests: two card tests (a mask of the lanes outside EXEC made in a branch taken wave-wide, counted
there and after the join; refused per lane and without the second try), victory-shader under
Proton on an RX 9070 XT (RADV 26.3.1): 345 passed, 15 card runs, none skipped. TRANSLATOR_VERSION 14.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 21:40:44 +00:00
Author
Owner

@⁠TheRifai on GitHub · 2026-12-02 16:06 UTC · original

Extra evidence for the TASKS "Wave-wide regions with per-path descriptors" row that this PR addresses, from current main bc86e65 (RX 9070 XT / RADV 26.3.1, GE-Proton11-16, Series X 3840x2160, house rt3, warm store, 75 s, no validation):

  • VKB_STRICT=1 aborts at start on exactly this rule-32 kind: pipeline with a program whose lane branches stayed per lane ... the wave-wide form refused at them. Exit status 1, no frames rendered.
  • In the same 75 s without strict mode the error fires 10 times for 5 distinct compute pipeline hashes (e4a9f58e…, aab1b3c7…, 2da4beb3…, 52ab310c…, 0ae69044…), two lines each.
  • A validation-layer run at the same scene reported 0 VUIDs, so this is a rule-32 loud counter, not a Vulkan validation error.

So the kind is not merely theoretical on the reference card, and strict mode cannot get past it even for a first frame. Evidence: /home/shlong/Documents/VKtory-capture/hunt-{base,strict,val}/.

**@⁠TheRifai** on GitHub · 2026-12-02 16:06 UTC · [original](https://github.com/vktory6/VKtory/pull/146#issuecomment-7351435827) Extra evidence for the TASKS "Wave-wide regions with per-path descriptors" row that this PR addresses, from current main `bc86e65` (RX 9070 XT / RADV 26.3.1, GE-Proton11-16, Series X 3840x2160, house `rt3`, warm store, 75 s, no validation): - `VKB_STRICT=1` aborts at start on exactly this rule-32 kind: `pipeline with a program whose lane branches stayed per lane ... the wave-wide form refused at them`. Exit status 1, no frames rendered. - In the same 75 s without strict mode the error fires 10 times for 5 distinct compute pipeline hashes (`e4a9f58e…`, `aab1b3c7…`, `2da4beb3…`, `52ab310c…`, `0ae69044…`), two lines each. - A validation-layer run at the same scene reported **0 VUIDs**, so this is a rule-32 loud counter, not a Vulkan validation error. So the kind is not merely theoretical on the reference card, and strict mode cannot get past it even for a first frame. Evidence: `/home/shlong/Documents/VKtory-capture/hunt-{base,strict,val}/`.
Author
Owner

@⁠vktory6 on GitHub · 2026-12-02 20:01 UTC · original

Thanks for the patience on this one. The GPU check passed on the main of that time: whole-store DXIL diff with 0 failures, per-lane pipelines down from 10 to 8 as intended, card tests passing, and the prison and boat picture gates passing (boat SSIM 0.76).

Since then #180 (two console lanes a thread for wave64 groups on 32-lane hosts) has landed, and it rewrote the code this PR builds on. Lower's exchange, local and halves, and the made block in mask_dword's refusal path, are gone, and emit no longer has halves (its wide-form match is Ok((shader, _))). A merge of main into your branch conflicts in emit/lower.rs and emit/mod.rs, and the result does not build. I tried resolving it and stopped: the remaining parts are your design decisions, not mechanical ones.

Could you rebase onto current main? Pointers from our attempt:

  • Keep both thread-locals (ONE_WAVE_MASKS and main's NO_PAIRS) and both runner functions.
  • Where you required self.halves.is_none(), the pair form now plays that role. self.pairs.is_none(), together with host_max_wave() >= self.s.wave_size, keeps "one host wave is the console wave" true also under without_pairs (32-lane waves, one console lane a thread). Please check that against your proof. On a 32-lane host the pair form computes masks per half and combines them, so the "every lane computes its bit" argument needs restating there, or the path excluded.
  • TRANSLATOR_VERSION becomes whatever main's next number is when it lands (15 or 16, depending on #206).

After the rebase we rerun the whole-store diff, the card tests and the two gates (they are cheap for us) and merge.

The translator's direction, including the wave model on 32-lane hosts and per-lane pipelines, is being discussed in https://github.com/vktory6/VKtory/discussions/270.

**@⁠vktory6** on GitHub · 2026-12-02 20:01 UTC · [original](https://github.com/vktory6/VKtory/pull/146#issuecomment-7357103714) Thanks for the patience on this one. The GPU check passed on the main of that time: whole-store DXIL diff with 0 failures, per-lane pipelines down from 10 to 8 as intended, card tests passing, and the prison and boat picture gates passing (boat SSIM 0.76). Since then https://git.gtahub.st/github/vktory6--VKtory/pulls/180 (two console lanes a thread for wave64 groups on 32-lane hosts) has landed, and it rewrote the code this PR builds on. `Lower`'s `exchange`, `local` and `halves`, and the `made` block in `mask_dword`'s refusal path, are gone, and `emit` no longer has `halves` (its wide-form match is `Ok((shader, _))`). A merge of main into your branch conflicts in emit/lower.rs and emit/mod.rs, and the result does not build. I tried resolving it and stopped: the remaining parts are your design decisions, not mechanical ones. Could you rebase onto current main? Pointers from our attempt: - Keep both thread-locals (`ONE_WAVE_MASKS` and main's `NO_PAIRS`) and both runner functions. - Where you required `self.halves.is_none()`, the pair form now plays that role. `self.pairs.is_none()`, together with `host_max_wave() >= self.s.wave_size`, keeps "one host wave is the console wave" true also under `without_pairs` (32-lane waves, one console lane a thread). Please check that against your proof. On a 32-lane host the pair form computes masks per half and combines them, so the "every lane computes its bit" argument needs restating there, or the path excluded. - `TRANSLATOR_VERSION` becomes whatever main's next number is when it lands (15 or 16, depending on #206). After the rebase we rerun the whole-store diff, the card tests and the two gates (they are cheap for us) and merge. The translator's direction, including the wave model on 32-lane hosts and per-lane pipelines, is being discussed in https://github.com/vktory6/VKtory/discussions/270.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/mod.rs
  • crates/victory-shader/src/lib.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/146/head:github-bot/gh-146'
git switch 'github-bot/gh-146'

Merge

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