Shaders: v_cndmask_b32 takes uniform and constant lane masks #98

Closed
github-bot wants to merge 0 commits from github-bot/gh-98 into main AGit
Owner

@⁠murillojndem on GitHub · 2026-12-01 11:35 UTC · original
amd/cndmask-uniform-and-constant-masks → main · +132 −5 · 5 files · 1 commits · closed without merging

What

Compilers turn a select by a uniform condition into a lane mask from an SCC select, then a VALU select by it:

s_cmp_eq_u32 s5, 0
s_cselect_b32 vcc_lo, -1, 0
v_cndmask_b32 v0, v1, v2, vcc_lo

v_cndmask_b32 took its condition from Structured::masks only, and the structure pass keeps such a mask, which no EXEC or VALU result decides, in its own other map. So:

  • in pixel and vertex programs the select was refused: "a select on an untracked mask is not supported";
  • in compute programs it read the register as a number and took the lane's bit, a cross-lane read. With console lanes off that trips debug_assert!(self.s.threads.is_none() || self.console_lanes) in cross_lane (in debug builds), and it marks the program as using wave operations;
  • an inline constant mask (v_cndmask_b32 v0, v1, v2, -1) was refused.

Change

  • structure.rs: Structured exports the builder's other masks by low dword, with split low dwords left out as for masks.
  • emit/lower.rs, v_cndmask_b32: a mask from other that is the same in every lane (only Atom::Uniform atoms, as an SCC select and scalar operations on it give) goes through boolean(), and an inline constant 0 or -1 is false or true. Every lane's bit is then that value whatever the wave, so no lane numbers are needed. When boolean() has no value for such a mask (an SCC set by a scalar operation on a lane mask, which the lowering refuses), the mask takes the number path as before, so a program that translated keeps translating. Other masks take the paths they took before.

TRANSLATOR_VERSION goes from 4 to 5, since compute programs with such selects translate differently: no waveGetLaneIndex or wave operations for them, and, from reading the code (no test covers it), one value may change: a select on the exit SCC of a do..while (EXEC) loop, which the structure pass takes as clear (clear_after_loop), now gives the false operand, as the console's clear SCC does, where the number path read the register the lowering computed for the select.

This ports Marvisak/VIctory@67c4f53 (by bartikele, co-author on the commit) in a stricter form: upstream passed any other mask to boolean() and took the lane's bit of other constants.

Tests

  • emit::valu_tests::v_cndmask_selects_by_uniform_and_constant_masks: in a compute program, s_cmp_eq_u32 s0, 0, s_cselect_b32 s6, -1, 0 and v_cndmask_b32 v0, v2, v3, s6 take v3 where s0 is 0 and v2 where it is not, and the constants -1 and 0 take v3 and v2.
  • emit::barycentric_tests::a_pixel_select_by_a_uniform_or_constant_mask_translates: the shape above in a pixel program, with VCC and with the constants -1 and 0, translates and validates. Masks whose lanes differ (the inline constant 1, s_mov_b32 vcc_lo, 0x55555555) stay refused.
  • emit::valu_tests::v_cndmask_by_a_select_on_a_lane_mask_operation_still_translates: s_cselect_b32 after s_and_b32 s6, vcc_lo, exec_lo, in a 32-thread program with console lanes (v_mbcnt_lo_u32_b32). It guards the fallback above: without it this program, which translates on main, was refused with "a lane mask read as data".

On main 5d91fde the pixel test is refused with the message above and the first compute test trips the debug_assert!. With this branch the three pass on WARP and on an RX 7900 XT (driver 32.0.32015.7029); WARP runs no 32-lane waves, so the values of the third come from the card.

Also run:

  • victory-shader --lib on WARP: 312 passed, 4 failed, 4 ignored (main: 309, 4, 4). The four failures are the same on main: three fail PSV0 validation with the SDK 10.0.22621 dxil.dll on this PC, and a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is is a hardware-only test that VICTORY_WARP=1 sends to WARP.
  • victory-shader --lib on the RX 7900 XT (and WARP, through the same harness): 313 passed, 3 failed, 4 ignored (main: 310, 3, 4). The three failures are the PSV0 ones.
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings, with and without --all-features: clean.
  • cargo test -p xtask: repository_passes_policy passes. documented_switches_are_read fails, the same way as on main (VICTORY_NAME in README.md).

