Standard Portable Intermediate Representation
Developer(s) | Khronos Group |
---|---|
Initial release | January 2014 |
Stable release | SPIR-V 1.6
/ December 16, 2021 |
Operating system | Cross-platform |
Platform | Cross-platform |
Type | Intermediate language |
Website | www |
Standard Portable Intermediate Representation (SPIR) 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 (JIT), 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.[1] The offline nature of compilation also allows for more flexible language improvements such as the use of newer C++ features.[2]
More importantly, SPIR-V allows the Vulkan API to use any shading language, including GLSL and HLSL.[3][4] SPIR-V can be compiled into several shading languages (GLSL, GLSL ES, MSL, HLSL) using SPIRV-Cross, so that these languages can be interconverted.[5] The textual shading language of WebGPU is designed as a thin layer over SPIR-V.[6]
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 |
|
Compute Constructs | Metadata/Intrinsics | Metadata/Intrinsics | Native |
Graphics Constructs | No | No | Native |
Supported Language & Feature Supported | OpenCL C 1.2 |
|
|
OpenCL Ingestion | OpenCL 1.2 Extension | OpenCL 2.0 Extension | OpenCL 2.1/2.2 Core |
Graphics API Ingestion | N/A | N/A |
|
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.[7] On July 22, 2013, a provisional specification SPIR 1.2 was announced at SIGGRAPH 2013.[8] The final SPIR 1.2 specification was released at HiPEAC 2014 on January 21, 2014.[9] On August 11th, 2014, a provisional specification for SPIR 2.0 was released at SIGGRAPH 2014.[10]
SPIR-V[]
SPIR-V 1.0 is a rewritten version of SPIR announced in March 2015,[11] and released on Nov. 16 2015.[12] 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 (SSA) 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 closer to optimum performance on the target devices.[13] A separate program by the Khronos Group allows for interconversion with LLVM IR.[14]
Support for ingestion of SPIR-V is incorporated in the core specification of OpenCL 2.1, the Vulkan API, and OpenGL version 4.6.
SPIR-V 1.1[]
On April 18, 2016, SPIR-V 1.1 was released at IWOCL 2016 along with Provisional OpenCL 2.2. SPIR-V 1.1 added support for OpenCL C++, initializer/finalizer function execution modes, named barriers, subgroup execution, program scope pipes and pipe storage.[15]
SPIR-V 1.2[]
On May 16, 2017, SPIR-V 1.2 was released at IWOCL 2017 along with OpenCL 2.2. SPIR-V 1.2 added support for runtime specialization of key tuning parameters in OpenCL 2.2.[16]
SPIR-V 1.3[]
On March 7, 2018, SPIR-V 1.3 was released along with Vulkan 1.1. SPIR-V 1.3 Added support for subgroup operations and enables enhanced compiler optimizations.[17]
SPIR-V 1.4[]
On May 7, 2019, SPIR-V 1.4 was released.[18]
SPIR-V 1.5[]
On September 13, 2019, SPIR-V 1.5 was released.[19]
SPIR-V 1.6[]
On December 16, 2021, SPIR-V 1.6 was released.[20]
SPIR-V for GLSL Cross-Compilation[]
Subsequent versions of the OpenGL Shading Language (GLSL) introduced a number of backwards-incompatible language changes. As a result, GLSL shaders that target multiple OpenGL versions are rewritten once for each version, which is exacerbated by practical compatibility concerns due implementations that are pegged to a specific older version of GLSL, such as for WebGL 1.0 and Apple's OpenGL implementation. One of the notable use cases of SPIR-V is its ability to be used as an interchange format between GLSL versions, using tools maintained by the Khronos Group for compiling GLSL to SPIR-V glslangValidator
,[21] optimizing SPIR-V spirv-opt
,[22] and cross-compiling to SPIR-V to different GLSL targets spirv-cross
.[23]
As a format, however, SPIR-V has some notable limitations for cross-compilation. Perhaps most critically is the requirement that every SPIR-V module have at least one entry-point symbol. This prevents the format from being easily used for separate compilation, where complex shaders could be assembled by a series of partial compile steps followed by a linking step. The analogy for a CPU-compiled language, is that SPIR-V can be used only for the creation of executables, but not for object files .o
, shared object files .so
or static libraries .a
. This runs counter to the stated goals of some SPIR-V tools such as spirv-link
,[24] which aims to provide full linking functionality for SPIR-V binary code.
See also[]
- High-Level Shading Language (HLSL)
- Cg (programming language)
- OpenGL Shading Language (GLSL)
- Tungsten Graphics Shader Infrastructure
- Compute kernel
- Parallel Thread Execution
- ARB assembly language
References[]
- ^ Farber, Rob (11 August 2014). "Commercial OpenCL! SPIR 2.0 Protects IP Yet Allows Powerful, Portable, Source Code Free Kernels". TechEnablement. Retrieved 5 April 2015.
- ^ Trevett, Neil. "OpenCL Overview and Update" (PDF).
- ^ "Shader modules". Vulkan Tutorial.
- ^ "HLSL as a First Class Vulkan Shading Language". The Khronos Group. 15 January 2020.
- ^ KhronosGroup/SPIRV-Cross, The Khronos Group, 2019-09-06, retrieved 2019-09-08
- ^ WebGPU Shading Language specification
- ^ Larabel, Michael (12 September 2012). "Khronos SPIR For OpenCL Brings Binary Compatibility". Phoronix. Retrieved 25 July 2015.
- ^ Smith, Ryan (22 July 2013). "Khronos @ SIGGRAPH 2013: OpenGL 4.4, OpenCL 2.0, & OpenCL 1.2 SPIR Announced". Anandtech. Retrieved 5 April 2015.
- ^ "Khronos Releases SPIR 1.2 Specification for Portable Encoding of OpenCL Device Programs". The Khronos Group. 2014-01-20. Retrieved 2019-08-05.
- ^ Smith, Ryan (11 August 2014). "Khronos Announces OpenCL SPIR 2.0". Anandtech. Retrieved 5 April 2015.
- ^ Parkerson, Stuart (4 March 2015). "Khronos Group Introduces New Vulkan Hardware Driver API and SPIR-V Intermediate Language Shared by Vulkan and OpenCL 2.1". App Developer Magazine. Retrieved 5 April 2015.
- ^ "Khronos Releases OpenCL 2.1 and SPIR-V 1.0 Specifications for Heterogeneous Parallel Programming". www.Khronos.org. 16 November 2015. Retrieved 16 November 2015.
- ^ Kessenich, John. "An Introduction to SPIR-V" (PDF). Khronos. Retrieved 25 July 2015.
- ^ "SPIRV-LLVM-Translator: A tool and a library for bi-directional translation between SPIR-V and LLVM IR". GitHub. The Khronos Group.
- ^ Trevett, Neil (18 April 2016). "OpenCL A State of the Union (IWOCL 2016)" (PDF). Khronos Group.
- ^ Trevett, Neil (16 May 2017). "OpenCL State of the Nation (IWOCL 2017)" (PDF). IWOCL.
- ^ "SPIR - The Industry Open Standard Intermediate Language for Parallel Compute and Graphics". The Khronos Group. 2014-01-20. Retrieved 2019-08-05.
- ^ "Khronos SPIR-V Registry - The Khronos Group Inc". www.khronos.org. Retrieved 2019-08-05.
- ^ "Khronos SPIR-V Registry - The Khronos Group Inc". www.khronos.org. Retrieved 2020-01-30.
- ^ "Khronos SPIR-V Registry - The Khronos Group Inc". www.khronos.org. Retrieved 2020-02-27.
- ^ "OpenGL / OpenGL ES Reference Compiler". www.khronos.org. Retrieved 2020-10-01.
- ^ "SPIR-V Tools". www.github.com. Retrieved 2020-10-01.
- ^ "SPIR-V Cross". www.github.com. Retrieved 2020-10-01.
- ^ "SPIR-V Tools". www.github.com. Retrieved 2020-10-01.
External links[]
- Compiler construction
- Shading languages