2 [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/KhronosGroup/SPIRV-Tools/badge)](https://securityscorecards.dev/viewer/?uri=github.com/KhronosGroup/SPIRV-Tools)
4 NEWS 2023-01-11: Development occurs on the `main` branch.
8 The SPIR-V Tools project provides an API and commands for processing SPIR-V
11 The project includes an assembler, binary module parser, disassembler,
12 validator, and optimizer for SPIR-V. Except for the optimizer, all are based
13 on a common static library. The library contains all of the implementation
14 details, and is used in the standalone tools whilst also enabling integration
15 into other code bases directly. The optimizer implementation resides in its
16 own library, which depends on the core library.
18 The interfaces have stabilized:
19 We don't anticipate making a breaking change for existing features.
21 SPIR-V is defined by the Khronos Group Inc.
22 See the [SPIR-V Registry][spirv-registry] for the SPIR-V specification,
23 headers, and XML registry.
27 The official releases for SPIRV-Tools can be found on LunarG's
28 [SDK download page](https://vulkan.lunarg.com/sdk/home).
30 For convenience, here are also links to the latest builds (HEAD).
31 Those are untested automated builds. Those are not official releases, nor
32 are guaranteed to work. Official releases builds are in the Vulkan SDK.
34 <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)
35 <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)
36 <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_vs2022_release.svg)](https://storage.googleapis.com/spirv-tools/badges/build_link_windows_vs2022_release.html)
38 [More downloads](docs/downloads.md)
40 ## Versioning SPIRV-Tools
42 See [`CHANGES`](CHANGES) for a high level summary of recent changes, by version.
44 SPIRV-Tools project version numbers are of the form `v`*year*`.`*index* and with
45 an optional `-dev` suffix to indicate work in progress. For example, the
46 following versions are ordered from oldest to newest:
54 Use the `--version` option on each command line tool to see the software
55 version. An API call reports the software version as a C-style string.
59 The official releases for SPIRV-Tools can be found on LunarG's
60 [SDK download page](https://vulkan.lunarg.com/sdk/home).
62 You can find either the prebuilt, and QA tested binaries, or download the
63 SDK Config, which lists the commits to use to build the release from scratch.
65 GitHub releases are deprecated, and we will not publish new releases until
70 ### Assembler, binary parser, and disassembler
72 * Support for SPIR-V 1.0, through 1.5
73 * Based on SPIR-V syntax described by JSON grammar files in the
74 [SPIRV-Headers](https://github.com/KhronosGroup/SPIRV-Headers) repository.
75 * Usually, support for a new version of SPIR-V is ready within days after
77 * Support for extended instruction sets:
78 * GLSL std450 version 1.0 Rev 3
79 * OpenCL version 1.0 Rev 2
80 * Assembler only does basic syntax checking. No cross validation of
81 IDs or types is performed, except to check literal arguments to
82 `OpConstant`, `OpSpecConstant`, and `OpSwitch`.
83 * Where tools expect binary input, a hex stream may be provided instead. See
86 See [`docs/syntax.md`](docs/syntax.md) for the assembly language syntax.
90 The validator checks validation rules described by the SPIR-V specification.
92 Khronos recommends that tools that create or transform SPIR-V modules use the
93 validator to ensure their outputs are valid, and that tools that consume SPIR-V
94 modules optionally use the validator to protect themselves from bad inputs.
95 This is especially encouraged for debug and development scenarios.
97 The validator has one-sided error: it will only return an error when it has
98 implemented a rule check and the module violates that rule.
100 The validator is incomplete.
101 See the [CHANGES](CHANGES) file for reports on completed work, and
103 sub-project](https://github.com/KhronosGroup/SPIRV-Tools/projects/1) for planned
104 and in-progress work.
106 *Note*: The validator checks some Universal Limits, from section 2.17 of the SPIR-V spec.
107 The validator will fail on a module that exceeds those minimum upper bound limits.
108 The validator has been parameterized to allow larger values, for use when targeting
109 a more-than-minimally-capable SPIR-V consumer.
111 See [`tools/val/val.cpp`](tools/val/val.cpp) or run `spirv-val --help` for the command-line help.
115 The optimizer is a collection of code transforms, or "passes".
116 Transforms are written for a diverse set of reasons:
118 * To restructure, simplify, or normalize the code for further processing.
119 * To eliminate undesirable code.
120 * To improve code quality in some metric such as size or performance.
121 **Note**: These transforms are not guaranteed to actually improve any
122 given metric. Users should always measure results for their own situation.
124 As of this writing, there are 67 transforms including examples such as:
127 * Strip reflection info
128 * Specialization Constants
129 * Set spec constant default value
130 * Freeze spec constant to default value
131 * Fold `OpSpecConstantOp` and `OpSpecConstantComposite`
133 * Eliminate dead constant
135 * Inline all function calls exhaustively
136 * Convert local access chains to inserts/extracts
137 * Eliminate local load/store in single block
138 * Eliminate local load/store with single store
139 * Eliminate local load/store with multiple stores
140 * Eliminate local extract from insert
141 * Eliminate dead instructions (aggressive)
142 * Eliminate dead branches
143 * Merge single successor / single predecessor block pairs
144 * Eliminate common uniform loads
145 * Remove duplicates: Capabilities, extended instruction imports, types, and
150 * Flatten decorations
152 * Convert AMD-specific instructions to KHR instructions
154 * Conditional constant propagation
158 * Loop-invariant code motion
161 * Graphics robust access
162 * Upgrade memory model to VulkanKHR
164 Additionally, certain sets of transformations have been packaged into
165 higher-level recipes. These include:
167 * Optimization for size (`spirv-opt -Os`)
168 * Optimization for performance (`spirv-opt -O`)
170 For the latest list with detailed documentation, please refer to
171 [`include/spirv-tools/optimizer.hpp`](include/spirv-tools/optimizer.hpp).
173 For suggestions on using the code reduction options, please refer to this [white paper](https://www.lunarg.com/shader-compiler-technologies/white-paper-spirv-opt/).
178 *Note:* The linker is still under development.
181 * Combine multiple SPIR-V binary modules together.
182 * Combine into a library (exports are retained) or an executable (no symbols
185 See the [CHANGES](CHANGES) file for reports on completed work, and the [General
186 sub-project](https://github.com/KhronosGroup/SPIRV-Tools/projects/2) for
187 planned and in-progress work.
192 *Note:* The reducer is still under development.
194 The reducer simplifies and shrinks a SPIR-V module with respect to a
195 user-supplied *interestingness function*. For example, given a large
196 SPIR-V module that cause some SPIR-V compiler to fail with a given
197 fatal error message, the reducer could be used to look for a smaller
198 version of the module that causes the compiler to fail with the same
201 To suggest an additional capability for the reducer, [file an
202 issue](https://github.com/KhronosGroup/SPIRV-Tools/issues]) with
203 "Reducer:" as the start of its title.
208 *Note:* The fuzzer is still under development.
210 The fuzzer applies semantics-preserving transformations to a SPIR-V binary
211 module, to produce an equivalent module. The original and transformed modules
212 should produce essentially identical results when executed on identical inputs:
213 their results should differ only due to floating-point round-off, if at all.
214 Significant differences in results can pinpoint bugs in tools that process
215 SPIR-V binaries, such as miscompilations. This *metamorphic testing* approach
216 is similar to the method used by the [GraphicsFuzz
217 project](https://github.com/google/graphicsfuzz) for fuzzing of GLSL shaders.
219 To suggest an additional capability for the fuzzer, [file an
220 issue](https://github.com/KhronosGroup/SPIRV-Tools/issues]) with
221 "Fuzzer:" as the start of its title.
226 *Note:* The diff tool is still under development.
228 The diff tool takes two SPIR-V files, either in binary or text format and
229 produces a diff-style comparison between the two. The instructions between the
230 src and dst modules are matched as best as the tool can, and output is produced
231 (in src id-space) that shows which instructions are removed in src, added in dst
232 or modified between them. The order of instructions are not retained.
234 Matching instructions between two SPIR-V modules is not trivial, and thus a
235 number of heuristics are applied in this tool. In particular, without debug
236 information, match functions is nontrivial as they can be reordered. As such,
237 this tool is primarily useful to produce the diff of two SPIR-V modules derived
238 from the same source, for example before and after a modification to the shader,
239 before and after a transformation, or SPIR-V produced from different tools.
244 * [Utility filters](#utility-filters)
245 * Build target `spirv-tools-vimsyntax` generates file `spvasm.vim`.
246 Copy that file into your `$HOME/.vim/syntax` directory to get SPIR-V assembly syntax
247 highlighting in Vim. This build target is not built by default.
251 The SPIR-V Tools project is maintained by members of the The Khronos Group Inc.,
252 and is hosted at https://github.com/KhronosGroup/SPIRV-Tools.
254 Consider joining the `public_spirv_tools_dev@khronos.org` mailing list, via
255 [https://www.khronos.org/spir/spirv-tools-mailing-list/](https://www.khronos.org/spir/spirv-tools-mailing-list/).
256 The mailing list is used to discuss development plans for the SPIRV-Tools as an open source project.
257 Once discussion is resolved,
258 specific work is tracked via issues and sometimes in one of the
259 [projects][spirv-tools-projects].
261 (To provide feedback on the SPIR-V _specification_, file an issue on the
262 [SPIRV-Headers][spirv-headers] GitHub repository.)
264 See [`docs/projects.md`](docs/projects.md) to see how we use the
266 feature](https://help.github.com/articles/tracking-the-progress-of-your-work-with-projects/)
267 to organize planned and in-progress work.
269 Contributions via merge request are welcome. Changes should:
270 * Be provided under the [Apache 2.0](#license).
271 * You'll be prompted with a one-time "click-through"
272 [Khronos Open Source Contributor License Agreement][spirv-tools-cla]
273 (CLA) dialog as part of submitting your pull request or
274 other contribution to GitHub.
275 * Include tests to cover updated functionality.
276 * C++ code should follow the [Google C++ Style Guide][cpp-style-guide].
277 * Code should be formatted with `clang-format`.
278 [kokoro/check-format/build.sh](kokoro/check-format/build.sh)
279 shows how to download it. Note that we currently use
280 `clang-format version 5.0.0` for SPIRV-Tools. Settings are defined by
281 the included [.clang-format](.clang-format) file.
283 We intend to maintain a linear history on the GitHub `main` branch.
285 ### Getting the source
287 Example of getting sources, assuming SPIRV-Tools is configured as a standalone project:
289 git clone https://github.com/KhronosGroup/SPIRV-Tools.git spirv-tools
292 # Check out sources for dependencies, at versions known to work together,
293 # as listed in the DEPS file.
294 python3 utils/git-sync-deps
296 For some kinds of development, you may need the latest sources from the third-party projects:
298 git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-tools/external/spirv-headers
299 git clone https://github.com/google/googletest.git spirv-tools/external/googletest
300 git clone https://github.com/google/effcee.git spirv-tools/external/effcee
301 git clone https://github.com/google/re2.git spirv-tools/external/re2
302 git clone https://github.com/abseil/abseil-cpp.git spirv-tools/external/abseil_cpp
304 #### Dependency on Effcee
306 Some tests depend on the [Effcee][effcee] library for stateful matching.
307 Effcee itself depends on [RE2][re2], and RE2 depends on [Abseil][abseil-cpp].
309 * If SPIRV-Tools is configured as part of a larger project that already uses
310 Effcee, then that project should include Effcee before SPIRV-Tools.
311 * Otherwise, SPIRV-Tools expects Effcee sources to appear in `external/effcee`,
312 RE2 sources to appear in `external/re2`, and Abseil sources to appear in
313 `external/abseil_cpp`.
315 ### Source code organization
317 * `example`: demo code of using SPIRV-Tools APIs
318 * `external/googletest`: Intended location for the
319 [googletest][googletest] sources, not provided
320 * `external/effcee`: Location of [Effcee][effcee] sources, if the `effcee` library
321 is not already configured by an enclosing project.
322 * `external/re2`: Location of [RE2][re2] sources, if the `re2` library is not already
323 configured by an enclosing project.
324 (The Effcee project already requires RE2.)
325 * `external/abseil_cpp`: Location of [Abseil][abseil-cpp] sources, if Abseil is
326 not already configured by an enclosing project.
327 (The RE2 project already requires Abseil.)
328 * `include/`: API clients should add this directory to the include search path
329 * `external/spirv-headers`: Intended location for
330 [SPIR-V headers][spirv-headers], not provided
331 * `include/spirv-tools/libspirv.h`: C API public interface
332 * `source/`: API implementation
333 * `test/`: Tests, using the [googletest][googletest] framework
334 * `tools/`: Command line executables
338 The project contains a number of tests, used to drive development
339 and ensure correctness. The tests are written using the
340 [googletest][googletest] framework. The `googletest`
341 source is not provided with this project. There are two ways to enable
343 * If SPIR-V Tools is configured as part of an enclosing project, then the
344 enclosing project should configure `googletest` before configuring SPIR-V Tools.
345 * If SPIR-V Tools is configured as a standalone project, then download the
346 `googletest` source into the `<spirv-dir>/external/googletest` directory before
347 configuring and building the project.
351 *Note*: Prebuilt binaries are available from the [downloads](docs/downloads.md) page.
353 First [get the sources](#getting-the-source).
354 Then build using CMake, Bazel, Android ndk-build, or the Emscripten SDK.
356 ### Build using CMake
357 You can build the project using [CMake][cmake]:
361 mkdir build && cd build
362 cmake [-G <platform-generator>] <spirv-dir>
365 Once the build files have been generated, build using the appropriate build
366 command (e.g. `ninja`, `make`, `msbuild`, etc.; this depends on the platform
367 generator used above), or use your IDE, or use CMake to run the appropriate build
371 cmake --build . [--config Debug] # runs `make` or `ninja` or `msbuild` etc.
374 #### Note about the fuzzer
376 The SPIR-V fuzzer, `spirv-fuzz`, can only be built via CMake, and is disabled by
377 default. To build it, clone protobuf and use the `SPIRV_BUILD_FUZZER` CMake
381 # In <spirv-dir> (the SPIRV-Tools repo root):
382 git clone --depth=1 --branch v3.13.0.1 https://github.com/protocolbuffers/protobuf external/protobuf
384 # In your build directory:
385 cmake [-G <platform-generator>] <spirv-dir> -DSPIRV_BUILD_FUZZER=ON
386 cmake --build . --config Debug
389 You can also add `-DSPIRV_ENABLE_LONG_FUZZER_TESTS=ON` to build additional
393 ### Build using Bazel
394 You can also use [Bazel](https://bazel.build/) to build the project.
400 ### Build a node.js package using Emscripten
402 The SPIRV-Tools core library can be built to a WebAssembly [node.js](https://nodejs.org)
403 module. The resulting `SpirvTools` WebAssembly module only exports methods to
404 assemble and disassemble SPIR-V modules.
406 First, make sure you have the [Emscripten SDK](https://emscripten.org).
411 ./source/wasm/build.sh
414 The resulting node package, with JavaScript and TypeScript bindings, is
415 written to `<spirv-dir>/out/web`.
417 Note: This builds the package locally. It does *not* publish it to [npm](https://npmjs.org).
422 node ./test/wasm/test.js
425 ### Tools you'll need
427 For building and testing SPIRV-Tools, the following tools should be
428 installed regardless of your OS:
430 - [CMake](http://www.cmake.org/): if using CMake for generating compilation
431 targets, you need to install CMake Version 2.8.12 or later.
432 - [Python 3](http://www.python.org/): for utility scripts and running the test
434 - [Bazel](https://bazel.build/) (optional): if building the source with Bazel,
435 you need to install Bazel Version 7.0.2 on your machine. Other versions may
436 also work, but are not verified.
437 - [Emscripten SDK](https://emscripten.org) (optional): if building the
440 SPIRV-Tools is regularly tested with the following compilers:
453 Note: Other compilers or later versions may work, but they are not tested.
457 The following CMake options are supported:
459 * `SPIRV_BUILD_FUZZER={ON|OFF}`, default `OFF` - Build the spirv-fuzz tool.
460 * `SPIRV_COLOR_TERMINAL={ON|OFF}`, default `ON` - Enables color console output.
461 * `SPIRV_SKIP_TESTS={ON|OFF}`, default `OFF`- Build only the library and
462 the command line tools. This will prevent the tests from being built.
463 * `SPIRV_SKIP_EXECUTABLES={ON|OFF}`, default `OFF`- Build only the library, not
464 the command line tools and tests.
465 * `SPIRV_USE_SANITIZER=<sanitizer>`, default is no sanitizing - On UNIX
466 platforms with an appropriate version of `clang` this option enables the use
467 of the sanitizers documented [here][clang-sanitizers].
468 This should only be used with a debug build.
469 * `SPIRV_WARN_EVERYTHING={ON|OFF}`, default `OFF` - On UNIX platforms enable
470 more strict warnings. The code might not compile with this option enabled.
471 For Clang, enables `-Weverything`. For GCC, enables `-Wpedantic`.
472 See [`CMakeLists.txt`](CMakeLists.txt) for details.
473 * `SPIRV_WERROR={ON|OFF}`, default `ON` - Forces a compilation error on any
474 warnings encountered by enabling the compiler-specific compiler front-end
475 option. No compiler front-end options are enabled when this option is OFF.
477 Additionally, you can pass additional C preprocessor definitions to SPIRV-Tools
478 via setting `SPIRV_TOOLS_EXTRA_DEFINITIONS`. For example, by setting it to
479 `/D_ITERATOR_DEBUG_LEVEL=0` on Windows, you can disable checked iterators and
482 ### Android ndk-build
484 SPIR-V Tools supports building static libraries `libSPIRV-Tools.a` and
485 `libSPIRV-Tools-opt.a` for Android. Using the Android NDK r25c or later:
490 export ANDROID_NDK=/path/to/your/ndk # NDK r25c or later
492 mkdir build && cd build
496 $ANDROID_NDK/ndk-build -C ../android_test \
498 NDK_LIBS_OUT=`pwd`/libs \
499 NDK_APP_OUT=`pwd`/app
504 Occasionally the entries in [DEPS](DEPS) will need to be updated. This is done on
505 demand when there is a request to do this, often due to downstream breakages.
506 To update `DEPS`, run `utils/roll_deps.sh` and confirm that tests pass.
507 The script requires Chromium's
508 [`depot_tools`](https://chromium.googlesource.com/chromium/tools/depot_tools).
514 The internals of the library use C++17 features, and are exposed via both a C
517 In order to use the library from an application, the include path should point
518 to `<spirv-dir>/include`, which will enable the application to include the
519 header `<spirv-dir>/include/spirv-tools/libspirv.h{|pp}` then linking against
520 the static library in `<spirv-build-dir>/source/libSPIRV-Tools.a` or
521 `<spirv-build-dir>/source/SPIRV-Tools.lib`.
522 For optimization, the header file is
523 `<spirv-dir>/include/spirv-tools/optimizer.hpp`, and the static library is
524 `<spirv-build-dir>/source/libSPIRV-Tools-opt.a` or
525 `<spirv-build-dir>/source/SPIRV-Tools-opt.lib`.
527 * `SPIRV-Tools` CMake target: Creates the static library:
528 * `<spirv-build-dir>/source/libSPIRV-Tools.a` on Linux and OS X.
529 * `<spirv-build-dir>/source/libSPIRV-Tools.lib` on Windows.
530 * `SPIRV-Tools-opt` CMake target: Creates the static library:
531 * `<spirv-build-dir>/source/libSPIRV-Tools-opt.a` on Linux and OS X.
532 * `<spirv-build-dir>/source/libSPIRV-Tools-opt.lib` on Windows.
536 The interfaces are still under development, and are expected to change.
538 There are five main entry points into the library in the C interface:
540 * `spvTextToBinary`: An assembler, translating text to a binary SPIR-V module.
541 * `spvBinaryToText`: A disassembler, translating a binary SPIR-V module to
543 * `spvBinaryParse`: The entry point to a binary parser API. It issues callbacks
544 for the header and each parsed instruction. The disassembler is implemented
545 as a client of `spvBinaryParse`.
546 * `spvValidate` implements the validator functionality. *Incomplete*
547 * `spvValidateBinary` implements the validator functionality. *Incomplete*
549 The C++ interface is comprised of three classes, `SpirvTools`, `Optimizer` and
550 `Linker`, all in the `spvtools` namespace.
551 * `SpirvTools` provides `Assemble`, `Disassemble`, and `Validate` methods.
552 * `Optimizer` provides methods for registering and running optimization passes.
553 * `Linker` provides methods for combining together multiple binaries.
555 ## Command line tools
557 Command line tools, which wrap the above library functions, are provided to
558 assemble or disassemble shader files. It's a convention to name SPIR-V
559 assembly and binary files with suffix `.spvasm` and `.spv`, respectively.
563 The assembler reads the assembly language text, and emits the binary form.
565 The standalone assembler is the executable called `spirv-as`, and is located in
566 `<spirv-build-dir>/tools/spirv-as`. The functionality of the assembler is implemented
567 by the `spvTextToBinary` library function.
569 * `spirv-as` - the standalone assembler
570 * `<spirv-dir>/tools/as`
572 Use option `-h` to print help.
574 ### Disassembler tool
576 The disassembler reads the binary form, and emits assembly language text.
578 The standalone disassembler is the executable called `spirv-dis`, and is located in
579 `<spirv-build-dir>/tools/spirv-dis`. The functionality of the disassembler is implemented
580 by the `spvBinaryToText` library function.
582 * `spirv-dis` - the standalone disassembler
583 * `<spirv-dir>/tools/dis`
585 Use option `-h` to print help.
587 The output includes syntax colouring when printing to the standard output stream,
588 on Linux, Windows, and OS X.
592 The linker combines multiple SPIR-V binary modules together, resulting in a single
593 binary module as output.
595 This is a work in progress.
596 The linker does not support OpenCL program linking options related to math
597 flags. (See section 5.6.5.2 in OpenCL 1.2)
599 * `spirv-link` - the standalone linker
600 * `<spirv-dir>/tools/link`
604 The optimizer processes a SPIR-V binary module, applying transformations
605 in the specified order.
607 This is a work in progress, with initially only few available transformations.
609 * `spirv-opt` - the standalone optimizer
610 * `<spirv-dir>/tools/opt`
614 *Warning:* This functionality is under development, and is incomplete.
616 The standalone validator is the executable called `spirv-val`, and is located in
617 `<spirv-build-dir>/tools/spirv-val`. The functionality of the validator is implemented
618 by the `spvValidate` library function.
620 The validator operates on the binary form.
622 * `spirv-val` - the standalone validator
623 * `<spirv-dir>/tools/val`
627 The reducer shrinks a SPIR-V binary module, guided by a user-supplied
628 *interestingness test*.
630 This is a work in progress, with initially only shrinks a module in a few ways.
632 * `spirv-reduce` - the standalone reducer
633 * `<spirv-dir>/tools/reduce`
635 Run `spirv-reduce --help` to see how to specify interestingness.
639 The fuzzer transforms a SPIR-V binary module into a semantically-equivalent
640 SPIR-V binary module by applying transformations in a randomized fashion.
642 This is a work in progress, with initially only a few semantics-preserving
645 * `spirv-fuzz` - the standalone fuzzer
646 * `<spirv-dir>/tools/fuzz`
648 Run `spirv-fuzz --help` for a detailed list of options.
650 ### Control flow dumper tool
652 The control flow dumper prints the control flow graph for a SPIR-V module as a
653 [GraphViz](http://www.graphviz.org/) graph.
655 This is experimental.
657 * `spirv-cfg` - the control flow graph dumper
658 * `<spirv-dir>/tools/cfg`
662 *Warning:* This functionality is under development, and is incomplete.
664 The diff tool produces a diff-style comparison between two SPIR-V modules.
666 * `spirv-diff` - the standalone diff tool
667 * `<spirv-dir>`/tools/diff`
671 * `spirv-lesspipe.sh` - Automatically disassembles `.spv` binary files for the
672 `less` program, on compatible systems. For example, set the `LESSOPEN`
673 environment variable as follows, assuming both `spirv-lesspipe.sh` and
674 `spirv-dis` are on your executable search path:
676 export LESSOPEN='| spirv-lesspipe.sh "%s"'
678 Then you page through a disassembled module as follows:
682 * The `spirv-lesspipe.sh` script will pass through any extra arguments to
683 `spirv-dis`. So, for example, you can turn off colours and friendly ID
686 export LESSOPEN='| spirv-lesspipe.sh "%s" --no-color --raw-id'
689 * [vim-spirv](https://github.com/kbenzie/vim-spirv) - A vim plugin which
690 supports automatic disassembly of `.spv` files using the `:edit` command and
691 assembly using the `:write` command. The plugin also provides additional
692 features which include; syntax highlighting; highlighting of all ID's matching
693 the ID under the cursor; and highlighting errors where the `Instruction`
694 operand of `OpExtInst` is used without an appropriate `OpExtInstImport`.
696 * `50spirv-tools.el` - Automatically disassembles '.spv' binary files when
697 loaded into the emacs text editor, and re-assembles them when saved,
698 provided any modifications to the file are valid. This functionality
699 must be explicitly requested by defining the symbol
700 SPIRV_TOOLS_INSTALL_EMACS_HELPERS as follows:
702 cmake -DSPIRV_TOOLS_INSTALL_EMACS_HELPERS=true ...
705 In addition, this helper is only installed if the directory /etc/emacs/site-start.d
706 exists, which is typically true if emacs is installed on the system.
708 Note that symbol IDs are not currently preserved through a load/edit/save operation.
709 This may change if the ability is added to spirv-as.
714 Tests are only built when googletest is found.
716 #### Running test with CMake
718 Use `ctest -j <num threads>` to run all the tests. To run tests using all threads:
723 To run a single test target, use `ctest [-j <N>] -R <test regex>`. For example,
724 you can run all `opt` tests with:
726 ctest -R 'spirv-tools-test_opt'
729 #### Running test with Bazel
731 Use `bazel test :all` to run all tests. This will run tests in parallel by default.
733 To run a single test target, specify `:my_test_target` instead of `:all`. Test target
734 names get printed when you run `bazel test :all`. For example, you can run
735 `opt_def_use_test` with:
739 bazel test --cxxopt=-std=c++17 :opt_def_use_test
744 bazel test --cxxopt=/std:c++17 :opt_def_use_test
748 <a name="future"></a>
750 _See the [projects pages](https://github.com/KhronosGroup/SPIRV-Tools/projects)
751 for more information._
753 ### Assembler and disassembler
755 * The disassembler could emit helpful annotations in comments. For example:
756 * Use variable name information from debug instructions to annotate
757 key operations on variables.
758 * Show control flow information by annotating `OpLabel` instructions with
759 that basic block's predecessors.
760 * Error messages could be improved.
764 This is a work in progress.
768 * The linker could accept math transformations such as allowing MADs, or other
769 math flags passed at linking-time in OpenCL.
770 * Linkage attributes can not be applied through a group.
771 * Check decorations of linked functions attributes.
772 * Remove dead instructions, such as OpName targeting imported symbols.
775 <a name="license"></a>
776 Full license terms are in [LICENSE](LICENSE)
778 Copyright (c) 2015-2016 The Khronos Group Inc.
780 Licensed under the Apache License, Version 2.0 (the "License");
781 you may not use this file except in compliance with the License.
782 You may obtain a copy of the License at
784 http://www.apache.org/licenses/LICENSE-2.0
786 Unless required by applicable law or agreed to in writing, software
787 distributed under the License is distributed on an "AS IS" BASIS,
788 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
789 See the License for the specific language governing permissions and
790 limitations under the License.
793 [spirv-tools-cla]: https://cla-assistant.io/KhronosGroup/SPIRV-Tools
794 [spirv-tools-projects]: https://github.com/KhronosGroup/SPIRV-Tools/projects
795 [spirv-tools-mailing-list]: https://www.khronos.org/spir/spirv-tools-mailing-list
796 [spirv-registry]: https://www.khronos.org/registry/spir-v/
797 [spirv-headers]: https://github.com/KhronosGroup/SPIRV-Headers
798 [googletest]: https://github.com/google/googletest
799 [googletest-pull-612]: https://github.com/google/googletest/pull/612
800 [googletest-issue-610]: https://github.com/google/googletest/issues/610
801 [effcee]: https://github.com/google/effcee
802 [re2]: https://github.com/google/re2
803 [abseil-cpp]: https://github.com/abseil/abseil-cpp
804 [CMake]: https://cmake.org/
805 [cpp-style-guide]: https://google.github.io/styleguide/cppguide.html
806 [clang-sanitizers]: http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation