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