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