fbpx
Wikipedia

Standard Portable Intermediate Representation

Standard Portable Intermediate Representation (SPIR) is an intermediate language for parallel compute and graphics by Khronos Group. It is used in multiple execution environments, including the Vulkan graphics API and the OpenCL compute API, to represent a shader or kernel. It is also used as an interchange language for cross compilation.[1][2]

SPIR-V
Developer(s)Khronos Group
Initial release2015
Stable release
SPIR-V 1.6 / December 16, 2021; 12 months ago (2021-12-16)
Operating systemCross-platform
PlatformCross-platform
TypeIntermediate language
Websitewww.khronos.org/registry/SPIR-V

SPIR-V was introduced in 2015 by the Khronos Group, and has since replaced the original SPIR, which was introduced in 2012.

Purpose

The purposes of SPIR-V are to natively represent the primitives needed by compute and graphics; to separate high-level language from the interface to compute and graphics drivers; to be the distribution form, or distribute fully compiled binaries; to be a fully self-contained specification; and to support multiple APIs. It is also used as an intermediate target for cross-compilation tools.

For example, 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] It also has paths to and/or from WebGPU, OpenCL, SYCL, and C++.


In target platforms, ingesting SPIR-V removes the need to build a high-level language source compiler into device drivers, which reduces driver complexity.[2]

Versions

SPIR was originally introduced in 2011 and SPIR-V was introduced in 2015.

SPIR and SPIR-V
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
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.[6] On July 22, 2013, a provisional specification SPIR 1.2 was announced at SIGGRAPH 2013.[7] The final SPIR 1.2 specification was released at HiPEAC 2014 on January 21, 2014.[8] On August 11th, 2014, a provisional specification for SPIR 2.0 was released at SIGGRAPH 2014.[9] SPIR-V does not use LLVM.[2]

SPIR-V

SPIR-V 1.0 is a new version of SPIR announced in March 2015,[10] and released on November 16, 2015.[11] The SPIR family now includes a true cross-API standard that is fully defined by Khronos with native support for shader and kernel features.

A separate program by the Khronos Group allows for interconversion with LLVM IR.[12]

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 Releases
Date Version Notes
April 18, 2016 1.1 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.[13]
May 16, 2017 1.2 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.[14]
March 7, 2018 1.3 Released along with Vulkan 1.1. SPIR-V 1.3 Added support for subgroup operations and enables enhanced compiler optimizations.[15]
May 7, 2019 1.4[1]
September 13, 2019 1.5[1]
December 16, 2021 1.6[1]

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.[16]

Extensibility

SPIR-V can be extended by writing extensions to add semantics, or reserving ranges of the token values for the party's use. Vendors can independently add desired semantics to SPIR-V.[17] Additional sets of extended instruction sets can be provided in separate specifications. Multiple sets can be imported without issue, as extended instructions are used by specifying the ID of the set and of the instruction within the set.[17]

Shaders

Debuggers include RenderDoc, SwiftShader, and Amber.[18]

Graphical shaders use structured control flow in SPIR-V to state how control flow nests. This helps in defining divergence and reconvergence of control flow on parallel execution environments.[19] Specialization reduces the number of variants of a shader that need to be distributed.[20]

Validation

The SPIR-V specification states the rules that must be followed to have a valid SPIR-V module. This allows for offline validation. Drivers are not obligated to handle invalid SPIR-V modules. In testing, conformance testing verifies that drivers behave correctly when consuming valid SPIR-V, while validators verify that front-ends properly generate SPIR-V.[21]

Linking

SPIR-V can express calls to functions in a different compilation unit. The standard version of SPIR-V uses this feature for OpenCL compute kernels, but not for shader stages, which the graphical APIs want fully linked into a single SPIR-V module.[22] There are extensions available to allow tools to temporarily use partially linked shaders and also kernels.[23]

Capabilities

A SPIR-V module is used by a client API to support that module's features, which are classified through capabilities, and declared early in the module. A validator can confirm that the module uses only its declared capabilities, and a client API can reject modules that declare unsupported capabilities.[24]

SPIR-V for GLSL Cross-Compilation

SPIR-V has been used to help deal with multiple versions of source-level languages. For example, the multiple versions of OpenGL Shading Language (GLSL) require distribution of multiple versions of shaders, due to 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,[25] optimizing SPIR-V spirv-opt,[21] and cross-compiling to SPIR-V to different GLSL targets spirv-cross.[26]

As a format, however, SPIR-V has some limitations for cross-compilation, including 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. This runs counter to the stated goals of some SPIR-V tools such as spirv-link,[21] which aims to provide full linking functionality for SPIR-V binary code.

See also

