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