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` - Enables color console output, enabled by default.
97 * `SPIRV_SKIP_EXECUTABLES=ON` - Build only the library, not the command line
98 tools. This will also prevent the tests from being built.
99 * `SPIRV_USE_SANITIZER=<sanitizer>` - On UNIX platforms with an appropriate
100 version of `clang` this option enables the use of the sanitizers documented
101 [here](http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation).
102 This should only be used with a debug build. Disabled by default.
103 * `SPIRV_WARN_EVERYTHING=OFF` - On UNIX platforms enable the `-Weverything`
104 compiler front end option, disabled by default.
105 * `SPIRV_WERROR=ON` - Forces a compilation error on any warnings encountered by
106 enabling the compiler-specific compiler front-end option, enabled by default.
112 The library provides a C API, but the internals use C++11.
114 In order to use the library from an application, the include path should point to
115 `<spirv-dir>/include`, which will enable the application to include the header
116 `<spirv-dir>/include/libspirv/libspirv.h` then linking against the static
117 library in `<spirv-build-dir>/libSPIRV-Tools.a` or
118 `<spirv-build-dir>/SPIRV-Tools.lib`.
120 * `SPIRV-Tools` CMake target: Creates the static library:
121 * `<spirv-build-dir>/libSPIRV-Tools.a` on Linux and OS X.
122 * `<spirv-build-dir>/libSPIRV-Tools.lib` on Windows.
126 The interfaces are still under development, and are expected to change.
128 There are three main entry points into the library.
130 * `spvTextToBinary`: An assembler, translating text to a binary SPIR-V module.
131 * `spvBinaryToText`: A disassembler, translating a binary SPIR-V module to
133 * `spvBinaryParse`: The entry point to a binary parser API. It issues callbacks
134 for the header and each parsed instruction. The disassembler is implemented
135 as a client of `spvBinaryParse`.
136 * `spvValidate` implements the validator functionality. *Incomplete*
138 ## Command line tools
142 The assembler reads the assembly language text, and emits the binary form.
144 The standalone assembler is the exectuable called `spirv-as`, and is located in
145 `<spirv-build-dir>/spirv-as`. The functionality of the assembler is implemented
146 by the `spvTextToBinary` library function.
148 * `spirv-as` - the standalone assembler
149 * `<spirv-dir>/spirv-as`
151 Use option `-h` to print help.
153 ### Disassembler tool
155 The disassembler reads the binary form, and emits assembly language text.
157 The standalone disassembler is the executable called `spirv-dis`, and is located in
158 `<spirv-build-dir>/spirv-dis`. The functionality of the disassembler is implemented
159 by the `spvBinaryToText` library function.
161 * `spirv-dis` - the standalone disassembler
162 * `<spirv-dir>/spirv-dis`
164 Use option `-h` to print help.
166 The output includes syntax colouring when printing to the standard output stream,
167 on Linux, Windows, and OS X.
171 *Warning:* This functionality is under development, and is incomplete.
173 The standalone validator is the executable called `spirv-val`, and is located in
174 `<spirv-build-dir>/spirv-val`. The functionality of the validator is implemented
175 by the `spvValidate` library function.
177 The validator operates on the binary form.
179 * `spirv-val` - the standalone validator
180 * `<spirv-dir>/spirv-val`
184 The `<spirv-build-dir>/UnitSPIRV` executable runs the project tests.
185 It supports the standard `googletest` command line options.
188 <a name="future"></a>
190 ### Assembler and disassembler
192 * Support 16-bit floating point literals.
193 * The disassembler could emit helpful annotations in comments. For example:
194 * Use variable name information from debug instructions to annotate
195 key operations on variables.
196 * Show control flow information by annotating `OpLabel` instructions with
197 that basic block's predecessors.
198 * Error messages could be improved.
202 This is a work in progress.
205 <a name="license"></a>
207 Copyright (c) 2015 The Khronos Group Inc.
209 Permission is hereby granted, free of charge, to any person obtaining a
210 copy of this software and/or associated documentation files (the
211 "Materials"), to deal in the Materials without restriction, including
212 without limitation the rights to use, copy, modify, merge, publish,
213 distribute, sublicense, and/or sell copies of the Materials, and to
214 permit persons to whom the Materials are furnished to do so, subject to
215 the following conditions:
217 The above copyright notice and this permission notice shall be included
218 in all copies or substantial portions of the Materials.
220 MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
221 KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
222 SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
223 https://www.khronos.org/registry/
225 THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
226 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
227 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
228 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
229 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
230 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
231 MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.