• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPIR-V Tools
2
3## Overview
4
5The SPIR-V Tools project provides an API and commands for processing SPIR-V
6modules.
7
8The project includes an assembler, binary module parser, disassembler,
9validator, and optimizer for SPIR-V. Except for the optimizer, all are based
10on a common static library.  The library contains all of the implementation
11details, and is used in the standalone tools whilst also enabling integration
12into other code bases directly. The optimizer implementation resides in its
13own library, which depends on the core library.
14
15The interfaces have stabilized:
16We don't anticipate making a breaking change for existing features.
17
18SPIR-V is defined by the Khronos Group Inc.
19See the [SPIR-V Registry][spirv-registry] for the SPIR-V specification,
20headers, and XML registry.
21
22## Downloads
23
24<img alt="Linux" src="kokoro/img/linux.png" width="20px" height="20px" hspace="2px"/>[![Linux Build Status](https://storage.googleapis.com/spirv-tools/badges/build_status_linux_clang_release.svg)](https://storage.googleapis.com/spirv-tools/badges/build_link_linux_clang_release.html)
25<img alt="MacOS" src="kokoro/img/macos.png" width="20px" height="20px" hspace="2px"/>[![MacOS Build Status](https://storage.googleapis.com/spirv-tools/badges/build_status_macos_clang_release.svg)](https://storage.googleapis.com/spirv-tools/badges/build_link_macos_clang_release.html)
26<img alt="Windows" src="kokoro/img/windows.png" width="20px" height="20px" hspace="2px"/>[![Windows Build Status](https://storage.googleapis.com/spirv-tools/badges/build_status_windows_release.svg)](https://storage.googleapis.com/spirv-tools/badges/build_link_windows_vs2017_release.html)
27
28[More downloads](docs/downloads.md)
29
30## Versioning SPIRV-Tools
31
32See [`CHANGES`](CHANGES) for a high level summary of recent changes, by version.
33
34SPIRV-Tools project version numbers are of the form `v`*year*`.`*index* and with
35an optional `-dev` suffix to indicate work in progress.  For example, the
36following versions are ordered from oldest to newest:
37
38* `v2016.0`
39* `v2016.1-dev`
40* `v2016.1`
41* `v2016.2-dev`
42* `v2016.2`
43
44Use the `--version` option on each command line tool to see the software
45version.  An API call reports the software version as a C-style string.
46
47## Releases
48
49Some versions of SPIRV-Tools are tagged as stable releases (see
50[tags](https://github.com/KhronosGroup/SPIRV-Tools/tags) on github).
51These versions undergo extra testing.
52Releases are not directly related to releases (or versions) of
53[SPIRV-Headers][spirv-headers].
54Releases of SPIRV-Tools are tested against the version of SPIRV-Headers listed
55in the [DEPS](DEPS) file.
56The release generally uses the most recent compatible version of SPIRV-Headers
57available at the time of release.
58No version of SPIRV-Headers other than the one listed in the DEPS file is
59guaranteed to work with the SPIRV-Tools release.
60
61## Supported features
62
63### Assembler, binary parser, and disassembler
64
65* Support for SPIR-V 1.0, through 1.5
66  * Based on SPIR-V syntax described by JSON grammar files in the
67    [SPIRV-Headers](https://github.com/KhronosGroup/SPIRV-Headers) repository.
68  * Usually, support for a new version of SPIR-V is ready within days after
69    publication.
70* Support for extended instruction sets:
71  * GLSL std450 version 1.0 Rev 3
72  * OpenCL version 1.0 Rev 2
73* Assembler only does basic syntax checking.  No cross validation of
74  IDs or types is performed, except to check literal arguments to
75  `OpConstant`, `OpSpecConstant`, and `OpSwitch`.
76
77See [`docs/syntax.md`](docs/syntax.md) for the assembly language syntax.
78
79### Validator
80
81The validator checks validation rules described by the SPIR-V specification.
82
83Khronos recommends that tools that create or transform SPIR-V modules use the
84validator to ensure their outputs are valid, and that tools that consume SPIR-V
85modules optionally use the validator to protect themselves from bad inputs.
86This is especially encouraged for debug and development scenarios.
87
88The validator has one-sided error: it will only return an error when it has
89implemented a rule check and the module violates that rule.
90
91The validator is incomplete.
92See the [CHANGES](CHANGES) file for reports on completed work, and
93the [Validator
94sub-project](https://github.com/KhronosGroup/SPIRV-Tools/projects/1) for planned
95and in-progress work.
96
97*Note*: The validator checks some Universal Limits, from section 2.17 of the SPIR-V spec.
98The validator will fail on a module that exceeds those minimum upper bound limits.
99It is [future work](https://github.com/KhronosGroup/SPIRV-Tools/projects/1#card-1052403)
100to parameterize the validator to allow larger
101limits accepted by a more than minimally capable SPIR-V consumer.
102
103
104### Optimizer
105
106The optimizer is a collection of code transforms, or "passes".
107Transforms are written for a diverse set of reasons:
108
109* To restructure, simplify, or normalize the code for further processing.
110* To eliminate undesirable code.
111* To improve code quality in some metric such as size or performance.
112  **Note**: These transforms are not guaranteed to actually improve any
113  given metric. Users should always measure results for their own situation.
114
115As of this writing, there are 67 transforms including examples such as:
116* Simplification
117  * Strip debug info
118  * Strip reflection info
119* Specialization Constants
120  * Set spec constant default value
121  * Freeze spec constant to default value
122  * Fold `OpSpecConstantOp` and `OpSpecConstantComposite`
123  * Unify constants
124  * Eliminate dead constant
125* Code Reduction
126  * Inline all function calls exhaustively
127  * Convert local access chains to inserts/extracts
128  * Eliminate local load/store in single block
129  * Eliminate local load/store with single store
130  * Eliminate local load/store with multiple stores
131  * Eliminate local extract from insert
132  * Eliminate dead instructions (aggressive)
133  * Eliminate dead branches
134  * Merge single successor / single predecessor block pairs
135  * Eliminate common uniform loads
136  * Remove duplicates: Capabilities, extended instruction imports, types, and
137    decorations.
138* Normalization
139  * Compact IDs
140  * CFG cleanup
141  * Flatten decorations
142  * Merge returns
143  * Convert AMD-specific instructions to KHR instructions
144* Code improvement
145  * Conditional constant propagation
146  * If-conversion
147  * Loop fission
148  * Loop fusion
149  * Loop-invariant code motion
150  * Loop unroll
151* Other
152  * Graphics robust access
153  * Upgrade memory model to VulkanKHR
154
155Additionally, certain sets of transformations have been packaged into
156higher-level recipes.  These include:
157
158* Optimization for size (`spirv-opt -Os`)
159* Optimization for performance (`spirv-opt -O`)
160
161For the latest list with detailed documentation, please refer to
162[`include/spirv-tools/optimizer.hpp`](include/spirv-tools/optimizer.hpp).
163
164For suggestions on using the code reduction options, please refer to this [white paper](https://www.lunarg.com/shader-compiler-technologies/white-paper-spirv-opt/).
165
166
167### Linker
168
169*Note:* The linker is still under development.
170
171Current features:
172* Combine multiple SPIR-V binary modules together.
173* Combine into a library (exports are retained) or an executable (no symbols
174  are exported).
175
176See the [CHANGES](CHANGES) file for reports on completed work, and the [General
177sub-project](https://github.com/KhronosGroup/SPIRV-Tools/projects/2) for
178planned and in-progress work.
179
180
181### Reducer
182
183*Note:* The reducer is still under development.
184
185The reducer simplifies and shrinks a SPIR-V module with respect to a
186user-supplied *interestingness function*.  For example, given a large
187SPIR-V module that cause some SPIR-V compiler to fail with a given
188fatal error message, the reducer could be used to look for a smaller
189version of the module that causes the compiler to fail with the same
190fatal error message.
191
192To suggest an additional capability for the reducer, [file an
193issue](https://github.com/KhronosGroup/SPIRV-Tools/issues]) with
194"Reducer:" as the start of its title.
195
196
197### Fuzzer
198
199*Note:* The fuzzer is still under development.
200
201The fuzzer applies semantics-preserving transformations to a SPIR-V binary
202module, to produce an equivalent module.  The original and transformed modules
203should produce essentially identical results when executed on identical inputs:
204their results should differ only due to floating-point round-off, if at all.
205Significant differences in results can pinpoint bugs in tools that process
206SPIR-V binaries, such as miscompilations.  This *metamorphic testing* approach
207is similar to the method used by the [GraphicsFuzz
208project](https://github.com/google/graphicsfuzz) for fuzzing of GLSL shaders.
209
210To suggest an additional capability for the fuzzer, [file an
211issue](https://github.com/KhronosGroup/SPIRV-Tools/issues]) with
212"Fuzzer:" as the start of its title.
213
214
215### Extras
216
217* [Utility filters](#utility-filters)
218* Build target `spirv-tools-vimsyntax` generates file `spvasm.vim`.
219  Copy that file into your `$HOME/.vim/syntax` directory to get SPIR-V assembly syntax
220  highlighting in Vim.  This build target is not built by default.
221
222## Contributing
223
224The SPIR-V Tools project is maintained by members of the The Khronos Group Inc.,
225and is hosted at https://github.com/KhronosGroup/SPIRV-Tools.
226
227Consider joining the `public_spirv_tools_dev@khronos.org` mailing list, via
228[https://www.khronos.org/spir/spirv-tools-mailing-list/](https://www.khronos.org/spir/spirv-tools-mailing-list/).
229The mailing list is used to discuss development plans for the SPIRV-Tools as an open source project.
230Once discussion is resolved,
231specific work is tracked via issues and sometimes in one of the
232[projects][spirv-tools-projects].
233
234(To provide feedback on the SPIR-V _specification_, file an issue on the
235[SPIRV-Headers][spirv-headers] GitHub repository.)
236
237See [`docs/projects.md`](docs/projects.md) to see how we use the
238[GitHub Project
239feature](https://help.github.com/articles/tracking-the-progress-of-your-work-with-projects/)
240to organize planned and in-progress work.
241
242Contributions via merge request are welcome. Changes should:
243* Be provided under the [Apache 2.0](#license).
244* You'll be prompted with a one-time "click-through"
245  [Khronos Open Source Contributor License Agreement][spirv-tools-cla]
246  (CLA) dialog as part of submitting your pull request or
247  other contribution to GitHub.
248* Include tests to cover updated functionality.
249* C++ code should follow the [Google C++ Style Guide][cpp-style-guide].
250* Code should be formatted with `clang-format`.
251  [kokoro/check-format/build.sh](kokoro/check-format/build.sh)
252  shows how to download it. Note that we currently use
253  `clang-format version 5.0.0` for SPIRV-Tools. Settings are defined by
254  the included [.clang-format](.clang-format) file.
255
256We intend to maintain a linear history on the GitHub `master` branch.
257
258### Getting the source
259
260Example of getting sources, assuming SPIRV-Tools is configured as a standalone project:
261
262    git clone https://github.com/KhronosGroup/SPIRV-Tools.git   spirv-tools
263    cd spirv-tools
264
265    # Check out sources for dependencies, at versions known to work together,
266    # as listed in the DEPS file.
267    python3 utils/git-sync-deps
268
269For some kinds of development, you may need the latest sources from the third-party projects:
270
271    git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-tools/external/spirv-headers
272    git clone https://github.com/google/googletest.git          spirv-tools/external/googletest
273    git clone https://github.com/google/effcee.git              spirv-tools/external/effcee
274    git clone https://github.com/google/re2.git                 spirv-tools/external/re2
275
276#### Dependency on Effcee
277
278Some tests depend on the [Effcee][effcee] library for stateful matching.
279Effcee itself depends on [RE2][re2].
280
281* If SPIRV-Tools is configured as part of a larger project that already uses
282  Effcee, then that project should include Effcee before SPIRV-Tools.
283* Otherwise, SPIRV-Tools expects Effcee sources to appear in `external/effcee`
284  and RE2 sources to appear in `external/re2`.
285
286### Source code organization
287
288* `example`: demo code of using SPIRV-Tools APIs
289* `external/googletest`: Intended location for the
290  [googletest][googletest] sources, not provided
291* `external/effcee`: Location of [Effcee][effcee] sources, if the `effcee` library
292  is not already configured by an enclosing project.
293* `external/re2`: Location of [RE2][re2] sources, if the `re2` library is not already
294  configured by an enclosing project.
295  (The Effcee project already requires RE2.)
296* `include/`: API clients should add this directory to the include search path
297* `external/spirv-headers`: Intended location for
298  [SPIR-V headers][spirv-headers], not provided
299* `include/spirv-tools/libspirv.h`: C API public interface
300* `source/`: API implementation
301* `test/`: Tests, using the [googletest][googletest] framework
302* `tools/`: Command line executables
303
304### Tests
305
306The project contains a number of tests, used to drive development
307and ensure correctness.  The tests are written using the
308[googletest][googletest] framework.  The `googletest`
309source is not provided with this project.  There are two ways to enable
310tests:
311* If SPIR-V Tools is configured as part of an enclosing project, then the
312  enclosing project should configure `googletest` before configuring SPIR-V Tools.
313* If SPIR-V Tools is configured as a standalone project, then download the
314  `googletest` source into the `<spirv-dir>/external/googletest` directory before
315  configuring and building the project.
316
317## Build
318
319*Note*: Prebuilt binaries are available from the [downloads](docs/downloads.md) page.
320
321First [get the sources](#getting-the-source).
322Then build using CMake, Bazel, Android ndk-build, or the Emscripten SDK.
323
324### Build using CMake
325You can build the project using [CMake][cmake]:
326
327```sh
328cd <spirv-dir>
329mkdir build && cd build
330cmake [-G <platform-generator>] <spirv-dir>
331```
332
333Once the build files have been generated, build using the appropriate build
334command (e.g. `ninja`, `make`, `msbuild`, etc.; this depends on the platform
335generator used above), or use your IDE, or use CMake to run the appropriate build
336command for you:
337
338```sh
339cmake --build . [--config Debug]  # runs `make` or `ninja` or `msbuild` etc.
340```
341
342#### Note about the fuzzer
343
344The SPIR-V fuzzer, `spirv-fuzz`, can only be built via CMake, and is disabled by
345default. To build it, clone protobuf and use the `SPIRV_BUILD_FUZZER` CMake
346option, like so:
347
348```sh
349# In <spirv-dir> (the SPIRV-Tools repo root):
350git clone --depth=1 --branch v3.13.0.1 https://github.com/protocolbuffers/protobuf external/protobuf
351
352# In your build directory:
353cmake [-G <platform-generator>] <spirv-dir> -DSPIRV_BUILD_FUZZER=ON
354cmake --build . --config Debug
355```
356
357You can also add `-DSPIRV_ENABLE_LONG_FUZZER_TESTS=ON` to build additional
358fuzzer tests.
359
360
361### Build using Bazel
362You can also use [Bazel](https://bazel.build/) to build the project.
363```sh
364cd <spirv-dir>
365bazel build :all
366```
367### Build a node.js package using Emscripten
368
369The SPIRV-Tools core library can be built to a WebAssembly [node.js](https://nodejs.org)
370module. The resulting `SpirvTools` WebAssembly module only exports methods to
371assemble and disassemble SPIR-V modules.
372
373First, make sure you have the [Emscripten SDK](https://emscripten.org).
374Then:
375
376```sh
377cd <spirv-dir>
378./source/wasm/build.sh
379```
380
381The resulting node package, with JavaScript and TypeScript bindings, is
382written to `<spirv-dir>/out/web`.
383
384Note: This builds the package locally. It does *not* publish it to [npm](https://npmjs.org).
385
386To test the result:
387
388```sh
389node ./test/wasm/test.js
390```
391
392### Tools you'll need
393
394For building and testing SPIRV-Tools, the following tools should be
395installed regardless of your OS:
396
397- [CMake](http://www.cmake.org/): if using CMake for generating compilation
398targets, you need to install CMake Version 2.8.12 or later.
399- [Python 3](http://www.python.org/): for utility scripts and running the test
400suite.
401- [Bazel](https://bazel.build/) (optional): if building the source with Bazel,
402you need to install Bazel Version 0.29.1 on your machine. Other versions may
403also work, but are not verified.
404- [Emscripten SDK](https://emscripten.org) (optional): if building the
405  WebAssembly module.
406
407SPIRV-Tools is regularly tested with the following compilers:
408
409On Linux
410- GCC version 9.3
411- Clang version 10.0
412
413On MacOS
414- AppleClang 11.0
415
416On Windows
417- Visual Studio 2015
418- Visual Studio 2017
419
420Other compilers or later versions may work, but they are not tested.
421
422### CMake options
423
424The following CMake options are supported:
425
426* `SPIRV_BUILD_FUZZER={ON|OFF}`, default `OFF` - Build the spirv-fuzz tool.
427* `SPIRV_COLOR_TERMINAL={ON|OFF}`, default `ON` - Enables color console output.
428* `SPIRV_SKIP_TESTS={ON|OFF}`, default `OFF`- Build only the library and
429  the command line tools.  This will prevent the tests from being built.
430* `SPIRV_SKIP_EXECUTABLES={ON|OFF}`, default `OFF`- Build only the library, not
431  the command line tools and tests.
432* `SPIRV_USE_SANITIZER=<sanitizer>`, default is no sanitizing - On UNIX
433  platforms with an appropriate version of `clang` this option enables the use
434  of the sanitizers documented [here][clang-sanitizers].
435  This should only be used with a debug build.
436* `SPIRV_WARN_EVERYTHING={ON|OFF}`, default `OFF` - On UNIX platforms enable
437  more strict warnings.  The code might not compile with this option enabled.
438  For Clang, enables `-Weverything`.  For GCC, enables `-Wpedantic`.
439  See [`CMakeLists.txt`](CMakeLists.txt) for details.
440* `SPIRV_WERROR={ON|OFF}`, default `ON` - Forces a compilation error on any
441  warnings encountered by enabling the compiler-specific compiler front-end
442  option.  No compiler front-end options are enabled when this option is OFF.
443
444Additionally, you can pass additional C preprocessor definitions to SPIRV-Tools
445via setting `SPIRV_TOOLS_EXTRA_DEFINITIONS`. For example, by setting it to
446`/D_ITERATOR_DEBUG_LEVEL=0` on Windows, you can disable checked iterators and
447iterator debugging.
448
449### Android ndk-build
450
451SPIR-V Tools supports building static libraries `libSPIRV-Tools.a` and
452`libSPIRV-Tools-opt.a` for Android:
453
454```
455cd <spirv-dir>
456
457export ANDROID_NDK=/path/to/your/ndk
458
459mkdir build && cd build
460mkdir libs
461mkdir app
462
463$ANDROID_NDK/ndk-build -C ../android_test     \
464                      NDK_PROJECT_PATH=.      \
465                      NDK_LIBS_OUT=`pwd`/libs \
466                      NDK_APP_OUT=`pwd`/app
467```
468
469### Updating DEPS
470
471Occasionally the entries in [DEPS](DEPS) will need to be updated. This is done on
472demand when there is a request to do this, often due to downstream breakages.
473To update `DEPS`, run `utils/roll_deps.sh` and confirm that tests pass.
474The script requires Chromium's
475[`depot_tools`](https://chromium.googlesource.com/chromium/tools/depot_tools).
476
477## Library
478
479### Usage
480
481The internals of the library use C++11 features, and are exposed via both a C
482and C++ API.
483
484In order to use the library from an application, the include path should point
485to `<spirv-dir>/include`, which will enable the application to include the
486header `<spirv-dir>/include/spirv-tools/libspirv.h{|pp}` then linking against
487the static library in `<spirv-build-dir>/source/libSPIRV-Tools.a` or
488`<spirv-build-dir>/source/SPIRV-Tools.lib`.
489For optimization, the header file is
490`<spirv-dir>/include/spirv-tools/optimizer.hpp`, and the static library is
491`<spirv-build-dir>/source/libSPIRV-Tools-opt.a` or
492`<spirv-build-dir>/source/SPIRV-Tools-opt.lib`.
493
494* `SPIRV-Tools` CMake target: Creates the static library:
495  * `<spirv-build-dir>/source/libSPIRV-Tools.a` on Linux and OS X.
496  * `<spirv-build-dir>/source/libSPIRV-Tools.lib` on Windows.
497* `SPIRV-Tools-opt` CMake target: Creates the static library:
498  * `<spirv-build-dir>/source/libSPIRV-Tools-opt.a` on Linux and OS X.
499  * `<spirv-build-dir>/source/libSPIRV-Tools-opt.lib` on Windows.
500
501#### Entry points
502
503The interfaces are still under development, and are expected to change.
504
505There are five main entry points into the library in the C interface:
506
507* `spvTextToBinary`: An assembler, translating text to a binary SPIR-V module.
508* `spvBinaryToText`: A disassembler, translating a binary SPIR-V module to
509  text.
510* `spvBinaryParse`: The entry point to a binary parser API.  It issues callbacks
511  for the header and each parsed instruction.  The disassembler is implemented
512  as a client of `spvBinaryParse`.
513* `spvValidate` implements the validator functionality. *Incomplete*
514* `spvValidateBinary` implements the validator functionality. *Incomplete*
515
516The C++ interface is comprised of three classes, `SpirvTools`, `Optimizer` and
517`Linker`, all in the `spvtools` namespace.
518* `SpirvTools` provides `Assemble`, `Disassemble`, and `Validate` methods.
519* `Optimizer` provides methods for registering and running optimization passes.
520* `Linker` provides methods for combining together multiple binaries.
521
522## Command line tools
523
524Command line tools, which wrap the above library functions, are provided to
525assemble or disassemble shader files.  It's a convention to name SPIR-V
526assembly and binary files with suffix `.spvasm` and `.spv`, respectively.
527
528### Assembler tool
529
530The assembler reads the assembly language text, and emits the binary form.
531
532The standalone assembler is the executable called `spirv-as`, and is located in
533`<spirv-build-dir>/tools/spirv-as`.  The functionality of the assembler is implemented
534by the `spvTextToBinary` library function.
535
536* `spirv-as` - the standalone assembler
537  * `<spirv-dir>/tools/as`
538
539Use option `-h` to print help.
540
541### Disassembler tool
542
543The disassembler reads the binary form, and emits assembly language text.
544
545The standalone disassembler is the executable called `spirv-dis`, and is located in
546`<spirv-build-dir>/tools/spirv-dis`. The functionality of the disassembler is implemented
547by the `spvBinaryToText` library function.
548
549* `spirv-dis` - the standalone disassembler
550  * `<spirv-dir>/tools/dis`
551
552Use option `-h` to print help.
553
554The output includes syntax colouring when printing to the standard output stream,
555on Linux, Windows, and OS X.
556
557### Linker tool
558
559The linker combines multiple SPIR-V binary modules together, resulting in a single
560binary module as output.
561
562This is a work in progress.
563The linker does not support OpenCL program linking options related to math
564flags. (See section 5.6.5.2 in OpenCL 1.2)
565
566* `spirv-link` - the standalone linker
567  * `<spirv-dir>/tools/link`
568
569### Optimizer tool
570
571The optimizer processes a SPIR-V binary module, applying transformations
572in the specified order.
573
574This is a work in progress, with initially only few available transformations.
575
576* `spirv-opt` - the standalone optimizer
577  * `<spirv-dir>/tools/opt`
578
579### Validator tool
580
581*Warning:* This functionality is under development, and is incomplete.
582
583The standalone validator is the executable called `spirv-val`, and is located in
584`<spirv-build-dir>/tools/spirv-val`. The functionality of the validator is implemented
585by the `spvValidate` library function.
586
587The validator operates on the binary form.
588
589* `spirv-val` - the standalone validator
590  * `<spirv-dir>/tools/val`
591
592### Reducer tool
593
594The reducer shrinks a SPIR-V binary module, guided by a user-supplied
595*interestingness test*.
596
597This is a work in progress, with initially only shrinks a module in a few ways.
598
599* `spirv-reduce` - the standalone reducer
600  * `<spirv-dir>/tools/reduce`
601
602Run `spirv-reduce --help` to see how to specify interestingness.
603
604### Fuzzer tool
605
606The fuzzer transforms a SPIR-V binary module into a semantically-equivalent
607SPIR-V binary module by applying transformations in a randomized fashion.
608
609This is a work in progress, with initially only a few semantics-preserving
610transformations.
611
612* `spirv-fuzz` - the standalone fuzzer
613  * `<spirv-dir>/tools/fuzz`
614
615Run `spirv-fuzz --help` for a detailed list of options.
616
617### Control flow dumper tool
618
619The control flow dumper prints the control flow graph for a SPIR-V module as a
620[GraphViz](http://www.graphviz.org/) graph.
621
622This is experimental.
623
624* `spirv-cfg` - the control flow graph dumper
625  * `<spirv-dir>/tools/cfg`
626
627### Utility filters
628
629* `spirv-lesspipe.sh` - Automatically disassembles `.spv` binary files for the
630  `less` program, on compatible systems.  For example, set the `LESSOPEN`
631  environment variable as follows, assuming both `spirv-lesspipe.sh` and
632  `spirv-dis` are on your executable search path:
633  ```
634   export LESSOPEN='| spirv-lesspipe.sh "%s"'
635  ```
636  Then you page through a disassembled module as follows:
637  ```
638  less foo.spv
639  ```
640  * The `spirv-lesspipe.sh` script will pass through any extra arguments to
641    `spirv-dis`.  So, for example, you can turn off colours and friendly ID
642    naming as follows:
643    ```
644    export LESSOPEN='| spirv-lesspipe.sh "%s" --no-color --raw-id'
645    ```
646
647* [vim-spirv](https://github.com/kbenzie/vim-spirv) - A vim plugin which
648  supports automatic disassembly of `.spv` files using the `:edit` command and
649  assembly using the `:write` command. The plugin also provides additional
650  features which include; syntax highlighting; highlighting of all ID's matching
651  the ID under the cursor; and highlighting errors where the `Instruction`
652  operand of `OpExtInst` is used without an appropriate `OpExtInstImport`.
653
654* `50spirv-tools.el` - Automatically disassembles '.spv' binary files when
655  loaded into the emacs text editor, and re-assembles them when saved,
656  provided any modifications to the file are valid.  This functionality
657  must be explicitly requested by defining the symbol
658  SPIRV_TOOLS_INSTALL_EMACS_HELPERS as follows:
659  ```
660  cmake -DSPIRV_TOOLS_INSTALL_EMACS_HELPERS=true ...
661  ```
662
663  In addition, this helper is only installed if the directory /etc/emacs/site-start.d
664  exists, which is typically true if emacs is installed on the system.
665
666  Note that symbol IDs are not currently preserved through a load/edit/save operation.
667  This may change if the ability is added to spirv-as.
668
669
670### Tests
671
672Tests are only built when googletest is found.
673
674#### Running test with CMake
675
676Use `ctest -j <num threads>` to run all the tests. To run tests using all threads:
677```shell
678ctest -j$(nproc)
679```
680
681To run a single test target, use `ctest [-j <N>] -R <test regex>`. For example,
682you can run all `opt` tests with:
683```shell
684ctest -R 'spirv-tools-test_opt'
685```
686
687#### Running test with Bazel
688
689Use `bazel test :all` to run all tests. This will run tests in parallel by default.
690
691To run a single test target, specify `:my_test_target` instead of `:all`. Test target
692names get printed when you run `bazel test :all`. For example, you can run
693`opt_def_use_test` with:
694```shell
695bazel test :opt_def_use_test
696```
697
698
699## Future Work
700<a name="future"></a>
701
702_See the [projects pages](https://github.com/KhronosGroup/SPIRV-Tools/projects)
703for more information._
704
705### Assembler and disassembler
706
707* The disassembler could emit helpful annotations in comments.  For example:
708  * Use variable name information from debug instructions to annotate
709    key operations on variables.
710  * Show control flow information by annotating `OpLabel` instructions with
711    that basic block's predecessors.
712* Error messages could be improved.
713
714### Validator
715
716This is a work in progress.
717
718### Linker
719
720* The linker could accept math transformations such as allowing MADs, or other
721  math flags passed at linking-time in OpenCL.
722* Linkage attributes can not be applied through a group.
723* Check decorations of linked functions attributes.
724* Remove dead instructions, such as OpName targeting imported symbols.
725
726## Licence
727<a name="license"></a>
728Full license terms are in [LICENSE](LICENSE)
729```
730Copyright (c) 2015-2016 The Khronos Group Inc.
731
732Licensed under the Apache License, Version 2.0 (the "License");
733you may not use this file except in compliance with the License.
734You may obtain a copy of the License at
735
736    http://www.apache.org/licenses/LICENSE-2.0
737
738Unless required by applicable law or agreed to in writing, software
739distributed under the License is distributed on an "AS IS" BASIS,
740WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
741See the License for the specific language governing permissions and
742limitations under the License.
743```
744
745[spirv-tools-cla]: https://cla-assistant.io/KhronosGroup/SPIRV-Tools
746[spirv-tools-projects]: https://github.com/KhronosGroup/SPIRV-Tools/projects
747[spirv-tools-mailing-list]: https://www.khronos.org/spir/spirv-tools-mailing-list
748[spirv-registry]: https://www.khronos.org/registry/spir-v/
749[spirv-headers]: https://github.com/KhronosGroup/SPIRV-Headers
750[googletest]: https://github.com/google/googletest
751[googletest-pull-612]: https://github.com/google/googletest/pull/612
752[googletest-issue-610]: https://github.com/google/googletest/issues/610
753[effcee]: https://github.com/google/effcee
754[re2]: https://github.com/google/re2
755[CMake]: https://cmake.org/
756[cpp-style-guide]: https://google.github.io/styleguide/cppguide.html
757[clang-sanitizers]: http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation
758