Limits

  • In pixel and vertex programs a mask that SCC values decide is now trusted the way a uniform branch is: each lane takes its bit from its own SCC value. Where that differs from the wave's (a select made in a loop the lanes leave one by one and read after it), the result follows the lane's SCC. Compute programs already gave these answers through the lane's own register value.
  • Joins of different SCC selects become a join atom and are not taken by this change, so pixel and vertex programs still refuse them.
  • The pixel test checks translation and validation, not values; the values are checked in compute, with one thread in the first test. The third test passes on main too, so it guards only the fallback, and its 32 threads store to one dword. No test covers wave64. Carry-ins (v_add_co_ci_u32 and the like) still take their mask from masks only.
  • I built and tested victory-shader only. My checkout leaves out crates/victory-formats/src/bcpack-tables.bin, so I did not build -p victory or run the workspace clippy.
  • No in-game run and no fps numbers; how many of the game's programs this lets through was not measured.
  • No environment switch: it is a translation fix. I can put it behind a switch if you prefer.
  • Other translator PRs bump the version too (#72 goes to 6, my #90 to #93 to 5). Whichever lands later needs the next number.

The same change is open as DexNom/VIctory#216. That one lacks the fallback above, which an independent review of this port found; I will add it there too.

Generated with Claude Code

**@⁠murillojndem** on GitHub · 2026-12-01 11:35 UTC · [original](https://github.com/eikkapine/victory-amd/pull/98) `amd/cndmask-uniform-and-constant-masks` → `main` · +132 −5 · 5 files · 1 commits · closed without merging ## What Compilers turn a select by a uniform condition into a lane mask from an SCC select, then a VALU select by it: ``` s_cmp_eq_u32 s5, 0 s_cselect_b32 vcc_lo, -1, 0 v_cndmask_b32 v0, v1, v2, vcc_lo ``` `v_cndmask_b32` took its condition from `Structured::masks` only, and the structure pass keeps such a mask, which no EXEC or VALU result decides, in its own `other` map. So: - in pixel and vertex programs the select was refused: "a select on an untracked mask is not supported"; - in compute programs it read the register as a number and took the lane's bit, a cross-lane read. With console lanes off that trips `debug_assert!(self.s.threads.is_none() || self.console_lanes)` in `cross_lane` (in debug builds), and it marks the program as using wave operations; - an inline constant mask (`v_cndmask_b32 v0, v1, v2, -1`) was refused. ## Change - `structure.rs`: `Structured` exports the builder's `other` masks by low dword, with split low dwords left out as for `masks`. - `emit/lower.rs`, `v_cndmask_b32`: a mask from `other` that is the same in every lane (only `Atom::Uniform` atoms, as an SCC select and scalar operations on it give) goes through `boolean()`, and an inline constant 0 or -1 is false or true. Every lane's bit is then that value whatever the wave, so no lane numbers are needed. When `boolean()` has no value for such a mask (an SCC set by a scalar operation on a lane mask, which the lowering refuses), the mask takes the number path as before, so a program that translated keeps translating. Other masks take the paths they took before. `TRANSLATOR_VERSION` goes from 4 to 5, since compute programs with such selects translate differently: no `waveGetLaneIndex` or wave operations for them, and, from reading the code (no test covers it), one value may change: a select on the exit SCC of a `do..while (EXEC)` loop, which the structure pass takes as clear (`clear_after_loop`), now gives the false operand, as the console's clear SCC does, where the number path read the register the lowering computed for the select. This ports Marvisak/VIctory@67c4f53 (by bartikele, co-author on the commit) in a stricter form: upstream passed any `other` mask to `boolean()` and took the lane's bit of other constants. ## Tests - `emit::valu_tests::v_cndmask_selects_by_uniform_and_constant_masks`: in a compute program, `s_cmp_eq_u32 s0, 0`, `s_cselect_b32 s6, -1, 0` and `v_cndmask_b32 v0, v2, v3, s6` take v3 where s0 is 0 and v2 where it is not, and the constants -1 and 0 take v3 and v2. - `emit::barycentric_tests::a_pixel_select_by_a_uniform_or_constant_mask_translates`: the shape above in a pixel program, with VCC and with the constants -1 and 0, translates and validates. Masks whose lanes differ (the inline constant 1, `s_mov_b32 vcc_lo, 0x55555555`) stay refused. - `emit::valu_tests::v_cndmask_by_a_select_on_a_lane_mask_operation_still_translates`: `s_cselect_b32` after `s_and_b32 s6, vcc_lo, exec_lo`, in a 32-thread program with console lanes (`v_mbcnt_lo_u32_b32`). It guards the fallback above: without it this program, which translates on main, was refused with "a lane mask read as data". On main 5d91fde the pixel test is refused with the message above and the first compute test trips the `debug_assert!`. With this branch the three pass on WARP and on an RX 7900 XT (driver 32.0.32015.7029); WARP runs no 32-lane waves, so the values of the third come from the card. Also run: - `victory-shader --lib` on WARP: 312 passed, 4 failed, 4 ignored (main: 309, 4, 4). The four failures are the same on main: three fail PSV0 validation with the SDK 10.0.22621 `dxil.dll` on this PC, and `a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is` is a hardware-only test that `VICTORY_WARP=1` sends to WARP. - `victory-shader --lib` on the RX 7900 XT (and WARP, through the same harness): 313 passed, 3 failed, 4 ignored (main: 310, 3, 4). The three failures are the PSV0 ones. - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`, with and without `--all-features`: clean. - `cargo test -p xtask`: `repository_passes_policy` passes. `documented_switches_are_read` fails, the same way as on main (`VICTORY_NAME` in README.md). ## Limits - In pixel and vertex programs a mask that SCC values decide is now trusted the way a uniform branch is: each lane takes its bit from its own SCC value. Where that differs from the wave's (a select made in a loop the lanes leave one by one and read after it), the result follows the lane's SCC. Compute programs already gave these answers through the lane's own register value. - Joins of different SCC selects become a join atom and are not taken by this change, so pixel and vertex programs still refuse them. - The pixel test checks translation and validation, not values; the values are checked in compute, with one thread in the first test. The third test passes on main too, so it guards only the fallback, and its 32 threads store to one dword. No test covers wave64. Carry-ins (`v_add_co_ci_u32` and the like) still take their mask from `masks` only. - I built and tested `victory-shader` only. My checkout leaves out `crates/victory-formats/src/bcpack-tables.bin`, so I did not build `-p victory` or run the workspace clippy. - No in-game run and no fps numbers; how many of the game's programs this lets through was not measured. - No environment switch: it is a translation fix. I can put it behind a switch if you prefer. - Other translator PRs bump the version too (#72 goes to 6, my #90 to #93 to 5). Whichever lands later needs the next number. The same change is open as DexNom/VIctory#216. That one lacks the fallback above, which an independent review of this port found; I will add it there too. Generated with [Claude Code](https://claude.com/claude-code)
Compilers turn a select by a uniform condition into a lane mask from an
SCC select, then a VALU select by it (s_cmp_eq_u32 s5, 0;
s_cselect_b32 vcc_lo, -1, 0; v_cndmask_b32 v0, v1, v2, vcc_lo).
v_cndmask_b32 took its condition from Structured::masks only, and the
structure pass keeps such a mask, which no EXEC or VALU result decides,
in its own `other` map. So:
- in pixel and vertex programs the select was refused ("a select on an
  untracked mask is not supported");
- in compute programs it read the register as a number and took the
  lane's bit, a cross-lane read; with console lanes off that trips the
  debug_assert in cross_lane (in debug builds), and it marks the program
  as using wave operations;
- an inline constant mask (v_cndmask_b32 v0, v1, v2, -1) was refused.

Structured now exports the builder's `other` masks by low dword, with
split low dwords left out as for `masks`. v_cndmask_b32 takes a mask
from `other` when it is the same in every lane (only uniform atoms, as
an SCC select and scalar operations on it give) through boolean(), and
an inline constant 0 or -1 as false or true. When boolean() has no value
for such a mask (an SCC set by a scalar operation on a lane mask, which
the lowering refuses), the mask takes the number path as before, so a
program that translated keeps translating. Other masks take the paths
they took before.

Tests:
- v_cndmask_selects_by_uniform_and_constant_masks: values in a compute
  program, on WARP and an RX 7900 XT;
- a_pixel_select_by_a_uniform_or_constant_mask_translates: the pixel
  program with VCC, -1 and 0 translates and validates; masks whose lanes
  differ stay refused;
- v_cndmask_by_a_select_on_a_lane_mask_operation_still_translates:
  s_cselect after s_and_b32 of VCC and EXEC, in a 32-thread program with
  console lanes; it translates on main and with this change, and was
  refused ("a lane mask read as data") without the fallback above.
Without the change the pixel test is refused and the compute test trips
the debug_assert.

Port of Marvisak/VIctory 67c4f53 in a stricter form: upstream passed any
`other` mask to boolean().

TRANSLATOR_VERSION 4 -> 5, since compute programs with such selects
translate differently.

Co-authored-by: bartikele <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 11:37:07 +00:00
github-bot closed this pull request 2026-12-01 18:59:38 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.