Add xml section for memory operand bit allocation tracking, and reserve two bits...
[platform/upstream/SPIRV-Headers.git] / README.md
1 # SPIR-V Headers
2
3 This repository contains machine-readable files for the
4 [SPIR-V Registry](https://www.khronos.org/registry/spir-v/).
5 This includes:
6
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.
12
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
15 their version.
16
17 In contrast, the XML registry file has a linear history, so it is
18 not tied to SPIR-V specification versions.
19
20 ## How is this repository updated?
21
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).
25
26 [The SPIR-V XML registry file](include/spirv/spir-v.xml)
27 is updated by Khronos whenever a new enum range is allocated.
28
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
33
34 ### Registering a SPIR-V Generator Magic Number
35
36 Tools that generate SPIR-V should use a magic number in the SPIR-V to help identify the
37 generator.
38
39 Care should be taken to follow existing precedent in populating the details of reserved tokens.
40 This includes:
41 - keeping generator numbers in numeric order
42 - filling out all the existing fields
43
44 ### Reserving tokens in the JSON grammar
45
46 Care should be taken to follow existing precedent in populating the details of reserved tokens.
47 This includes:
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"`
52
53 ## How to install the headers
54
55 ```
56 mkdir build
57 cd build
58 cmake ..
59 cmake --build . --target install
60 ```
61
62 Then, for example, you will have `/usr/local/include/spirv/unified1/spirv.h`
63
64 If you want to install them somewhere else, then use
65 `-DCMAKE_INSTALL_PREFIX=/other/path` on the first `cmake` command.
66
67 ## Using the headers without installing
68
69 ### Using CMake
70 A CMake-based project can use the headers without installing, as follows:
71
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`
74    directive.
75 3. In your C or C++ source code use `#include` directives that explicitly mention
76    the `spirv` path component.
77 ```
78 #include "spirv/unified1/GLSL.std.450.h"
79 #include "spirv/unified1/OpenCL.std.h"
80 #include "spirv/unified1/spirv.hpp"
81 ```
82
83 See also the [example](example/) subdirectory.  But since that example is
84 *inside* this repostory, it doesn't use and `add_subdirectory` directive.
85
86 ### Using Bazel
87 A Bazel-based project can use the headers without installing, as follows:
88
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
92 `WORKSPACE` file:
93
94 ```
95 local_repository(
96     name = "spirv_headers",
97     path = "external/spirv-headers",
98 )
99 ```
100
101 2. Add one of the following to the `deps` attribute of your build target based
102 on your needs:
103 ```
104 @spirv_headers//:spirv_c_headers
105 @spirv_headers//:spirv_cpp_headers
106 @spirv_headers//:spirv_cpp11_headers
107 ```
108
109 For example:
110
111 ```
112 cc_library(
113   name = "project",
114   srcs = [
115     # Path to project sources
116   ],
117   hdrs = [
118     # Path to project headers
119   ],
120   deps = [
121     "@spirv_tools//:spirv_c_headers",
122     # Other dependencies,
123   ],
124 )
125 ```
126
127 3. In your C or C++ source code use `#include` directives that explicitly mention
128    the `spirv` path component.
129 ```
130 #include "spirv/unified1/GLSL.std.450.h"
131 #include "spirv/unified1/OpenCL.std.h"
132 #include "spirv/unified1/spirv.hpp"
133 ```
134
135 ## Generating headers from the JSON grammar for the SPIR-V core instruction set
136
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.
141
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.)
147
148 Notes:
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
152
153 ## Generating C headers for extended instruction sets
154
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.
158
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)
164 grammar file.
165
166 To generate these C/C++ headers, first make sure `python3` is in your PATH, then
167 invoke the build script as follows:
168 ```
169 cd tools/buildHeaders
170 python3 bin/makeExtinstHeaders.py
171 ```
172
173 ## FAQ
174
175 * *How are different versions published?*
176
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.
180
181 * *How do you handle the evolution of extended instruction sets?*
182
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.
186
187 ## License
188 <a name="license"></a>
189 ```
190 Copyright (c) 2015-2018 The Khronos Group Inc.
191
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:
199
200 The above copyright notice and this permission notice shall be included
201 in all copies or substantial portions of the Materials.
202
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/
207
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.
215 ```