1*8975f5c5SAndroid Build Coastguard Worker# SPIR-V Headers 2*8975f5c5SAndroid Build Coastguard Worker 3*8975f5c5SAndroid Build Coastguard WorkerThis repository contains machine-readable files for the 4*8975f5c5SAndroid Build Coastguard Worker[SPIR-V Registry](https://www.khronos.org/registry/spir-v/). 5*8975f5c5SAndroid Build Coastguard WorkerThis includes: 6*8975f5c5SAndroid Build Coastguard Worker 7*8975f5c5SAndroid Build Coastguard Worker* Header files for various languages. 8*8975f5c5SAndroid Build Coastguard Worker* JSON files describing the grammar for the SPIR-V core instruction set 9*8975f5c5SAndroid Build Coastguard Worker and the extended instruction sets. 10*8975f5c5SAndroid Build Coastguard Worker* The XML registry file. 11*8975f5c5SAndroid Build Coastguard Worker* A tool to build the headers from the JSON grammar. 12*8975f5c5SAndroid Build Coastguard Worker 13*8975f5c5SAndroid Build Coastguard WorkerHeaders are provided in the [include](include) directory, with up-to-date 14*8975f5c5SAndroid Build Coastguard Workerheaders in the `unified1` subdirectory. Older headers are provided according to 15*8975f5c5SAndroid Build Coastguard Workertheir version. 16*8975f5c5SAndroid Build Coastguard Worker 17*8975f5c5SAndroid Build Coastguard WorkerIn contrast, the XML registry file has a linear history, so it is 18*8975f5c5SAndroid Build Coastguard Workernot tied to SPIR-V specification versions. 19*8975f5c5SAndroid Build Coastguard Worker 20*8975f5c5SAndroid Build Coastguard Worker## How is this repository updated? 21*8975f5c5SAndroid Build Coastguard Worker 22*8975f5c5SAndroid Build Coastguard WorkerWhen a new version or revision of the SPIR-V specification is published, 23*8975f5c5SAndroid Build Coastguard Workerthe SPIR-V Working Group will push new commits onto master, updating 24*8975f5c5SAndroid Build Coastguard Workerthe files under [include](include). 25*8975f5c5SAndroid Build Coastguard Worker 26*8975f5c5SAndroid Build Coastguard Worker[The SPIR-V XML registry file](include/spirv/spir-v.xml) 27*8975f5c5SAndroid Build Coastguard Workeris updated by Khronos whenever a new enum range is allocated. 28*8975f5c5SAndroid Build Coastguard Worker 29*8975f5c5SAndroid Build Coastguard WorkerPull requests can be made to 30*8975f5c5SAndroid Build Coastguard Worker- request allocation of new enum ranges in the XML registry file 31*8975f5c5SAndroid Build Coastguard Worker- register a new magic number for a SPIR-V generator 32*8975f5c5SAndroid Build Coastguard Worker- reserve specific tokens in the JSON grammar 33*8975f5c5SAndroid Build Coastguard Worker 34*8975f5c5SAndroid Build Coastguard Worker### Registering a SPIR-V Generator Magic Number 35*8975f5c5SAndroid Build Coastguard Worker 36*8975f5c5SAndroid Build Coastguard WorkerTools that generate SPIR-V should use a magic number in the SPIR-V to help identify the 37*8975f5c5SAndroid Build Coastguard Workergenerator. 38*8975f5c5SAndroid Build Coastguard Worker 39*8975f5c5SAndroid Build Coastguard WorkerCare should be taken to follow existing precedent in populating the details of reserved tokens. 40*8975f5c5SAndroid Build Coastguard WorkerThis includes: 41*8975f5c5SAndroid Build Coastguard Worker- keeping generator numbers in numeric order 42*8975f5c5SAndroid Build Coastguard Worker- filling out all the existing fields 43*8975f5c5SAndroid Build Coastguard Worker 44*8975f5c5SAndroid Build Coastguard Worker### Reserving tokens in the JSON grammar 45*8975f5c5SAndroid Build Coastguard Worker 46*8975f5c5SAndroid Build Coastguard WorkerCare should be taken to follow existing precedent in populating the details of reserved tokens. 47*8975f5c5SAndroid Build Coastguard WorkerThis includes: 48*8975f5c5SAndroid Build Coastguard Worker- pointing to what extension has more information, when possible 49*8975f5c5SAndroid Build Coastguard Worker- keeping enumerants in numeric order 50*8975f5c5SAndroid Build Coastguard Worker- when there are aliases, listing the preferred spelling first 51*8975f5c5SAndroid Build Coastguard Worker- adding the statement `"version" : "None"` 52*8975f5c5SAndroid Build Coastguard Worker 53*8975f5c5SAndroid Build Coastguard Worker## How to install the headers 54*8975f5c5SAndroid Build Coastguard Worker 55*8975f5c5SAndroid Build Coastguard Worker``` 56*8975f5c5SAndroid Build Coastguard Workermkdir build 57*8975f5c5SAndroid Build Coastguard Workercd build 58*8975f5c5SAndroid Build Coastguard Workercmake .. 59*8975f5c5SAndroid Build Coastguard Workercmake --build . --target install 60*8975f5c5SAndroid Build Coastguard Worker``` 61*8975f5c5SAndroid Build Coastguard Worker 62*8975f5c5SAndroid Build Coastguard WorkerThen, for example, you will have `/usr/local/include/spirv/unified1/spirv.h` 63*8975f5c5SAndroid Build Coastguard Worker 64*8975f5c5SAndroid Build Coastguard WorkerIf you want to install them somewhere else, then use 65*8975f5c5SAndroid Build Coastguard Worker`-DCMAKE_INSTALL_PREFIX=/other/path` on the first `cmake` command. 66*8975f5c5SAndroid Build Coastguard Worker 67*8975f5c5SAndroid Build Coastguard Worker## Using the headers without installing 68*8975f5c5SAndroid Build Coastguard Worker 69*8975f5c5SAndroid Build Coastguard Worker### Using CMake 70*8975f5c5SAndroid Build Coastguard WorkerA CMake-based project can use the headers without installing, as follows: 71*8975f5c5SAndroid Build Coastguard Worker 72*8975f5c5SAndroid Build Coastguard Worker1. Add an `add_subdirectory` directive to include this source tree. 73*8975f5c5SAndroid Build Coastguard Worker2. Use `${SPIRV-Headers_SOURCE_DIR}/include}` in a `target_include_directories` 74*8975f5c5SAndroid Build Coastguard Worker directive. 75*8975f5c5SAndroid Build Coastguard Worker3. In your C or C++ source code use `#include` directives that explicitly mention 76*8975f5c5SAndroid Build Coastguard Worker the `spirv` path component. 77*8975f5c5SAndroid Build Coastguard Worker``` 78*8975f5c5SAndroid Build Coastguard Worker#include "spirv/unified1/GLSL.std.450.h" 79*8975f5c5SAndroid Build Coastguard Worker#include "spirv/unified1/OpenCL.std.h" 80*8975f5c5SAndroid Build Coastguard Worker#include "spirv/unified1/spirv.hpp" 81*8975f5c5SAndroid Build Coastguard Worker``` 82*8975f5c5SAndroid Build Coastguard Worker 83*8975f5c5SAndroid Build Coastguard WorkerSee also the [example](example/) subdirectory. But since that example is 84*8975f5c5SAndroid Build Coastguard Worker*inside* this repostory, it doesn't use and `add_subdirectory` directive. 85*8975f5c5SAndroid Build Coastguard Worker 86*8975f5c5SAndroid Build Coastguard Worker### Using Bazel 87*8975f5c5SAndroid Build Coastguard WorkerA Bazel-based project can use the headers without installing, as follows: 88*8975f5c5SAndroid Build Coastguard Worker 89*8975f5c5SAndroid Build Coastguard Worker1. Add SPIRV-Headers as a submodule of your project, and add a 90*8975f5c5SAndroid Build Coastguard Worker`local_repository` to your `WORKSPACE` file. For example, if you place 91*8975f5c5SAndroid Build Coastguard WorkerSPIRV-Headers under `external/spirv-headers`, then add the following to your 92*8975f5c5SAndroid Build Coastguard Worker`WORKSPACE` file: 93*8975f5c5SAndroid Build Coastguard Worker 94*8975f5c5SAndroid Build Coastguard Worker``` 95*8975f5c5SAndroid Build Coastguard Workerlocal_repository( 96*8975f5c5SAndroid Build Coastguard Worker name = "spirv_headers", 97*8975f5c5SAndroid Build Coastguard Worker path = "external/spirv-headers", 98*8975f5c5SAndroid Build Coastguard Worker) 99*8975f5c5SAndroid Build Coastguard Worker``` 100*8975f5c5SAndroid Build Coastguard Worker 101*8975f5c5SAndroid Build Coastguard Worker2. Add one of the following to the `deps` attribute of your build target based 102*8975f5c5SAndroid Build Coastguard Workeron your needs: 103*8975f5c5SAndroid Build Coastguard Worker``` 104*8975f5c5SAndroid Build Coastguard Worker@spirv_headers//:spirv_c_headers 105*8975f5c5SAndroid Build Coastguard Worker@spirv_headers//:spirv_cpp_headers 106*8975f5c5SAndroid Build Coastguard Worker@spirv_headers//:spirv_cpp11_headers 107*8975f5c5SAndroid Build Coastguard Worker``` 108*8975f5c5SAndroid Build Coastguard Worker 109*8975f5c5SAndroid Build Coastguard WorkerFor example: 110*8975f5c5SAndroid Build Coastguard Worker 111*8975f5c5SAndroid Build Coastguard Worker``` 112*8975f5c5SAndroid Build Coastguard Workercc_library( 113*8975f5c5SAndroid Build Coastguard Worker name = "project", 114*8975f5c5SAndroid Build Coastguard Worker srcs = [ 115*8975f5c5SAndroid Build Coastguard Worker # Path to project sources 116*8975f5c5SAndroid Build Coastguard Worker ], 117*8975f5c5SAndroid Build Coastguard Worker hdrs = [ 118*8975f5c5SAndroid Build Coastguard Worker # Path to project headers 119*8975f5c5SAndroid Build Coastguard Worker ], 120*8975f5c5SAndroid Build Coastguard Worker deps = [ 121*8975f5c5SAndroid Build Coastguard Worker "@spirv_tools//:spirv_c_headers", 122*8975f5c5SAndroid Build Coastguard Worker # Other dependencies, 123*8975f5c5SAndroid Build Coastguard Worker ], 124*8975f5c5SAndroid Build Coastguard Worker) 125*8975f5c5SAndroid Build Coastguard Worker``` 126*8975f5c5SAndroid Build Coastguard Worker 127*8975f5c5SAndroid Build Coastguard Worker3. In your C or C++ source code use `#include` directives that explicitly mention 128*8975f5c5SAndroid Build Coastguard Worker the `spirv` path component. 129*8975f5c5SAndroid Build Coastguard Worker``` 130*8975f5c5SAndroid Build Coastguard Worker#include "spirv/unified1/GLSL.std.450.h" 131*8975f5c5SAndroid Build Coastguard Worker#include "spirv/unified1/OpenCL.std.h" 132*8975f5c5SAndroid Build Coastguard Worker#include "spirv/unified1/spirv.hpp" 133*8975f5c5SAndroid Build Coastguard Worker``` 134*8975f5c5SAndroid Build Coastguard Worker 135*8975f5c5SAndroid Build Coastguard Worker## Generating headers from the JSON grammar for the SPIR-V core instruction set 136*8975f5c5SAndroid Build Coastguard Worker 137*8975f5c5SAndroid Build Coastguard WorkerThis will generally be done by Khronos, for a change to the JSON grammar. 138*8975f5c5SAndroid Build Coastguard WorkerHowever, the project for the tool to do this is included in this repository, 139*8975f5c5SAndroid Build Coastguard Workerand can be used to test a PR, or even to include the results in the PR. 140*8975f5c5SAndroid Build Coastguard WorkerThis is not required though. 141*8975f5c5SAndroid Build Coastguard Worker 142*8975f5c5SAndroid Build Coastguard WorkerThe header-generation project is under the `tools/buildHeaders` directory. 143*8975f5c5SAndroid Build Coastguard WorkerUse CMake to build and install the project, in a `build` subdirectory (under `tools/buildHeaders`). 144*8975f5c5SAndroid Build Coastguard WorkerThere is then a bash script at `bin/makeHeaders` that shows how to use the built 145*8975f5c5SAndroid Build Coastguard Workerheader-generator binary to generate the headers from the JSON grammar. 146*8975f5c5SAndroid Build Coastguard Worker(Execute `bin/makeHeaders` from the `tools/buildHeaders` directory.) 147*8975f5c5SAndroid Build Coastguard WorkerHere's a complete example: 148*8975f5c5SAndroid Build Coastguard Worker 149*8975f5c5SAndroid Build Coastguard Worker``` 150*8975f5c5SAndroid Build Coastguard Workercd tools/buildHeaders 151*8975f5c5SAndroid Build Coastguard Workermkdir build 152*8975f5c5SAndroid Build Coastguard Workercd build 153*8975f5c5SAndroid Build Coastguard Workercmake .. 154*8975f5c5SAndroid Build Coastguard Workercmake --build . --target install 155*8975f5c5SAndroid Build Coastguard Workercd .. 156*8975f5c5SAndroid Build Coastguard Worker./bin/makeHeaders 157*8975f5c5SAndroid Build Coastguard Worker``` 158*8975f5c5SAndroid Build Coastguard Worker 159*8975f5c5SAndroid Build Coastguard WorkerNotes: 160*8975f5c5SAndroid Build Coastguard Worker- this generator is used in a broader context within Khronos to generate the specification, 161*8975f5c5SAndroid Build Coastguard Worker and that influences the languages used, for legacy reasons 162*8975f5c5SAndroid Build Coastguard Worker- the C++ structures built may similarly include more than strictly necessary, for the same reason 163*8975f5c5SAndroid Build Coastguard Worker 164*8975f5c5SAndroid Build Coastguard Worker## Generating C headers for extended instruction sets 165*8975f5c5SAndroid Build Coastguard Worker 166*8975f5c5SAndroid Build Coastguard WorkerThe [GLSL.std.450.h](include/spirv/unified1/GLSL.std.450.h) 167*8975f5c5SAndroid Build Coastguard Workerand [OpenCL.std.h](include/spirv/unified1/OpenCL.std.h) extended instruction set headers 168*8975f5c5SAndroid Build Coastguard Workerare maintained manually. 169*8975f5c5SAndroid Build Coastguard Worker 170*8975f5c5SAndroid Build Coastguard WorkerThe C/C++ header for each of the other extended instruction sets 171*8975f5c5SAndroid Build Coastguard Workeris generated from the corresponding JSON grammar file. For example, the 172*8975f5c5SAndroid Build Coastguard Worker[OpenCLDebugInfo100.h](include/spirv/unified1/OpenCLDebugInfo100.h) header 173*8975f5c5SAndroid Build Coastguard Workeris generated from the 174*8975f5c5SAndroid Build Coastguard Worker[extinst.opencl.debuginfo.100.grammar.json](include/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json) 175*8975f5c5SAndroid Build Coastguard Workergrammar file. 176*8975f5c5SAndroid Build Coastguard Worker 177*8975f5c5SAndroid Build Coastguard WorkerTo generate these C/C++ headers, first make sure `python3` is in your PATH, then 178*8975f5c5SAndroid Build Coastguard Workerinvoke the build script as follows: 179*8975f5c5SAndroid Build Coastguard Worker``` 180*8975f5c5SAndroid Build Coastguard Workercd tools/buildHeaders 181*8975f5c5SAndroid Build Coastguard Workerpython3 bin/makeExtinstHeaders.py 182*8975f5c5SAndroid Build Coastguard Worker``` 183*8975f5c5SAndroid Build Coastguard Worker 184*8975f5c5SAndroid Build Coastguard Worker## FAQ 185*8975f5c5SAndroid Build Coastguard Worker 186*8975f5c5SAndroid Build Coastguard Worker* *How are different versions published?* 187*8975f5c5SAndroid Build Coastguard Worker 188*8975f5c5SAndroid Build Coastguard Worker The multiple versions of the headers have been simplified into a 189*8975f5c5SAndroid Build Coastguard Worker single `unified1` view. The JSON grammar has a "version" field saying 190*8975f5c5SAndroid Build Coastguard Worker what version things first showed up in. 191*8975f5c5SAndroid Build Coastguard Worker 192*8975f5c5SAndroid Build Coastguard Worker* *How do you handle the evolution of extended instruction sets?* 193*8975f5c5SAndroid Build Coastguard Worker 194*8975f5c5SAndroid Build Coastguard Worker Extended instruction sets evolve asynchronously from the core spec. 195*8975f5c5SAndroid Build Coastguard Worker Right now there is only a single version of both the GLSL and OpenCL 196*8975f5c5SAndroid Build Coastguard Worker headers. So we don't yet have a problematic example to resolve. 197*8975f5c5SAndroid Build Coastguard Worker 198*8975f5c5SAndroid Build Coastguard Worker## License 199*8975f5c5SAndroid Build Coastguard Worker<a name="license"></a> 200*8975f5c5SAndroid Build Coastguard Worker``` 201*8975f5c5SAndroid Build Coastguard WorkerCopyright (c) 2015-2024 The Khronos Group Inc. 202*8975f5c5SAndroid Build Coastguard Worker 203*8975f5c5SAndroid Build Coastguard WorkerPermission is hereby granted, free of charge, to any person obtaining a 204*8975f5c5SAndroid Build Coastguard Workercopy of this software and/or associated documentation files (the 205*8975f5c5SAndroid Build Coastguard Worker"Materials"), to deal in the Materials without restriction, including 206*8975f5c5SAndroid Build Coastguard Workerwithout limitation the rights to use, copy, modify, merge, publish, 207*8975f5c5SAndroid Build Coastguard Workerdistribute, sublicense, and/or sell copies of the Materials, and to 208*8975f5c5SAndroid Build Coastguard Workerpermit persons to whom the Materials are furnished to do so, subject to 209*8975f5c5SAndroid Build Coastguard Workerthe following conditions: 210*8975f5c5SAndroid Build Coastguard Worker 211*8975f5c5SAndroid Build Coastguard WorkerThe above copyright notice and this permission notice shall be included 212*8975f5c5SAndroid Build Coastguard Workerin all copies or substantial portions of the Materials. 213*8975f5c5SAndroid Build Coastguard Worker 214*8975f5c5SAndroid Build Coastguard WorkerMODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS 215*8975f5c5SAndroid Build Coastguard WorkerKHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS 216*8975f5c5SAndroid Build Coastguard WorkerSPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT 217*8975f5c5SAndroid Build Coastguard Worker https://www.khronos.org/registry/ 218*8975f5c5SAndroid Build Coastguard Worker 219*8975f5c5SAndroid Build Coastguard WorkerTHE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 220*8975f5c5SAndroid Build Coastguard WorkerEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 221*8975f5c5SAndroid Build Coastguard WorkerMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 222*8975f5c5SAndroid Build Coastguard WorkerIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 223*8975f5c5SAndroid Build Coastguard WorkerCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 224*8975f5c5SAndroid Build Coastguard WorkerTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 225*8975f5c5SAndroid Build Coastguard WorkerMATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 226*8975f5c5SAndroid Build Coastguard Worker``` 227