5 The SPIR-V Tools provides an API and commands for processing SPIR-V modules.
7 The project includes an assembler, binary module parser, disassembler, and
8 validator for SPIR-V, all based on a common static library. The library contains
9 all of the implementation details, and is used in the standalone tools whilst
10 also enabling integration into other code bases directly.
12 The interfaces are still under development, and are expected to change.
14 SPIR-V is defined by the Khronos Group Inc.
15 See the [SPIR-V Registry](https://www.khronos.org/registry/spir-v/) for the
16 SPIR-V specification, headers, and XML registry.
20 ### Assembler, binary parser, and disassembler
22 * Based on SPIR-V 1.0 Revision 2.
23 * Supports GLSL std450 extended instructions.
24 * Supports OpenCL extended instructions.
25 * Assembler only does basic syntax checking. No cross validation of
26 IDs or types is performed, except to check literal arguments to
27 `OpConstant`, `OpSpecConstant`, and `OpSwitch`.
29 See [`syntax.md`](syntax.md) for the assembly language syntax.
33 *Warning:* The validator is incomplete.
37 The SPIR-V Tools are maintained by members of the The Khronos Group Inc.,
38 at [https://github.com/KhronosGroup/SPIRV-Tools](https://github.com/KhronosGroup/SPIRV-Tools).
40 Contributions via merge request are welcome. Changes should:
41 * Be provided under the [Khronos license](#license).
42 * Include tests to cover updated functionality.
43 * C++ code should follow the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html).
44 * Code should be formatted with `clang-format`. Settings are defined by
45 the included [.clang-format](.clang-format) file.
47 We intend to maintain a linear history on the GitHub `master` branch.
49 ### Source code organization
51 * `external/headers`: Standard SPIR-V header files used by the implementation,
52 from the SPIR-V Registry
53 * `external/googletest`: Intended location for the
54 [googletest](https://github.com/google/googletest) sources, not provided.
55 * `include/libspirv/libspirv.h`: C API public interface
56 * `source/`: API implementation
57 * `test/`: Tests, using the [googletest](https://github.com/google/googletest)
59 * `tools/`: Command line executables
63 The project contains a number of tests, used to drive development
64 and ensure correctness. The tests are written using the
65 [googletest](https://github.com/google/googletest) framework. The `googletest`
66 source is not provided with this project. Download the `googletest` source
67 into the `<spirv-dir>/external/googletest` directory before configuring
68 and building the project.
72 The project uses [CMake](https://cmake.org/) to generate platform-specific
73 build configurations. To generate these build files, issue the following
77 mkdir <spirv-dir>/build
79 cmake [-G <platform-generator>] <spirv-dir>
82 Once the build files have been generated, build using your preferred
83 development environment.
87 The following CMake options are supported:
89 * `SPIRV_COLOR_TERMINAL=ON` - Enables color console output, enabled by default.
90 * `SPIRV_SKIP_EXECUTABLES=ON` - Build only the library, not the command line
91 tools. This will also prevent the tests from being built.
92 * `SPIRV_USE_SANITIZER=<sanitizer>` - On UNIX platforms with an appropriate
93 version of `clang` this option enables the use of the sanitizers documented
94 [here](http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation).
95 This should only be used with a debug build. Disabled by default.
96 * `SPIRV_WARN_EVERYTHING=OFF` - On UNIX platforms enable the `-Weverything`
97 compiler front end option, disabled by default.
98 * `SPIRV_WERROR=OFF` - On UNIX platforms enable the `-Werror` compiler front end
99 option, disabled by default.
105 The library provides a C API, but the internals use C++11.
107 In order to use the library from an application, the include path should point to
108 `<spirv-dir>/include`, which will enable the application to include the header
109 `<spirv-dir>/include/libspirv/libspirv.h` then linking against the static
110 library in `<spirv-build-dir>/bin/libSPIRV-Tools.a` or
111 `<spirv-build-dir>/bin/SPIRV-Tools.lib`.
113 * `SPIRV-Tools` CMake target: Creates the static library:
114 * `<spirv-build-dir>/lib/libSPIRV-Tools.a` on Linux and OS X.
115 * `<spirv-build-dir>/lib/libSPIRV-Tools.lib` on Windows.
119 The interfaces are still under development, and are expected to change.
121 There are three main entry points into the library.
123 * `spvTextToBinary`: An assembler, translating text to a binary SPIR-V module.
124 * `spvBinaryToText`: A disassembler, translating a binary SPIR-V module to
126 * `spvBinaryParse`: The entry point to a binary parser API. It issues callbacks
127 for the header and each parsed instruction. The disassembler is implemented
128 as a client of `spvBinaryParse`.
129 * `spvValidate` implements the validator functionality. *Incomplete*
131 ## Command line tools
135 The assembler reads the assembly language text, and emits the binary form.
137 The standalone assembler is the exectuable called `spirv-as`, and is located in
138 `<spirv-build-dir>/bin/spirv-as`. The functionality of the assembler is
139 implemented by the `spvTextToBinary` library function.
141 * `spirv-as` - the standalone assembler
142 * `<spirv-dir>/bin/spirv-as`
144 Use option `-h` to print help.
146 ### Disassembler tool
148 The disassembler reads the binary form, and emits assembly language text.
150 The standalone disassembler is the executable called `spirv-dis`, and is located in
151 `<spirv-build-dir>/bin/spirv-dis`. The functionality of the disassembler is
152 implemented by the `spvBinaryToText` library function.
154 * `spirv-dis` - the standalone disassembler
155 * `<spirv-dir>/bin/spirv-dis`
157 Use option `-h` to print help.
159 The output includes syntax colouring when printing to the standard output stream,
160 on Linux, Windows, and OS X.
164 *Warning:* This functionality is under development, and is incomplete.
166 The standalone validator is the executable called `spirv-val`, and is located in
167 `<spirv-build-dir>/bin/spirv-val`. The functionality of the validator is
168 implemented by the `spvValidate` library function.
170 The validator operates on the binary form.
172 * `spirv-val` - the standalone validator
173 * `<spirv-dir>/bin/spirv-val`
177 The `<spirv-build-dir>/bin/UnitSPIRV` executable runs the project tests.
178 It supports the standard `googletest` command line options.
181 <a name="future"></a>
183 ### Assembler and disassembler
185 * Support 16-bit floating point literals.
186 * The disassembler could emit helpful annotations in comments. For example:
187 * Use variable name information from debug instructions to annotate
188 key operations on variables.
189 * Show control flow information by annotating `OpLabel` instructions with
190 that basic block's predecessors.
191 * Error messages could be improved.
195 This is a work in progress.
198 <a name="license"></a>
200 Copyright (c) 2015 The Khronos Group Inc.
202 Permission is hereby granted, free of charge, to any person obtaining a
203 copy of this software and/or associated documentation files (the
204 "Materials"), to deal in the Materials without restriction, including
205 without limitation the rights to use, copy, modify, merge, publish,
206 distribute, sublicense, and/or sell copies of the Materials, and to
207 permit persons to whom the Materials are furnished to do so, subject to
208 the following conditions:
210 The above copyright notice and this permission notice shall be included
211 in all copies or substantial portions of the Materials.
213 MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
214 KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
215 SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
216 https://www.khronos.org/registry/
218 THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
219 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
220 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
221 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
222 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
223 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
224 MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.