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