References

  1. ^ a b c d "Khronos SPIR-V Registry - The Khronos Group Inc". www.khronos.org. Retrieved 2019-08-05.
  2. ^ a b c Terzo, Olivier; Djemame, Karim; Scionti, Alberto; Pezuela, Clara (10 September 2019). Heterogeneous Computing Architectures: Challenges and Vision. CRC Press. ISBN 9780429680038. Retrieved 24 June 2022.
  3. ^ "Shader modules". Vulkan Tutorial.
  4. ^ "HLSL as a First Class Vulkan Shading Language". The Khronos Group. 15 January 2020.
  5. ^ KhronosGroup/SPIRV-Cross, The Khronos Group, 2019-09-06, retrieved 2019-09-08
  6. ^ Larabel, Michael (12 September 2012). "Khronos SPIR For OpenCL Brings Binary Compatibility". Phoronix. Retrieved 25 July 2015.
  7. ^ Smith, Ryan (22 July 2013). "Khronos @ SIGGRAPH 2013: OpenGL 4.4, OpenCL 2.0, & OpenCL 1.2 SPIR Announced". Anandtech. Retrieved 5 April 2015.
  8. ^ "Khronos Releases SPIR 1.2 Specification for Portable Encoding of OpenCL Device Programs". The Khronos Group. 2014-01-20. Retrieved 2019-08-05.
  9. ^ Smith, Ryan (11 August 2014). "Khronos Announces OpenCL SPIR 2.0". Anandtech. Retrieved 5 April 2015.
  10. ^ 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.
  11. ^ "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.
  12. ^ "SPIRV-LLVM-Translator: A tool and a library for bi-directional translation between SPIR-V and LLVM IR". GitHub. The Khronos Group.
  13. ^ Trevett, Neil (18 April 2016). "OpenCL A State of the Union (IWOCL 2016)" (PDF). Khronos Group.
  14. ^ Trevett, Neil (16 May 2017). "OpenCL State of the Nation (IWOCL 2017)" (PDF). IWOCL.
  15. ^ "SPIR - The Industry Open Standard Intermediate Language for Parallel Compute and Graphics". The Khronos Group. 2014-01-20. Retrieved 2019-08-05.
  16. ^ Kessenich, John. "An Introduction to SPIR-V" (PDF). Khronos. Retrieved 25 July 2015.
  17. ^ a b "SPIRV-Guide". github.com. Retrieved 24 June 2022.
  18. ^ "Google Open-Sources 'Amber' Multi-API Shader Test Framework". phoronix.com. Retrieved 24 June 2022.
  19. ^ "SPIR-V Specification: Structured Control Flow". khronos.org. Retrieved 24 June 2022.
  20. ^ "Specialization Constants". veldrid.dev. Retrieved 24 June 2022.
  21. ^ a b c "SPIR-V Tools". www.github.com. Retrieved 2020-10-01.
  22. ^ "Shader Fundamentals". informit.com. Retrieved 24 June 2022.
  23. ^ "SPIR-V Extension for Visual Studio". saschawillems.de. Retrieved 24 June 2022.
  24. ^ "SPIR-V Specification: Language Capabilities". khronos.org. Retrieved 24 June 2022.
  25. ^ "OpenGL / OpenGL ES Reference Compiler". www.khronos.org. Retrieved 2020-10-01.
  26. ^ "SPIR-V Cross". www.github.com. Retrieved 2020-10-01.

External links

  • Khronos SPIR webpage
  • SPIR-V specification

