Shaders: v_cndmask_b32 takes uniform and constant lane masks #98
No reviewers
Labels
No labels
accessibility
bug
crash
documentation
duplicate
enhancement
good first issue
graphics
help wanted
invalid
needs logs
performance
question
rdna2
rdna3
rdna4
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/eikkapine--victory-amd!98
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-98"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 mergingWhat
Compilers turn a select by a uniform condition into a lane mask from an SCC select, then a VALU select by it:
v_cndmask_b32took its condition fromStructured::masksonly, and the structure pass keeps such a mask, which no EXEC or VALU result decides, in its ownothermap. So:debug_assert!(self.s.threads.is_none() || self.console_lanes)incross_lane(in debug builds), and it marks the program as using wave operations;v_cndmask_b32 v0, v1, v2, -1) was refused.Change
structure.rs:Structuredexports the builder'sothermasks by low dword, with split low dwords left out as formasks.emit/lower.rs,v_cndmask_b32: a mask fromotherthat is the same in every lane (onlyAtom::Uniformatoms, as an SCC select and scalar operations on it give) goes throughboolean(), 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. Whenboolean()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_VERSIONgoes from 4 to 5, since compute programs with such selects translate differently: nowaveGetLaneIndexor wave operations for them, and, from reading the code (no test covers it), one value may change: a select on the exit SCC of ado..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
othermask toboolean()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, 0andv_cndmask_b32 v0, v2, v3, s6take 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_b32afters_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
5d91fdethe pixel test is refused with the message above and the first compute test trips thedebug_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 --libon 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.22621dxil.dllon this PC, anda_lane_mask_joined_with_a_number_is_read_as_the_number_it_isis a hardware-only test thatVICTORY_WARP=1sends to WARP.victory-shader --libon 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_policypasses.documented_switches_are_readfails, the same way as on main (VICTORY_NAMEin README.md).Limits
v_add_co_ci_u32and the like) still take their mask frommasksonly.victory-shaderonly. My checkout leaves outcrates/victory-formats/src/bcpack-tables.bin, so I did not build-p victoryor run the workspace clippy.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
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]>Pull request closed