3 [![Build Status](https://travis-ci.org/KhronosGroup/SPIRV-Tools.svg?branch=master)](https://travis-ci.org/KhronosGroup/SPIRV-Tools)
7 The SPIR-V Tools project provides an API and commands for processing SPIR-V
10 The project includes an assembler, binary module parser, disassembler, and
11 validator for SPIR-V, all based on a common static library. The library contains
12 all of the implementation details, and is used in the standalone tools whilst
13 also enabling integration into other code bases directly.
15 The interfaces are still under development, and are expected to change.
17 SPIR-V is defined by the Khronos Group Inc.
18 See the [SPIR-V Registry][spirv-registry] for the SPIR-V specification,
19 headers, and XML registry.
21 ## Verisoning SPIRV-Tools
23 See [`CHANGES`](CHANGES) for a high level summary of recent changes, by version.
25 SPIRV-Tools project version numbers are of the form `v`*year*`.`*index* and with
26 an optional `-dev` suffix to indicate work in progress. For exampe, the
27 following versions are ordered from oldest to newest:
35 Use the `--version` option on each command line tool to see the software
36 version. An API call reports the software version as a C-style string.
40 ### Assembler, binary parser, and disassembler
42 * Based on SPIR-V version 1.1 Rev 1
43 * Support for extended instruction sets:
44 * GLSL std450 version 1.0 Rev 3
45 * OpenCL version 1.0 Rev 2
46 * Support for SPIR-V 1.0 (with or without additional restrictions from Vulkan 1.0)
47 * Assembler only does basic syntax checking. No cross validation of
48 IDs or types is performed, except to check literal arguments to
49 `OpConstant`, `OpSpecConstant`, and `OpSwitch`.
51 See [`syntax.md`](syntax.md) for the assembly language syntax.
55 *Warning:* The validator is incomplete.
59 The SPIR-V Tools are maintained by members of the The Khronos Group Inc.,
60 at https://github.com/KhronosGroup/SPIRV-Tools.
62 Contributions via merge request are welcome. Changes should:
63 * Be provided under the [Khronos license](#license).
64 * Include tests to cover updated functionality.
65 * C++ code should follow the [Google C++ Style Guide][cpp-style-guide].
66 * Code should be formatted with `clang-format`. Settings are defined by
67 the included [.clang-format](.clang-format) file.
69 We intend to maintain a linear history on the GitHub `master` branch.
71 ### Source code organization
73 * `external/googletest`: Intended location for the
74 [googletest][googletest] sources, not provided
75 * `include/`: API clients should add this directory to the include search path
76 * `include/spirv-tools/libspirv.h`: C API public interface
77 * `include/spirv/` : Contains header files from the SPIR-V Registry, required
79 * `source/`: API implementation
80 * `test/`: Tests, using the [googletest][googletest] framework
81 * `tools/`: Command line executables
85 The project contains a number of tests, used to drive development
86 and ensure correctness. The tests are written using the
87 [googletest][googletest] framework. The `googletest`
88 source is not provided with this project. There are two ways to enable
90 * If SPIR-V Tools is configured as part of an enclosing project, then the
91 enclosing project should configure `googletest` before configuring SPIR-V Tools.
92 * If SPIR-V Tools is configured as a standalone project, then download the
93 `googletest` source into the `<spirv-dir>/external/googletest` directory before
94 configuring and building the project.
96 *Note*: You must use a version of googletest that includes
97 [a fix][googletest-pull-612] for [googletest issue 610][googletest-issue-610].
98 The fix is included on the googletest master branch any time after 2015-11-10.
99 In particular, googletest must be newer than version 1.7.0.
103 The project uses [CMake][cmake] to generate platform-specific build
104 configurations. To generate these build files, issue the following commands:
107 mkdir <spirv-dir>/build
109 cmake [-G <platform-generator>] <spirv-dir>
112 Once the build files have been generated, build using your preferred
113 development environment.
117 The following CMake options are supported:
119 * `SPIRV_COLOR_TERMINAL={ON|OFF}`, default `ON` - Enables color console output.
120 * `SPIRV_SKIP_EXECUTABLES={ON|OFF}`, default `OFF`- Build only the library, not
121 the command line tools. This will also prevent the tests from being built.
122 * `SPIRV_USE_SANITIZER=<sanitizer>`, default is no sanitizing - On UNIX
123 platforms with an appropriate version of `clang` this option enables the use
124 of the sanitizers documented [here][clang-sanitizers].
125 This should only be used with a debug build.
126 * `SPIRV_WARN_EVERYTHING={ON|OFF}`, default `OFF` - On UNIX platforms enable
127 more strict warnings. The code might not compile with this option enabled.
128 For Clang, enables `-Weverything`. For GCC, enables `-Wpedantic`.
129 See [`CMakeLists.txt`](CMakeLists.txt) for details.
130 * `SPIRV_WERROR={ON|OFF}`, default `ON` - Forces a compilation error on any
131 warnings encountered by enabling the compiler-specific compiler front-end
138 The library provides a C API, but the internals use C++11.
140 In order to use the library from an application, the include path should point
141 to `<spirv-dir>/include`, which will enable the application to include the
142 header `<spirv-dir>/include/libspirv/libspirv.h` then linking against the
143 static library in `<spirv-build-dir>/libSPIRV-Tools.a` or
144 `<spirv-build-dir>/SPIRV-Tools.lib`.
146 * `SPIRV-Tools` CMake target: Creates the static library:
147 * `<spirv-build-dir>/libSPIRV-Tools.a` on Linux and OS X.
148 * `<spirv-build-dir>/libSPIRV-Tools.lib` on Windows.
152 The interfaces are still under development, and are expected to change.
154 There are three main entry points into the library.
156 * `spvTextToBinary`: An assembler, translating text to a binary SPIR-V module.
157 * `spvBinaryToText`: A disassembler, translating a binary SPIR-V module to
159 * `spvBinaryParse`: The entry point to a binary parser API. It issues callbacks
160 for the header and each parsed instruction. The disassembler is implemented
161 as a client of `spvBinaryParse`.
162 * `spvValidate` implements the validator functionality. *Incomplete*
164 ## Command line tools
166 Command line tools, which wrap the above library functions, are provided to
167 assemble or disassemble shader files. It's a convention to name SPIR-V
168 assembly and binary files with suffix `.spvasm` and `.spv`, respectively.
172 The assembler reads the assembly language text, and emits the binary form.
174 The standalone assembler is the exectuable called `spirv-as`, and is located in
175 `<spirv-build-dir>/spirv-as`. The functionality of the assembler is implemented
176 by the `spvTextToBinary` library function.
178 * `spirv-as` - the standalone assembler
179 * `<spirv-dir>/spirv-as`
181 Use option `-h` to print help.
183 ### Disassembler tool
185 The disassembler reads the binary form, and emits assembly language text.
187 The standalone disassembler is the executable called `spirv-dis`, and is located in
188 `<spirv-build-dir>/spirv-dis`. The functionality of the disassembler is implemented
189 by the `spvBinaryToText` library function.
191 * `spirv-dis` - the standalone disassembler
192 * `<spirv-dir>/spirv-dis`
194 Use option `-h` to print help.
196 The output includes syntax colouring when printing to the standard output stream,
197 on Linux, Windows, and OS X.
201 *Warning:* This functionality is under development, and is incomplete.
203 The standalone validator is the executable called `spirv-val`, and is located in
204 `<spirv-build-dir>/spirv-val`. The functionality of the validator is implemented
205 by the `spvValidate` library function.
207 The validator operates on the binary form.
209 * `spirv-val` - the standalone validator
210 * `<spirv-dir>/spirv-val`
214 Tests are only built when googletest is found.
216 The `<spirv-build-dir>/UnitSPIRV` executable runs the project tests.
217 It supports the standard `googletest` command line options.
219 The project also adds a CMake test `spirv-tools-testsuite`, which executes
220 `UnitSPIRV`. That way it's possible to run the tests using `ctest`.
223 <a name="future"></a>
225 ### Assembler and disassembler
227 * The disassembler could emit helpful annotations in comments. For example:
228 * Use variable name information from debug instructions to annotate
229 key operations on variables.
230 * Show control flow information by annotating `OpLabel` instructions with
231 that basic block's predecessors.
232 * Error messages could be improved.
236 This is a work in progress.
239 <a name="license"></a>
241 Copyright (c) 2015-2016 The Khronos Group Inc.
243 Permission is hereby granted, free of charge, to any person obtaining a
244 copy of this software and/or associated documentation files (the
245 "Materials"), to deal in the Materials without restriction, including
246 without limitation the rights to use, copy, modify, merge, publish,
247 distribute, sublicense, and/or sell copies of the Materials, and to
248 permit persons to whom the Materials are furnished to do so, subject to
249 the following conditions:
251 The above copyright notice and this permission notice shall be included
252 in all copies or substantial portions of the Materials.
254 MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
255 KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
256 SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
257 https://www.khronos.org/registry/
259 THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
260 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
261 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
262 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
263 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
264 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
265 MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
268 [spirv-registry]: https://www.khronos.org/registry/spir-v/
269 [googletest]: https://github.com/google/googletest
270 [googletest-pull-612]: https://github.com/google/googletest/pull/612
271 [googletest-issue-610]: https://github.com/google/googletest/issues/610
272 [CMake]: https://cmake.org/
273 [cpp-style-guide]: https://google.github.io/styleguide/cppguide.html
274 [clang-sanitizers]: http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation