{"id":13732372,"url":"https://github.com/KhronosGroup/SPIRV-Tools","last_synced_at":"2025-05-08T06:32:13.875Z","repository":{"id":37465126,"uuid":"45981801","full_name":"KhronosGroup/SPIRV-Tools","owner":"KhronosGroup","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-30T02:26:38.000Z","size":26632,"stargazers_count":1078,"open_issues_count":407,"forks_count":555,"subscribers_count":86,"default_branch":"main","last_synced_at":"2024-10-30T05:00:39.942Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KhronosGroup.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-11T12:56:25.000Z","updated_at":"2024-10-28T17:33:31.000Z","dependencies_parsed_at":"2023-10-15T04:08:16.840Z","dependency_job_id":"eac4c68f-52b5-43e3-8eeb-f254ccb84a53","html_url":"https://github.com/KhronosGroup/SPIRV-Tools","commit_stats":{"total_commits":3952,"total_committers":277,"mean_commits":"14.267148014440433","dds":0.840587044534413,"last_synced_commit":"4a2e0c9b3663d1bacc91821ae5699965bff4e5e9"},"previous_names":[],"tags_count":78,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhronosGroup%2FSPIRV-Tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhronosGroup%2FSPIRV-Tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhronosGroup%2FSPIRV-Tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhronosGroup%2FSPIRV-Tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KhronosGroup","download_url":"https://codeload.github.com/KhronosGroup/SPIRV-Tools/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224708220,"owners_count":17356502,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T02:01:54.712Z","updated_at":"2024-11-14T23:32:15.095Z","avatar_url":"https://github.com/KhronosGroup.png","language":"C++","readme":"# SPIR-V Tools\n[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/KhronosGroup/SPIRV-Tools/badge)](https://securityscorecards.dev/viewer/?uri=github.com/KhronosGroup/SPIRV-Tools)\n\nNEWS 2023-01-11: Development occurs on the `main` branch.\n\n## Overview\n\nThe SPIR-V Tools project provides an API and commands for processing SPIR-V\nmodules.\n\nThe project includes an assembler, binary module parser, disassembler,\nvalidator, and optimizer for SPIR-V. Except for the optimizer, all are based\non a common static library.  The library contains all of the implementation\ndetails, and is used in the standalone tools whilst also enabling integration\ninto other code bases directly. The optimizer implementation resides in its\nown library, which depends on the core library.\n\nThe interfaces have stabilized:\nWe don't anticipate making a breaking change for existing features.\n\nSPIR-V is defined by the Khronos Group Inc.\nSee the [SPIR-V Registry][spirv-registry] for the SPIR-V specification,\nheaders, and XML registry.\n\n## Downloads\n\nThe official releases for SPIRV-Tools can be found on LunarG's\n[SDK download page](https://vulkan.lunarg.com/sdk/home).\n\nFor convenience, here are also links to the latest builds (HEAD).\nThose are untested automated builds. Those are not official releases, nor\nare guaranteed to work. Official releases builds are in the Vulkan SDK.\n\n\u003cimg alt=\"Linux\" src=\"kokoro/img/linux.png\" width=\"20px\" height=\"20px\" hspace=\"2px\"/\u003e[![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)\n\u003cimg alt=\"MacOS\" src=\"kokoro/img/macos.png\" width=\"20px\" height=\"20px\" hspace=\"2px\"/\u003e[![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)\n\u003cimg alt=\"Windows\" src=\"kokoro/img/windows.png\" width=\"20px\" height=\"20px\" hspace=\"2px\"/\u003e[![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_vs2019_release.html)\n\n[More downloads](docs/downloads.md)\n\n## Versioning SPIRV-Tools\n\nSee [`CHANGES`](CHANGES) for a high level summary of recent changes, by version.\n\nSPIRV-Tools project version numbers are of the form `v`*year*`.`*index* and with\nan optional `-dev` suffix to indicate work in progress.  For example, the\nfollowing versions are ordered from oldest to newest:\n\n* `v2016.0`\n* `v2016.1-dev`\n* `v2016.1`\n* `v2016.2-dev`\n* `v2016.2`\n\nUse the `--version` option on each command line tool to see the software\nversion.  An API call reports the software version as a C-style string.\n\n## Releases\n\nThe official releases for SPIRV-Tools can be found on LunarG's\n[SDK download page](https://vulkan.lunarg.com/sdk/home).\n\nYou can find either the prebuilt, and QA tested binaries, or download the\nSDK Config, which lists the commits to use to build the release from scratch.\n\nGitHub releases are deprecated, and we will not publish new releases until\nfurther notice.\n\n## Supported features\n\n### Assembler, binary parser, and disassembler\n\n* Support for SPIR-V 1.0, through 1.5\n  * Based on SPIR-V syntax described by JSON grammar files in the\n    [SPIRV-Headers](https://github.com/KhronosGroup/SPIRV-Headers) repository.\n  * Usually, support for a new version of SPIR-V is ready within days after\n    publication.\n* Support for extended instruction sets:\n  * GLSL std450 version 1.0 Rev 3\n  * OpenCL version 1.0 Rev 2\n* Assembler only does basic syntax checking.  No cross validation of\n  IDs or types is performed, except to check literal arguments to\n  `OpConstant`, `OpSpecConstant`, and `OpSwitch`.\n* Where tools expect binary input, a hex stream may be provided instead.  See\n  `spirv-dis --help`.\n\nSee [`docs/syntax.md`](docs/syntax.md) for the assembly language syntax.\n\n### Validator\n\nThe validator checks validation rules described by the SPIR-V specification.\n\nKhronos recommends that tools that create or transform SPIR-V modules use the\nvalidator to ensure their outputs are valid, and that tools that consume SPIR-V\nmodules optionally use the validator to protect themselves from bad inputs.\nThis is especially encouraged for debug and development scenarios.\n\nThe validator has one-sided error: it will only return an error when it has\nimplemented a rule check and the module violates that rule.\n\nThe validator is incomplete.\nSee the [CHANGES](CHANGES) file for reports on completed work, and\nthe [Validator\nsub-project](https://github.com/KhronosGroup/SPIRV-Tools/projects/1) for planned\nand in-progress work.\n\n*Note*: The validator checks some Universal Limits, from section 2.17 of the SPIR-V spec.\nThe validator will fail on a module that exceeds those minimum upper bound limits.\nThe validator has been parameterized to allow larger values, for use when targeting \na more-than-minimally-capable SPIR-V consumer.\n\nSee [`tools/val/val.cpp`](tools/val/val.cpp) or run `spirv-val --help` for the command-line help.\n\n### Optimizer\n\nThe optimizer is a collection of code transforms, or \"passes\".\nTransforms are written for a diverse set of reasons:\n\n* To restructure, simplify, or normalize the code for further processing.\n* To eliminate undesirable code.\n* To improve code quality in some metric such as size or performance.\n  **Note**: These transforms are not guaranteed to actually improve any\n  given metric. Users should always measure results for their own situation.\n\nAs of this writing, there are 67 transforms including examples such as:\n* Simplification\n  * Strip debug info\n  * Strip reflection info\n* Specialization Constants\n  * Set spec constant default value\n  * Freeze spec constant to default value\n  * Fold `OpSpecConstantOp` and `OpSpecConstantComposite`\n  * Unify constants\n  * Eliminate dead constant\n* Code Reduction\n  * Inline all function calls exhaustively\n  * Convert local access chains to inserts/extracts\n  * Eliminate local load/store in single block\n  * Eliminate local load/store with single store\n  * Eliminate local load/store with multiple stores\n  * Eliminate local extract from insert\n  * Eliminate dead instructions (aggressive)\n  * Eliminate dead branches\n  * Merge single successor / single predecessor block pairs\n  * Eliminate common uniform loads\n  * Remove duplicates: Capabilities, extended instruction imports, types, and\n    decorations.\n* Normalization\n  * Compact IDs\n  * CFG cleanup\n  * Flatten decorations\n  * Merge returns\n  * Convert AMD-specific instructions to KHR instructions\n* Code improvement\n  * Conditional constant propagation\n  * If-conversion\n  * Loop fission\n  * Loop fusion\n  * Loop-invariant code motion\n  * Loop unroll\n* Other\n  * Graphics robust access\n  * Upgrade memory model to VulkanKHR\n\nAdditionally, certain sets of transformations have been packaged into\nhigher-level recipes.  These include:\n\n* Optimization for size (`spirv-opt -Os`)\n* Optimization for performance (`spirv-opt -O`)\n\nFor the latest list with detailed documentation, please refer to\n[`include/spirv-tools/optimizer.hpp`](include/spirv-tools/optimizer.hpp).\n\nFor suggestions on using the code reduction options, please refer to this [white paper](https://www.lunarg.com/shader-compiler-technologies/white-paper-spirv-opt/).\n\n\n### Linker\n\n*Note:* The linker is still under development.\n\nCurrent features:\n* Combine multiple SPIR-V binary modules together.\n* Combine into a library (exports are retained) or an executable (no symbols\n  are exported).\n\nSee the [CHANGES](CHANGES) file for reports on completed work, and the [General\nsub-project](https://github.com/KhronosGroup/SPIRV-Tools/projects/2) for\nplanned and in-progress work.\n\n\n### Reducer\n\n*Note:* The reducer is still under development.\n\nThe reducer simplifies and shrinks a SPIR-V module with respect to a\nuser-supplied *interestingness function*.  For example, given a large\nSPIR-V module that cause some SPIR-V compiler to fail with a given\nfatal error message, the reducer could be used to look for a smaller\nversion of the module that causes the compiler to fail with the same\nfatal error message.\n\nTo suggest an additional capability for the reducer, [file an\nissue](https://github.com/KhronosGroup/SPIRV-Tools/issues]) with\n\"Reducer:\" as the start of its title.\n\n\n### Fuzzer\n\n*Note:* The fuzzer is still under development.\n\nThe fuzzer applies semantics-preserving transformations to a SPIR-V binary\nmodule, to produce an equivalent module.  The original and transformed modules\nshould produce essentially identical results when executed on identical inputs:\ntheir results should differ only due to floating-point round-off, if at all.\nSignificant differences in results can pinpoint bugs in tools that process\nSPIR-V binaries, such as miscompilations.  This *metamorphic testing* approach\nis similar to the method used by the [GraphicsFuzz\nproject](https://github.com/google/graphicsfuzz) for fuzzing of GLSL shaders.\n\nTo suggest an additional capability for the fuzzer, [file an\nissue](https://github.com/KhronosGroup/SPIRV-Tools/issues]) with\n\"Fuzzer:\" as the start of its title.\n\n\n### Diff\n\n*Note:* The diff tool is still under development.\n\nThe diff tool takes two SPIR-V files, either in binary or text format and\nproduces a diff-style comparison between the two.  The instructions between the\nsrc and dst modules are matched as best as the tool can, and output is produced\n(in src id-space) that shows which instructions are removed in src, added in dst\nor modified between them.  The order of instructions are not retained.\n\nMatching instructions between two SPIR-V modules is not trivial, and thus a\nnumber of heuristics are applied in this tool.  In particular, without debug\ninformation, match functions is nontrivial as they can be reordered.  As such,\nthis tool is primarily useful to produce the diff of two SPIR-V modules derived\nfrom the same source, for example before and after a modification to the shader,\nbefore and after a transformation, or SPIR-V produced from different tools.\n\n\n### Extras\n\n* [Utility filters](#utility-filters)\n* Build target `spirv-tools-vimsyntax` generates file `spvasm.vim`.\n  Copy that file into your `$HOME/.vim/syntax` directory to get SPIR-V assembly syntax\n  highlighting in Vim.  This build target is not built by default.\n\n## Contributing\n\nThe SPIR-V Tools project is maintained by members of the The Khronos Group Inc.,\nand is hosted at https://github.com/KhronosGroup/SPIRV-Tools.\n\nConsider joining the `public_spirv_tools_dev@khronos.org` mailing list, via\n[https://www.khronos.org/spir/spirv-tools-mailing-list/](https://www.khronos.org/spir/spirv-tools-mailing-list/).\nThe mailing list is used to discuss development plans for the SPIRV-Tools as an open source project.\nOnce discussion is resolved,\nspecific work is tracked via issues and sometimes in one of the\n[projects][spirv-tools-projects].\n\n(To provide feedback on the SPIR-V _specification_, file an issue on the\n[SPIRV-Headers][spirv-headers] GitHub repository.)\n\nSee [`docs/projects.md`](docs/projects.md) to see how we use the\n[GitHub Project\nfeature](https://help.github.com/articles/tracking-the-progress-of-your-work-with-projects/)\nto organize planned and in-progress work.\n\nContributions via merge request are welcome. Changes should:\n* Be provided under the [Apache 2.0](#license).\n* You'll be prompted with a one-time \"click-through\"\n  [Khronos Open Source Contributor License Agreement][spirv-tools-cla]\n  (CLA) dialog as part of submitting your pull request or\n  other contribution to GitHub.\n* Include tests to cover updated functionality.\n* C++ code should follow the [Google C++ Style Guide][cpp-style-guide].\n* Code should be formatted with `clang-format`.\n  [kokoro/check-format/build.sh](kokoro/check-format/build.sh)\n  shows how to download it. Note that we currently use\n  `clang-format version 5.0.0` for SPIRV-Tools. Settings are defined by\n  the included [.clang-format](.clang-format) file.\n\nWe intend to maintain a linear history on the GitHub `main` branch.\n\n### Getting the source\n\nExample of getting sources, assuming SPIRV-Tools is configured as a standalone project:\n\n    git clone https://github.com/KhronosGroup/SPIRV-Tools.git   spirv-tools\n    cd spirv-tools\n\n    # Check out sources for dependencies, at versions known to work together,\n    # as listed in the DEPS file.\n    python3 utils/git-sync-deps\n\nFor some kinds of development, you may need the latest sources from the third-party projects:\n\n    git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-tools/external/spirv-headers\n    git clone https://github.com/google/googletest.git          spirv-tools/external/googletest\n    git clone https://github.com/google/effcee.git              spirv-tools/external/effcee\n    git clone https://github.com/google/re2.git                 spirv-tools/external/re2\n    git clone https://github.com/abseil/abseil-cpp.git          spirv-tools/external/abseil_cpp\n\n#### Dependency on Effcee\n\nSome tests depend on the [Effcee][effcee] library for stateful matching.\nEffcee itself depends on [RE2][re2], and RE2 depends on [Abseil][abseil-cpp].\n\n* If SPIRV-Tools is configured as part of a larger project that already uses\n  Effcee, then that project should include Effcee before SPIRV-Tools.\n* Otherwise, SPIRV-Tools expects Effcee sources to appear in `external/effcee`,\n  RE2 sources to appear in `external/re2`, and Abseil sources to appear in \n  `external/abseil_cpp`.\n\n### Source code organization\n\n* `example`: demo code of using SPIRV-Tools APIs\n* `external/googletest`: Intended location for the\n  [googletest][googletest] sources, not provided\n* `external/effcee`: Location of [Effcee][effcee] sources, if the `effcee` library\n  is not already configured by an enclosing project.\n* `external/re2`: Location of [RE2][re2] sources, if the `re2` library is not already\n  configured by an enclosing project.\n  (The Effcee project already requires RE2.)\n* `external/abseil_cpp`: Location of [Abseil][abseil-cpp] sources, if Abseil is\n   not already configured by an enclosing project.\n  (The RE2 project already requires Abseil.)\n* `include/`: API clients should add this directory to the include search path\n* `external/spirv-headers`: Intended location for\n  [SPIR-V headers][spirv-headers], not provided\n* `include/spirv-tools/libspirv.h`: C API public interface\n* `source/`: API implementation\n* `test/`: Tests, using the [googletest][googletest] framework\n* `tools/`: Command line executables\n\n### Tests\n\nThe project contains a number of tests, used to drive development\nand ensure correctness.  The tests are written using the\n[googletest][googletest] framework.  The `googletest`\nsource is not provided with this project.  There are two ways to enable\ntests:\n* If SPIR-V Tools is configured as part of an enclosing project, then the\n  enclosing project should configure `googletest` before configuring SPIR-V Tools.\n* If SPIR-V Tools is configured as a standalone project, then download the\n  `googletest` source into the `\u003cspirv-dir\u003e/external/googletest` directory before\n  configuring and building the project.\n\n## Build\n\n*Note*: Prebuilt binaries are available from the [downloads](docs/downloads.md) page.\n\nFirst [get the sources](#getting-the-source).\nThen build using CMake, Bazel, Android ndk-build, or the Emscripten SDK.\n\n### Build using CMake\nYou can build the project using [CMake][cmake]:\n\n```sh\ncd \u003cspirv-dir\u003e\nmkdir build \u0026\u0026 cd build\ncmake [-G \u003cplatform-generator\u003e] \u003cspirv-dir\u003e\n```\n\nOnce the build files have been generated, build using the appropriate build\ncommand (e.g. `ninja`, `make`, `msbuild`, etc.; this depends on the platform\ngenerator used above), or use your IDE, or use CMake to run the appropriate build\ncommand for you:\n\n```sh\ncmake --build . [--config Debug]  # runs `make` or `ninja` or `msbuild` etc.\n```\n\n#### Note about the fuzzer\n\nThe SPIR-V fuzzer, `spirv-fuzz`, can only be built via CMake, and is disabled by\ndefault. To build it, clone protobuf and use the `SPIRV_BUILD_FUZZER` CMake\noption, like so:\n\n```sh\n# In \u003cspirv-dir\u003e (the SPIRV-Tools repo root):\ngit clone --depth=1 --branch v3.13.0.1 https://github.com/protocolbuffers/protobuf external/protobuf\n\n# In your build directory:\ncmake [-G \u003cplatform-generator\u003e] \u003cspirv-dir\u003e -DSPIRV_BUILD_FUZZER=ON\ncmake --build . --config Debug\n```\n\nYou can also add `-DSPIRV_ENABLE_LONG_FUZZER_TESTS=ON` to build additional\nfuzzer tests.\n\n\n### Build using Bazel\nYou can also use [Bazel](https://bazel.build/) to build the project.\n\n```sh\nbazel build :all\n```\n\n### Build a node.js package using Emscripten\n\nThe SPIRV-Tools core library can be built to a WebAssembly [node.js](https://nodejs.org)\nmodule. The resulting `SpirvTools` WebAssembly module only exports methods to\nassemble and disassemble SPIR-V modules.\n\nFirst, make sure you have the [Emscripten SDK](https://emscripten.org).\nThen:\n\n```sh\ncd \u003cspirv-dir\u003e\n./source/wasm/build.sh\n```\n\nThe resulting node package, with JavaScript and TypeScript bindings, is\nwritten to `\u003cspirv-dir\u003e/out/web`.\n\nNote: This builds the package locally. It does *not* publish it to [npm](https://npmjs.org).\n\nTo test the result:\n\n```sh\nnode ./test/wasm/test.js\n```\n\n### Tools you'll need\n\nFor building and testing SPIRV-Tools, the following tools should be\ninstalled regardless of your OS:\n\n- [CMake](http://www.cmake.org/): if using CMake for generating compilation\ntargets, you need to install CMake Version 2.8.12 or later.\n- [Python 3](http://www.python.org/): for utility scripts and running the test\nsuite.\n- [Bazel](https://bazel.build/) (optional): if building the source with Bazel,\nyou need to install Bazel Version 7.0.2 on your machine. Other versions may\nalso work, but are not verified.\n- [Emscripten SDK](https://emscripten.org) (optional): if building the\n  WebAssembly module.\n\nSPIRV-Tools is regularly tested with the following compilers:\n\nOn Linux\n- GCC version 9.3\n- Clang version 10.0\n\nOn MacOS\n- AppleClang 11.0\n\nOn Windows\n- Visual Studio 2017\n- Visual Studio 2019\n- Visual Studio 2022\n\nNote: Visual Studio 2017 has incomplete c++17 support. We might stop\ntesting it soon. Other compilers or later versions may work, but they are not\ntested.\n\n### CMake options\n\nThe following CMake options are supported:\n\n* `SPIRV_BUILD_FUZZER={ON|OFF}`, default `OFF` - Build the spirv-fuzz tool.\n* `SPIRV_COLOR_TERMINAL={ON|OFF}`, default `ON` - Enables color console output.\n* `SPIRV_SKIP_TESTS={ON|OFF}`, default `OFF`- Build only the library and\n  the command line tools.  This will prevent the tests from being built.\n* `SPIRV_SKIP_EXECUTABLES={ON|OFF}`, default `OFF`- Build only the library, not\n  the command line tools and tests.\n* `SPIRV_USE_SANITIZER=\u003csanitizer\u003e`, default is no sanitizing - On UNIX\n  platforms with an appropriate version of `clang` this option enables the use\n  of the sanitizers documented [here][clang-sanitizers].\n  This should only be used with a debug build.\n* `SPIRV_WARN_EVERYTHING={ON|OFF}`, default `OFF` - On UNIX platforms enable\n  more strict warnings.  The code might not compile with this option enabled.\n  For Clang, enables `-Weverything`.  For GCC, enables `-Wpedantic`.\n  See [`CMakeLists.txt`](CMakeLists.txt) for details.\n* `SPIRV_WERROR={ON|OFF}`, default `ON` - Forces a compilation error on any\n  warnings encountered by enabling the compiler-specific compiler front-end\n  option.  No compiler front-end options are enabled when this option is OFF.\n\nAdditionally, you can pass additional C preprocessor definitions to SPIRV-Tools\nvia setting `SPIRV_TOOLS_EXTRA_DEFINITIONS`. For example, by setting it to\n`/D_ITERATOR_DEBUG_LEVEL=0` on Windows, you can disable checked iterators and\niterator debugging.\n\n### Android ndk-build\n\nSPIR-V Tools supports building static libraries `libSPIRV-Tools.a` and\n`libSPIRV-Tools-opt.a` for Android.  Using the Android NDK r25c or later:\n\n```\ncd \u003cspirv-dir\u003e\n\nexport ANDROID_NDK=/path/to/your/ndk   # NDK r25c or later\n\nmkdir build \u0026\u0026 cd build\nmkdir libs\nmkdir app\n\n$ANDROID_NDK/ndk-build -C ../android_test     \\\n                      NDK_PROJECT_PATH=.      \\\n                      NDK_LIBS_OUT=`pwd`/libs \\\n                      NDK_APP_OUT=`pwd`/app\n```\n\n### Updating DEPS\n\nOccasionally the entries in [DEPS](DEPS) will need to be updated. This is done on\ndemand when there is a request to do this, often due to downstream breakages.\nTo update `DEPS`, run `utils/roll_deps.sh` and confirm that tests pass.\nThe script requires Chromium's\n[`depot_tools`](https://chromium.googlesource.com/chromium/tools/depot_tools).\n\n## Library\n\n### Usage\n\nThe internals of the library use C++17 features, and are exposed via both a C\nand C++ API.\n\nIn order to use the library from an application, the include path should point\nto `\u003cspirv-dir\u003e/include`, which will enable the application to include the\nheader `\u003cspirv-dir\u003e/include/spirv-tools/libspirv.h{|pp}` then linking against\nthe static library in `\u003cspirv-build-dir\u003e/source/libSPIRV-Tools.a` or\n`\u003cspirv-build-dir\u003e/source/SPIRV-Tools.lib`.\nFor optimization, the header file is\n`\u003cspirv-dir\u003e/include/spirv-tools/optimizer.hpp`, and the static library is\n`\u003cspirv-build-dir\u003e/source/libSPIRV-Tools-opt.a` or\n`\u003cspirv-build-dir\u003e/source/SPIRV-Tools-opt.lib`.\n\n* `SPIRV-Tools` CMake target: Creates the static library:\n  * `\u003cspirv-build-dir\u003e/source/libSPIRV-Tools.a` on Linux and OS X.\n  * `\u003cspirv-build-dir\u003e/source/libSPIRV-Tools.lib` on Windows.\n* `SPIRV-Tools-opt` CMake target: Creates the static library:\n  * `\u003cspirv-build-dir\u003e/source/libSPIRV-Tools-opt.a` on Linux and OS X.\n  * `\u003cspirv-build-dir\u003e/source/libSPIRV-Tools-opt.lib` on Windows.\n\n#### Entry points\n\nThe interfaces are still under development, and are expected to change.\n\nThere are five main entry points into the library in the C interface:\n\n* `spvTextToBinary`: An assembler, translating text to a binary SPIR-V module.\n* `spvBinaryToText`: A disassembler, translating a binary SPIR-V module to\n  text.\n* `spvBinaryParse`: The entry point to a binary parser API.  It issues callbacks\n  for the header and each parsed instruction.  The disassembler is implemented\n  as a client of `spvBinaryParse`.\n* `spvValidate` implements the validator functionality. *Incomplete*\n* `spvValidateBinary` implements the validator functionality. *Incomplete*\n\nThe C++ interface is comprised of three classes, `SpirvTools`, `Optimizer` and\n`Linker`, all in the `spvtools` namespace.\n* `SpirvTools` provides `Assemble`, `Disassemble`, and `Validate` methods.\n* `Optimizer` provides methods for registering and running optimization passes.\n* `Linker` provides methods for combining together multiple binaries.\n\n## Command line tools\n\nCommand line tools, which wrap the above library functions, are provided to\nassemble or disassemble shader files.  It's a convention to name SPIR-V\nassembly and binary files with suffix `.spvasm` and `.spv`, respectively.\n\n### Assembler tool\n\nThe assembler reads the assembly language text, and emits the binary form.\n\nThe standalone assembler is the executable called `spirv-as`, and is located in\n`\u003cspirv-build-dir\u003e/tools/spirv-as`.  The functionality of the assembler is implemented\nby the `spvTextToBinary` library function.\n\n* `spirv-as` - the standalone assembler\n  * `\u003cspirv-dir\u003e/tools/as`\n\nUse option `-h` to print help.\n\n### Disassembler tool\n\nThe disassembler reads the binary form, and emits assembly language text.\n\nThe standalone disassembler is the executable called `spirv-dis`, and is located in\n`\u003cspirv-build-dir\u003e/tools/spirv-dis`. The functionality of the disassembler is implemented\nby the `spvBinaryToText` library function.\n\n* `spirv-dis` - the standalone disassembler\n  * `\u003cspirv-dir\u003e/tools/dis`\n\nUse option `-h` to print help.\n\nThe output includes syntax colouring when printing to the standard output stream,\non Linux, Windows, and OS X.\n\n### Linker tool\n\nThe linker combines multiple SPIR-V binary modules together, resulting in a single\nbinary module as output.\n\nThis is a work in progress.\nThe linker does not support OpenCL program linking options related to math\nflags. (See section 5.6.5.2 in OpenCL 1.2)\n\n* `spirv-link` - the standalone linker\n  * `\u003cspirv-dir\u003e/tools/link`\n\n### Optimizer tool\n\nThe optimizer processes a SPIR-V binary module, applying transformations\nin the specified order.\n\nThis is a work in progress, with initially only few available transformations.\n\n* `spirv-opt` - the standalone optimizer\n  * `\u003cspirv-dir\u003e/tools/opt`\n\n### Validator tool\n\n*Warning:* This functionality is under development, and is incomplete.\n\nThe standalone validator is the executable called `spirv-val`, and is located in\n`\u003cspirv-build-dir\u003e/tools/spirv-val`. The functionality of the validator is implemented\nby the `spvValidate` library function.\n\nThe validator operates on the binary form.\n\n* `spirv-val` - the standalone validator\n  * `\u003cspirv-dir\u003e/tools/val`\n\n### Reducer tool\n\nThe reducer shrinks a SPIR-V binary module, guided by a user-supplied\n*interestingness test*.\n\nThis is a work in progress, with initially only shrinks a module in a few ways.\n\n* `spirv-reduce` - the standalone reducer\n  * `\u003cspirv-dir\u003e/tools/reduce`\n\nRun `spirv-reduce --help` to see how to specify interestingness.\n\n### Fuzzer tool\n\nThe fuzzer transforms a SPIR-V binary module into a semantically-equivalent\nSPIR-V binary module by applying transformations in a randomized fashion.\n\nThis is a work in progress, with initially only a few semantics-preserving\ntransformations.\n\n* `spirv-fuzz` - the standalone fuzzer\n  * `\u003cspirv-dir\u003e/tools/fuzz`\n\nRun `spirv-fuzz --help` for a detailed list of options.\n\n### Control flow dumper tool\n\nThe control flow dumper prints the control flow graph for a SPIR-V module as a\n[GraphViz](http://www.graphviz.org/) graph.\n\nThis is experimental.\n\n* `spirv-cfg` - the control flow graph dumper\n  * `\u003cspirv-dir\u003e/tools/cfg`\n\n### Diff tool\n\n*Warning:* This functionality is under development, and is incomplete.\n\nThe diff tool produces a diff-style comparison between two SPIR-V modules.\n\n* `spirv-diff` - the standalone diff tool\n  * `\u003cspirv-dir\u003e`/tools/diff`\n\n### Utility filters\n\n* `spirv-lesspipe.sh` - Automatically disassembles `.spv` binary files for the\n  `less` program, on compatible systems.  For example, set the `LESSOPEN`\n  environment variable as follows, assuming both `spirv-lesspipe.sh` and\n  `spirv-dis` are on your executable search path:\n  ```\n   export LESSOPEN='| spirv-lesspipe.sh \"%s\"'\n  ```\n  Then you page through a disassembled module as follows:\n  ```\n  less foo.spv\n  ```\n  * The `spirv-lesspipe.sh` script will pass through any extra arguments to\n    `spirv-dis`.  So, for example, you can turn off colours and friendly ID\n    naming as follows:\n    ```\n    export LESSOPEN='| spirv-lesspipe.sh \"%s\" --no-color --raw-id'\n    ```\n\n* [vim-spirv](https://github.com/kbenzie/vim-spirv) - A vim plugin which\n  supports automatic disassembly of `.spv` files using the `:edit` command and\n  assembly using the `:write` command. The plugin also provides additional\n  features which include; syntax highlighting; highlighting of all ID's matching\n  the ID under the cursor; and highlighting errors where the `Instruction`\n  operand of `OpExtInst` is used without an appropriate `OpExtInstImport`.\n\n* `50spirv-tools.el` - Automatically disassembles '.spv' binary files when\n  loaded into the emacs text editor, and re-assembles them when saved,\n  provided any modifications to the file are valid.  This functionality\n  must be explicitly requested by defining the symbol\n  SPIRV_TOOLS_INSTALL_EMACS_HELPERS as follows:\n  ```\n  cmake -DSPIRV_TOOLS_INSTALL_EMACS_HELPERS=true ...\n  ```\n\n  In addition, this helper is only installed if the directory /etc/emacs/site-start.d\n  exists, which is typically true if emacs is installed on the system.\n\n  Note that symbol IDs are not currently preserved through a load/edit/save operation.\n  This may change if the ability is added to spirv-as.\n\n\n### Tests\n\nTests are only built when googletest is found.\n\n#### Running test with CMake\n\nUse `ctest -j \u003cnum threads\u003e` to run all the tests. To run tests using all threads:\n```shell\nctest -j$(nproc)\n```\n\nTo run a single test target, use `ctest [-j \u003cN\u003e] -R \u003ctest regex\u003e`. For example,\nyou can run all `opt` tests with:\n```shell\nctest -R 'spirv-tools-test_opt'\n```\n\n#### Running test with Bazel\n\nUse `bazel test :all` to run all tests. This will run tests in parallel by default.\n\nTo run a single test target, specify `:my_test_target` instead of `:all`. Test target\nnames get printed when you run `bazel test :all`. For example, you can run\n`opt_def_use_test` with:\n\non linux:\n```shell\nbazel test --cxxopt=-std=c++17 :opt_def_use_test\n```\n\non windows:\n```shell\nbazel test --cxxopt=/std:c++17 :opt_def_use_test\n```\n\n## Future Work\n\u003ca name=\"future\"\u003e\u003c/a\u003e\n\n_See the [projects pages](https://github.com/KhronosGroup/SPIRV-Tools/projects)\nfor more information._\n\n### Assembler and disassembler\n\n* The disassembler could emit helpful annotations in comments.  For example:\n  * Use variable name information from debug instructions to annotate\n    key operations on variables.\n  * Show control flow information by annotating `OpLabel` instructions with\n    that basic block's predecessors.\n* Error messages could be improved.\n\n### Validator\n\nThis is a work in progress.\n\n### Linker\n\n* The linker could accept math transformations such as allowing MADs, or other\n  math flags passed at linking-time in OpenCL.\n* Linkage attributes can not be applied through a group.\n* Check decorations of linked functions attributes.\n* Remove dead instructions, such as OpName targeting imported symbols.\n\n## Licence\n\u003ca name=\"license\"\u003e\u003c/a\u003e\nFull license terms are in [LICENSE](LICENSE)\n```\nCopyright (c) 2015-2016 The Khronos Group Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n\n[spirv-tools-cla]: https://cla-assistant.io/KhronosGroup/SPIRV-Tools\n[spirv-tools-projects]: https://github.com/KhronosGroup/SPIRV-Tools/projects\n[spirv-tools-mailing-list]: https://www.khronos.org/spir/spirv-tools-mailing-list\n[spirv-registry]: https://www.khronos.org/registry/spir-v/\n[spirv-headers]: https://github.com/KhronosGroup/SPIRV-Headers\n[googletest]: https://github.com/google/googletest\n[googletest-pull-612]: https://github.com/google/googletest/pull/612\n[googletest-issue-610]: https://github.com/google/googletest/issues/610\n[effcee]: https://github.com/google/effcee\n[re2]: https://github.com/google/re2\n[abseil-cpp]: https://github.com/abseil/abseil-cpp\n[CMake]: https://cmake.org/\n[cpp-style-guide]: https://google.github.io/styleguide/cppguide.html\n[clang-sanitizers]: http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation\n","funding_links":[],"categories":["Tools"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKhronosGroup%2FSPIRV-Tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKhronosGroup%2FSPIRV-Tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKhronosGroup%2FSPIRV-Tools/lists"}