standard, portable, intermediate, representation, spir, intermediate, language, parallel, compute, graphics, khronos, group, used, multiple, execution, environments, including, vulkan, graphics, opencl, compute, represent, shader, kernel, also, used, interchan. Standard Portable Intermediate Representation SPIR is an intermediate language for parallel compute and graphics by Khronos Group It is used in multiple execution environments including the Vulkan graphics API and the OpenCL compute API to represent a shader or kernel It is also used as an interchange language for cross compilation 1 2 SPIR VDeveloper s Khronos GroupInitial release2015Stable releaseSPIR V 1 6 December 16 2021 12 months ago 2021 12 16 Operating systemCross platformPlatformCross platformTypeIntermediate languageWebsitewww wbr khronos wbr org wbr registry wbr SPIR VSPIR V was introduced in 2015 by the Khronos Group and has since replaced the original SPIR which was introduced in 2012 Contents 1 Purpose 2 Versions 2 1 LLVM based versions 2 2 SPIR V 3 Features 3 1 Extensibility 3 2 Shaders 3 3 Validation 3 4 Linking 3 5 Capabilities 4 SPIR V for GLSL Cross Compilation 5 See also 6 References 7 External linksPurpose EditThe purposes of SPIR V are to natively represent the primitives needed by compute and graphics to separate high level language from the interface to compute and graphics drivers to be the distribution form or distribute fully compiled binaries to be a fully self contained specification and to support multiple APIs It is also used as an intermediate target for cross compilation tools For example 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 It also has paths to and or from WebGPU OpenCL SYCL and C In target platforms ingesting SPIR V removes the need to build a high level language source compiler into device drivers which reduces driver complexity 2 Versions EditSPIR was originally introduced in 2011 and SPIR V was introduced in 2015 SPIR and SPIR V SPIR 1 2 SPIR 2 0 SPIR V 1 XLLVM Interaction LLVM IR version 3 2 LLVM IR version 3 4 100 Khronos defined Round trip lossless conversionCompute Constructs Metadata Intrinsics Metadata Intrinsics NativeGraphics Constructs No No NativeSupported Language amp Feature Supported OpenCL C 1 2 OpenCL C 1 2 OpenCL C 2 0 OpenCL C 1 2 2 X OpenCL C GLSLOpenCL Ingestion OpenCL 1 2 Extension OpenCL 2 0 Extension OpenCL 2 1 2 2 CoreGraphics API Ingestion Vulkan 1 X OpenGL 4 6 CoreLLVM based versions Edit 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 6 On July 22 2013 a provisional specification SPIR 1 2 was announced at SIGGRAPH 2013 7 The final SPIR 1 2 specification was released at HiPEAC 2014 on January 21 2014 8 On August 11th 2014 a provisional specification for SPIR 2 0 was released at SIGGRAPH 2014 9 SPIR V does not use LLVM 2 SPIR V Edit SPIR V 1 0 is a new version of SPIR announced in March 2015 10 and released on November 16 2015 11 The SPIR family now includes a true cross API standard that is fully defined by Khronos with native support for shader and kernel features A separate program by the Khronos Group allows for interconversion with LLVM IR 12 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 Releases Date Version NotesApril 18 2016 1 1 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 13 May 16 2017 1 2 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 14 March 7 2018 1 3 Released along with Vulkan 1 1 SPIR V 1 3 Added support for subgroup operations and enables enhanced compiler optimizations 15 May 7 2019 1 4 1 September 13 2019 1 5 1 December 16 2021 1 6 1 Features EditSPIR 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 16 Extensibility Edit SPIR V can be extended by writing extensions to add semantics or reserving ranges of the token values for the party s use Vendors can independently add desired semantics to SPIR V 17 Additional sets of extended instruction sets can be provided in separate specifications Multiple sets can be imported without issue as extended instructions are used by specifying the ID of the set and of the instruction within the set 17 Shaders Edit Debuggers include RenderDoc SwiftShader and Amber 18 Graphical shaders use structured control flow in SPIR V to state how control flow nests This helps in defining divergence and reconvergence of control flow on parallel execution environments 19 Specialization reduces the number of variants of a shader that need to be distributed 20 Validation Edit The SPIR V specification states the rules that must be followed to have a valid SPIR V module This allows for offline validation Drivers are not obligated to handle invalid SPIR V modules In testing conformance testing verifies that drivers behave correctly when consuming valid SPIR V while validators verify that front ends properly generate SPIR V 21 Linking Edit SPIR V can express calls to functions in a different compilation unit The standard version of SPIR V uses this feature for OpenCL compute kernels but not for shader stages which the graphical APIs want fully linked into a single SPIR V module 22 There are extensions available to allow tools to temporarily use partially linked shaders and also kernels 23 Capabilities Edit A SPIR V module is used by a client API to support that module s features which are classified through capabilities and declared early in the module A validator can confirm that the module uses only its declared capabilities and a client API can reject modules that declare unsupported capabilities 24 SPIR V for GLSL Cross Compilation EditSPIR V has been used to help deal with multiple versions of source level languages For example the multiple versions of OpenGL Shading Language GLSL require distribution of multiple versions of shaders due to 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 25 optimizing SPIR V spirv opt 21 and cross compiling to SPIR V to different GLSL targets spirv cross 26 As a format however SPIR V has some limitations for cross compilation including 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 This runs counter to the stated goals of some SPIR V tools such as spirv link 21 which aims to provide full linking functionality for SPIR V binary code See also EditHigh Level Shading Language HLSL Cg programming language OpenGL Shading Language GLSL Tungsten Graphics Shader Infrastructure Compute kernel Parallel Thread Execution ARB assembly languageReferences Edit a b c d Khronos SPIR V Registry The Khronos Group Inc www khronos org Retrieved 2019 08 05 a b c Terzo Olivier Djemame Karim Scionti Alberto Pezuela Clara 10 September 2019 Heterogeneous Computing Architectures Challenges and Vision CRC Press ISBN 9780429680038 Retrieved 24 June 2022 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 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 amp 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 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 Kessenich John An Introduction to SPIR V PDF Khronos Retrieved 25 July 2015 a b SPIRV Guide github com Retrieved 24 June 2022 Google Open Sources Amber Multi API Shader Test Framework phoronix com Retrieved 24 June 2022 SPIR V Specification Structured Control Flow khronos org Retrieved 24 June 2022 Specialization Constants veldrid dev Retrieved 24 June 2022 a b c SPIR V Tools www github com Retrieved 2020 10 01 Shader Fundamentals informit com Retrieved 24 June 2022 SPIR V Extension for Visual Studio saschawillems de Retrieved 24 June 2022 SPIR V Specification Language Capabilities khronos org Retrieved 24 June 2022 OpenGL OpenGL ES Reference Compiler www khronos org Retrieved 2020 10 01 SPIR V Cross www github com Retrieved 2020 10 01 External links EditKhronos SPIR webpage SPIR V specification Retrieved from https en wikipedia org w index php title Standard Portable Intermediate Representation amp oldid 1119646603, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.