Standard Portable Intermediate Representation
Standard Portable Intermediate Representation is an intermediate language for parallel compute and graphics by Khronos Group, originally developed for use with OpenCL. SPIR was rewritten into SPIR-V in March 2015.
Purpose
OpenCL uses just-in-time compilation, necessitating one of two software distribution patterns: developers can distribute device-specific pre-compiled binaries, or they can distribute relevant source code, which is limited by the desire to protect intellectual property. SPIR enables the creation and distribution of device-independent binaries within the OpenCL stack. The offline nature of compilation also allows for more flexible language improvements such as the use of newer C++ features.More importantly, SPIR-V allows the Vulkan API to use any shading language, including GLSL and HLSL. SPIR-V can be disassembled into several shading languages using SPIRV-Cross, so that these languages can be interconverted. The textual shading language of WebGPU is designed as a thin layer over SPIR-V.
Versions
SPIR was originally introduced in 2011 and SPIR-V was introduced in 2015.SPIR 1.2 | SPIR 2.0 | SPIR-V 1.X | |
LLVM Interaction | LLVM IR version 3.2 | LLVM IR version 3.4 | 100% Khronos defined Round-trip lossless conversion |
Compute Constructs | Metadata/Intrinsics | Metadata/Intrinsics | Native |
Graphics Constructs | No | No | Native |
Supported Language & Feature Supported | OpenCL C 1.2 | OpenCL C 1.2 OpenCL C 2.0 | OpenCL C 1.2 / 2.X OpenCL C++ GLSL |
OpenCL Ingestion | OpenCL 1.2 Extension | OpenCL 2.0 Extension | OpenCL 2.1/2.2 Core |
Graphics API Ingestion | NA | NA | Vulkan 1.X OpenGL 4.6 Core |
LLVM-based versions
SPIR prior to the 2015 SPIR-V release was based on the LLVM Intermediate Representation. A provisional specification for SPIR 1.0 was announced in 2012. On July 22, 2013, a provisional specification SPIR 1.2 was announced at SIGGRAPH 2013. The final SPIR 1.2 specification was released at HiPEAC 2014 on January 21, 2014. On August 11th, 2014, a provisional specification for SPIR 2.0 was released at SIGGRAPH 2014.SPIR-V
SPIR-V 1.0 is a rewritten version of SPIR announced in March 2015, and released on Nov. 16 2015. The SPIR family now includes a true cross-API standard that is fully defined by Khronos with native support for shader and kernel features.SPIR-V is a high-level intermediate language, exchanged in binary form. Functions are represented by a control flow graph of basic blocks, using static single assignment form. Data structures retain high-level hierarchical representation. It is not lossy like previous byte-code or virtual machine-like intermediate representations used for graphical shaders. This allows higher performance lowering to target devices. A separate program by the Khronos Group allows for interconversion with LLVM IR.
Support for ingestion of SPIR-V is incorporated in the core specification of OpenCL 2.1, the Vulkan API, and OpenGL version 4.6.