What: in a fragment function, Metal's quad_all and quad_any are now
SPV_KHR_quad_control's OpGroupNonUniformQuadAllKHR and
OpGroupNonUniformQuadAnyKHR of the predicate, in place of the quad's four
bits of the ballot of the predicate (compared with the ballot of the
active lanes for quad_all). Kernels and vertex functions have no helpers
and keep the ballot form. The IR gains GroupInst::QuadAll beside
QuadAny (no scope operand; QuadControlKHR, SPV_KHR_quad_control and
shaderQuadControl), and the builder's group_quad_any becomes
group_quad_vote(all, pred), as group_vote is. The interpreter, the
serializer and the requirement deriver follow. items.txt lists
GroupNonUniformQuadAllKHR, and scripts/regen-spirv-grammar regenerated
spv.rs from SPIRV-Headers vulkan-sdk-1.4.341.0: the opcode loses its
cfg(test); the test parser's table already held it.
Why: Metal's helpers are active lanes of their quad and take part in
its votes. Vulkan section 9.31 runs quad group operations over a quad's
helpers in every entry, and its other group operations, the ballot
among them, only where the entry declares MaximallyReconvergesKHR. AMD's
open Vulkan driver leaves a partly covered quad's helper out of the
ballot even though the entry declares MaximallyReconvergesKHR beside
RequireFullQuadsKHR (report 142), so a vote read through the ballot
missed the helper: the runtime test quad_votes read quad_any(x > y) = 0
and quad_all(x <= y) = 1 on the 12 covered pixels of the diagonal quads,
where Metal answers 1 and 0 (m3-max-70847, AMDVLK 2025.Q2.1 on the RX
7900 XTX and the Radeon 780M; RADV right on both). The quad vote
instructions are right by the spec on every device whatever the entry's
reconvergence (rung 1), the form the quad reductions took (54517169dd).
What full_quads asks: unchanged, shaderQuadControl. A fragment vote's
operation class moves from Ballot to Quad, which Vulkan requires
wherever shaderQuadControl is supported. No new query.
Still through the ballot in a fragment: quad_ballot, the active mask,
is_first, broadcast_first, the quad prefix sums, and every simdgroup
operation.
Tests: operation_classes_follow_the_tier gains a fragment's quad All and
Any (Quad); fragment_quad_votes_are_quad_vote_instructions compiles a
fragment of both votes on every committed profile with quad control (one
QuadAllKHR, one QuadAnyKHR, no ballot) and checks a kernel's votes
(a3_quad_votes_divergent) take neither instruction.
regen-spirv-grammar
Generates the translator's SPIR-V grammar items from Khronos's machine-readable SPIR-V grammar
(SPIRV-Headers, MIT-licensed) with our own generator, generate.py. Nothing else feeds it.
| Output | Role |
|---|---|
crates/metal2vulkan/src/spv.rs |
The opcodes (Op), enumerants (Capability, Decoration, BuiltIn, ...), masks and GlslStd450Op the translator names, with their grammar values |
crates/metal2vulkan/src/spirv_binary/table.rs |
Test only: every core instruction's operands and every enumerant's parameters, which the test parser (spirv_binary/) reads |
What spv.rs holds
Only what items.txt lists: each kind the code names, the values it names, and from_u32 where
the code converts words back. Values that only tests name are cfg(test). The compiler checks the
list: a value the code names that is missing fails to build, and a listed value nothing uses is
dead code where rustc can see it. When code needs a new opcode or enumerant, add it to
items.txt and regenerate.
Names follow the grammar's, with a few changes Rust's and Clippy's naming rules need (see
variant_name and const_name in generate.py): an opcode drops its Op prefix, leading digits
move to the end (Dim::D2), a name of four or more capitals only is written with one capital
(Capability::Fmakhr), SpecConstantOp is SpecConstantOperation, and a mask's bits are
capitalized consts (FPFastMathMode::NOT_NAN). Debug always prints the grammar's own name.
Revision
SPIRV-Headers tag vulkan-sdk-1.4.341.0 (SPIR-V 1.6 revision 4; GLSL.std.450 version 100
revision 2). HEADERS_REF=<tag> selects another. Every generated file's header names the source,
its revision and Khronos's MIT notice.
Run
./scripts/regen-spirv-grammar/regen-spirv-grammar.sh
cargo nextest run -p metal2vulkan --all-features
The script fetches spirv.core.grammar.json, extinst.glsl.std.450.grammar.json and LICENSE
once per tag into .cache/spirv-headers/<tag>/ (gitignored; METAL2VULKAN_GRAMMAR_CACHE names
another directory), runs generate.py and formats both outputs with rustfmt. It needs curl,
Python 3 and rustfmt, and network access for a tag not yet fetched.