Repository navigation
v0.22.6
Added
-
The ballot-mask built-in variables are now written on MSL, HLSL and DXIL (card P2-IR-042). Those backends
have no such built-in, so each mask is synthesised from the invocation's lane index and the subgroup size per
32-bit word — never from a ballot of true, which holds only the active lanes while the spec's mask spans
every invocation of the subgroup. A new internal package holds the extension's equations as the semantic
oracle, exhaustively tested over every power-of-two size up to 128 and every lane; each writer's test
transcribes its emitted formula line for line and checks it against the oracle. HLSL writes helper functions
callingWaveGetLaneIndex/WaveGetLaneCount; MSL declares each mask as a kernel local over
thread_index_in_simdgroup/threads_per_simdgroup; DXIL builds the vec4 through
dx.op.waveGetLaneIndex/dx.op.waveGetLaneCount, and IDxcValidator accepts the emitted DXIL for every mask.
The GLSL subgroup matrix's mask row now compiles through its SPIR-V, MSL and HLSL legs. A mask as a struct
member stays refused on MSL with the limitation named (no attribute could carry it). -
Ballot-mask built-in variables across the IR, both frontends and the backends that can express them (card
P2-IR-041, ADR-014 D5). The IR gainsir.BuiltinSubgroupEqMask,GeMask,GtMask,LeMaskandLtMask
— vec4 inputs whose bit i is set when i = ID / i >= ID / i > ID / i <= ID / i < ID (ID = the subgroup
invocation id, bits above the subgroup size zero), SPIR-V'sSubgroupEqMask…SubgroupLtMaskBuiltIns
(4416–4420), none of which Rust naga has. Validation adds the BALLOT operation class to theCapSubgroupthe
subgroup variables already needed. The GLSL frontend lowersgl_SubgroupEqMask…gl_SubgroupLtMask
(previously refused), gated by the ballot family's extension; the SPIR-V frontend maps the five decorations;
the SPIR-V backend writes the decorated Input variables with GroupNonUniformBallot, and the GLSL text
backend writes the variable names — and now requests the subgroup extensions for any shader that merely
reads one of the nine subgroup variables, a gap that left a scalar-only use without its#extension.
MSL, HLSL and DXIL refuse the five with a named limitation: the spec's mask spans every invocation while a
ballot of true holds only the active lanes, so a correct synthesis needs lane-and-subgroup-size word
arithmetic — its own card (P2-IR-042) with a Go evaluator of the equations as the oracle. Verified end to
end: glslang accepts the source, the emitted SPIR-V passes spirv-val with the five decorated Input
variables, the GLSL output round-trips, and the MSL/HLSL refusals are asserted by the matrix. -
Clustered subgroup forms across the IR, both frontends and the backends that can express them (card
P2-IR-040, ADR-014 D4). The IR gainsir.CollectiveOperationClusteredReduceand aClusterSize uint32
field onir.StmtSubgroupCollectiveOperation— the clustered reductions ofGL_KHR_shader_subgroup
(subgroupClusteredAdd/Mul/Min/Max/And/Or/Xor, "an integral constant expression. At least 1. A power of
2.") and SPIR-V'sClusteredReducegroup operation with its optional Cluster Size operand, none of which
Rust naga has. Validation addsvalid.SubgroupClustered(the bit Rust reserved and left commented out),
requires the size to be at least 1 and a power of 2, requires it to stay 0 on every other collective, and
refuses the votes under it. The GLSL frontend lowers the seven builtins with glslang's error texts for a
non-constant, zero, negative or non-power-of-2 size, and the SPIR-V frontend mapsClusteredReducewith
its constant operand. The SPIR-V backend writes the native form withGroupNonUniformClustered, the GLSL
text backend writes the builtins; MSL, HLSL (before the SM 6.5 multi-prefix operations) and DXIL have no
clustered form and refuse with a named limitation — a shuffle-based emulation is future work. Verified end
to end: spirv-val on the emitted SPIR-V, glslang on every matrix source, and the GLSL subgroup matrix;
unit tests pin the IR shape, the operand rules, the frontend mappings and each backend's output or refusal. -
Ballot bit operations across the IR, both frontends and every backend (card P2-IR-039, ADR-014 D3).
The IR gainsir.StmtSubgroupBallotBitand their.SubgroupBallotBitOperationenum (Extract, Count,
InclusiveCount, ExclusiveCount, FindLSB, FindMSB, InverseBallot) — the seven ballot bit forms of
GL_KHR_shader_subgroup_ballotand SPIR-V'sGroupNonUniformBallotcapability, none of which Rust naga
has. The result reusesir.ExprSubgroupOperationResult(bool for extract and inverse ballot, u32 for the
counts and finds); validation is the existing BALLOT class withMaskvec4 andIndexa u32 scalar
read by extract only. The GLSL frontend lowerssubgroupBallotBitExtract,subgroupBallotBitCount,
subgroupBallotInclusiveBitCount,subgroupBallotExclusiveBitCount,subgroupBallotFindLSB,
subgroupBallotFindMSBandsubgroupInverseBallot(previously refused or unrecognized), converting an
ivec4 mask or int index to uint as glslang does; the SPIR-V frontend maps the fiveOpGroupNonUniform*
opcodes. Every backend writes the forms: SPIR-V natively (opcodes 340–344), GLSL text as the builtins, and
HLSL, MSL and DXIL as arithmetic over the four mask words (countbits/firstbitlow/firstbithigh,
metal::popcount/ctz/clz,dx.op.unaryBitsCountbits/FirstbitLo/FirstbitHi), masked to the subgroup
size as the SPIR-V and GLSL specs require — the wave count intrinsics count the live wave's predicate, not
a mask value, so they are not used. MSL threads the subgroup size and lane index kernel inputs to callees
by value. Verified end to end: spirv-val on the emitted SPIR-V, dxccs_6_0on the emitted HLSL,
IDxcValidator on the emitted DXIL (including the conversions and a mixed-builtin module), and the GLSL
subgroup matrix; unit tests per layer pin the IR shape, the operand rules and each backend's output.
Fixed
valid.MissingCapabilitiesnow reports SUBGROUP for an elect-only module (found while implementing
P2-IR-039; card P2-IR-038 follow-up). The capability collector listed the ballot, collective and gather
statements but notStmtSubgroupElect, so a module whose only subgroup operation was an elect passed a
backend'sMissingCapabilitiesgate even when subgroups were unsupported. Elect and the new ballot bit
statement are now collected; a gate-table case pins it, proven to fail on the previous code.