3 This repository contains machine-readable files for the
4 [SPIR-V Registry](https://www.khronos.org/registry/spir-v/).
7 * Header files for various languages.
8 * JSON files describing the grammar for the SPIR-V core instruction set
9 and the extended instruction sets.
10 * The XML registry file.
11 * A tool to build the headers from the JSON grammar.
13 Headers are provided in the [include](include) directory, with up-to-date
14 headers in the `unified1` subdirectory. Older headers are provided according to
17 In contrast, the XML registry file has a linear history, so it is
18 not tied to SPIR-V specification versions.
20 ## How is this repository updated?
22 When a new version or revision of the SPIR-V specification is published,
23 the SPIR-V Working Group will push new commits onto master, updating
24 the files under [include](include).
26 [The SPIR-V XML registry file](include/spirv/spir-v.xml)
27 is updated by Khronos whenever a new enum range is allocated.
29 Pull requests can be made to
30 - request allocation of new enum ranges in the XML registry file
31 - register a new magic number for a SPIR-V generator
32 - reserve specific tokens in the JSON grammar
34 ### Registering a SPIR-V Generator Magic Number
36 Tools that generate SPIR-V should use a magic number in the SPIR-V to help identify the
39 Care should be taken to follow existing precedent in populating the details of reserved tokens.
41 - keeping generator numbers in numeric order
42 - filling out all the existing fields
44 ### Reserving tokens in the JSON grammar
46 Care should be taken to follow existing precedent in populating the details of reserved tokens.
48 - pointing to what extension has more information, when possible
49 - keeping enumerants in numeric order
50 - when there are aliases, listing the preferred spelling first
51 - adding the statement `"version" : "None"`
53 ## How to install the headers
59 cmake --build . --target install
62 Then, for example, you will have `/usr/local/include/spirv/unified1/spirv.h`
64 If you want to install them somewhere else, then use
65 `-DCMAKE_INSTALL_PREFIX=/other/path` on the first `cmake` command.
67 ## Using the headers without installing
70 A CMake-based project can use the headers without installing, as follows:
72 1. Add an `add_subdirectory` directive to include this source tree.
73 2. Use `${SPIRV-Headers_SOURCE_DIR}/include}` in a `target_include_directories`
75 3. In your C or C++ source code use `#include` directives that explicitly mention
76 the `spirv` path component.
78 #include "spirv/unified1/GLSL.std.450.h"
79 #include "spirv/unified1/OpenCL.std.h"
80 #include "spirv/unified1/spirv.hpp"
83 See also the [example](example/) subdirectory. But since that example is
84 *inside* this repostory, it doesn't use and `add_subdirectory` directive.
87 A Bazel-based project can use the headers without installing, as follows:
89 1. Add SPIRV-Headers as a submodule of your project, and add a
90 `local_repository` to your `WORKSPACE` file. For example, if you place
91 SPIRV-Headers under `external/spirv-headers`, then add the following to your
96 name = "spirv_headers",
97 path = "external/spirv-headers",
101 2. Add one of the following to the `deps` attribute of your build target based
104 @spirv_headers//:spirv_c_headers
105 @spirv_headers//:spirv_cpp_headers
106 @spirv_headers//:spirv_cpp11_headers
115 # Path to project sources
118 # Path to project headers
121 "@spirv_tools//:spirv_c_headers",
122 # Other dependencies,
127 3. In your C or C++ source code use `#include` directives that explicitly mention
128 the `spirv` path component.
130 #include "spirv/unified1/GLSL.std.450.h"
131 #include "spirv/unified1/OpenCL.std.h"
132 #include "spirv/unified1/spirv.hpp"
135 ## Generating headers from the JSON grammar for the SPIR-V core instruction set
137 This will generally be done by Khronos, for a change to the JSON grammar.
138 However, the project for the tool to do this is included in this repository,
139 and can be used to test a PR, or even to include the results in the PR.
140 This is not required though.
142 The header-generation project is under the `tools/buildHeaders` directory.
143 Use CMake to build the project, in a `build` subdirectory (under `tools/buildHeaders`).
144 There is then a bash script at `bin/makeHeaders` that shows how to use the built
145 header-generator binary to generate the headers from the JSON grammar.
146 (Execute `bin/makeHeaders` from the `tools/buildHeaders` directory.)
149 - this generator is used in a broader context within Khronos to generate the specification,
150 and that influences the languages used, for legacy reasons
151 - the C++ structures built may similarly include more than strictly necessary, for the same reason
153 ## Generating C headers for extended instruction sets
155 The [GLSL.std.450.h](include/spirv/unified1/GLSL.std.450.h)
156 and [OpenCL.std.h](include/spirv/unified1/OpenCL.std.h) extended instruction set headers
157 are maintained manually.
159 The C/C++ header for each of the other extended instruction sets
160 is generated from the corresponding JSON grammar file. For example, the
161 [OpenCLDebugInfo100.h](include/spirv/unified1/OpenCLDebugInfo100.h) header
162 is generated from the
163 [extinst.opencl.debuginfo.100.grammar.json](include/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json)
166 To generate these C/C++ headers, first make sure `python3` is in your PATH, then
167 invoke the build script as follows:
169 cd tools/buildHeaders
170 python3 bin/makeExtinstHeaders.py
175 * *How are different versions published?*
177 The multiple versions of the headers have been simplified into a
178 single `unified1` view. The JSON grammar has a "version" field saying
179 what version things first showed up in.
181 * *How do you handle the evolution of extended instruction sets?*
183 Extended instruction sets evolve asynchronously from the core spec.
184 Right now there is only a single version of both the GLSL and OpenCL
185 headers. So we don't yet have a problematic example to resolve.
188 <a name="license"></a>
190 Copyright (c) 2015-2018 The Khronos Group Inc.
192 Permission is hereby granted, free of charge, to any person obtaining a
193 copy of this software and/or associated documentation files (the
194 "Materials"), to deal in the Materials without restriction, including
195 without limitation the rights to use, copy, modify, merge, publish,
196 distribute, sublicense, and/or sell copies of the Materials, and to
197 permit persons to whom the Materials are furnished to do so, subject to
198 the following conditions:
200 The above copyright notice and this permission notice shall be included
201 in all copies or substantial portions of the Materials.
203 MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
204 KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
205 SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
206 https://www.khronos.org/registry/
208 THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
209 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
210 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
211 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
212 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
213 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
214 MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.