The Khronos Group defines SPIR-V in its SPIR-V Specification; this page follows the unified edition, version 1.6, revision 8, which covers every version from 1.0. A module is a single linear stream of 32-bit words. Only the major and minor version are recorded in a module; the major version has been fixed at 1.
Header
| Word | Byte offset | Field | Meaning |
|---|---|---|---|
| 0 | 0 | Magic number | 0x07230203. |
| 1 | 4 | Version | Bytes, from high-order to low-order: 0, major, minor, 0. Version 1.3 is 0x00010300, 1.6 is 0x00010600. |
| 2 | 8 | Generator | Identifies the tool that wrote the module; see generators. It does not change the meaning of the module and may be 0, but a non-zero value is encouraged. |
| 3 | 12 | Bound | Every ID in the module satisfies 0 < ID < bound; smaller is better. |
| 4 | 16 | Schema | Reserved for an instruction schema; 0. |
| 5 | 20 | — | First word of the instruction stream. |
The specification defines a module as words, not bytes. When it is stored as bytes, as
in a .spv file, the magic number’s byte order shows the file’s byte order:
a little-endian file starts 03 02 23 07.
Instruction encoding
| Word | Contents |
|---|---|
| 0 | High 16 bits: the word count, the instruction’s total length in words including this word. Low 16 bits: the opcode (see opcodes). |
| 1… | An optional result type ID, an optional result ID, then the operands. How many operands there are follows from the word count. |
Because every instruction states its own length, a reader can step over instructions it does not understand. Operands that are not IDs are literals or values from the enumerations.
Literal strings
A string operand is NUL-terminated, case-sensitive UTF-8. Its bytes are packed four to
a word, the first byte in the lowest-order 8 bits. The last word holds the NUL, and any
bytes after it in that word are 0. For example main takes two words:
0x6E69616D (m a i n) and 0x00000000.
Logical layout
Instructions must appear in this order:
- All
OpCapabilityinstructions. - Optional
OpExtensioninstructions. - Optional
OpExtInstImportinstructions. - The single required
OpMemoryModel. - All entry points (
OpEntryPoint). - All execution modes (
OpExecutionMode,OpExecutionModeId). - Debug instructions, in this order:
OpString,OpSourceExtension,OpSourceandOpSourceContinued(without forward references); thenOpNameandOpMemberName; thenOpModuleProcessed. - All annotations (decorations).
- Type declarations, constants and global variables (
OpVariablenot in theFunctionstorage class). - Function declarations:
OpFunction,OpFunctionParameter,OpFunctionEnd. - Function definitions:
OpFunction,OpFunctionParameter, the blocks,OpFunctionEnd.
Generators
The high 16 bits of the generator word are a tool ID registered with Khronos (unique
across all SPIR-V generators); the low 16 bits are left to the tool, usually a version
number. The registry in spir-v.xml lists:
| ID | Vendor | Tool |
|---|---|---|
| 0 | Khronos | — |
| 1 | LunarG | — |
| 2 | Valve | — |
| 3 | Codeplay | — |
| 4 | NVIDIA | — |
| 5 | ARM | — |
| 6 | Khronos | LLVM/SPIR-V Translator |
| 7 | Khronos | SPIR-V Tools Assembler |
| 8 | Khronos | Glslang Reference Front End |
| 9 | Qualcomm | — |
| 10 | AMD | — |
| 11 | Intel | — |
| 12 | Imagination | — |
| 13 | Shaderc over Glslang | |
| 14 | spiregg | |
| 15 | rspirv | |
| 16 | X-LEGEND | Mesa3D GLSL-IR/SPIR-V Translator |
| 17 | Khronos | SPIR-V Tools Linker |
| 18 | Wine | VKD3D Shader Compiler |
| 19 | Tellusim | Clay Shader Compiler |
| 20 | W3C WebGPU Group | WHLSL Shader Translator |
| 21 | Clspv | |
| 22 | LLVM | MLIR SPIR-V Serializer |
| 23 | Tint Compiler | |
| 24 | ANGLE Shader Compiler | |
| 25 | Netease Games | Messiah Shader Compiler |
| 26 | Xenia | Xenia Emulator Microcode Translator |
| 27 | Embark Studios | Rust GPU Compiler Backend |
| 28 | gfx-rs community | Naga |
| 29 | Mikkosoft Productions | MSP Shader Compiler |
| 30 | SpvGenTwo community | SpvGenTwo SPIR-V IR Tools |
| 31 | Skia SkSL | |
| 32 | TornadoVM | Beehive SPIRV Toolkit |
| 33 | DragonJoker | ShaderWriter |
| 34 | Rayan Hatout | SPIRVSmith |
| 35 | Saarland University | Shady |
| 36 | Taichi Graphics | Taichi |
| 37 | heroseh | Hero C Compiler |
| 38 | Meta | SparkSL |
| 39 | SirLynix | Nazara ShaderLang Compiler |
| 40 | Khronos | Slang Compiler |
| 41 | Zig Software Foundation | Zig Compiler |
| 42 | Rendong Liang | spq |
| 43 | LLVM | LLVM SPIR-V Backend |
| 44 | Robert Konrad | Kongruent |
| 45 | Kitsunebi Games | Nuvk SPIR-V Emitter and DLSL compiler |
| 46 | Nintendo | — |
| 47 | ARM | — |
| 48 | Goopax | — |
| 49 | Icyllis Milica | Arc3D Shader Compiler |
| 50 | Isochron | Pred |
| 51 | apilatosba | Apila Jai Compiler |
“—” means the ID is registered to the vendor without a tool name.
Sources
- SPIR-V Specification – Khronos, unified version 1.6 revision 8: sections 1.3 (versions), 2.2 (literal strings), 2.3 (physical layout) and 2.4 (logical layout)
- spir-v.xml – Khronos SPIRV-Headers: the registered generator tool IDs
The byte-order remark about .spv files follows from the magic number’s value;
the string example was worked out for this page.