From 4ab693c814f3cca0945fd6faea52e38ac3718917 Mon Sep 17 00:00:00 2001 From: aznohonza Date: Mon, 30 Nov 2026 22:25:18 +0100 Subject: [PATCH 1/2] rdna2spirv: quad_any's docstring says partial quads are exact The comment still claimed an absent invocation in a partial non-fragment quad gave an undefined value natively, while the non-fragment branch reads every lane's activity with OpGroupNonUniformBallot. Wording only. DOC-QUAD-ANY-PARTIAL. --- tools/rdna2spirv.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/rdna2spirv.py b/tools/rdna2spirv.py index 7e4529e75c..15640c0534 100644 --- a/tools/rdna2spirv.py +++ b/tools/rdna2spirv.py @@ -7172,8 +7172,9 @@ def quad_any(self, v): exact. Without emulation the subgroup's quad ops do it (the invocations of a quad are 4 consecutive subgroup invocations; in a fragment shader the 2x2 quad, which on hardware is also 4 consecutive lanes; vertex, geometry and mesh shaders shuffle, as quad operations are only guaranteed in fragment and compute stages); - emulated, the four lanes' values are read through the exchange buffer. Not handled: an absent invocation in - a partial quad (a compute group whose size is not a multiple of 4) gives an undefined value natively.""" + emulated, the four lanes' values are read through the exchange buffer. In a non-fragment stage a partial quad + (a group whose size is not a multiple of 4) is exact too: the lanes' activity is read with + OpGroupNonUniformBallot, so absent invocations do not matter.""" b = self.tmp() self.emit(f"{b} = OpSelect %uint {self.tmp_bool_nz(v)} {self.cu(1)} {self.cu(0)}") if self.emulate: From d696c86509c6742aed5d0c219c028791f51c76be Mon Sep 17 00:00:00 2001 From: aznohonza Date: Tue, 1 Dec 2026 08:04:17 +0100 Subject: [PATCH 2/2] rdna2spirv: fix quad_any's other stale partial-quad wording --- tests/semantic/test_salu_wqm32.py | 2 +- tools/rdna2spirv.py | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/semantic/test_salu_wqm32.py b/tests/semantic/test_salu_wqm32.py index 5ab78a0695..3d0f23c391 100644 --- a/tests/semantic/test_salu_wqm32.py +++ b/tests/semantic/test_salu_wqm32.py @@ -5,7 +5,7 @@ Covers both: - Data path (32-bit nibble expansion + SCC) via tools/rdna2spirv.py -> spirv_mini_interp.py. - Lane-mask path (32-lane wave32, 8 quads) via tools/rdna2spirv.py -> spirv_wave_interp.py (vertex stage - uses OpGroupNonUniformShuffle for quad_any; fragment/compute stages are checked for OpGroupNonUniformQuadSwap). + uses OpGroupNonUniformBallot for quad_any; the fragment stage is checked for OpGroupNonUniformQuadSwap). Standard library only; no game data. """ diff --git a/tools/rdna2spirv.py b/tools/rdna2spirv.py index 15640c0534..9860d40edb 100644 --- a/tools/rdna2spirv.py +++ b/tools/rdna2spirv.py @@ -7169,12 +7169,10 @@ def wave_mask(self, a): def quad_any(self, v): """This lane's value after whole-quad mode: all ones if any of the 4 lanes of its quad (4n .. 4n+3 of the wave) has `v` non-zero, else 0. A quad never crosses the 32/32 half of a wave64, so a 32-wide subgroup is - exact. Without emulation the subgroup's quad ops do it (the invocations of a quad are 4 consecutive subgroup - invocations; in a fragment shader the 2x2 quad, which on hardware is also 4 consecutive lanes; vertex, - geometry and mesh shaders shuffle, as quad operations are only guaranteed in fragment and compute stages); - emulated, the four lanes' values are read through the exchange buffer. In a non-fragment stage a partial quad - (a group whose size is not a multiple of 4) is exact too: the lanes' activity is read with - OpGroupNonUniformBallot, so absent invocations do not matter.""" + exact. Without emulation the subgroup's ops do it: in a fragment shader the 2x2 quad, which on hardware is + also 4 consecutive lanes; every other stage ballots, so a partial quad (fewer than 4 of the quad's lanes + running, e.g. 2 active lanes of a 32-lane subgroup) is exact too, as a lane's bit is set only when it is + running with `v` non-zero. Emulated, the four lanes' values are read through the exchange buffer.""" b = self.tmp() self.emit(f"{b} = OpSelect %uint {self.tmp_bool_nz(v)} {self.cu(1)} {self.cu(0)}") if self.emulate: @@ -7203,10 +7201,11 @@ def quad_any(self, v): self.emit(f"{o} = OpBitwiseOr %uint {acc} {sw}") acc = o else: - # Non-fragment stages (CS/VS/GS/MS) can have partial quads (subgroup size or thread count not a multiple - # of 4), where QuadSwap or unguarded shuffles from absent lanes are undefined in SPIR-V. Ballot sets bit l - # iff lane l is running with `v != 0`, so extracting this lane's 4-bit quad nibble is exact on any partial - # subgroup up to 128 lanes without needing GroupNonUniformQuad or any shuffle. + # Non-fragment stages (CS/VS/GS/MS) can have partial quads (fewer than 4 of the quad's lanes running: a + # subgroup or workgroup size not a multiple of 4, or a partial wave, e.g. 2 active lanes of a 32-lane + # subgroup), where QuadSwap or unguarded shuffles from absent lanes are undefined in SPIR-V. Ballot sets + # bit l iff lane l is running with `v != 0`, so extracting this lane's 4-bit quad nibble is exact on any + # partial subgroup up to 128 lanes without needing GroupNonUniformQuad or any shuffle. self.uses_subgroup = self.uses_ballot = True nz = self.tmp_bool_nz(v) bal, widx, word, qoff, shifted, acc = (self.tmp() for _ in range(6))