Files
metal2vulkan/scripts/regen-spirv-grammar
Anees Iqbal 10f2539a71 8-bit floats widen through the device's own type where it has one
Owner rule 1: where a device has a native 8-bit float type, its conversion is the only form.
VK_EXT_shader_float8's shaderFloat8 (the SPIR-V capability Float8EXT, SPV_EXT_float8) is now a
VkFeature the device enables and the profile reads (leaf.float8); the SPIR-V IR has
Type::Float8 { encoding } (OpTypeFloat 8 with its FPEncoding, from the regenerated grammar items),
and the interpreter reads OCP's E4M3 and E5M2.

The shared decode, narrow::fp8_to_f32, widens through the device's type where the layout names
one (Fp8Layout::on): each u32 lane bitcast to four 8-bit floats, the low byte's widened by
OpFConvert, so no 8-bit integer type is needed. f8e4m3fn and a tensor's e4m3 take Float8E4M3EXT,
f8e5m2 and a tensor's e5m2 Float8E5M2EXT; the IEEE-like f8e4m3 has no device encoding and keeps
the integer decode. Every site takes it: air.convert's 8-bit float sources, simdgroup-matrix fp8
cells, and matmul2d, whose expansion now widens each element by an air.convert of the tensor's
format (Fp8::TensorE4M3, Fp8::TensorE5M2: Metal's reading, qualified on the M3 Max, e4m3 with no
specials, e5m2's NaNs 0x7FC00000; never parsed from a name, built by Out::air_call). A device
without shaderFloat8 decodes with integers, as before.

Where a tensor's element widens natively the stage records PrecisionNote::NativeFloat8
(native-float8): the device's e4m3 reads 0x7F and 0xFF as NaN where Metal reads 480 and -480,
and an e5m2 NaN's bits are the device's. Validation classes it Unbounded; the conformance suite
lists it among the native notes; FAST-PATHS.md has its device-gap row and API.md its catalogue
entry. The other formats record none: Metal on Apple M3 does not compile them.

The refusal of a matmul2d of 8-bit floats on such a device (Entry::float8_products, the select
check) goes. REFUSALS.md and api_signatures.tsv regenerated.

Tests: matmul2d's fp8 fused sums on the RTX 50 profile (Float8EXT declared, the note recorded,
e4m3 NaN sums) beside MoltenVK, RADV and lavapipe (neither); air.convert widenings on the RTX 50
profile and lavapipe; simdgroup-matrix fp8 cells on the RTX 50 profile too. Not yet built here:
the build and these tests run next on the cluster.
2026-11-13 01:11:22 -08:00
..

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.