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