Format:SPIR-V
| Vendor | Khronos Group |
|---|---|
| Magic | 03 02 23 07 (little-endian word 0x07230203) |
| Extensions | .spv, .spirv |
| Endianness | either; the magic word shows which |
| License | Headers MIT |
| On this wiki | Facts · Code · Notes · Topics |
Khronos's binary intermediate language for shaders and compute kernels (Vulkan, OpenCL, OpenGL 4.6): a stream of 32-bit words starting with the magic 0x07230203, a five-word header (version, generator, bound, schema) and then instructions whose first word holds the word count in the high 16 bits and the opcode in the low 16.
Overview
SPIR-V is what Vulkan shaders are shipped as: games and apps embed .spv files, resources inside archives, or arrays of uint32 in code (often found by the magic). Compilers produce it from GLSL, HLSL or other languages; the header tells which one.
Identification
- Word 0 is the magic 0x07230203. A little-endian file starts with the bytes 03 02 23 07; a file in the other byte order shows 07 23 02 03 and every word must be swapped.
- The file length is a multiple of 4.
- See Technique:Compiled GPU shader formats for the other shader container formats.
Header
Five words, then instructions (SPIRV-Tools names them SPV_INDEX_MAGIC_NUMBER 0 ... SPV_INDEX_INSTRUCTION 5):
- word 0: magic
- word 1: version, as 0x00MMmm00 (1.0 = 0x00010000, 1.6 = 0x00010600); the low and high bytes must be 0
- word 2: generator magic: the high 16 bits are a tool id registered with Khronos in spir-v.xml, the low 16 bits are chosen by the tool (for example its version)
- word 3: bound: every result id in the module is smaller than this
- word 4: schema, reserved, 0
Instructions
Each instruction starts with a word whose high 16 bits are the total word count (including that word) and whose low 16 bits are the opcode (SpvOpCodeMask 0xffff, SpvWordCountShift 16). Operands follow; a result type id and a result id come first when the opcode has them. Unverified: literal strings are UTF-8, NUL-terminated and padded to a whole word.
Module layout and common opcodes
The spec fixes an order: OpCapability (17), OpExtension, OpExtInstImport (11), OpMemoryModel (14), OpEntryPoint (15), OpExecutionMode (16), debug instructions (OpSource 3, OpName 5), annotations (OpDecorate 71, OpMemberDecorate 72), types and constants, global variables (OpVariable 59), then functions (OpFunction 54 ... OpFunctionEnd 56) made of blocks that start with OpLabel (248). Unverified: the exact order rules are from the specification, which I did not read.
To find what a shader exposes: OpEntryPoint names the execution model (Vertex 0, Fragment 4, GLCompute 5, Kernel 6), the function id, the entry name and the interface variables; OpDecorate with Location (30), Binding (33), DescriptorSet (34) or BuiltIn (11) on a variable id gives the pipeline interface. OpName and OpSource are debug info and are often stripped.
Generators
The generator word identifies the compiler: for example 8 Glslang, 13 Shaderc over Glslang, 7 SPIR-V Tools assembler, 18 VKD3D Shader Compiler, 23 Tint, 28 Naga, 40 Slang, 43 LLVM SPIR-V backend. Full list on the fact Fact:SPIR-V/enum/Registered generator tool ids.
Tools
SPIRV-Tools (spirv-dis, spirv-val, spirv-opt, spirv-cross is separate) disassembles and validates; SPIRV-Headers holds the grammar JSON (spirv.core.grammar.json) with every opcode and operand layout. Unverified: tool command names are from memory.
Code & repositories
- https://github.com/KhronosGroup/SPIRV-Headers @
86f980c731e62ae4eaf383d320449d71687936bf· license: MIT (declared by the contributor for the files used; GitHub reports MIT (read from LICENSE; GitHub's detector did not classify it) for the repository)
Official SPIR-V headers, grammar JSON and the registry of generator tool ids (spir-v.xml).
Tested on: source read, not run: read only · checked 2026-10-19; last activity 2026-10-02 - https://github.com/KhronosGroup/SPIRV-Tools @
71f287f18ed78d496e724fbfb1c3feae3a2af75a· license: Apache-2.0
Assembler, disassembler, validator and optimizer for SPIR-V; source/binary.cpp is a reference binary parser.
Tested on: source read, not run: read only · checked 2026-10-19; last activity 2026-10-18