5 The SPIR-V Tools project provides an API and commands for processing SPIR-V
8 The project includes an assembler, binary module parser, disassembler, and
9 validator for SPIR-V, all based on a common static library. The library contains
10 all of the implementation details, and is used in the standalone tools whilst
11 also enabling integration into other code bases directly.
13 The interfaces are still under development, and are expected to change.
15 SPIR-V is defined by the Khronos Group Inc.
16 See the [SPIR-V Registry](https://www.khronos.org/registry/spir-v/) for the
17 SPIR-V specification, headers, and XML registry.
21 ### Assembler, binary parser, and disassembler
23 * Based on SPIR-V 1.0 Revision 2.
24 * Supports GLSL std450 extended instructions.
25 * Supports OpenCL extended instructions.
26 * Assembler only does basic syntax checking. No cross validation of
27 IDs or types is performed, except to check literal arguments to
28 `OpConstant`, `OpSpecConstant`, and `OpSwitch`.
30 See [`syntax.md`](syntax.md) for the assembly language syntax.
34 *Warning:* The validator is incomplete.
38 The SPIR-V Tools are maintained by members of the The Khronos Group Inc.,
39 at [https://github.com/KhronosGroup/SPIRV-Tools](https://github.com/KhronosGroup/SPIRV-Tools).
41 Contributions via merge request are welcome. Changes should:
42 * Be provided under the [Khronos license](#license).
43 * Include tests to cover updated functionality.
44 * C++ code should follow the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html).
45 * Code should be formatted with `clang-format`. Settings are defined by
46 the included [.clang-format](.clang-format) file.
48 We intend to maintain a linear history on the GitHub `master` branch.
50 ### Source code organization
52 * `external/headers`: Standard SPIR-V header files used by the implementation,
53 from the SPIR-V Registry
54 * `external/googletest`: Intended location for the
55 [googletest](https://github.com/google/googletest) sources, not provided.
56 * `include/libspirv/libspirv.h`: C API public interface
57 * `source/`: API implementation
58 * `test/`: Tests, using the [googletest](https://github.com/google/googletest)
60 * `tools/`: Command line executables
64 The project contains a number of tests, used to drive development
65 and ensure correctness. The tests are written using the
66 [googletest](https://github.com/google/googletest) framework. The `googletest`
67 source is not provided with this project. Download the `googletest` source
68 into the `<spirv-dir>/external/googletest` directory before configuring
69 and building the project.
71 *Note*: You must use a version of googletest that includes
72 [a fix](https://github.com/google/googletest/pull/612) for
73 [googletest issue 610](https://github.com/google/googletest/issues/610).
74 The fix is included on the googletest master branch any time after 2015-11-10.
75 In particular, googletest must be newer than version 1.7.0.
79 The project uses [CMake](https://cmake.org/) to generate platform-specific
80 build configurations. To generate these build files, issue the following
84 mkdir <spirv-dir>/build
86 cmake [-G <platform-generator>] <spirv-dir>
89 Once the build files have been generated, build using your preferred
90 development environment.
94 The following CMake options are supported:
96 * `SPIRV_COLOR_TERMINAL={ON|OFF}`, default `ON` - Enables color console output.
97 * `SPIRV_SKIP_EXECUTABLES={ON|OFF}`, default `OFF`- Build only the library, not
98 the command line tools. This will also prevent the tests from being built.
99 * `SPIRV_USE_SANITIZER=<sanitizer>`, default is no sanitizing - On UNIX platforms
100 with an appropriate version of `clang` this option enables the use of the
101 sanitizers documented
102 [here](http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation).
103 This should only be used with a debug build.
104 * `SPIRV_WARN_EVERYTHING={ON|OFF}`, default `OFF` - On UNIX platforms enable
105 more strict warnings. The code might not compile with this option enabled.
106 For Clang, enables `-Weverything`. For GCC, enables `-Wpedantic`.
107 See [`CMakeLists.txt`](CMakeLists.txt) for details.
108 * `SPIRV_WERROR={ON|OFF}`, default `ON` - Forces a compilation error on any
109 warnings encountered by enabling the compiler-specific compiler front-end
116 The library provides a C API, but the internals use C++11.
118 In order to use the library from an application, the include path should point to
119 `<spirv-dir>/include`, which will enable the application to include the header
120 `<spirv-dir>/include/libspirv/libspirv.h` then linking against the static
121 library in `<spirv-build-dir>/libSPIRV-Tools.a` or
122 `<spirv-build-dir>/SPIRV-Tools.lib`.
124 * `SPIRV-Tools` CMake target: Creates the static library:
125 * `<spirv-build-dir>/libSPIRV-Tools.a` on Linux and OS X.
126 * `<spirv-build-dir>/libSPIRV-Tools.lib` on Windows.
130 The interfaces are still under development, and are expected to change.
132 There are three main entry points into the library.
134 * `spvTextToBinary`: An assembler, translating text to a binary SPIR-V module.
135 * `spvBinaryToText`: A disassembler, translating a binary SPIR-V module to
137 * `spvBinaryParse`: The entry point to a binary parser API. It issues callbacks
138 for the header and each parsed instruction. The disassembler is implemented
139 as a client of `spvBinaryParse`.
140 * `spvValidate` implements the validator functionality. *Incomplete*
142 ## Command line tools
146 The assembler reads the assembly language text, and emits the binary form.
148 The standalone assembler is the exectuable called `spirv-as`, and is located in
149 `<spirv-build-dir>/spirv-as`. The functionality of the assembler is implemented
150 by the `spvTextToBinary` library function.
152 * `spirv-as` - the standalone assembler
153 * `<spirv-dir>/spirv-as`
155 Use option `-h` to print help.
157 ### Disassembler tool
159 The disassembler reads the binary form, and emits assembly language text.
161 The standalone disassembler is the executable called `spirv-dis`, and is located in
162 `<spirv-build-dir>/spirv-dis`. The functionality of the disassembler is implemented
163 by the `spvBinaryToText` library function.
165 * `spirv-dis` - the standalone disassembler
166 * `<spirv-dir>/spirv-dis`
168 Use option `-h` to print help.
170 The output includes syntax colouring when printing to the standard output stream,
171 on Linux, Windows, and OS X.
175 *Warning:* This functionality is under development, and is incomplete.
177 The standalone validator is the executable called `spirv-val`, and is located in
178 `<spirv-build-dir>/spirv-val`. The functionality of the validator is implemented
179 by the `spvValidate` library function.
181 The validator operates on the binary form.
183 * `spirv-val` - the standalone validator
184 * `<spirv-dir>/spirv-val`
188 The `<spirv-build-dir>/UnitSPIRV` executable runs the project tests.
189 It supports the standard `googletest` command line options.
192 <a name="future"></a>
194 ### Assembler and disassembler
196 * The disassembler could emit helpful annotations in comments. For example:
197 * Use variable name information from debug instructions to annotate
198 key operations on variables.
199 * Show control flow information by annotating `OpLabel` instructions with
200 that basic block's predecessors.
201 * Error messages could be improved.
205 This is a work in progress.
208 <a name="license"></a>
210 Copyright (c) 2015-2016 The Khronos Group Inc.
212 Permission is hereby granted, free of charge, to any person obtaining a
213 copy of this software and/or associated documentation files (the
214 "Materials"), to deal in the Materials without restriction, including
215 without limitation the rights to use, copy, modify, merge, publish,
216 distribute, sublicense, and/or sell copies of the Materials, and to
217 permit persons to whom the Materials are furnished to do so, subject to
218 the following conditions:
220 The above copyright notice and this permission notice shall be included
221 in all copies or substantial portions of the Materials.
223 MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
224 KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
225 SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
226 https://www.khronos.org/registry/
228 THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
229 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
230 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
231 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
232 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
233 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
234 MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.