Turned warnings-as-errors on by default.
[platform/upstream/SPIRV-Tools.git] / README.md
1 # SPIR-V Tools
2
3 ## Overview
4
5 The SPIR-V Tools project provides an API and commands for processing SPIR-V
6 modules.
7
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.
12
13 The interfaces are still under development, and are expected to change.
14
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.
18
19 ## Supported features
20
21 ### Assembler, binary parser, and disassembler
22
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`.
29
30 See [`syntax.md`](syntax.md) for the assembly language syntax.
31
32 ### Validator
33
34 *Warning:* The validator is incomplete.
35
36 ## Source code
37
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).
40
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.
47
48 We intend to maintain a linear history on the GitHub `master` branch.
49
50 ### Source code organization
51
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)
59   framework.
60 * `tools/`: Command line executables
61
62 ### Tests
63
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.
70
71 ## Build
72
73 The project uses [CMake](https://cmake.org/) to generate platform-specific
74 build configurations.  To generate these build files, issue the following
75 commands:
76
77 ```
78 mkdir <spirv-dir>/build
79 cd <spirv-dir>/build
80 cmake [-G <platform-generator>] <spirv-dir>
81 ```
82
83 Once the build files have been generated, build using your preferred
84 development environment.
85
86 ### CMake options
87
88 The following CMake options are supported:
89
90 * `SPIRV_COLOR_TERMINAL=ON` - Enables color console output, enabled by default.
91 * `SPIRV_SKIP_EXECUTABLES=ON` - Build only the library, not the command line
92   tools.  This will also prevent the tests from being built.
93 * `SPIRV_USE_SANITIZER=<sanitizer>` - On UNIX platforms with an appropriate
94   version of `clang` this option enables the use of the sanitizers documented
95   [here](http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation).
96   This should only be used with a debug build. Disabled by default.
97 * `SPIRV_WARN_EVERYTHING=OFF` - On UNIX platforms enable the `-Weverything`
98   compiler front end option, disabled by default.
99 * `SPIRV_WERROR=ON` - Forces a compilation error on any warnings encountered by
100   enabling the compiler-specific compiler front-end option, enabled by default.
101
102 ## Library
103
104 ### Usage
105
106 The library provides a C API, but the internals use C++11.
107
108 In order to use the library from an application, the include path should point to
109 `<spirv-dir>/include`, which will enable the application to include the header
110 `<spirv-dir>/include/libspirv/libspirv.h` then linking against the static
111 library in `<spirv-build-dir>/bin/libSPIRV-Tools.a` or
112 `<spirv-build-dir>/bin/SPIRV-Tools.lib`.
113
114 * `SPIRV-Tools` CMake target: Creates the static library:
115   * `<spirv-build-dir>/lib/libSPIRV-Tools.a` on Linux and OS X.
116   * `<spirv-build-dir>/lib/libSPIRV-Tools.lib` on Windows.
117
118 #### Entry points
119
120 The interfaces are still under development, and are expected to change.
121
122 There are three main entry points into the library.
123
124 * `spvTextToBinary`: An assembler, translating text to a binary SPIR-V module.
125 * `spvBinaryToText`: A disassembler, translating a binary SPIR-V module to
126   text.
127 * `spvBinaryParse`: The entry point to a binary parser API.  It issues callbacks
128   for the header and each parsed instruction.  The disassembler is implemented
129   as a client of `spvBinaryParse`.
130 * `spvValidate` implements the validator functionality. *Incomplete*
131
132 ## Command line tools
133
134 ### Assembler tool
135
136 The assembler reads the assembly language text, and emits the binary form.
137
138 The standalone assembler is the exectuable called `spirv-as`, and is located in
139 `<spirv-build-dir>/bin/spirv-as`.  The functionality of the assembler is
140 implemented by the `spvTextToBinary` library function.
141
142 * `spirv-as` - the standalone assembler
143   * `<spirv-dir>/bin/spirv-as`
144
145 Use option `-h` to print help.
146
147 ### Disassembler tool
148
149 The disassembler reads the binary form, and emits assembly language text.
150
151 The standalone disassembler is the executable called `spirv-dis`, and is located in
152 `<spirv-build-dir>/bin/spirv-dis`. The functionality of the disassembler is
153 implemented by the `spvBinaryToText` library function.
154
155 * `spirv-dis` - the standalone disassembler
156   * `<spirv-dir>/bin/spirv-dis`
157
158 Use option `-h` to print help.
159
160 The output includes syntax colouring when printing to the standard output stream,
161 on Linux, Windows, and OS X.
162
163 ### Validator tool
164
165 *Warning:* This functionality is under development, and is incomplete.
166
167 The standalone validator is the executable called `spirv-val`, and is located in
168 `<spirv-build-dir>/bin/spirv-val`. The functionality of the validator is
169 implemented by the `spvValidate` library function.
170
171 The validator operates on the binary form.
172
173 * `spirv-val` - the standalone validator
174   * `<spirv-dir>/bin/spirv-val`
175
176 ### UnitSPIRV tool
177
178 The `<spirv-build-dir>/bin/UnitSPIRV` executable runs the project tests.
179 It supports the standard `googletest` command line options.
180
181 ## Future Work
182 <a name="future"></a>
183
184 ### Assembler and disassembler
185
186 * Support 16-bit floating point literals.
187 * The disassembler could emit helpful annotations in comments.  For example:
188   * Use variable name information from debug instructions to annotate
189     key operations on variables.
190   * Show control flow information by annotating `OpLabel` instructions with
191     that basic block's predecessors.
192 * Error messages could be improved.
193
194 ### Validator
195
196 This is a work in progress.
197
198 ## Licence
199 <a name="license"></a>
200 ```
201 Copyright (c) 2015 The Khronos Group Inc.
202
203 Permission is hereby granted, free of charge, to any person obtaining a
204 copy of this software and/or associated documentation files (the
205 "Materials"), to deal in the Materials without restriction, including
206 without limitation the rights to use, copy, modify, merge, publish,
207 distribute, sublicense, and/or sell copies of the Materials, and to
208 permit persons to whom the Materials are furnished to do so, subject to
209 the following conditions:
210
211 The above copyright notice and this permission notice shall be included
212 in all copies or substantial portions of the Materials.
213
214 MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
215 KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
216 SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
217    https://www.khronos.org/registry/
218
219 THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
220 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
221 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
222 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
223 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
224 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
225 MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
226 ```