spirv-tools: vendor as full-fork recipe (path=source, patches baked)

This commit is contained in:
2026-08-01 04:44:12 +03:00
parent 9695e81f9c
commit f0fa0fd58f
1744 changed files with 714530 additions and 3 deletions
+6 -3
View File
@@ -7,9 +7,12 @@ version = "0.3.1"
description = "SPIR-V Tools (KhronosGroup/SPIRV-Tools) — libSPIRV-Tools assembler/validator/optimizer. Host-built, consumed by Mesa's native mesa_clc/intel_clc."
[source]
git = "https://github.com/KhronosGroup/SPIRV-Tools.git"
branch = "main"
shallow_clone = true
# Vendored local fork (full-fork model): builds from the committed source/
# tree (offline, reproducible). source/ = pristine upstream + the patches below
# BAKED IN. .patch files kept tracked so a version bump can re-apply them via
# sync-recipe-source.sh.
# upstream: https://github.com/KhronosGroup/SPIRV-Tools.git
path = "source"
[build]
template = "custom"
@@ -0,0 +1,7 @@
# Enable Bzlmod for every Bazel command
common --enable_bzlmod
build --enable_platform_specific_config
build:linux --cxxopt=-std=c++17
build:macos --cxxopt=-std=c++17
build:windows --cxxopt=/std:c++17
@@ -0,0 +1 @@
7.4.0
@@ -0,0 +1,6 @@
---
Language: Cpp
BasedOnStyle: Google
DerivePointerAlignment: false
SortIncludes: true
...
@@ -0,0 +1,25 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
groups:
github-actions:
patterns:
- "*"
open-pull-requests-limit: 3
@@ -0,0 +1,59 @@
name: Update dependencies
permissions:
contents: read
on:
schedule:
- cron: '0 2 * * *'
workflow_dispatch:
jobs:
update-dependencies:
if: github.repository == 'KhronosGroup/SPIRV-Tools'
permissions:
contents: write
pull-requests: write
name: Update dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
# Checkout the depot tools they are needed by roll_deps.sh
- name: Checkout depot tools
run: git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git $GITHUB_WORKSPACE/../depot_tools
- name: Update PATH
run: echo "$GITHUB_WORKSPACE/../depot_tools" >> $GITHUB_PATH
- name: Download dependencies
run: python3 utils/git-sync-deps
- name: Setup git user information
run: |
git config user.name "GitHub Actions[bot]"
git config user.email "<>"
git checkout -b roll_deps
- name: Update dependencies
run: |
utils/roll_deps.sh
if [[ `git diff HEAD..origin/main --name-only | wc -l` == 0 ]]; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
id: update_dependencies
- name: Push changes and create PR
if: steps.update_dependencies.outputs.changed == 'true'
run: |
git push --force https://x-access-token:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git roll_deps
# Create a PR. If it aready exists, the command fails, so ignore the return code.
gh pr create --head roll_deps --base main -f || true
# Add the 'kokoro:run' label so that the kokoro tests will be run.
gh pr edit roll_deps --add-label 'kokoro:run'
gh pr merge roll_deps --auto --squash
env:
GITHUB_TOKEN: ${{ github.token }}
@@ -0,0 +1,62 @@
name: Build and Test with Bazel
permissions:
contents: read
on:
push:
branches:
- 'main'
pull_request:
types: [opened, synchronize, reopened, unlabeled]
jobs:
build:
if: github.event.action != 'unlabeled' || github.event.label.name == 'kokoro:run'
timeout-minutes: 120
strategy:
matrix:
os: [ubuntu-latest, windows-2025]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: '0'
persist-credentials: false
- name: Download dependencies
run: python3 utils/git-sync-deps
- name: Mount Bazel cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.bazel/cache
# Force a new cache version by updating the number in 'generationN'
key: bazel-cache-${{ runner.os }}-generation3
- name: Build All
run: bazel --output_user_root=~/.bazel/cache build //...
- name: Test All
run: bazel --output_user_root=~/.bazel/cache test --test_output=errors //...
# iOS is 10x expensive to run on GitHub machines, so only run if we know something else passed
# The steps are unfortunately duplicated because github actions requires 2 jobs for a dependency
build-macos:
needs: build
timeout-minutes: 120
runs-on: macos-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: '0'
persist-credentials: false
- name: Download dependencies
run: python3 utils/git-sync-deps
- name: Mount Bazel cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.bazel/cache
key: bazel-cache-${{ runner.os }}
- name: Build All
run: bazel --output_user_root=~/.bazel/cache build //...
- name: Test All
run: bazel --output_user_root=~/.bazel/cache test --test_output=errors //...
@@ -0,0 +1,35 @@
name: iOS
permissions:
contents: read
on:
workflow_run:
# iOS is 10x expensive to run on GitHub machines, so only run if we know something else passed
workflows: ["Wasm Build"]
types:
- completed
jobs:
build:
runs-on: macos-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- uses: lukka/get-cmake@e6906078ebd1ccb8ce51ab4626ac46a1b5a517e3 # v4.4.0
- name: Download dependencies
run: python3 utils/git-sync-deps
# NOTE: The MacOS SDK ships universal binaries. CI should reflect this.
- name: Configure Universal Binary for iOS
run: |
cmake -S . -B build \
-D CMAKE_BUILD_TYPE=Debug \
-D CMAKE_SYSTEM_NAME=iOS \
"-D CMAKE_OSX_ARCHITECTURES=arm64;x86_64" \
-G Ninja
env:
# Linker warnings as errors
LDFLAGS: -Wl,-fatal_warnings
- run: cmake --build build
- run: cmake --install build --prefix /tmp
@@ -0,0 +1,27 @@
name: Create a release branch from release tag
permissions:
contents: write
on:
push:
tags:
- 'v[0-9]+.[0-9]+'
- 'vulkan-sdk-[0-9]+.[0-9]+.[0-9]+.[0-9]+'
- '!v[0-9]+.[0-9]+.rc*'
jobs:
prepare-release-job:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Prepare CHANGELOG for version
run: |
python utils/generate_changelog.py CHANGES "${GITHUB_REF_NAME}" VERSION_CHANGELOG
- name: Create release
run: |
gh release create -t "Release ${GITHUB_REF_NAME}" -F VERSION_CHANGELOG "${GITHUB_REF_NAME}"
env:
GITHUB_TOKEN: ${{ github.token }}
@@ -0,0 +1,53 @@
name: Scorecard supply-chain security
on:
# For Branch-Protection check. Only the default branch is supported. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
branch_protection_rule:
# To guarantee Maintained check is occasionally updated. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
schedule:
- cron: '36 17 * * 5'
push:
branches: [ "main" ]
# Declare default permissions as read only.
permissions: read-all
jobs:
analysis:
name: Scorecard analysis
runs-on: ubuntu-latest
permissions:
security-events: write # to upload the results to code-scanning dashboard
id-token: write # to publish results and get a badge
steps:
- name: "Checkout code"
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: "Run analysis"
uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
with:
results_file: results.sarif
results_format: sarif
# To enable Branch-Protection uncomment the `repo_token` line below
# To create the Fine-grained PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-fine-grained-pat-optional.
# repo_token: ${{ secrets.SCORECARD_TOKEN }}
publish_results: true # allows the repo to include the Scorecard badge
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: SARIF file
path: results.sarif
retention-days: 5
# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1
with:
sarif_file: results.sarif
@@ -0,0 +1,25 @@
name: Wasm Build
permissions:
contents: read
on:
push:
branches:
- 'main'
pull_request:
types: [opened, synchronize, reopened, unlabeled]
jobs:
build:
if: github.event.action != 'unlabeled' || github.event.label.name == 'kokoro:run'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: '0'
persist-credentials: false
- name: Build web
run: docker compose -f source/wasm/docker-compose.yml --project-directory . up
- name: Run tests
run: node test/wasm/test.js
@@ -0,0 +1,40 @@
.clang_complete
.ycm_extra_conf.py*
*.pyc
android_test/lib
android_test/app
compile_commands.json
/build*/
/buildtools/
/external/abseil_cpp/
/external/googletest
/external/SPIRV-Headers
/external/spirv-headers
/external/effcee
/external/re2
/external/protobuf
/external/mimalloc
/out
/TAGS
/third_party/llvm-build/
/testing
/tools/clang/
/utils/clang-format-diff.py
bazel-bin
bazel-genfiles
bazel-out
bazel-spirv-tools
bazel-SPIRV-Tools
bazel-testlogs
MODULE.bazel.lock
# Vim
[._]*.s[a-w][a-z]
*~
# C-Lion
/.idea/
/cmake-build-*/
# VSCode
/.vscode/*
+20
View File
@@ -0,0 +1,20 @@
# Copyright 2018 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
buildconfig = "//build/config/BUILDCONFIG.gn"
default_args = {
clang_use_chrome_plugins = false
use_custom_libcxx = false
}
@@ -0,0 +1 @@
SPIRV-Tools.git
@@ -0,0 +1,331 @@
LOCAL_PATH := $(call my-dir)
SPVTOOLS_OUT_PATH=$(if $(call host-path-is-absolute,$(TARGET_OUT)),$(TARGET_OUT),$(abspath $(TARGET_OUT)))
ifeq ($(SPVHEADERS_LOCAL_PATH),)
SPVHEADERS_LOCAL_PATH := $(LOCAL_PATH)/external/spirv-headers
endif
SPVTOOLS_SRC_FILES := \
source/assembly_grammar.cpp \
source/binary.cpp \
source/diagnostic.cpp \
source/disassemble.cpp \
source/ext_inst.cpp \
source/extensions.cpp \
source/libspirv.cpp \
source/name_mapper.cpp \
source/opcode.cpp \
source/operand.cpp \
source/parsed_operand.cpp \
source/print.cpp \
source/software_version.cpp \
source/spirv_endian.cpp \
source/spirv_optimizer_options.cpp \
source/spirv_target_env.cpp \
source/spirv_validator_options.cpp \
source/table.cpp \
source/table2.cpp \
source/text.cpp \
source/text_handler.cpp \
source/to_string.cpp \
source/util/bit_vector.cpp \
source/util/parse_number.cpp \
source/util/string_utils.cpp \
source/util/timer.cpp \
source/val/basic_block.cpp \
source/val/construct.cpp \
source/val/function.cpp \
source/val/instruction.cpp \
source/val/validation_state.cpp \
source/val/validate.cpp \
source/val/validate_adjacency.cpp \
source/val/validate_annotation.cpp \
source/val/validate_arithmetics.cpp \
source/val/validate_atomics.cpp \
source/val/validate_barriers.cpp \
source/val/validate_bitwise.cpp \
source/val/validate_builtins.cpp \
source/val/validate_capability.cpp \
source/val/validate_cfg.cpp \
source/val/validate_composites.cpp \
source/val/validate_constants.cpp \
source/val/validate_conversion.cpp \
source/val/validate_debug.cpp \
source/val/validate_decorations.cpp \
source/val/validate_derivatives.cpp \
source/val/validate_dot_product.cpp \
source/val/validate_explicit_layout.cpp \
source/val/validate_extensions.cpp \
source/val/validate_execution_limitations.cpp \
source/val/validate_function.cpp \
source/val/validate_graph.cpp \
source/val/validate_group.cpp \
source/val/validate_id.cpp \
source/val/validate_image.cpp \
source/val/validate_interfaces.cpp \
source/val/validate_instruction.cpp \
source/val/validate_memory.cpp \
source/val/validate_memory_semantics.cpp \
source/val/validate_mesh_shading.cpp \
source/val/validate_misc.cpp \
source/val/validate_mode_setting.cpp \
source/val/validate_layout.cpp \
source/val/validate_literals.cpp \
source/val/validate_logical_pointers.cpp \
source/val/validate_logicals.cpp \
source/val/validate_non_uniform.cpp \
source/val/validate_pipe.cpp \
source/val/validate_primitives.cpp \
source/val/validate_ray_query.cpp \
source/val/validate_ray_tracing.cpp \
source/val/validate_ray_tracing_reorder.cpp \
source/val/validate_scopes.cpp \
source/val/validate_small_type_uses.cpp \
source/val/validate_tensor.cpp \
source/val/validate_tensor_layout.cpp \
source/val/validate_type.cpp\
source/val/validate_invalid_type.cpp
SPVTOOLS_OPT_SRC_FILES := \
source/opt/aggressive_dead_code_elim_pass.cpp \
source/opt/amd_ext_to_khr.cpp \
source/opt/analyze_live_input_pass.cpp \
source/opt/basic_block.cpp \
source/opt/block_merge_pass.cpp \
source/opt/block_merge_util.cpp \
source/opt/build_module.cpp \
source/opt/cfg.cpp \
source/opt/cfg_cleanup_pass.cpp \
source/opt/ccp_pass.cpp \
source/opt/code_sink.cpp \
source/opt/combine_access_chains.cpp \
source/opt/compact_ids_pass.cpp \
source/opt/composite.cpp \
source/opt/const_folding_rules.cpp \
source/opt/constants.cpp \
source/opt/control_dependence.cpp \
source/opt/convert_to_sampled_image_pass.cpp \
source/opt/convert_to_half_pass.cpp \
source/opt/copy_prop_arrays.cpp \
source/opt/dataflow.cpp \
source/opt/dead_branch_elim_pass.cpp \
source/opt/dead_insert_elim_pass.cpp \
source/opt/dead_variable_elimination.cpp \
source/opt/decoration_manager.cpp \
source/opt/debug_info_manager.cpp \
source/opt/def_use_manager.cpp \
source/opt/desc_sroa.cpp \
source/opt/desc_sroa_util.cpp \
source/opt/dominator_analysis.cpp \
source/opt/dominator_tree.cpp \
source/opt/eliminate_dead_constant_pass.cpp \
source/opt/eliminate_dead_functions_pass.cpp \
source/opt/eliminate_dead_functions_util.cpp \
source/opt/eliminate_dead_io_components_pass.cpp \
source/opt/eliminate_dead_members_pass.cpp \
source/opt/eliminate_dead_output_stores_pass.cpp \
source/opt/feature_manager.cpp \
source/opt/fix_func_call_arguments.cpp \
source/opt/fix_storage_class.cpp \
source/opt/flatten_decoration_pass.cpp \
source/opt/fold.cpp \
source/opt/folding_rules.cpp \
source/opt/fold_spec_constant_op_and_composite_pass.cpp \
source/opt/freeze_spec_constant_value_pass.cpp \
source/opt/function.cpp \
source/opt/graph.cpp \
source/opt/graphics_robust_access_pass.cpp \
source/opt/if_conversion.cpp \
source/opt/inline_pass.cpp \
source/opt/inline_exhaustive_pass.cpp \
source/opt/inline_opaque_pass.cpp \
source/opt/instruction.cpp \
source/opt/instruction_list.cpp \
source/opt/interface_var_sroa.cpp \
source/opt/interp_fixup_pass.cpp \
source/opt/invocation_interlock_placement_pass.cpp \
source/opt/ir_context.cpp \
source/opt/ir_loader.cpp \
source/opt/legalize_multidim_array_pass.cpp \
source/opt/licm_pass.cpp \
source/opt/liveness.cpp \
source/opt/local_access_chain_convert_pass.cpp \
source/opt/local_redundancy_elimination.cpp \
source/opt/local_single_block_elim_pass.cpp \
source/opt/local_single_store_elim_pass.cpp \
source/opt/loop_dependence.cpp \
source/opt/loop_dependence_helpers.cpp \
source/opt/loop_descriptor.cpp \
source/opt/loop_fission.cpp \
source/opt/loop_fusion.cpp \
source/opt/loop_fusion_pass.cpp \
source/opt/loop_peeling.cpp \
source/opt/loop_unroller.cpp \
source/opt/loop_unswitch_pass.cpp \
source/opt/loop_utils.cpp \
source/opt/mem_pass.cpp \
source/opt/merge_return_pass.cpp \
source/opt/modify_maximal_reconvergence.cpp \
source/opt/module.cpp \
source/opt/opextinst_forward_ref_fixup_pass.cpp \
source/opt/optimizer.cpp \
source/opt/pass.cpp \
source/opt/pass_manager.cpp \
source/opt/private_to_local_pass.cpp \
source/opt/propagator.cpp \
source/opt/reduce_load_size.cpp \
source/opt/redundancy_elimination.cpp \
source/opt/register_pressure.cpp \
source/opt/relax_float_ops_pass.cpp \
source/opt/canonicalize_ids_pass.cpp \
source/opt/remove_dontinline_pass.cpp \
source/opt/remove_duplicates_pass.cpp \
source/opt/remove_unused_interface_variables_pass.cpp \
source/opt/replace_desc_array_access_using_var_index.cpp \
source/opt/replace_invalid_opc.cpp \
source/opt/resolve_binding_conflicts_pass.cpp \
source/opt/scalar_analysis.cpp \
source/opt/scalar_analysis_simplification.cpp \
source/opt/scalar_replacement_pass.cpp \
source/opt/set_spec_constant_default_value_pass.cpp \
source/opt/simplification_pass.cpp \
source/opt/split_combined_image_sampler_pass.cpp \
source/opt/spread_volatile_semantics.cpp \
source/opt/ssa_rewrite_pass.cpp \
source/opt/strength_reduction_pass.cpp \
source/opt/strip_debug_info_pass.cpp \
source/opt/strip_nonsemantic_info_pass.cpp \
source/opt/struct_cfg_analysis.cpp \
source/opt/struct_packing_pass.cpp \
source/opt/switch_descriptorset_pass.cpp \
source/opt/trim_capabilities_pass.cpp \
source/opt/type_manager.cpp \
source/opt/types.cpp \
source/opt/unify_const_pass.cpp \
source/opt/upgrade_memory_model.cpp \
source/opt/value_number_table.cpp \
source/opt/vector_dce.cpp \
source/opt/workaround1209.cpp \
source/opt/wrap_opkill.cpp
# Locations of grammar files.
GRAMMAR_DIR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1
define gen_spvtools_grammar_tables
# $1 is the output directory, which is unique per ABI.
# Rules for creating grammar tables. They are statically compiled
# into the SPIRV-Tools code.
$(call generate-file-dir,$(1)/core_tables_body.inc)
$(1)/core_tables_body.inc \
$(1)/core_tables_header.inc \
: \
$(LOCAL_PATH)/utils/ggt.py \
$(GRAMMAR_DIR)/extinst.debuginfo.grammar.json \
$(GRAMMAR_DIR)/extinst.glsl.std.450.grammar.json \
$(GRAMMAR_DIR)/extinst.nonsemantic.clspvreflection.grammar.json \
$(GRAMMAR_DIR)/extinst.nonsemantic.graph.debuginfo.grammar.json \
$(GRAMMAR_DIR)/extinst.nonsemantic.shader.debuginfo.100.grammar.json \
$(GRAMMAR_DIR)/extinst.nonsemantic.vkspreflection.grammar.json \
$(GRAMMAR_DIR)/extinst.opencl.debuginfo.100.grammar.json \
$(GRAMMAR_DIR)/extinst.opencl.std.100.grammar.json \
$(GRAMMAR_DIR)/extinst.spv-amd-gcn-shader.grammar.json \
$(GRAMMAR_DIR)/extinst.spv-amd-shader-ballot.grammar.json \
$(GRAMMAR_DIR)/extinst.spv-amd-shader-explicit-vertex-parameter.grammar.json \
$(GRAMMAR_DIR)/extinst.spv-amd-shader-trinary-minmax.grammar.json \
$(GRAMMAR_DIR)/spirv.core.grammar.json
@$(HOST_PYTHON) $(LOCAL_PATH)/utils/ggt.py \
--core-tables-body-output=$(1)/core_tables_body.inc \
--core-tables-header-output=$(1)/core_tables_header.inc \
--spirv-core-grammar=$(GRAMMAR_DIR)/spirv.core.grammar.json \
--extinst=,$(GRAMMAR_DIR)/extinst.debuginfo.grammar.json \
--extinst=,$(GRAMMAR_DIR)/extinst.glsl.std.450.grammar.json \
--extinst=,$(GRAMMAR_DIR)/extinst.nonsemantic.clspvreflection.grammar.json \
--extinst=SHDEBUG100_,$(GRAMMAR_DIR)/extinst.nonsemantic.shader.debuginfo.100.grammar.json \
--extinst=,$(GRAMMAR_DIR)/extinst.nonsemantic.vkspreflection.grammar.json \
--extinst=CLDEBUG100_,$(GRAMMAR_DIR)/extinst.opencl.debuginfo.100.grammar.json \
--extinst=,$(GRAMMAR_DIR)/extinst.opencl.std.100.grammar.json \
--extinst=,$(GRAMMAR_DIR)/extinst.spv-amd-gcn-shader.grammar.json \
--extinst=,$(GRAMMAR_DIR)/extinst.spv-amd-shader-ballot.grammar.json \
--extinst=,$(GRAMMAR_DIR)/extinst.spv-amd-shader-explicit-vertex-parameter.grammar.json \
--extinst=,$(GRAMMAR_DIR)/extinst.spv-amd-shader-trinary-minmax.grammar.json
@echo "[$(TARGET_ARCH_ABI)] Grammar tables <= grammar JSON files"
# Make all source files depend on the generated core tables
$(foreach F,$(SPVTOOLS_SRC_FILES) $(SPVTOOLS_OPT_SRC_FILES),$(LOCAL_PATH)/$F ) \
: $(1)/core_tables_body.inc \
$(1)/core_tables_header.inc
endef
$(eval $(call gen_spvtools_grammar_tables,$(SPVTOOLS_OUT_PATH)))
define gen_spvtools_lang_headers
# Generate language-specific headers. So far we only generate C headers
# $1 is the output directory.
# $2 is the base name of the header file, e.g. "DebugInfo".
# $3 is the grammar file containing token definitions.
$(call generate-file-dir,$(1)/$(2).h)
$(1)/$(2).h : \
$(LOCAL_PATH)/utils/generate_language_headers.py \
$(3)
@$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_language_headers.py \
--extinst-grammar=$(3) \
--extinst-output-path=$(1)/$(2).h
@echo "[$(TARGET_ARCH_ABI)] Generate language specific header for $(2): headers <= grammar"
$(foreach F,$(SPVTOOLS_SRC_FILES) $(SPVTOOLS_OPT_SRC_FILES),$(LOCAL_PATH)/$F ) \
: $(1)/$(2).h
endef
# Generate C++ headers for some extended instruction sets.
$(eval $(call gen_spvtools_lang_headers,$(SPVTOOLS_OUT_PATH),DebugInfo,$(GRAMMAR_DIR)/extinst.debuginfo.grammar.json))
$(eval $(call gen_spvtools_lang_headers,$(SPVTOOLS_OUT_PATH),OpenCLDebugInfo100,$(GRAMMAR_DIR)/extinst.opencl.debuginfo.100.grammar.json))
$(eval $(call gen_spvtools_lang_headers,$(SPVTOOLS_OUT_PATH),NonSemanticShaderDebugInfo100,$(GRAMMAR_DIR)/extinst.nonsemantic.shader.debuginfo.100.grammar.json))
define gen_spvtools_build_version_inc
$(call generate-file-dir,$(1)/dummy_filename)
$(1)/build-version.inc: \
$(LOCAL_PATH)/utils/update_build_version.py \
$(LOCAL_PATH)/CHANGES
@$(HOST_PYTHON) $(LOCAL_PATH)/utils/update_build_version.py \
$(LOCAL_PATH)/CHANGES $(1)/build-version.inc
@echo "[$(TARGET_ARCH_ABI)] Generate : build-version.inc <= CHANGES"
$(LOCAL_PATH)/source/software_version.cpp: $(1)/build-version.inc
endef
$(eval $(call gen_spvtools_build_version_inc,$(SPVTOOLS_OUT_PATH)))
define gen_spvtools_generators_inc
$(call generate-file-dir,$(1)/dummy_filename)
$(1)/generators.inc: \
$(LOCAL_PATH)/utils/generate_registry_tables.py \
$(SPVHEADERS_LOCAL_PATH)/include/spirv/spir-v.xml
@$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_registry_tables.py \
--xml=$(SPVHEADERS_LOCAL_PATH)/include/spirv/spir-v.xml \
--generator-output=$(1)/generators.inc
@echo "[$(TARGET_ARCH_ABI)] Generate : generators.inc <= spir-v.xml"
$(LOCAL_PATH)/source/opcode.cpp: $(1)/generators.inc
endef
$(eval $(call gen_spvtools_generators_inc,$(SPVTOOLS_OUT_PATH)))
include $(CLEAR_VARS)
LOCAL_MODULE := SPIRV-Tools
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/include \
$(SPVHEADERS_LOCAL_PATH)/include \
$(SPVTOOLS_OUT_PATH)
LOCAL_EXPORT_C_INCLUDES := \
$(LOCAL_PATH)/include
LOCAL_CXXFLAGS:=-std=c++17 -fno-exceptions -fno-rtti -Werror
LOCAL_SRC_FILES:= $(SPVTOOLS_SRC_FILES)
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := SPIRV-Tools-opt
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/include \
$(LOCAL_PATH)/source \
$(SPVHEADERS_LOCAL_PATH)/include \
$(SPVTOOLS_OUT_PATH)
LOCAL_CXXFLAGS:=-std=c++17 -fno-exceptions -fno-rtti -Werror
LOCAL_STATIC_LIBRARIES:=SPIRV-Tools
LOCAL_SRC_FILES:= $(SPVTOOLS_OPT_SRC_FILES)
include $(BUILD_STATIC_LIBRARY)
@@ -0,0 +1,736 @@
load(
":build_defs.bzl",
"CLDEBUGINFO100_GRAMMAR_JSON_FILE",
"COMMON_COPTS",
"DEBUGINFO_GRAMMAR_JSON_FILE",
"SHDEBUGINFO100_GRAMMAR_JSON_FILE",
"TEST_COPTS",
"create_grammar_tables_target",
"ExtInst",
"generate_extinst_lang_headers",
"incompatible_with",
)
load("@rules_python//python:defs.bzl", "py_binary")
package(
default_visibility = ["//visibility:private"],
features = [
"layering_check",
],
)
licenses(["notice"])
exports_files([
"CHANGES",
"LICENSE",
])
py_binary(
# The script that generates compressed grammar tables for
# instructions and operands.
name = "ggt",
main = "utils/ggt.py", # The file found by $(location :ggt)
srcs = [
"utils/ggt.py",
"utils/Table/__init__.py",
"utils/Table/Context.py",
"utils/Table/IndexRange.py",
"utils/Table/Operand.py",
"utils/Table/StringList.py",
],
)
py_binary(
name = "generate_language_headers",
srcs = ["utils/generate_language_headers.py"],
)
create_grammar_tables_target(
name="core", # unused
extinsts = [
ExtInst("glsl.std.450", target="spirv_glsl_grammar_unified1"),
ExtInst("opencl.std.100", target="spirv_opencl_grammar_unified1"),
ExtInst("opencl.debuginfo.100", prefix="CLDEBUG100_"),
ExtInst("nonsemantic.shader.debuginfo", prefix="SHDEBUG100_"),
ExtInst("tosa.001000.1", target="spirv_ext_inst_tosa_001000_1", prefix="TOSA_"),
ExtInst("arm.motion-engine.100", target="spirv_ext_inst_arm_motion_engine_100"),
ExtInst("nonsemantic.graph.debuginfo", target="spirv_ext_inst_non_semantic_graph_debuginfo_grammar_unified1"),
ExtInst("arm.experimental-ml-operations", target="spirv_ext_inst_arm_experimental_ml_operations"),
] + [ExtInst(e) for e in [
"spv-amd-shader-explicit-vertex-parameter",
"spv-amd-shader-trinary-minmax",
"spv-amd-gcn-shader",
"spv-amd-shader-ballot",
"debuginfo",
"nonsemantic.clspvreflection",
"nonsemantic.vkspreflection",
]
]
)
generate_extinst_lang_headers(
name = "DebugInfo",
grammar = DEBUGINFO_GRAMMAR_JSON_FILE,
)
generate_extinst_lang_headers(
name = "OpenCLDebugInfo100",
grammar = CLDEBUGINFO100_GRAMMAR_JSON_FILE,
)
generate_extinst_lang_headers(
name = "NonSemanticShaderDebugInfo100",
grammar = SHDEBUGINFO100_GRAMMAR_JSON_FILE,
)
py_binary(
name = "generate_registry_tables",
srcs = ["utils/generate_registry_tables.py"],
)
genrule(
name = "generators_inc",
srcs = ["@spirv_headers//:spirv_xml_registry"],
outs = ["generators.inc"],
cmd = "$(location :generate_registry_tables) --xml=$(location @spirv_headers//:spirv_xml_registry) --generator-output=$(location generators.inc)",
cmd_bat = "$(location :generate_registry_tables) --xml=$(location @spirv_headers//:spirv_xml_registry) --generator-output=$(location generators.inc)",
tools = [":generate_registry_tables"],
)
py_binary(
name = "update_build_version",
srcs = ["utils/update_build_version.py"],
)
genrule(
name = "build_version_inc",
srcs = ["CHANGES"],
outs = ["build-version.inc"],
cmd = "SOURCE_DATE_EPOCH=0 $(location :update_build_version) $(location CHANGES) $(location build-version.inc)",
cmd_bat = "set SOURCE_DATE_EPOCH=0 && $(location :update_build_version) $(location CHANGES) $(location build-version.inc)",
tools = [":update_build_version"],
)
# Libraries
cc_library(
name = "spirv_tools",
hdrs = [
"include/spirv-tools/libspirv.h",
"include/spirv-tools/libspirv.hpp",
],
copts = COMMON_COPTS,
includes = ["include"],
linkstatic = 1,
visibility = ["//visibility:public"],
deps = [
":spirv_tools_internal",
],
)
cc_library(
name = "spirv_tools_internal",
srcs = glob([
"source/*.cpp",
"source/util/*.cpp",
"source/val/*.cpp",
], exclude = [
"source/mimalloc.cpp"
]) + [
":build_version_inc",
":gen_compressed_tables",
":gen_extinst_lang_headers_DebugInfo",
":gen_extinst_lang_headers_NonSemanticShaderDebugInfo100",
":gen_extinst_lang_headers_OpenCLDebugInfo100",
":generators_inc",
],
hdrs = [
"include/spirv-tools/libspirv.h",
"include/spirv-tools/libspirv.hpp",
":gen_extinst_lang_headers_DebugInfo",
":gen_extinst_lang_headers_NonSemanticShaderDebugInfo100",
":gen_extinst_lang_headers_OpenCLDebugInfo100",
] + glob([
"source/*.h",
"source/util/*.h",
"source/val/*.h",
]),
copts = COMMON_COPTS,
includes = ["include"],
deps = [
"@spirv_headers//:spirv_common_headers",
"@spirv_headers//:spirv_cpp11_headers",
],
)
cc_library(
name = "spirv_tools_opt",
hdrs = [
"include/spirv-tools/optimizer.hpp",
],
copts = COMMON_COPTS,
linkstatic = 1,
visibility = ["//visibility:public"],
deps = [
":spirv_tools",
":spirv_tools_opt_internal",
],
)
cc_library(
name = "spirv_tools_opt_internal",
srcs = glob(["source/opt/*.cpp"]),
hdrs = glob(["source/opt/*.h"]) + [
"include/spirv-tools/optimizer.hpp",
],
copts = COMMON_COPTS,
deps = [
":spirv_tools_internal",
"@spirv_headers//:spirv_common_headers",
"@spirv_headers//:spirv_c_headers",
],
)
cc_library(
name = "spirv_tools_reduce",
srcs = glob(["source/reduce/*.cpp"]),
hdrs = glob(["source/reduce/*.h"]),
copts = COMMON_COPTS,
deps = [
":spirv_tools_internal",
":spirv_tools_opt_internal",
],
)
cc_library(
name = "spirv_tools_link",
srcs = glob(["source/link/*.cpp"]),
hdrs = ["include/spirv-tools/linker.hpp", "source/link/fnvar.h"],
copts = COMMON_COPTS,
linkstatic = 1,
visibility = ["//visibility:public"],
deps = [
":spirv_tools_internal",
":spirv_tools_opt_internal",
],
)
cc_library(
name = "spirv_tools_lint_internal",
srcs = glob([
"source/lint/*.cpp",
"source/lint/*.h",
]),
hdrs = ["include/spirv-tools/linter.hpp"] + glob([
"source/lint/*.h",
]),
copts = COMMON_COPTS,
includes = ["include"],
deps = [
":spirv_tools_internal",
":spirv_tools_opt_internal",
],
)
cc_library(
name = "spirv_tools_lint",
hdrs = ["include/spirv-tools/linter.hpp"],
copts = COMMON_COPTS,
includes = ["include"],
linkstatic = 1,
visibility = ["//visibility:public"],
deps = [
":spirv_tools",
":spirv_tools_lint_internal",
],
)
cc_library(
name = "tools_util",
srcs = glob(["tools/util/*.cpp"]),
hdrs = glob(["tools/util/*.h"]),
copts = COMMON_COPTS,
deps = [":spirv_tools"],
)
cc_library(
name = "tools_io",
hdrs = ["tools/io.h"],
srcs = ["tools/io.cpp"],
copts = COMMON_COPTS,
)
# Tools
cc_binary(
name = "spirv-as",
srcs = [
"tools/as/as.cpp",
],
copts = COMMON_COPTS,
visibility = ["//visibility:public"],
deps = [
":spirv_tools_internal",
":tools_io",
":tools_util",
],
)
cc_binary(
name = "spirv-dis",
srcs = [
"tools/dis/dis.cpp",
],
copts = COMMON_COPTS,
visibility = ["//visibility:public"],
deps = [
":spirv_tools",
":tools_io",
":tools_util",
],
)
cc_binary(
name = "spirv-objdump",
srcs = [
"tools/objdump/extract_source.cpp",
"tools/objdump/extract_source.h",
"tools/objdump/objdump.cpp",
],
copts = COMMON_COPTS,
visibility = ["//visibility:public"],
deps = [
":spirv_tools_internal",
":spirv_tools_opt_internal",
":tools_io",
":tools_util",
"@spirv_headers//:spirv_cpp_headers",
],
)
cc_binary(
name = "spirv-val",
srcs = [
"tools/val/val.cpp",
],
copts = COMMON_COPTS,
visibility = ["//visibility:public"],
deps = [
":spirv_tools_internal",
":tools_io",
":tools_util",
],
)
cc_binary(
name = "spirv-opt",
srcs = [
"tools/opt/opt.cpp",
],
copts = COMMON_COPTS,
visibility = ["//visibility:public"],
deps = [
":spirv_tools_internal",
":spirv_tools_opt_internal",
":tools_io",
":tools_util",
],
)
cc_binary(
name = "spirv-reduce",
srcs = [
"tools/reduce/reduce.cpp",
],
copts = COMMON_COPTS,
visibility = ["//visibility:public"],
deps = [
":spirv_tools_internal",
":spirv_tools_opt_internal",
":spirv_tools_reduce",
":tools_io",
":tools_util",
],
)
cc_binary(
name = "spirv-link",
srcs = [
"tools/link/linker.cpp",
],
copts = COMMON_COPTS,
visibility = ["//visibility:public"],
deps = [
":spirv_tools_internal",
":spirv_tools_link",
":tools_io",
":tools_util",
],
)
cc_binary(
name = "spirv-lint",
srcs = [
"tools/lint/lint.cpp",
],
copts = COMMON_COPTS,
visibility = ["//visibility:public"],
deps = [
":spirv_tools_lint",
":spirv_tools_opt_internal",
":tools_io",
":tools_util",
],
)
cc_binary(
name = "spirv-cfg",
srcs = [
"tools/cfg/bin_to_dot.cpp",
"tools/cfg/bin_to_dot.h",
"tools/cfg/cfg.cpp",
],
copts = COMMON_COPTS,
visibility = ["//visibility:public"],
deps = [
":spirv_tools_internal",
":tools_io",
":tools_util",
],
)
# Unit tests
cc_library(
name = "test_lib",
testonly = 1,
srcs = [
"test/unit_spirv.cpp",
],
hdrs = [
"test/test_fixture.h",
"test/unit_spirv.h",
],
copts = TEST_COPTS,
deps = [
":spirv_tools_internal",
"@googletest//:gtest",
],
)
# PCH (precompiled header) tests only work when using CMake and MSVC on Windows,
# so they will be skipped in the Bazel builds.
[cc_test(
name = "base_{testcase}_test".format(testcase = f[len("test/"):-len("_test.cpp")]),
size = "small",
srcs = [f],
copts = TEST_COPTS + ["-DTESTING"],
linkstatic = 1,
target_compatible_with = {
"test/timer_test.cpp": incompatible_with(["@bazel_tools//src/conditions:windows"]),
}.get(f, []),
deps = [
"tools_util",
":spirv_tools_internal",
":test_lib",
":tools_io",
"@googletest//:gtest",
"@googletest//:gtest_main",
"@spirv_headers//:spirv_common_headers",
],
) for f in glob(
[
"test/*_test.cpp",
"test/tools/*_test.cpp",
],
exclude = [
"test/cpp_interface_test.cpp",
"test/pch_test.cpp",
],
)]
cc_test(
name = "base_cpp_interface_test",
size = "small",
srcs = ["test/cpp_interface_test.cpp"],
linkstatic = 1,
deps = [
":spirv_tools_opt_internal",
"@googletest//:gtest",
"@googletest//:gtest_main",
"@spirv_headers//:spirv_cpp11_headers",
],
)
cc_test(
name = "base_ilist_test",
size = "small",
srcs = ["test/util/ilist_test.cpp"],
copts = TEST_COPTS,
linkstatic = 1,
deps = [
":spirv_tools_internal",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)
cc_library(
name = "link_test_lib",
testonly = 1,
hdrs = ["test/link/linker_fixture.h"],
copts = TEST_COPTS,
deps = [
":spirv_tools_internal",
":spirv_tools_link",
":test_lib",
"@effcee//:effcee",
"@re2//:re2",
],
)
[cc_test(
name = "link_{testcase}_test".format(testcase = f[len("test/link/"):-len("_test.cpp")]),
size = "small",
srcs = [f],
copts = TEST_COPTS,
linkstatic = 1,
deps = [
":link_test_lib",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
) for f in glob(
["test/link/*_test.cpp"],
)]
[cc_test(
name = "lint_{testcase}_test".format(testcase = f[len("test/lint/"):-len("_test.cpp")]),
size = "small",
srcs = [f],
copts = TEST_COPTS,
linkstatic = 1,
deps = [
":spirv_tools",
":spirv_tools_lint_internal",
":spirv_tools_opt_internal",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
) for f in glob(
["test/lint/*_test.cpp"],
)]
cc_library(
name = "opt_test_lib",
testonly = 1,
srcs = [
"test/opt/pass_utils.cpp",
],
hdrs = [
"test/opt/assembly_builder.h",
"test/opt/function_utils.h",
"test/opt/module_utils.h",
"test/opt/pass_fixture.h",
"test/opt/pass_utils.h",
],
copts = TEST_COPTS,
deps = [
":spirv_tools_internal",
":spirv_tools_opt_internal",
"@effcee//:effcee",
"@googletest//:gtest",
],
)
[cc_test(
name = "opt_{testcase}_test".format(testcase = f[len("test/opt/"):-len("_test.cpp")]),
size = "small",
timeout = "moderate" if f[len("test/opt/"):-len("_test.cpp")] == "fold" else "short",
srcs = [f],
copts = TEST_COPTS,
linkstatic = 1,
deps = [
":opt_test_lib",
":spirv_tools_internal",
":spirv_tools_opt_internal",
":test_lib",
"@effcee//:effcee",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
) for f in glob(["test/opt/*_test.cpp"])]
[cc_test(
name = "opt_dom_tree_{testcase}_test".format(testcase = f[len("test/opt/dominator_tree/"):-len(".cpp")]),
size = "small",
srcs = [f],
copts = TEST_COPTS,
linkstatic = 1,
deps = [
":opt_test_lib",
":spirv_tools_opt_internal",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
) for f in glob(
["test/opt/dominator_tree/*.cpp"],
exclude = ["test/opt/dominator_tree/pch_test_opt_dom.cpp"],
)]
[cc_test(
name = "opt_loop_{testcase}_test".format(testcase = f[len("test/opt/loop_optimizations/"):-len(".cpp")]),
size = "small",
srcs = [f],
copts = TEST_COPTS,
linkstatic = 1,
deps = [
":opt_test_lib",
":spirv_tools",
":spirv_tools_opt_internal",
"@effcee//:effcee",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
) for f in glob(
["test/opt/loop_optimizations/*.cpp"],
exclude = ["test/opt/loop_optimizations/pch_test_opt_loop.cpp"],
)]
cc_library(
name = "reduce_test_lib",
testonly = 1,
srcs = [
"test/reduce/reduce_test_util.cpp",
],
hdrs = ["test/reduce/reduce_test_util.h"],
copts = TEST_COPTS,
deps = [
":spirv_tools",
":spirv_tools_opt_internal",
":spirv_tools_reduce",
":test_lib",
":tools_io",
"@googletest//:gtest",
],
)
[cc_test(
name = "reduce_{testcase}_test".format(testcase = f[len("test/reduce/"):-len("_test.cpp")]),
size = "small",
srcs = [f],
copts = TEST_COPTS,
linkstatic = 1,
deps = [
":reduce_test_lib",
":spirv_tools_internal",
":spirv_tools_opt_internal",
":spirv_tools_reduce",
"@googletest//:gtest_main",
],
) for f in glob(["test/reduce/*_test.cpp"])]
[cc_test(
name = "util_{testcase}_test".format(testcase = f[len("test/util/"):-len("_test.cpp")]),
size = "small",
srcs = [f],
copts = TEST_COPTS,
linkstatic = 1,
deps = [
":spirv_tools_internal",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
) for f in glob(["test/util/*_test.cpp"])]
cc_library(
name = "val_test_lib",
testonly = 1,
srcs = [
"test/val/val_code_generator.cpp",
],
hdrs = [
"test/val/val_code_generator.h",
"test/val/val_fixtures.h",
],
copts = TEST_COPTS,
deps = [
":spirv_tools_internal",
":test_lib",
],
)
[cc_test(
name = "val_{testcase}_test".format(testcase = f[len("test/val/val_"):-len("_test.cpp")]),
size = "small",
srcs = [f],
copts = TEST_COPTS,
linkstatic = 1,
deps = [
":spirv_tools_internal",
":test_lib",
":val_test_lib",
"@googletest//:gtest",
"@googletest//:gtest_main",
"@spirv_headers//:spirv_cpp11_headers",
],
) for f in glob(
["test/val/val_*_test.cpp"],
exclude = [
"test/val/val_capability_test.cpp",
"test/val/val_ext_inst_debug_test.cpp",
"test/val/val_limits_test.cpp",
],
)]
cc_test(
name = "val_ext_inst_debug_test",
size = "small",
srcs = ["test/val/val_ext_inst_debug_test.cpp"],
copts = TEST_COPTS,
linkstatic = 1,
deps = [
":spirv_tools_internal",
":test_lib",
":val_test_lib",
"@googletest//:gtest",
"@googletest//:gtest_main",
"@spirv_headers//:spirv_common_headers",
"@spirv_headers//:spirv_cpp11_headers",
],
)
cc_test(
name = "val_capability_test",
size = "large",
timeout = "long",
srcs = ["test/val/val_capability_test.cpp"],
copts = TEST_COPTS + ["-O3"],
linkstatic = 1,
deps = [
":spirv_tools_internal",
":test_lib",
":val_test_lib",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)
cc_test(
name = "val_limits_test",
size = "large",
timeout = "long",
srcs = ["test/val/val_limits_test.cpp"],
copts = TEST_COPTS + [
"-O3",
],
linkstatic = 1,
deps = [
":test_lib",
":val_test_lib",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,421 @@
# Copyright (c) 2015-2023 The Khronos Group Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.22.1)
project(spirv-tools)
# Avoid a bug in CMake 3.22.1. By default it will set -std=c++11 for
# targets in test/*, when those tests need -std=c++17.
# https://github.com/KhronosGroup/SPIRV-Tools/issues/5340
# The bug is fixed in CMake 3.22.2
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.22.1")
if (${CMAKE_VERSION} VERSION_LESS "3.22.2")
cmake_policy(SET CMP0128 NEW)
endif()
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
enable_testing()
set(SPIRV_TOOLS "SPIRV-Tools")
include(GNUInstallDirs)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Require at least C++17
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
if(${CMAKE_CXX_STANDARD} LESS 17)
message(FATAL_ERROR "SPIRV-Tools requires C++17 or later, but is configured for C++${CMAKE_CXX_STANDARD})")
endif()
set(CMAKE_CXX_EXTENSIONS OFF)
option(ENABLE_RTTI "Enables RTTI" OFF)
option(SPIRV_ALLOW_TIMERS "Allow timers via clock_gettime on supported platforms" ON)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(SPIRV_TIMER_ENABLED ${SPIRV_ALLOW_TIMERS})
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Windows")
add_definitions(-DSPIRV_WINDOWS)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN")
add_definitions(-DSPIRV_WINDOWS)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
set(SPIRV_TIMER_ENABLED ${SPIRV_ALLOW_TIMERS})
endif()
if (${SPIRV_TIMER_ENABLED})
add_definitions(-DSPIRV_TIMER_ENABLED)
endif()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
message(STATUS "No build type selected, default to Debug")
set(CMAKE_BUILD_TYPE "Debug")
endif()
option(SKIP_SPIRV_TOOLS_INSTALL "Skip installation" ${SKIP_SPIRV_TOOLS_INSTALL})
if(NOT ${SKIP_SPIRV_TOOLS_INSTALL})
set(ENABLE_SPIRV_TOOLS_INSTALL ON)
endif()
option(SPIRV_BUILD_COMPRESSION "Build SPIR-V compressing codec" OFF)
if(SPIRV_BUILD_COMPRESSION)
message(FATAL_ERROR "SPIR-V compression codec has been removed from SPIR-V tools. "
"Please remove SPIRV_BUILD_COMPRESSION from your build options.")
endif(SPIRV_BUILD_COMPRESSION)
option(SPIRV_BUILD_FUZZER "Build spirv-fuzz" OFF)
set(SPIRV_LIB_FUZZING_ENGINE_LINK_OPTIONS "" CACHE STRING "Used by OSS-Fuzz to control, via link options, which fuzzing engine should be used")
option(SPIRV_BUILD_LIBFUZZER_TARGETS "Build libFuzzer targets" OFF)
option(SPIRV_WERROR "Enable error on warning" ON)
if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR (("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") AND (NOT CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")))
set(COMPILER_IS_LIKE_GNU TRUE)
endif()
if(${COMPILER_IS_LIKE_GNU})
set(SPIRV_WARNINGS -Wall -Wextra -Wnon-virtual-dtor -Wno-missing-field-initializers)
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Wno-self-assign)
endif()
option(SPIRV_WARN_EVERYTHING "Enable -Weverything" ${SPIRV_WARN_EVERYTHING})
if(${SPIRV_WARN_EVERYTHING})
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(SPIRV_WARNINGS ${SPIRV_WARNINGS}
-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Wpedantic -pedantic-errors)
else()
message(STATUS "Unknown compiler ${CMAKE_CXX_COMPILER_ID}, "
"so SPIRV_WARN_EVERYTHING has no effect")
endif()
endif()
if(${SPIRV_WERROR})
set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Werror)
endif()
elseif(MSVC)
set(SPIRV_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS /wd4800 /wd4819 /wd4251 /W2 /WX)
if(${SPIRV_WERROR})
set(SPIRV_WARNINGS ${SPIRV_WARNINGS} /WX)
endif()
endif()
if (PROJECT_IS_TOP_LEVEL)
# enable parallel builds for msbuild
list(APPEND CMAKE_VS_GLOBALS UseMultiToolTask=true)
list(APPEND CMAKE_VS_GLOBALS EnforceProcessCountAcrossBuilds=true)
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/)
option(SPIRV_COLOR_TERMINAL "Enable color terminal output" ON)
if(${SPIRV_COLOR_TERMINAL})
add_definitions(-DSPIRV_COLOR_TERMINAL)
endif()
option(SPIRV_LOG_DEBUG "Enable excessive debug output" OFF)
if(${SPIRV_LOG_DEBUG})
add_definitions(-DSPIRV_LOG_DEBUG)
endif()
if (DEFINED SPIRV_TOOLS_EXTRA_DEFINITIONS)
add_definitions(${SPIRV_TOOLS_EXTRA_DEFINITIONS})
endif()
# Library build setting definitions:
#
# * SPIRV_TOOLS_BUILD_STATIC - ON or OFF - Defaults to ON.
# If enabled the following targets will be created:
# ${SPIRV_TOOLS}-static - STATIC library.
# Has full public symbol visibility.
# ${SPIRV_TOOLS}-shared - SHARED library.
# Has default-hidden symbol visibility.
# ${SPIRV_TOOLS} - will alias to one of above, based on BUILD_SHARED_LIBS.
# If disabled the following targets will be created:
# ${SPIRV_TOOLS} - either STATIC or SHARED based on SPIRV_TOOLS_LIBRARY_TYPE.
# Has full public symbol visibility.
# ${SPIRV_TOOLS}-shared - SHARED library.
# Has default-hidden symbol visibility.
#
# * SPIRV_TOOLS_LIBRARY_TYPE - SHARED or STATIC.
# Specifies the library type used for building SPIRV-Tools libraries.
# Defaults to SHARED when BUILD_SHARED_LIBS=1, otherwise STATIC.
#
# * SPIRV_TOOLS_FULL_VISIBILITY - "${SPIRV_TOOLS}-static" or "${SPIRV_TOOLS}"
# Evaluates to the SPIRV_TOOLS target library name that has no hidden symbols.
# This is used by internal targets for accessing symbols that are non-public.
# Note this target provides no API stability guarantees.
#
# Ideally, all of these will go away - see https://github.com/KhronosGroup/SPIRV-Tools/issues/3909.
option(ENABLE_EXCEPTIONS_ON_MSVC "Build SPIRV-TOOLS with c++ exceptions enabled in MSVC" ON)
option(SPIRV_TOOLS_BUILD_STATIC "Build ${SPIRV_TOOLS}-static target. ${SPIRV_TOOLS} will alias to ${SPIRV_TOOLS}-static or ${SPIRV_TOOLS}-shared based on BUILD_SHARED_LIBS" ON)
if(SPIRV_TOOLS_BUILD_STATIC)
set(SPIRV_TOOLS_FULL_VISIBILITY ${SPIRV_TOOLS}-static)
set(SPIRV_TOOLS_LIBRARY_TYPE "STATIC")
else(SPIRV_TOOLS_BUILD_STATIC)
set(SPIRV_TOOLS_FULL_VISIBILITY ${SPIRV_TOOLS})
if (NOT DEFINED SPIRV_TOOLS_LIBRARY_TYPE)
if(BUILD_SHARED_LIBS)
set(SPIRV_TOOLS_LIBRARY_TYPE "SHARED")
else()
set(SPIRV_TOOLS_LIBRARY_TYPE "STATIC")
endif()
endif()
endif(SPIRV_TOOLS_BUILD_STATIC)
function(spvtools_default_compile_options TARGET)
target_compile_options(${TARGET} PRIVATE ${SPIRV_WARNINGS})
if (${COMPILER_IS_LIKE_GNU})
target_compile_options(${TARGET} PRIVATE
-Wall -Wextra -Wno-long-long -Wshadow -Wundef -Wconversion
-Wno-sign-conversion -fno-exceptions)
if(NOT ENABLE_RTTI)
add_compile_options(-fno-rtti)
endif()
# For good call stacks in profiles, keep the frame pointers.
if(NOT "${SPIRV_PERF}" STREQUAL "")
target_compile_options(${TARGET} PRIVATE -fno-omit-frame-pointer)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
set(SPIRV_USE_SANITIZER "" CACHE STRING
"Use the clang sanitizer [address|memory|thread|...]")
if(NOT "${SPIRV_USE_SANITIZER}" STREQUAL "")
target_compile_options(${TARGET} PRIVATE
-fsanitize=${SPIRV_USE_SANITIZER})
set_target_properties(${TARGET} PROPERTIES
LINK_FLAGS -fsanitize=${SPIRV_USE_SANITIZER})
endif()
target_compile_options(${TARGET} PRIVATE
-ftemplate-depth=1024)
else()
target_compile_options(${TARGET} PRIVATE
-Wno-missing-field-initializers)
endif()
endif()
if (MSVC)
# Specify /EHs for exception handling. This makes using SPIRV-Tools as
# dependencies in other projects easier.
if(ENABLE_EXCEPTIONS_ON_MSVC)
target_compile_options(${TARGET} PRIVATE /EHs)
endif()
endif()
# For MinGW cross compile, statically link to the C++ runtime.
# But it still depends on MSVCRT.dll.
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if (NOT MSVC)
set_target_properties(${TARGET} PROPERTIES
LINK_FLAGS -static -static-libgcc -static-libstdc++)
endif()
endif()
endfunction()
if(NOT COMMAND find_host_package)
macro(find_host_package)
find_package(${ARGN})
endmacro()
endif()
if(NOT COMMAND find_host_program)
macro(find_host_program)
find_program(${ARGN})
endmacro()
endif()
# Tests require Python3
find_host_package(Python3 REQUIRED)
# Check type annotations in Perl code. Assumes mypy.
add_custom_target(spirv-tools-check-python-types
COMMAND mypy Table
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/utils
)
set_target_properties(spirv-tools-check-python-types
PROPERTIES EXCLUDE_FROM_ALL ON)
# Run Python unit tests
add_custom_target(spirv-tools-check-python-tests
COMMAND Python3::Interpreter -m unittest discover -v -p "*test.py"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/utils
)
# Check for symbol exports on Linux.
# At the moment, this check will fail on the OSX build machines for the Android NDK.
# It appears they don't have objdump.
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
macro(spvtools_check_symbol_exports TARGET)
if (NOT "${SPIRV_SKIP_TESTS}")
add_test(NAME spirv-tools-symbol-exports-${TARGET}
COMMAND Python3::Interpreter
${spirv-tools_SOURCE_DIR}/utils/check_symbol_exports.py "$<TARGET_FILE:${TARGET}>")
endif()
endmacro()
else()
macro(spvtools_check_symbol_exports TARGET)
if (NOT "${SPIRV_SKIP_TESTS}")
message("Skipping symbol exports test for ${TARGET}")
endif()
endmacro()
endif()
if(ENABLE_SPIRV_TOOLS_INSTALL)
if(WIN32 AND NOT MINGW)
macro(spvtools_config_package_dir TARGET PATH)
set(${PATH} ${TARGET}/cmake)
endmacro()
else()
macro(spvtools_config_package_dir TARGET PATH)
set(${PATH} ${CMAKE_INSTALL_LIBDIR}/cmake/${TARGET})
endmacro()
endif()
macro(spvtools_generate_config_file TARGET)
file(WRITE ${CMAKE_BINARY_DIR}/${TARGET}Config.cmake
"include(CMakeFindDependencyMacro)\n"
"find_dependency(${SPIRV_TOOLS})\n"
"include(\${CMAKE_CURRENT_LIST_DIR}/${TARGET}Targets.cmake)\n"
"set(${TARGET}_LIBRARIES ${TARGET})\n"
"get_target_property(${TARGET}_INCLUDE_DIRS ${TARGET} INTERFACE_INCLUDE_DIRECTORIES)\n")
endmacro()
endif()
# Currently iOS and Android are very similar.
# They both have their own packaging (APP/APK).
# Which makes regular executables/testing problematic.
#
# Currently the only deliverables for these platforms are
# libraries (either STATIC or SHARED).
#
# Furthermore testing is equally problematic.
if (IOS OR ANDROID)
set(SPIRV_SKIP_EXECUTABLES ON)
endif()
option(SPIRV_SKIP_EXECUTABLES "Skip building the executable and tests along with the library")
if (SPIRV_SKIP_EXECUTABLES)
set(SPIRV_SKIP_TESTS ON)
endif()
option(SPIRV_SKIP_TESTS "Skip building tests along with the library")
# Defaults to ON. The checks can be time consuming.
# Turn off if they take too long.
option(SPIRV_CHECK_CONTEXT "In a debug build, check if the IR context is in a valid state." ON)
if (${SPIRV_CHECK_CONTEXT})
add_compile_options($<$<CONFIG:Debug>:-DSPIRV_CHECK_CONTEXT>)
endif()
# Precompiled header macro. Parameters are source file list and filename for pch cpp file.
macro(spvtools_pch SRCS PCHPREFIX)
if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio" AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(PCH_NAME "$(IntDir)\\${PCHPREFIX}.pch")
# make source files use/depend on PCH_NAME
set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS "/Yu${PCHPREFIX}.h /FI${PCHPREFIX}.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}")
# make PCHPREFIX.cpp file compile and generate PCH_NAME
set_source_files_properties("${PCHPREFIX}.cpp" PROPERTIES COMPILE_FLAGS "/Yc${PCHPREFIX}.h /Fp${PCH_NAME} /Zm300" OBJECT_OUTPUTS "${PCH_NAME}")
list(APPEND ${SRCS} "${PCHPREFIX}.cpp")
endif()
endmacro(spvtools_pch)
add_subdirectory(external)
# Warning about extra semi-colons.
#
# This is not supported on all compilers/versions. so enabling only
# for clang, since that works for all versions that our bots run.
#
# This is intentionally done after adding the external subdirectory,
# so we don't enforce this flag on our dependencies, some of which do
# not pass it.
#
# If the minimum version of CMake supported is updated to 3.0 or
# later, then check_cxx_compiler_flag could be used instead.
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
add_compile_options("-Wextra-semi")
endif()
add_subdirectory(source)
add_subdirectory(tools)
add_subdirectory(test)
add_subdirectory(examples)
if(ENABLE_SPIRV_TOOLS_INSTALL)
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/libspirv.h
${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/libspirv.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/optimizer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/linker.hpp
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/spirv-tools/)
endif(ENABLE_SPIRV_TOOLS_INSTALL)
if (NOT "${SPIRV_SKIP_TESTS}")
add_test(NAME spirv-tools-copyrights
COMMAND Python3::Interpreter utils/check_copyright.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
set(SPIRV_LIBRARIES "-lSPIRV-Tools-opt -lSPIRV-Tools -lSPIRV-Tools-link")
set(SPIRV_SHARED_LIBRARIES "-lSPIRV-Tools-shared")
# Build pkg-config file
# Use a first-class target so it's regenerated when relevant files are updated.
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools.pc
COMMAND ${CMAKE_COMMAND}
-DCHANGES_FILE=${CMAKE_CURRENT_SOURCE_DIR}/CHANGES
-DTEMPLATE_FILE=${CMAKE_CURRENT_SOURCE_DIR}/cmake/SPIRV-Tools.pc.in
-DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools.pc
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
-DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}
-DSPIRV_LIBRARIES=${SPIRV_LIBRARIES}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/write_pkg_config.cmake
DEPENDS "CHANGES" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/SPIRV-Tools.pc.in" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/write_pkg_config.cmake")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools-shared.pc
COMMAND ${CMAKE_COMMAND}
-DCHANGES_FILE=${CMAKE_CURRENT_SOURCE_DIR}/CHANGES
-DTEMPLATE_FILE=${CMAKE_CURRENT_SOURCE_DIR}/cmake/SPIRV-Tools-shared.pc.in
-DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools-shared.pc
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
-DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}
-DSPIRV_SHARED_LIBRARIES=${SPIRV_SHARED_LIBRARIES}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/write_pkg_config.cmake
DEPENDS "CHANGES" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/SPIRV-Tools-shared.pc.in" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/write_pkg_config.cmake")
add_custom_target(spirv-tools-pkg-config
ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools-shared.pc ${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools.pc)
# Install pkg-config file
if (ENABLE_SPIRV_TOOLS_INSTALL)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools.pc
${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools-shared.pc
DESTINATION
${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()
@@ -0,0 +1 @@
A reminder that this issue tracker is managed by the Khronos Group. Interactions here should follow the Khronos Code of Conduct (https://www.khronos.org/developers/code-of-conduct), which prohibits aggressive or derogatory language. Please keep the discussion friendly and civil.
@@ -0,0 +1,149 @@
# Contributing to SPIR-V Tools
## For users: Reporting bugs and requesting features
We organize known future work in GitHub projects. See
[Tracking SPIRV-Tools work with GitHub projects](https://github.com/KhronosGroup/SPIRV-Tools/blob/main/docs/projects.md)
for more.
To report a new bug or request a new feature, please file a GitHub issue. Please
ensure the bug has not already been reported by searching
[issues](https://github.com/KhronosGroup/SPIRV-Tools/issues) and
[projects](https://github.com/KhronosGroup/SPIRV-Tools/projects). If the bug has
not already been reported open a new one
[here](https://github.com/KhronosGroup/SPIRV-Tools/issues/new).
When opening a new issue for a bug, make sure you provide the following:
* A clear and descriptive title.
* We want a title that will make it easy for people to remember what the
issue is about. Simply using "Segfault in spirv-opt" is not helpful
because there could be (but hopefully aren't) multiple bugs with
segmentation faults with different causes.
* A test case that exposes the bug, with the steps and commands to reproduce
it.
* The easier it is for a developer to reproduce the problem, the quicker a
fix can be found and verified. It will also make it easier for someone
to possibly realize the bug is related to another issue.
For feature requests, we use
[issues](https://github.com/KhronosGroup/SPIRV-Tools/issues) as well. Please
create a new issue, as with bugs. In the issue provide
* A description of the problem that needs to be solved.
* Examples that demonstrate the problem.
## For developers: Contributing a patch
Before we can use your code, you must sign the
[Khronos Open Source Contributor License Agreement](https://cla-assistant.io/KhronosGroup/SPIRV-Tools)
(CLA), which you can do online. The CLA is necessary mainly because you own the
copyright to your changes, even after your contribution becomes part of our
codebase, so we need your permission to use and distribute your code. We also
need to be sure of various other things -- for instance that you'll tell us if
you know that your code infringes on other people's patents. You don't have to
sign the CLA until after you've submitted your code for review and a member has
approved it, but you must do it before we can put your code into our codebase.
See
[README.md](https://github.com/KhronosGroup/SPIRV-Tools/blob/main/README.md)
for instruction on how to get, build, and test the source. Once you have made
your changes:
* Ensure the code follows the
[Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html).
Running `clang-format -style=file -i [modified-files]` can help.
* Create a pull request (PR) with your patch.
* Make sure the PR description clearly identified the problem, explains the
solution, and references the issue if applicable.
* If your patch completely fixes bug 1234, the commit message should say
`Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1234` When you do
this, the issue will be closed automatically when the commit goes into
main. Also, this helps us update the [CHANGES](CHANGES) file.
* Watch the continuous builds to make sure they pass.
* Request a code review.
The reviewer can either approve your PR or request changes. If changes are
requested:
* Please add new commits to your branch, instead of amending your commit.
Adding new commits makes it easier for the reviewer to see what has changed
since the last review.
* Once you are ready for another round of reviews, add a comment at the
bottom, such as "Ready for review" or "Please take a look" (or "PTAL"). This
explicit handoff is useful when responding with multiple small commits.
After the PR has been reviewed it is the job of the reviewer to merge the PR.
Instructions for this are given below.
## For maintainers: Reviewing a PR
The formal code reviews are done on GitHub. Reviewers are to look for all of the
usual things:
* Coding style follows the
[Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html)
* Identify potential functional problems.
* Identify code duplication.
* Ensure the unit tests have enough coverage.
* Ensure continuous integration (CI) bots run on the PR. If not run (in the
case of PRs by external contributors), add the "kokoro:run" label to the
pull request which will trigger running all CI jobs.
When looking for functional problems, there are some common problems reviewers
should pay particular attention to:
* Does the code work for both Shader (Vulkan and OpenGL) and Kernel (OpenCL)
scenarios? The respective SPIR-V dialects are slightly different.
* Changes are made to a container while iterating through it. You have to be
careful that iterators are not invalidated or that elements are not skipped.
* For SPIR-V transforms: The module is changed, but the analyses are not
updated. For example, a new instruction is added, but the def-use manager is
not updated. Later on, it is possible that the def-use manager will be used,
and give wrong results.
* If a pass gets the id of a type from the type manager, make sure the type is
not a struct or array. It there are two structs that look the same, the type
manager can return the wrong one.
## For maintainers: Merging a PR
We intend to maintain a linear history on the GitHub main branch, and the
build and its tests should pass at each commit in that history. A linear
always-working history is easier to understand and to bisect in case we want to
find which commit introduced a bug. The
[Squash and Merge](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/about-pull-request-merges#squash-and-merge-your-commits)
button on the GitHub web interface. All other ways of merging on the web
interface have been disabled.
Before merging, we generally require:
1. All tests except for the smoke test pass. See
[failing smoke test](#failing-smoke-test).
1. The PR is approved by at least one of the maintainers. If the PR modifies
different parts of the code, then multiple reviewers might be necessary.
The squash-and-merge button will turn green when these requirements are met.
Maintainers have the to power to merge even if the button is not green, but that
is discouraged.
### Failing smoke test
The purpose of the smoke test is to let us know if
[shaderc](https://github.com/google/shaderc) fails to build with the change. If
it fails, the maintainer needs to determine if the reason for the failure is a
problem in the current PR or if another repository needs to be changed. Most of
the time [Glslang](https://github.com/KhronosGroup/glslang) needs to be updated
to account for the change in SPIR-V Tools.
The PR can still be merged if the problem is not with that PR.
## For maintainers: Running tests
For security reasons, not all tests will run automatically. When they do not, a
maintainer will have to start the tests.
If the Github actions tests do not run on a PR, they can be initiated by closing
and reopening the PR.
If the kokoro tests are not run, they can be run by adding the label
`kokoro:run` to the PR.
+45
View File
@@ -0,0 +1,45 @@
use_relative_paths = True
vars = {
'github': 'https://github.com',
'abseil_revision': 'c34b1491291f7673fd758ea3aa08517231497b97',
'effcee_revision': '910ed15722d5d05c9d71ecf36c1a22243cb79b02',
'googletest_revision': 'a25f43576effe4ebe887412a603cddfa8fc3ba64',
# Use a recent protobuf, which can depend on abseil
'protobuf_revision': '35cd01f9fe9afbeea38cc7b979a3b6bfcde82c03',
're2_revision': '972a15cedd008d846f1a39b2e88ce48d7f166cbd',
'spirv_headers_revision': '29981f65241605e08b0ede4cfeb999fe3b723c6a',
'mimalloc_revision': '76d3f8a934f9761e4ee75fa8b071e58d482f2758',
}
deps = {
'external/abseil_cpp':
Var('github') + '/abseil/abseil-cpp.git@' + Var('abseil_revision'),
'external/effcee':
Var('github') + '/google/effcee.git@' + Var('effcee_revision'),
'external/googletest':
Var('github') + '/google/googletest.git@' + Var('googletest_revision'),
'external/protobuf':
Var('github') + '/protocolbuffers/protobuf.git@' + Var('protobuf_revision'),
'external/re2':
Var('github') + '/google/re2.git@' + Var('re2_revision'),
'external/spirv-headers':
Var('github') + '/KhronosGroup/SPIRV-Headers.git@' +
Var('spirv_headers_revision'),
'external/mimalloc':
Var('github') + '/microsoft/mimalloc.git@' + Var('mimalloc_revision'),
}
@@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
@@ -0,0 +1,35 @@
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "googletest", dev_dependency = True)
local_path_override(
module_name = "googletest",
path = "external/googletest",
)
bazel_dep(name = "re2", dev_dependency = True)
local_path_override(
module_name = "re2",
path = "external/re2",
)
bazel_dep(name = "effcee", dev_dependency = True)
local_path_override(
module_name = "effcee",
path = "external/effcee",
)
bazel_dep(name = "rules_python",
version = "2.1.0")
# https://rules-python.readthedocs.io/en/stable/toolchains.html#library-modules-with-dev-only-python-usage
python = use_extension(
"@rules_python//python/extensions:python.bzl",
"python",
dev_dependency = True
)
python.toolchain(python_version = "3.12",
is_default = True,
ignore_root_user_error = True)
bazel_dep(name = "rules_cc", version = "0.2.20")
@@ -0,0 +1,42 @@
# Copyright (c) 2018 The Khronos Group Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Presubmit script for SPIRV-Tools.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into depot_tools.
"""
USE_PYTHON3 = True
LINT_FILTERS = [
"-build/storage_class",
"-readability/casting",
"-readability/fn_size",
"-readability/todo",
"-runtime/explicit",
"-runtime/int",
"-runtime/printf",
"-runtime/references",
"-runtime/string",
]
def CheckChangeOnUpload(input_api, output_api):
results = []
results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api)
results += input_api.canned_checks.CheckChangeLintsClean(
input_api, output_api, None, LINT_FILTERS)
return results
@@ -0,0 +1,829 @@
# SPIR-V Tools
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/KhronosGroup/SPIRV-Tools/badge)](https://securityscorecards.dev/viewer/?uri=github.com/KhronosGroup/SPIRV-Tools)
NEWS 2023-01-11: Development occurs on the `main` branch.
## Overview
The SPIR-V Tools project provides an API and commands for processing SPIR-V
modules.
The project includes an assembler, binary module parser, disassembler,
validator, and optimizer for SPIR-V. Except for the optimizer, all are based
on a common static library. The library contains all of the implementation
details, and is used in the standalone tools whilst also enabling integration
into other code bases directly. The optimizer implementation resides in its
own library, which depends on the core library.
The interfaces have stabilized:
We don't anticipate making a breaking change for existing features.
SPIR-V is defined by the Khronos Group Inc.
See the [SPIR-V Registry][spirv-registry] for the SPIR-V specification,
headers, and XML registry.
## Downloads
The official releases for SPIRV-Tools can be found on LunarG's
[SDK download page](https://vulkan.lunarg.com/sdk/home).
For convenience, here are also links to the latest builds (HEAD).
Those are untested automated builds. Those are not official releases, nor
are guaranteed to work. Official releases builds are in the Vulkan SDK.
<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)
<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)
<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)
[More downloads](docs/downloads.md)
## Versioning SPIRV-Tools
See [`CHANGES`](CHANGES) for a high level summary of recent changes, by version.
SPIRV-Tools project version numbers are of the form `v`*year*`.`*index* and with
an optional `-dev` suffix to indicate work in progress. For example, the
following versions are ordered from oldest to newest:
* `v2016.0`
* `v2016.1-dev`
* `v2016.1`
* `v2016.2-dev`
* `v2016.2`
Use the `--version` option on each command line tool to see the software
version. An API call reports the software version as a C-style string.
## Releases
The official releases for SPIRV-Tools can be found on LunarG's
[SDK download page](https://vulkan.lunarg.com/sdk/home).
You can find either the prebuilt, and QA tested binaries, or download the
SDK Config, which lists the commits to use to build the release from scratch.
GitHub releases are deprecated, and we will not publish new releases until
further notice.
## Supported features
### Assembler, binary parser, and disassembler
* Support for SPIR-V 1.0, through 1.5
* Based on SPIR-V syntax described by JSON grammar files in the
[SPIRV-Headers](https://github.com/KhronosGroup/SPIRV-Headers) repository.
* Usually, support for a new version of SPIR-V is ready within days after
publication.
* Support for extended instruction sets:
* GLSL std450 version 1.0 Rev 3
* OpenCL version 1.0 Rev 2
* Assembler only does basic syntax checking. No cross validation of
IDs or types is performed, except to check literal arguments to
`OpConstant`, `OpSpecConstant`, and `OpSwitch`.
* Where tools expect binary input, a hex stream may be provided instead. See
`spirv-dis --help`.
See [`docs/syntax.md`](docs/syntax.md) for the assembly language syntax.
### Validator
The validator checks validation rules described by the SPIR-V specification.
Khronos recommends that tools that create or transform SPIR-V modules use the
validator to ensure their outputs are valid, and that tools that consume SPIR-V
modules optionally use the validator to protect themselves from bad inputs.
This is especially encouraged for debug and development scenarios.
The validator has one-sided error: it will only return an error when it has
implemented a rule check and the module violates that rule.
The validator is incomplete.
See the [CHANGES](CHANGES) file for reports on completed work, and
the [Validator
sub-project](https://github.com/KhronosGroup/SPIRV-Tools/projects/1) for planned
and in-progress work.
*Note*: The validator checks some Universal Limits, from section 2.17 of the SPIR-V spec.
The validator will fail on a module that exceeds those minimum upper bound limits.
The validator has been parameterized to allow larger values, for use when targeting
a more-than-minimally-capable SPIR-V consumer.
See [`tools/val/val.cpp`](tools/val/val.cpp) or run `spirv-val --help` for the command-line help.
### Optimizer
The optimizer is a collection of code transforms, or "passes".
Transforms are written for a diverse set of reasons:
* To restructure, simplify, or normalize the code for further processing.
* To eliminate undesirable code.
* To improve code quality in some metric such as size or performance.
**Note**: These transforms are not guaranteed to actually improve any
given metric. Users should always measure results for their own situation.
As of this writing, there are 67 transforms including examples such as:
* Simplification
* Strip debug info
* Strip reflection info
* Specialization Constants
* Set spec constant default value
* Freeze spec constant to default value
* Fold `OpSpecConstantOp` and `OpSpecConstantComposite`
* Unify constants
* Eliminate dead constant
* Code Reduction
* Inline all function calls exhaustively
* Convert local access chains to inserts/extracts
* Eliminate local load/store in single block
* Eliminate local load/store with single store
* Eliminate local load/store with multiple stores
* Eliminate local extract from insert
* Eliminate dead instructions (aggressive)
* Eliminate dead branches
* Merge single successor / single predecessor block pairs
* Eliminate common uniform loads
* Remove duplicates: Capabilities, extended instruction imports, types, and
decorations.
* Normalization
* Compact IDs
* Canonicalize IDs
* CFG cleanup
* Flatten decorations
* Merge returns
* Convert AMD-specific instructions to KHR instructions
* Code improvement
* Conditional constant propagation
* If-conversion
* Loop fission
* Loop fusion
* Loop-invariant code motion
* Loop unroll
* Other
* Graphics robust access
* Upgrade memory model to VulkanKHR
Additionally, certain sets of transformations have been packaged into
higher-level recipes. These include:
* Optimization for size (`spirv-opt -Os`)
* Optimization for performance (`spirv-opt -O`)
For the latest list with detailed documentation, please refer to
[`include/spirv-tools/optimizer.hpp`](include/spirv-tools/optimizer.hpp).
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/).
### Linker
*Note:* The linker is still under development.
Current features:
* Combine multiple SPIR-V binary modules together.
* Combine into a library (exports are retained) or an executable (no symbols
are exported).
See the [CHANGES](CHANGES) file for reports on completed work, and the [General
sub-project](https://github.com/KhronosGroup/SPIRV-Tools/projects/2) for
planned and in-progress work.
### Reducer
*Note:* The reducer is still under development.
The reducer simplifies and shrinks a SPIR-V module with respect to a
user-supplied *interestingness function*. For example, given a large
SPIR-V module that cause some SPIR-V compiler to fail with a given
fatal error message, the reducer could be used to look for a smaller
version of the module that causes the compiler to fail with the same
fatal error message.
To suggest an additional capability for the reducer, [file an
issue](https://github.com/KhronosGroup/SPIRV-Tools/issues]) with
"Reducer:" as the start of its title.
### Fuzzer
*Note:* The fuzzer is still under development.
The fuzzer applies semantics-preserving transformations to a SPIR-V binary
module, to produce an equivalent module. The original and transformed modules
should produce essentially identical results when executed on identical inputs:
their results should differ only due to floating-point round-off, if at all.
Significant differences in results can pinpoint bugs in tools that process
SPIR-V binaries, such as miscompilations. This *metamorphic testing* approach
is similar to the method used by the [GraphicsFuzz
project](https://github.com/google/graphicsfuzz) for fuzzing of GLSL shaders.
To suggest an additional capability for the fuzzer, [file an
issue](https://github.com/KhronosGroup/SPIRV-Tools/issues]) with
"Fuzzer:" as the start of its title.
### Diff
*Note:* The diff tool is still under development.
The diff tool takes two SPIR-V files, either in binary or text format and
produces a diff-style comparison between the two. The instructions between the
src and dst modules are matched as best as the tool can, and output is produced
(in src id-space) that shows which instructions are removed in src, added in dst
or modified between them. The order of instructions are not retained.
Matching instructions between two SPIR-V modules is not trivial, and thus a
number of heuristics are applied in this tool. In particular, without debug
information, match functions is nontrivial as they can be reordered. As such,
this tool is primarily useful to produce the diff of two SPIR-V modules derived
from the same source, for example before and after a modification to the shader,
before and after a transformation, or SPIR-V produced from different tools.
### Extras
* [Utility filters](#utility-filters)
* Build target `spirv-tools-vimsyntax` generates file `spvasm.vim`.
Copy that file into your `$HOME/.vim/syntax` directory to get SPIR-V assembly syntax
highlighting in Vim. This build target is not built by default.
## Contributing
The SPIR-V Tools project is maintained by members of the The Khronos Group Inc.,
and is hosted at https://github.com/KhronosGroup/SPIRV-Tools.
Consider joining the `public_spirv_tools_dev@khronos.org` mailing list, via
[https://www.khronos.org/spir/spirv-tools-mailing-list/](https://www.khronos.org/spir/spirv-tools-mailing-list/).
The mailing list is used to discuss development plans for the SPIRV-Tools as an open source project.
Once discussion is resolved,
specific work is tracked via issues and sometimes in one of the
[projects][spirv-tools-projects].
(To provide feedback on the SPIR-V _specification_, file an issue on the
[SPIRV-Headers][spirv-headers] GitHub repository.)
See [`docs/projects.md`](docs/projects.md) to see how we use the
[GitHub Project
feature](https://help.github.com/articles/tracking-the-progress-of-your-work-with-projects/)
to organize planned and in-progress work.
Contributions via merge request are welcome. Changes should:
* Be provided under the [Apache 2.0](#license).
* You'll be prompted with a one-time "click-through"
[Khronos Open Source Contributor License Agreement][spirv-tools-cla]
(CLA) dialog as part of submitting your pull request or
other contribution to GitHub.
* Include tests to cover updated functionality.
* C++ code should follow the [Google C++ Style Guide][cpp-style-guide].
* Code should be formatted with `clang-format`.
[kokoro/check-format/build.sh](kokoro/check-format/build.sh)
shows how to download it. Note that we currently use
`clang-format version 5.0.0` for SPIRV-Tools. Settings are defined by
the included [.clang-format](.clang-format) file.
We intend to maintain a linear history on the GitHub `main` branch.
### Getting the source
Example of getting sources, assuming SPIRV-Tools is configured as a standalone project:
git clone https://github.com/KhronosGroup/SPIRV-Tools.git spirv-tools
cd spirv-tools
# Check out sources for dependencies, at versions known to work together,
# as listed in the DEPS file.
python3 utils/git-sync-deps
For some kinds of development, you may need the latest sources from the third-party projects:
git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-tools/external/spirv-headers
git clone https://github.com/google/googletest.git spirv-tools/external/googletest
git clone https://github.com/google/effcee.git spirv-tools/external/effcee
git clone https://github.com/google/re2.git spirv-tools/external/re2
git clone https://github.com/abseil/abseil-cpp.git spirv-tools/external/abseil_cpp
git clone https://github.com/microsoft/mimalloc.git spirv-tools/external/mimalloc
#### Dependency on Effcee
Some tests depend on the [Effcee][effcee] library for stateful matching.
Effcee itself depends on [RE2][re2], and RE2 depends on [Abseil][abseil-cpp].
* If SPIRV-Tools is configured as part of a larger project that already uses
Effcee, then that project should include Effcee before SPIRV-Tools.
* Otherwise, SPIRV-Tools expects Effcee sources to appear in `external/effcee`,
RE2 sources to appear in `external/re2`, and Abseil sources to appear in
`external/abseil_cpp`.
#### Dependency on mimalloc
SPIRV-Tools may be configured to use the [mimalloc][mimalloc] library to improve memory
allocation performance.
In the CMake build, usage of mimalloc is controlled by the `SPIRV_TOOLS_USE_MIMALLOC`
option. This variable defaults on `ON` when building for Windows and `OFF` when building
for other platforms. Enabling this option on non-Windows platforms is supported and is
expected to work normally, but this has not been tested as thoroughly and extensively as
the Windows version. In the future, the `SPIRV_TOOLS_USE_MIMALLOC` option may default to
`ON` for non-Windows platforms as well.
In order to avoid unexpectedly changing allocation behavior of applications that link
SPIRV-Tools libraries statically, mimalloc is disabled by default on static libraries.
The option 'SPIRV_TOOLS_USE_MIMALLOC_IN_STATIC_BUILD' can be used to force the usage of
mimalloc on static libraries.
*Note*: mimalloc is currently only supported when building with CMake. When using Bazel,
mimalloc is not used.
### Source code organization
* `example`: demo code of using SPIRV-Tools APIs
* `external/googletest`: Intended location for the
[googletest][googletest] sources, not provided
* `external/effcee`: Location of [Effcee][effcee] sources, if the `effcee` library
is not already configured by an enclosing project.
* `external/re2`: Location of [RE2][re2] sources, if the `re2` library is not already
configured by an enclosing project.
(The Effcee project already requires RE2.)
* `external/abseil_cpp`: Location of [Abseil][abseil-cpp] sources, if Abseil is
not already configured by an enclosing project.
(The RE2 project already requires Abseil.)
* `external/mimalloc`: Intended location for [mimalloc][mimalloc] sources, not provided
* `include/`: API clients should add this directory to the include search path
* `external/spirv-headers`: Intended location for
[SPIR-V headers][spirv-headers], not provided
* `include/spirv-tools/libspirv.h`: C API public interface
* `source/`: API implementation
* `test/`: Tests, using the [googletest][googletest] framework
* `tools/`: Command line executables
### Tests
The project contains a number of tests, used to drive development
and ensure correctness. The tests are written using the
[googletest][googletest] framework. The `googletest`
source is not provided with this project. There are two ways to enable
tests:
* If SPIR-V Tools is configured as part of an enclosing project, then the
enclosing project should configure `googletest` before configuring SPIR-V Tools.
* If SPIR-V Tools is configured as a standalone project, then download the
`googletest` source into the `<spirv-dir>/external/googletest` directory before
configuring and building the project.
## Build
*Note*: Prebuilt binaries are available from the [downloads](docs/downloads.md) page.
First [get the sources](#getting-the-source).
Then build using CMake, Bazel, Android ndk-build, or the Emscripten SDK.
### Build using CMake
You can build the project using [CMake][cmake]:
```sh
cd <spirv-dir>
mkdir build && cd build
cmake [-G <platform-generator>] <spirv-dir>
```
Once the build files have been generated, build using the appropriate build
command (e.g. `ninja`, `make`, `msbuild`, etc.; this depends on the platform
generator used above), or use your IDE, or use CMake to run the appropriate build
command for you:
```sh
cmake --build . [--config Debug] # runs `make` or `ninja` or `msbuild` etc.
```
#### Note about the fuzzer
The SPIR-V fuzzer, `spirv-fuzz`, can only be built via CMake, and is disabled by
default. To build it, clone protobuf and use the `SPIRV_BUILD_FUZZER` CMake
option, like so:
```sh
# In <spirv-dir> (the SPIRV-Tools repo root):
git clone --depth=1 --branch v35.1 https://github.com/protocolbuffers/protobuf external/protobuf
# In your build directory:
cmake [-G <platform-generator>] <spirv-dir> -DSPIRV_BUILD_FUZZER=ON
cmake --build . --config Debug
```
You can also add `-DSPIRV_ENABLE_LONG_FUZZER_TESTS=ON` to build additional
fuzzer tests.
### Build using Bazel
You can also use [Bazel](https://bazel.build/) to build the project.
```sh
bazel build :all
```
### Build a node.js package using Emscripten
The SPIRV-Tools core library can be built to a WebAssembly [node.js](https://nodejs.org)
module. The resulting `SpirvTools` WebAssembly module only exports methods to
assemble and disassemble SPIR-V modules.
First, make sure you have the [Emscripten SDK](https://emscripten.org).
Then:
```sh
cd <spirv-dir>
./source/wasm/build.sh
```
The resulting node package, with JavaScript and TypeScript bindings, is
written to `<spirv-dir>/out/web`.
Note: This builds the package locally. It does *not* publish it to [npm](https://npmjs.org).
To test the result:
```sh
node ./test/wasm/test.js
```
### Tools you'll need
For building and testing SPIRV-Tools, the following tools should be
installed regardless of your OS:
- [CMake](http://www.cmake.org/): if using CMake for generating compilation
targets, you need to install CMake Version 2.8.12 or later.
- [Python 3](http://www.python.org/): for utility scripts and running the test
suite.
- [Bazel](https://bazel.build/) (optional): if building the source with Bazel,
you need to install Bazel Version 7.4.0 on your machine. Other versions may
also work, but are not verified.
- [Emscripten SDK](https://emscripten.org) (optional): if building the
WebAssembly module.
SPIRV-Tools is regularly tested with the following compilers:
On Linux
- GCC version 15
- Clang version 18
On MacOS
- AppleClang 15.0
On Windows
- Visual Studio 2022
Note: Other compilers or later versions may work, but they are not tested.
### CMake options
The following CMake options are supported:
* `SPIRV_BUILD_FUZZER={ON|OFF}`, default `OFF` - Build the spirv-fuzz tool.
* `SPIRV_COLOR_TERMINAL={ON|OFF}`, default `ON` - Enables color console output.
* `SPIRV_SKIP_TESTS={ON|OFF}`, default `OFF`- Build only the library and
the command line tools. This will prevent the tests from being built.
* `SPIRV_SKIP_EXECUTABLES={ON|OFF}`, default `OFF`- Build only the library, not
the command line tools and tests.
* `SPIRV_USE_SANITIZER=<sanitizer>`, default is no sanitizing - On UNIX
platforms with an appropriate version of `clang` this option enables the use
of the sanitizers documented [here][clang-sanitizers].
This should only be used with a debug build.
* `SPIRV_WARN_EVERYTHING={ON|OFF}`, default `OFF` - On UNIX platforms enable
more strict warnings. The code might not compile with this option enabled.
For Clang, enables `-Weverything`. For GCC, enables `-Wpedantic`.
See [`CMakeLists.txt`](CMakeLists.txt) for details.
* `SPIRV_WERROR={ON|OFF}`, default `ON` - Forces a compilation error on any
warnings encountered by enabling the compiler-specific compiler front-end
option. No compiler front-end options are enabled when this option is OFF.
Additionally, you can pass additional C preprocessor definitions to SPIRV-Tools
via setting `SPIRV_TOOLS_EXTRA_DEFINITIONS`. For example, by setting it to
`/D_ITERATOR_DEBUG_LEVEL=0` on Windows, you can disable checked iterators and
iterator debugging.
### Android ndk-build
SPIR-V Tools supports building static libraries `libSPIRV-Tools.a` and
`libSPIRV-Tools-opt.a` for Android. Using the Android NDK r25c or later:
```
cd <spirv-dir>
export ANDROID_NDK=/path/to/your/ndk # NDK r25c or later
mkdir build && cd build
mkdir libs
mkdir app
$ANDROID_NDK/ndk-build -C ../android_test \
NDK_PROJECT_PATH=. \
NDK_LIBS_OUT=`pwd`/libs \
NDK_APP_OUT=`pwd`/app
```
### Updating DEPS
Occasionally the entries in [DEPS](DEPS) will need to be updated. This is done on
demand when there is a request to do this, often due to downstream breakages.
To update `DEPS`, run `utils/roll_deps.sh` and confirm that tests pass.
The script requires Chromium's
[`depot_tools`](https://chromium.googlesource.com/chromium/tools/depot_tools).
## Library
### Usage
The internals of the library use C++17 features, and are exposed via both a C
and C++ API.
In order to use the library from an application, the include path should point
to `<spirv-dir>/include`, which will enable the application to include the
header `<spirv-dir>/include/spirv-tools/libspirv.h{|pp}` then linking against
the static library in `<spirv-build-dir>/source/libSPIRV-Tools.a` or
`<spirv-build-dir>/source/SPIRV-Tools.lib`.
For optimization, the header file is
`<spirv-dir>/include/spirv-tools/optimizer.hpp`, and the static library is
`<spirv-build-dir>/source/libSPIRV-Tools-opt.a` or
`<spirv-build-dir>/source/SPIRV-Tools-opt.lib`.
* `SPIRV-Tools` CMake target: Creates the static library:
* `<spirv-build-dir>/source/libSPIRV-Tools.a` on Linux and OS X.
* `<spirv-build-dir>/source/libSPIRV-Tools.lib` on Windows.
* `SPIRV-Tools-opt` CMake target: Creates the static library:
* `<spirv-build-dir>/source/libSPIRV-Tools-opt.a` on Linux and OS X.
* `<spirv-build-dir>/source/libSPIRV-Tools-opt.lib` on Windows.
#### Entry points
The interfaces are still under development, and are expected to change.
There are five main entry points into the library in the C interface:
* `spvTextToBinary`: An assembler, translating text to a binary SPIR-V module.
* `spvBinaryToText`: A disassembler, translating a binary SPIR-V module to
text.
* `spvBinaryParse`: The entry point to a binary parser API. It issues callbacks
for the header and each parsed instruction. The disassembler is implemented
as a client of `spvBinaryParse`.
* `spvValidate` implements the validator functionality. *Incomplete*
* `spvValidateBinary` implements the validator functionality. *Incomplete*
The C++ interface is comprised of three classes, `SpirvTools`, `Optimizer` and
`Linker`, all in the `spvtools` namespace.
* `SpirvTools` provides `Assemble`, `Disassemble`, and `Validate` methods.
* `Optimizer` provides methods for registering and running optimization passes.
* `Linker` provides methods for combining together multiple binaries.
## Command line tools
Command line tools, which wrap the above library functions, are provided to
assemble or disassemble shader files. It's a convention to name SPIR-V
assembly and binary files with suffix `.spvasm` and `.spv`, respectively.
### Assembler tool
The assembler reads the assembly language text, and emits the binary form.
The standalone assembler is the executable called `spirv-as`, and is located in
`<spirv-build-dir>/tools/spirv-as`. The functionality of the assembler is implemented
by the `spvTextToBinary` library function.
* `spirv-as` - the standalone assembler
* `<spirv-dir>/tools/as`
Use option `-h` to print help.
### Disassembler tool
The disassembler reads the binary form, and emits assembly language text.
The standalone disassembler is the executable called `spirv-dis`, and is located in
`<spirv-build-dir>/tools/spirv-dis`. The functionality of the disassembler is implemented
by the `spvBinaryToText` library function.
* `spirv-dis` - the standalone disassembler
* `<spirv-dir>/tools/dis`
Use option `-h` to print help.
The output includes syntax colouring when printing to the standard output stream,
on Linux, Windows, and OS X.
### Linker tool
The linker combines multiple SPIR-V binary modules together, resulting in a single
binary module as output.
This is a work in progress.
The linker does not support OpenCL program linking options related to math
flags. (See section 5.6.5.2 in OpenCL 1.2)
* `spirv-link` - the standalone linker
* `<spirv-dir>/tools/link`
### Optimizer tool
The optimizer processes a SPIR-V binary module, applying transformations
in the specified order.
This is a work in progress, with initially only few available transformations.
* `spirv-opt` - the standalone optimizer
* `<spirv-dir>/tools/opt`
### Validator tool
*Warning:* This functionality is under development, and is incomplete.
The standalone validator is the executable called `spirv-val`, and is located in
`<spirv-build-dir>/tools/spirv-val`. The functionality of the validator is implemented
by the `spvValidate` library function.
The validator operates on the binary form.
* `spirv-val` - the standalone validator
* `<spirv-dir>/tools/val`
### Reducer tool
The reducer shrinks a SPIR-V binary module, guided by a user-supplied
*interestingness test*.
This is a work in progress, with initially only shrinks a module in a few ways.
* `spirv-reduce` - the standalone reducer
* `<spirv-dir>/tools/reduce`
Run `spirv-reduce --help` to see how to specify interestingness.
### Fuzzer tool
The fuzzer transforms a SPIR-V binary module into a semantically-equivalent
SPIR-V binary module by applying transformations in a randomized fashion.
This is a work in progress, with initially only a few semantics-preserving
transformations.
* `spirv-fuzz` - the standalone fuzzer
* `<spirv-dir>/tools/fuzz`
Run `spirv-fuzz --help` for a detailed list of options.
### Control flow dumper tool
The control flow dumper prints the control flow graph for a SPIR-V module as a
[GraphViz](http://www.graphviz.org/) graph.
This is experimental.
* `spirv-cfg` - the control flow graph dumper
* `<spirv-dir>/tools/cfg`
### Diff tool
*Warning:* This functionality is under development, and is incomplete.
The diff tool produces a diff-style comparison between two SPIR-V modules.
* `spirv-diff` - the standalone diff tool
* `<spirv-dir>`/tools/diff`
### Utility filters
* `spirv-lesspipe.sh` - Automatically disassembles `.spv` binary files for the
`less` program, on compatible systems. For example, set the `LESSOPEN`
environment variable as follows, assuming both `spirv-lesspipe.sh` and
`spirv-dis` are on your executable search path:
```
export LESSOPEN='| spirv-lesspipe.sh "%s"'
```
Then you page through a disassembled module as follows:
```
less foo.spv
```
* The `spirv-lesspipe.sh` script will pass through any extra arguments to
`spirv-dis`. So, for example, you can turn off colours and friendly ID
naming as follows:
```
export LESSOPEN='| spirv-lesspipe.sh "%s" --no-color --raw-id'
```
* [vim-spirv](https://github.com/kbenzie/vim-spirv) - A vim plugin which
supports automatic disassembly of `.spv` files using the `:edit` command and
assembly using the `:write` command. The plugin also provides additional
features which include; syntax highlighting; highlighting of all ID's matching
the ID under the cursor; and highlighting errors where the `Instruction`
operand of `OpExtInst` is used without an appropriate `OpExtInstImport`.
* `50spirv-tools.el` - Automatically disassembles '.spv' binary files when
loaded into the emacs text editor, and re-assembles them when saved,
provided any modifications to the file are valid. This functionality
must be explicitly requested by defining the symbol
SPIRV_TOOLS_INSTALL_EMACS_HELPERS as follows:
```
cmake -DSPIRV_TOOLS_INSTALL_EMACS_HELPERS=true ...
```
In addition, this helper is only installed if the directory /etc/emacs/site-start.d
exists, which is typically true if emacs is installed on the system.
Note that symbol IDs are not currently preserved through a load/edit/save operation.
This may change if the ability is added to spirv-as.
### Tests
Tests are only built when googletest is found.
#### Running test with CMake
Use `ctest -j <num threads>` to run all the tests. To run tests using all threads:
```shell
ctest -j$(nproc)
```
To run a single test target, use `ctest [-j <N>] -R <test regex>`. For example,
you can run all `opt` tests with:
```shell
ctest -R 'spirv-tools-test_opt'
```
#### Running test with Bazel
Use `bazel test :all` to run all tests. This will run tests in parallel by default.
To run a single test target, specify `:my_test_target` instead of `:all`. Test target
names get printed when you run `bazel test :all`. For example, you can run
`opt_def_use_test` with:
on linux:
```shell
bazel test --cxxopt=-std=c++17 :opt_def_use_test
```
on windows:
```shell
bazel test --cxxopt=/std:c++17 :opt_def_use_test
```
## Future Work
<a name="future"></a>
_See the [projects pages](https://github.com/KhronosGroup/SPIRV-Tools/projects)
for more information._
### Assembler and disassembler
* The disassembler could emit helpful annotations in comments. For example:
* Use variable name information from debug instructions to annotate
key operations on variables.
* Show control flow information by annotating `OpLabel` instructions with
that basic block's predecessors.
* Error messages could be improved.
### Validator
This is a work in progress.
### Linker
* The linker could accept math transformations such as allowing MADs, or other
math flags passed at linking-time in OpenCL.
* Linkage attributes can not be applied through a group.
* Check decorations of linked functions attributes.
* Remove dead instructions, such as OpName targeting imported symbols.
## Licence
<a name="license"></a>
Full license terms are in [LICENSE](LICENSE)
```
Copyright (c) 2015-2016 The Khronos Group Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
[spirv-tools-cla]: https://cla-assistant.io/KhronosGroup/SPIRV-Tools
[spirv-tools-projects]: https://github.com/KhronosGroup/SPIRV-Tools/projects
[spirv-tools-mailing-list]: https://www.khronos.org/spir/spirv-tools-mailing-list
[spirv-registry]: https://www.khronos.org/registry/spir-v/
[spirv-headers]: https://github.com/KhronosGroup/SPIRV-Headers
[googletest]: https://github.com/google/googletest
[googletest-pull-612]: https://github.com/google/googletest/pull/612
[googletest-issue-610]: https://github.com/google/googletest/issues/610
[effcee]: https://github.com/google/effcee
[re2]: https://github.com/google/re2
[abseil-cpp]: https://github.com/abseil/abseil-cpp
[mimalloc]: https://github.com/microsoft/mimalloc
[CMake]: https://cmake.org/
[cpp-style-guide]: https://google.github.io/styleguide/cppguide.html
[clang-sanitizers]: http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation
@@ -0,0 +1,13 @@
# Security Policy
## Supported Versions
Security updates are applied only to the latest release.
## Reporting a Vulnerability
If you have discovered a security vulnerability in this project, please report it privately. **Do not disclose it as a public issue.** This gives us time to work with you to fix the issue before public exposure, reducing the chance that the exploit will be used before a patch is released.
Please disclose it at [security advisory](https://github.com/KhronosGroup/SPIRV-Tools/security/advisories/new).
This project is maintained by a team of volunteers on a reasonable-effort basis. As such, please give us at least 90 days to work on a fix before public exposure.
@@ -0,0 +1,9 @@
local_repository(
name = "spirv_headers",
path = "external/spirv-headers",
)
local_repository(
name = "abseil-cpp",
path = "external/abseil_cpp",
)
@@ -0,0 +1,12 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CPP_EXTENSION := .cc .cpp .cxx
LOCAL_SRC_FILES:=test.cpp
LOCAL_MODULE:=spirvtools_test
LOCAL_LDLIBS:=-landroid
LOCAL_CXXFLAGS:=-std=c++17 -fno-exceptions -fno-rtti -Werror
LOCAL_STATIC_LIBRARIES=SPIRV-Tools SPIRV-Tools-opt
include $(BUILD_SHARED_LIBRARY)
include $(LOCAL_PATH)/../Android.mk
@@ -0,0 +1,5 @@
APP_ABI := all
APP_BUILD_SCRIPT := Android.mk
APP_STL := c++_static
APP_PLATFORM := android-24
NDK_TOOLCHAIN_VERSION := 4.9
@@ -0,0 +1,22 @@
// Copyright (c) 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <memory>
#include "spirv-tools/libspirv.hpp"
#include "spirv-tools/optimizer.hpp"
void android_main(struct android_app* /*state*/) {
spvtools::SpirvTools tools(SPV_ENV_UNIVERSAL_1_2);
spvtools::Optimizer optimizer(SPV_ENV_UNIVERSAL_1_2);
}
@@ -0,0 +1,160 @@
"""Constants and macros for spirv-tools BUILD."""
COMMON_COPTS = [
"-DSPIRV_CHECK_CONTEXT",
"-DSPIRV_COLOR_TERMINAL",
] + select({
"@platforms//os:windows": [],
"//conditions:default": [
"-DSPIRV_LINUX",
"-DSPIRV_TIMER_ENABLED",
"-fvisibility=hidden",
"-fno-exceptions",
"-fno-rtti",
"-Wall",
"-Wextra",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-Werror",
"-Wno-long-long",
"-Wshadow",
"-Wundef",
"-Wconversion",
"-Wno-sign-conversion",
],
})
TEST_COPTS = COMMON_COPTS + [
] + select({
"@platforms//os:windows": [
# Disable C4503 "decorated name length exceeded" warning,
# triggered by some heavily templated types.
# We don't care much about that in test code.
# Important to do since we have warnings-as-errors.
"/wd4503",
],
"//conditions:default": [
"-Wno-undef",
"-Wno-self-assign",
"-Wno-shadow",
"-Wno-unused-parameter",
# Work around looseness in protobuf parse table generated code
"-Wno-implicit-int-conversion",
],
})
def incompatible_with(incompatible_constraints):
return select(_merge_dicts([{"//conditions:default": []}, {
constraint: ["@platforms//:incompatible"]
for constraint in incompatible_constraints
}]))
SPIRV_CORE_GRAMMAR_JSON_FILE = "@spirv_headers//:spirv_core_grammar_unified1"
DEBUGINFO_GRAMMAR_JSON_FILE = "@spirv_headers//:spirv_ext_inst_debuginfo_grammar_unified1"
CLDEBUGINFO100_GRAMMAR_JSON_FILE = "@spirv_headers//:spirv_ext_inst_opencl_debuginfo_100_grammar_unified1"
SHDEBUGINFO100_GRAMMAR_JSON_FILE = "@spirv_headers//:spirv_ext_inst_nonsemantic_shader_debuginfo_100_grammar_unified1"
def _merge_dicts(dicts):
merged = {}
for d in dicts:
merged.update(d)
return merged
def ExtInst(name, target = "", prefix = ""):
"""
Returns a dictionary specifying the info needed to
process an extended instruction set.
Args:
name: The extension name; forms part of the .json grammar file.
target: if non-empty, the name of the bazel target in spirv-headers
that names the JSON grammar file for the extended instrution set.
If empty, the target name is derived from 'name'.
prefix: The optional prefix for names of operand enums.
Returns a dictionary with keys 'name', 'target', 'prefix' and the
corresponding values.
"""
return {"name": name, "target": target, "prefix": prefix}
def _extinst_grammar_target(e):
"""
Args: e, as returned from extinst
Returns the SPIRV-Headers target for the given extended instruction set spec.
"""
target = e["target"]
name = e["name"]
if len(target) > 0:
return "@spirv_headers//:{}".format(target)
name_part = name.replace("-", "_").replace(".", "_")
return "@spirv_headers//:spirv_ext_inst_{}_grammar_unified1".format(name_part)
def create_grammar_tables_target(name, extinsts):
"""
Creates a ":gen_compressed_tables" target for SPIR-V instruction
set grammar tables.
Args:
name: unused. Required by convention.
extinsts: list of extended instruction specs.
Each spec is a dictionary, as returned from 'extinst'.
"""
grammars = dict(
core_grammar = SPIRV_CORE_GRAMMAR_JSON_FILE,
)
outs = dict(
core_tables_header_output = "core_tables_header.inc",
core_tables_body_output = "core_tables_body.inc",
)
extinst_args = []
for e in extinsts:
extinst_args.append("--extinst={},$(location {})".format(e["prefix"], _extinst_grammar_target(e)))
cmd = (
"$(location :ggt)" +
" --spirv-core-grammar=$(location {core_grammar})" +
" --core-tables-body-output=$(location {core_tables_body_output})" +
" --core-tables-header-output=$(location {core_tables_header_output})" +
" " + " ".join(extinst_args)
).format(**_merge_dicts([grammars, outs]))
native.genrule(
name = "gen_compressed_tables",
srcs = grammars.values() + [_extinst_grammar_target(e) for e in extinsts],
outs = outs.values(),
cmd = cmd,
cmd_bat = cmd,
tools = [":ggt"],
visibility = ["//visibility:private"],
)
def generate_extinst_lang_headers(name, grammar = None):
"""
Creates a :gen_extinst_lang_headers_* target for a C++ header
the enums in a SPIR-V extended instruction set.
Args:
name: the basename of the emitted header file.
grammar: the path to the JSON grammar file for the extended
instruction set.
"""
if not grammar:
fail("Must specify grammar", "grammar")
outs = dict(
extinst_output_path = name + ".h",
)
cmd = (
"$(location :generate_language_headers)" +
" --extinst-grammar=$<" +
" --extinst-output-path=$(location {extinst_output_path})"
).format(**outs)
native.genrule(
name = "gen_extinst_lang_headers_{}".format(name),
srcs = [grammar],
outs = outs.values(),
cmd = cmd,
cmd_bat = cmd,
tools = [":generate_language_headers"],
visibility = ["//visibility:private"],
)
@@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: SPIRV-Tools
Description: Tools for SPIR-V
Version: @CURRENT_VERSION@
URL: https://github.com/KhronosGroup/SPIRV-Tools
Libs: -L${libdir} @SPIRV_SHARED_LIBRARIES@
Cflags: -I${includedir}
@@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: SPIRV-Tools
Description: Tools for SPIR-V
Version: @CURRENT_VERSION@
URL: https://github.com/KhronosGroup/SPIRV-Tools
Libs: -L${libdir} @SPIRV_LIBRARIES@
Cflags: -I${includedir}
@@ -0,0 +1,31 @@
# Copyright (c) 2017 Pierre Moreau
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# First, retrieve the current version from CHANGES
file(STRINGS ${CHANGES_FILE} CHANGES_CONTENT)
string(
REGEX
MATCH "v[0-9]+(.[0-9]+)?(-dev)? [0-9]+-[0-9]+-[0-9]+"
FIRST_VERSION_LINE
${CHANGES_CONTENT})
string(
REGEX
REPLACE "^v([^ ]+) .+$" "\\1"
CURRENT_VERSION
"${FIRST_VERSION_LINE}")
# If this is a development version, replace "-dev" by ".0" as pkg-config nor
# CMake support "-dev" in the version.
# If it's not a "-dev" version then ensure it ends with ".1"
string(REGEX REPLACE "-dev.1" ".0" CURRENT_VERSION "${CURRENT_VERSION}.1")
configure_file(${TEMPLATE_FILE} ${OUT_FILE} @ONLY)
@@ -0,0 +1,2 @@
# This file is used by git cl to get repository specific information.
CODE_REVIEW_SERVER: github.com
@@ -0,0 +1,31 @@
# Downloads
## Vulkan SDK
The official releases for SPIRV-Tools can be found on LunarG's
[SDK download page](https://vulkan.lunarg.com/sdk/home).
The Vulkan SDK is updated approximately every six weeks.
## Android NDK
SPIRV-Tools host executables, and library sources are published as
part of the [Android NDK](https://developer.android.com/ndk/downloads).
## Automated builds
For convenience, here are also links to the latest builds (HEAD).
Those are untested automated builds. Those are not official releases, nor
are guaranteed to work. Official releases builds are in the Android NDK or
Vulkan SDK.
Download the latest builds of the [main](https://github.com/KhronosGroup/SPIRV-Tools/tree/main) branch.
| Platform | Processor | Compiler | Release build | Debug build |
| --- | --- | --- | --- | --- |
| Windows | x86-64 | VisualStudio 2022 (MSVC v143) | Download: <a href="https://storage.googleapis.com/spirv-tools/badges/build_link_windows_vs2022_release.html"> <img src="https://storage.googleapis.com/spirv-tools/badges/build_status_windows_vs2022_release.svg" alt="status of VS 2022 release build"></a> | Download: <a href="https://storage.googleapis.com/spirv-tools/badges/build_link_windows_vs2022_debug.html"> <img src="https://storage.googleapis.com/spirv-tools/badges/build_status_windows_vs2022_debug.svg" alt="status of VS 2022 debug build"></a> |
| Linux | x86-64 | GCC 15 | Download: <a href="https://storage.googleapis.com/spirv-tools/badges/build_link_linux_gcc_release.html"> <img src="https://storage.googleapis.com/spirv-tools/badges/build_status_linux_gcc_release.svg" alt="status of Linux GCC build"></a> | Download: <a href="https://storage.googleapis.com/spirv-tools/badges/build_link_linux_gcc_debug.html"> <img src="https://storage.googleapis.com/spirv-tools/badges/build_status_linux_gcc_debug.svg" alt="status of Linux GCC debug build"></a> |
| macOS | x86-64 | Clang 15 | Download: <a href="https://storage.googleapis.com/spirv-tools/badges/build_link_macos_clang_release.html"> <img src="https://storage.googleapis.com/spirv-tools/badges/build_status_macos_clang_release.svg" alt="status of macOS Clang build"></a> | Download: <a href="https://storage.googleapis.com/spirv-tools/badges/build_link_macos_clang_debug.html"> <img src="https://storage.googleapis.com/spirv-tools/badges/build_status_macos_clang_debug.svg" alt="status of macOS Clang build"></a> |
Note: If you suspect something is wrong with the compiler versions mentioned,
check the scripts and configurations in the [kokoro](../kokoro) source tree,
or the results of the checks on the latest commits on the `main` branch.
@@ -0,0 +1,82 @@
# Tracking SPIRV-Tools work with GitHub projects
We are experimenting with using the [GitHub Project
feature](https://help.github.com/articles/tracking-the-progress-of-your-work-with-projects/)
to track progress toward large goals.
For more on GitHub Projects in general, see:
* [Introductory blog post](https://github.com/blog/2256-a-whole-new-github-universe-announcing-new-tools-forums-and-features)
* [Introductory video](https://www.youtube.com/watch?v=C6MGKHkNtxU)
The current SPIRV-Tools project list can be found at
[https://github.com/KhronosGroup/SPIRV-Tools/projects](https://github.com/KhronosGroup/SPIRV-Tools/projects)
## How we use a Project
A GitHub Project is a set of work with an overall purpose, and
consists of a collection of *Cards*.
Each card is either a *Note* or a regular GitHub *Issue.*
A Note can be converted to an Issue.
In our projects, a card represents work, i.e. a change that can
be applied to the repository.
The work could be a feature, a bug to be fixed, documentation to be
updated, etc.
A project and its cards are used as a [Kanban
board](https://en.wikipedia.org/wiki/Kanban_board), where cards progress
through a workflow starting with ideas through to implementation and completion.
In our usage, a *project manager* is someone who organizes the work.
They manage the creation and movement of cards
through the project workflow:
* They create cards to capture ideas, or to decompose large ideas into smaller
ones.
* They determine if the work for a card has been completed.
* Normally they are the person (or persons) who can approve and merge a pull
request into the `main` branch.
Our projects organize cards into the following columns:
* `Ideas`: Work which could be done, captured either as Cards or Notes.
* A card in this column could be marked as a [PLACEHOLDER](#placeholders).
* `Ready to start`: Issues which represent work we'd like to do, and which
are not blocked by other work.
* The issue should be narrow enough that it can usually be addressed by a
single pull request.
* We want these to be Issues (not Notes) so that someone can claim the work
by updating the Issue with their intent to do the work.
Once an Issue is claimed, the project manager moves the corresponding card
from `Ready to start` to `In progress`.
* `In progress`: Issues which were in `Ready to start` but which have been
claimed by someone.
* `Done`: Issues which have been resolved, by completing their work.
* The changes have been applied to the repository, typically by being pushed
into the `main` branch.
* Other kinds of work could update repository settings, for example.
* `Rejected ideas`: Work which has been considered, but which we don't want
implemented.
* We keep rejected ideas so they are not proposed again. This serves
as a form of institutional memory.
* We should record why an idea is rejected. For this reason, a rejected
idea is likely to be an Issue which has been closed.
## Prioritization
We are considering prioritizing cards in the `Ideas` and `Ready to start`
columns so that things that should be considered first float up to the top.
Experience will tell us if we stick to that rule, and if it proves helpful.
## Placeholders
A *placeholder* is a Note or Issue that represents a possibly large amount
of work that can be broadly defined but which may not have been broken down
into small implementable pieces of work.
Use a placeholder to capture a big idea, but without doing the upfront work
to consider all the details of how it should be implemented.
Over time, break off pieces of the placeholder into implementable Issues.
Move those Issues into the `Ready to start` column when they become unblocked.
We delete the placeholder when all its work has been decomposed into
implementable cards.
@@ -0,0 +1,83 @@
# Guide to writing a spirv-fuzz fuzzer pass
Writing a spirv-fuzz fuzzer pass usually requires two main contributions:
- A *transformation*, capturing a small semantics-preserving change that can be made to a SPIR-V module. This requires adding a protobuf message representing the transformation, and a corresponding class that implements the `Transformation` interface.
- A new *fuzzer pass* class, implementing the `FuzzerPass` interface, that knows how to walk a SPIR-V module and apply the new transformation in a randomized fashion.
In some cases, more than one kind of transformation is required for a single fuzzer pass, and in some cases the transformations that a new fuzzer pass requires have already been introduced by existing passes. But the most common case is to introduce a transformation and fuzzer pass together.
As an example, let's consider the `TransformationSetSelectionControl` transformation. In SPIR-V, an `OpSelectionMerge` instruction (which intuitively indicates the start of an `if` or `switch` statement in a function) has a *selection control* mask, that can be one of `None`, `Flatten` or `DontFlatten`. The details of these do not matter much for this little tutorial, but in brief, this parameter provides a hint to the shader compiler as to whether it would be profitable to attempt to flatten a piece of conditional code so that all of its statements are executed in a predicated fashion.
As the selection control mask is just a hint, changing the value of this mask should have no semantic impact on the module. The `TransformationSelectionControl` transformation specifies a new value for a given selection control mask.
## Adding a new protobuf message
Take a look at the `Transformation` message in `spvtoolsfuzz.proto`. This has a `oneof` field that can be any one of the different spirv-fuzz transformations. Observe that one of the options is `TransformationSetSelectionControl`. When adding a transformation you first need to add an option for your transformation to the end of the `oneof` declaration.
Now look at the `TransformationSetSelectionControl` message. If adding your own transformation you need to add a new message for your transformation, and it should be placed alphabetically with respect to other transformations.
The fields of `TransformationSetSelectionControl` provide just enough information to (a) determine whether a given example of this transformation is actually applicable, and (b) apply the transformation in the case that it is applicable. The details of the transformation message will vary a lot between transformations. In this case, the message has a `block_id` field, specifying a block that must end with `OpSelectionMerge`, and a `selection_control` field, which is the new value for the selection control mask of the `OpSelectionMerge` instruction.
## Adding a new transformation class
If your transformation is called `TransformationSomeThing`, you need to add `transformation_some_thing.h` and `transformation_some_thing.cpp` to `source/fuzz` and the corresponding `CMakeLists.txt` file. So for `TransformationSetSelectionControl` we have `transformation_selection_control.h` and `transformation_selection_control.cpp`, and we will use this as an example to illustrate the expected contents of these files.
The header file contains the specification of a class, `TransformationSetSelectionControl`, that implements the `Transformation` interface (from `transformation.h`).
A transformation class should always have a single field, which should be the associated protobuf message; in our case:
```
private:
protobufs::TransformationSetSelectionControl message_;
```
and two public constructors, one that takes a protobuf message; in our case:
```
explicit TransformationSetSelectionControl(
const protobufs::TransformationSetSelectionControl& message);
```
and one that takes a parameter for each protobuf message field; in our case:
```
TransformationSetSelectionControl(uint32_t block_id);
```
The first constructor allows an instance of the class to be created from a corresponding protobuf message. The second should provide the ingredients necessary to populate a protobuf message.
The class should also override the `IsApplicable`, `Apply` and `ToMessage` methods from `Transformation`.
See `transformation_set_selection_control.h` for an example.
The `IsApplicable` method should have a comment in the header file describing the conditions for applicability in simple terms. These conditions should be implemented in the body of this method in the `.cpp` file.
In the case of `TransformationSetSelectionControl`, `IsApplicable` involves checking that `block_id` is indeed the id of a block that has an `OpSelectionMerge` instruction, and that `selection_control` is a valid selection mask.
The `Apply` method should have a comment in the header file summarising the result of applying the transformation. It should be implemented in the `.cpp` file, and you should assume that `IsApplicable` holds whenever `Apply` is invoked.
## Writing tests for the transformation class
Whenever you add a transformation class, `TransformationSomeThing`, you should add an associated test file, `transformation_some_thing_test.cpp`, under `test/fuzz`, adding it to the associated `CMakeLists.txt` file.
For example `test/fuzz/transformation_set_selection_control_test.cpp` contains tests for `TransformationSetSelectionControl`. Your tests should aim to cover one example from each scenario where the transformation is inapplicable, and check that it is indeed deemed inapplicable, and then check that the transformation does the right thing when applied in a few different ways.
For example, the tests for `TransformationSetSelectionControl` check that a transformation of this kind is inapplicable if the `block_id` field of the transformation is not a block, or does not end in `OpSelectionMerge`, or if the `selection_control` mask has an illegal value. It also checks that applying a sequence of valid transformations to a SPIR-V shader leads to a shader with appropriately modified selection controls.
## Adding a new fuzzer pass class
A *fuzzer pass* traverses a SPIR-V module looking for places to apply a certain kind of transformation, and randomly decides at which of these points to actually apply the transformation. It might be necessary to apply other transformations in order to apply a given transformation (for example, if a transformation requires a certain type to be present in the module, said type can be added if not already present via another transformation).
A fuzzer pass implements the `FuzzerPass` interface, and overrides its `Apply` method. If your fuzzer pass is named `FuzzerPassSomeThing` then it should be represented by `fuzzer_pass_some_thing.h` and `fuzzer_pass_some_thing.cpp`, under `source/fuzz`; these should be added to the associated `CMakeLists.txt` file.
Have a look at the source filed for `FuzzerPassAdjustSelectionControls`. This pass considers every block that ends with `OpSelectionMerge`. It decides randomly whether to adjust the selection control of this merge instruction via:
```
if (!GetFuzzerContext()->ChoosePercentage(
GetFuzzerContext()->GetChanceOfAdjustingSelectionControl())) {
continue;
}
```
The `GetChanceOfAddingSelectionControl()` method has been added to `FuzzerContext` specifically to support this pass, and returns a percentage between 0 and 100. It returns the `chance_of_adjusting_selection_control_` of `FuzzerContext`, which is randomly initialized to lie with the interval defined by `kChanceOfAdjustingSelectionControl` in `fuzzer_context.cpp`. For any pass you write, you will need to add an analogous `GetChanceOf...` method to `FuzzerContext`, backed by an appropriate field, and you will need to decide on lower and upper bounds for this field and specify these via a `kChanceOf...` constant.
@@ -0,0 +1,285 @@
# SPIR-V Assembly language syntax
## Overview
The assembly attempts to adhere to the binary form from Section 3 of the SPIR-V
spec as closely as possible, with one exception aiming at improving the text's
readability. The `<result-id>` generated by an instruction is moved to the
beginning of that instruction and followed by an `=` sign. This allows us to
distinguish between variable definitions and uses and locate value definitions
more easily.
Here is an example:
```
OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint GLCompute %3 "main"
OpExecutionMode %3 LocalSize 64 64 1
%1 = OpTypeVoid
%2 = OpTypeFunction %1
%3 = OpFunction %1 None %2
%4 = OpLabel
OpReturn
OpFunctionEnd
```
A module is a sequence of instructions, separated by whitespace.
An instruction is an opcode name followed by operands, separated by
whitespace. Typically each instruction is presented on its own line,
but the assembler does not enforce this rule.
The opcode names and expected operands are described in Section 3 of
the SPIR-V specification. An operand is one of:
* a literal integer: A decimal integer, or a hexadecimal integer.
A hexadecimal integer is indicated by a leading `0x` or `0X`. A hex
integer supplied for a signed integer value will be sign-extended.
For example, `0xffff` supplied as the literal for an `OpConstant`
on a signed 16-bit integer type will be interpreted as the value `-1`.
* a literal floating point number, in decimal or hexadecimal form.
See [below](#floats).
* a literal string.
* A literal string is everything following a double-quote `"` until the
following un-escaped double-quote. This includes special characters such
as newlines.
* A backslash `\` may be used to escape characters in the string. The `\`
may be used to escape a double-quote or a `\` but is simply ignored when
preceding any other character.
* a named enumerated value, specific to that operand position. For example,
the `OpMemoryModel` takes a named Addressing Model operand (e.g. `Logical` or
`Physical32`), and a named Memory Model operand (e.g. `Simple` or `OpenCL`).
Named enumerated values are only meaningful in specific positions, and will
otherwise generate an error.
* a mask expression, consisting of one or more mask enum names separated
by `|`. For example, the expression `NotNaN|NotInf|NSZ` denotes the mask
which is the combination of the `NotNaN`, `NotInf`, and `NSZ` flags.
* an injected immediate integer: `!<integer>`. See [below](#immediate).
* an ID, e.g. `%foo`. See [below](#id).
* the name of an extended instruction. For example, `sqrt` in an extended
instruction such as `%f = OpExtInst %f32 %OpenCLImport sqrt %arg`
* the name of an opcode for OpSpecConstantOp, but where the `Op` prefix
is removed. For example, the following indicates the use of an integer
addition in a specialization constant computation:
`%sum = OpSpecConstantOp %i32 IAdd %a %b`
## ID Definitions & Usage
<a name="id"></a>
An ID _definition_ pertains to the `<result-id>` of an instruction, and ID
_usage_ is a use of an ID as an input to an instruction.
An ID in the assembly language begins with `%` and must be followed by a name
consisting of one or more letters, numbers or underscore characters.
For every ID in the assembly program, the assembler generates a unique number
called the ID's internal number. Then each ID reference translates into its
internal number in the SPIR-V output. Internal numbers are unique within the
compilation unit: no two IDs in the same unit will share internal numbers.
The disassembler generates IDs where the name is always a decimal number
greater than 0.
So the example can be rewritten using more user-friendly names, as follows:
```
OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 64 64 1
%void = OpTypeVoid
%fnMain = OpTypeFunction %void
%main = OpFunction %void None %fnMain
%lbMain = OpLabel
OpReturn
OpFunctionEnd
```
## Floating point literals
<a name="floats"></a>
The assembler and disassembler support floating point literals in both
decimal and hexadecimal form.
The syntax for a floating point literal is the same as floating point
constants in the C programming language, except:
* An optional leading minus (`-`) or leading plus (`+`) is part of the literal.
* An optional type specifier suffix is not allowed.
Infinity and NaN values are expressed in hexadecimal float literals
by using the maximum representable exponent for the bit width.
For example, in 32-bit floating point, 8 bits are used for the exponent, and the
exponent bias is 127. So the maximum representable unbiased exponent is 128.
Therefore, we represent the infinities and some NaNs as follows:
```
%float32 = OpTypeFloat 32
%inf = OpConstant %float32 0x1p+128
%neginf = OpConstant %float32 -0x1p+128
%aNaN = OpConstant %float32 0x1.8p+128
%moreNaN = OpConstant %float32 -0x1.0002p+128
```
The assembler preserves all the bits of a NaN value. For example, the encoding
of `%aNaN` in the previous example is the same as the word with bits
`0x7fc00000`, and `%moreNaN` is encoded as `0xff800100`.
The disassembler prints infinite, NaN, and subnormal values in hexadecimal form.
Zero and normal values are printed in decimal form with enough digits
to preserve all significand bits.
Hex float values that underflow are rounded to zero. If there is a leading
minus sign, underflow goes to negative zero.
## Arbitrary Integers
<a name="immediate"></a>
When writing tests it can be useful to emit an invalid 32 bit word into the
binary stream at arbitrary positions within the assembly. To specify an
arbitrary word into the stream the prefix `!` is used, this takes the form
`!<integer>`. Here is an example.
```
OpCapability !0x0000FF00
```
Any token in a valid assembly program may be replaced by `!<integer>` -- even
tokens that dictate how the rest of the instruction is parsed. Consider, for
example, the following assembly program:
```
%4 = OpConstant %1 123 456 789 OpExecutionMode %2 LocalSize 11 22 33
OpExecutionMode %3 InputLines
```
The tokens `OpConstant`, `LocalSize`, and `InputLines` may be replaced by random
`!<integer>` values, and the assembler will still assemble an output binary with
three instructions. It will not necessarily be valid SPIR-V, but it will
faithfully reflect the input text.
You may wonder how the assembler recognizes the instruction structure (including
instruction boundaries) in the text with certain crucial tokens replaced by
arbitrary integers. If, say, `OpConstant` becomes a `!<integer>` whose value
differs from the binary representation of `OpConstant` (remember that this
feature is intended for fine-grain control in SPIR-V testing), the assembler
generally has no idea what that value stands for. So how does it know there is
exactly one `<id>` and three number literals following in that instruction,
before the next one begins? And if `LocalSize` is replaced by an arbitrary
`!<integer>`, how does it know to take the next three tokens (instead of zero or
one, both of which are possible in the absence of certainty that `LocalSize`
provided)? The answer is a simple rule governing the parsing of instructions
with `!<integer>` in them:
When a token in the assembly program is a `!<integer>`, that integer value is
emitted into the binary output, and parsing proceeds differently than before:
each subsequent token not recognized as an OpCode or a `<result-id>` is emitted
into the binary output without any checking; when a recognizable OpCode or a
`<result-id>` is eventually encountered, it begins a new instruction and parsing
returns to normal. (If a subsequent OpCode is never found, then this alternate
parsing mode handles all the remaining tokens in the program.)
The assembler processes the tokens encountered in alternate parsing mode as
follows:
* If the token is a number literal, since context may be lost, the number
is interpreted as a 32-bit value and output as a single word. In order to
specify multiple-word literals in alternate-parsing mode, further uses of
`!<integer>` tokens may be required.
All formats supported by `strtoul()` are accepted.
* If the token is a string literal, it outputs a sequence of words representing
the string as defined in the SPIR-V specification for Literal String.
* If the token is an ID, it outputs the ID's internal number.
* If the token is another `!<integer>`, it outputs that integer.
* Any other token causes the assembler to quit with an error.
Note that this has some interesting consequences, including:
* When an OpCode is replaced by `!<integer>`, the integer value should encode
the instruction's word count, as specified in the physical-layout section of
the SPIR-V specification.
* Consecutive instructions may have their OpCode replaced by `!<integer>` and
still produce valid SPIR-V. For example, `!262187 %1 %2 "abc" !327739 %1 %3 6
%2` will successfully assemble into SPIR-V declaring a constant and a
PrivateGlobal variable.
* Enums (such as `DontInline` or `SubgroupMemory`, for instance) are not handled
by the alternate parsing mode. They must be replaced by `!<integer>` for
successful assembly.
* The `<result-id>` on the left-hand side of an assignment cannot be a
`!<integer>`. The `<result-id>` can be still be manually controlled if desired
by expressing the entire instruction as `!<integer>` tokens for its opcode and
operands.
* The `=` sign cannot be processed by the alternate parsing mode if the OpCode
following it is a `!<integer>`.
* When replacing a named ID with `!<integer>`, it is possible to generate
unintentionally valid SPIR-V. If the integer provided happens to equal a
number generated for an existing named ID, it will result in a reference to
that named ID being output. This may be valid SPIR-V, contrary to the
presumed intention of the writer.
## OpUnknown
<a name="op-unknown"></a>
HLSL has a feature that allows users to specify an exact SPIR-V type using [the
`SpirvType` template](https://github.com/microsoft/hlsl-specs/blob/main/proposals/0011-inline-spirv.md#types).
This feature allows the user to specify a type opcode that the compiler does
not know. In this case, it will be unable to generate assembly using the
correct mnemonic.
In order to represent unknown opcodes in assembly format, the `OpUnknown`
pseudo-instruction may be used. The syntax is:
```
OpUnknown(<enumerant>, <WordCount>) <operand 1> ...
```
`enumerant` is the opcode enumerant, and `WordCount` is the number of words in
the instruction. These will be assembled into a single word representing the
opcode. Operands will be parsed according to the alternate parsing mode
described in [Arbitrary Integers](#op-unknown). Named enumerated values cannot
be handled by this mode and must be represented using the arbitrary integer
syntax.
It must be used at the beginning of a new instruction, and if there is a result
ID it must explicitly be passed in as an operand. This is because the physical
layout of a SPIR-V instruction may include a result type operand before the
result ID operand, but it depends on the opcode and cannot be inferred for an
unknown operand.
For example, a 32-bit signed integer type could be represented like this:
```
OpUnknown(21, 4) %int_t 32 1
```
An OpStore instruction could be represented as:
```
OpUnknown(62, 3) %9 %12
```
The enumerant and word count must be decimal integers.
## Notes
* Some enumerants cannot be used by name, because the target instruction
in which they are meaningful take an ID reference instead of a literal value.
For example:
* Named enumerated value `CmdExecTime` from section 3.30 Kernel
Profiling Info is used in constructing a mask value supplied as
an ID for `OpCaptureEventProfilingInfo`. But no other instruction
has enough context to bring the enumerant names from section 3.30
into scope.
* Similarly, the names in section 3.29 Kernel Enqueue Flags are used to
construct a value supplied as an ID to the Flags argument of
OpEnqueueKernel.
* Similarly for the names in section 3.25 Memory Semantics.
* Similarly for the names in section 3.27 Scope.
* Some enumerants cannot be used by name, because they only name values
returned by an instruction:
* Enumerants from 3.12 Image Channel Order name possible values returned
by the `OpImageQueryOrder` instruction.
* Enumerants from 3.13 Image Channel Data Type name possible values
returned by the `OpImageQueryFormat` instruction.
@@ -0,0 +1,35 @@
# Copyright (c) 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Add a SPIR-V Tools example. Signature:
# add_spvtools_example(
# TARGET target_name
# SRCS src_file1.cpp src_file2.cpp
# LIBS lib_target1 lib_target2
# )
function(add_spvtools_example)
if (NOT ${SPIRV_SKIP_EXECUTABLES})
set(one_value_args TARGET)
set(multi_value_args SRCS LIBS)
cmake_parse_arguments(
ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN})
add_executable(${ARG_TARGET} ${ARG_SRCS})
spvtools_default_compile_options(${ARG_TARGET})
target_link_libraries(${ARG_TARGET} PRIVATE ${ARG_LIBS})
set_property(TARGET ${ARG_TARGET} PROPERTY FOLDER "SPIRV-Tools examples")
endif()
endfunction()
add_subdirectory(cpp-interface)
@@ -0,0 +1,19 @@
# Copyright (c) 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
add_spvtools_example(
TARGET spirv-tools-cpp-example
SRCS main.cpp
LIBS SPIRV-Tools-opt
)
@@ -0,0 +1,65 @@
// Copyright (c) 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This program demonstrates basic SPIR-V module processing using
// SPIRV-Tools C++ API:
// * Assembling
// * Validating
// * Optimizing
// * Disassembling
#include <iostream>
#include <string>
#include <vector>
#include "spirv-tools/libspirv.hpp"
#include "spirv-tools/optimizer.hpp"
int main() {
const std::string source =
" OpCapability Linkage "
" OpCapability Shader "
" OpMemoryModel Logical GLSL450 "
" OpSource GLSL 450 "
" OpDecorate %spec SpecId 1 "
" %int = OpTypeInt 32 1 "
" %spec = OpSpecConstant %int 0 "
"%const = OpConstant %int 42";
spvtools::SpirvTools core(SPV_ENV_UNIVERSAL_1_3);
spvtools::Optimizer opt(SPV_ENV_UNIVERSAL_1_3);
auto print_msg_to_stderr = [](spv_message_level_t, const char*,
const spv_position_t&, const char* m) {
std::cerr << "error: " << m << std::endl;
};
core.SetMessageConsumer(print_msg_to_stderr);
opt.SetMessageConsumer(print_msg_to_stderr);
std::vector<uint32_t> spirv;
if (!core.Assemble(source, &spirv)) return 1;
if (!core.Validate(spirv)) return 1;
opt.RegisterPass(spvtools::CreateSetSpecConstantDefaultValuePass({{1, "42"}}))
.RegisterPass(spvtools::CreateFreezeSpecConstantValuePass())
.RegisterPass(spvtools::CreateUnifyConstantPass())
.RegisterPass(spvtools::CreateStripDebugInfoPass());
if (!opt.Run(spirv.data(), spirv.size(), &spirv)) return 1;
std::string disassembly;
if (!core.Disassemble(spirv, &disassembly)) return 1;
std::cout << disassembly << "\n";
return 0;
}
@@ -0,0 +1,233 @@
# Copyright (c) 2015-2016 The Khronos Group Inc.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Utility functions for pushing & popping variables.
function(push_variable var val)
set("${var}_SAVE_STACK" "${${var}}" "${${var}_SAVE_STACK}" PARENT_SCOPE)
set(${var} ${val} PARENT_SCOPE)
endfunction()
function(pop_variable var)
set(save_stack "${${var}_SAVE_STACK}")
list(GET save_stack 0 val)
list(REMOVE_AT save_stack 0)
set("${var}_SAVE_STACK" "${save_stack}" PARENT_SCOPE)
set(${var} ${val} PARENT_SCOPE)
endfunction()
if (DEFINED mimalloc_SOURCE_DIR)
# This allows flexible position of the mimalloc repo.
set(MIMALLOC_DIR ${mimalloc_SOURCE_DIR})
else()
if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mimalloc)
set(MIMALLOC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/mimalloc)
endif()
endif()
# Used on Windows by default, but allow opt-in on other platforms
if (WIN32)
set(SPIRV_TOOLS_USE_MIMALLOC_DEFAULT_VALUE ON)
set(SPIRV_TOOLS_USE_MIMALLOC_IN_STATIC_BUILD_DEFAULT_VALUE OFF)
else()
set(SPIRV_TOOLS_USE_MIMALLOC_DEFAULT_VALUE OFF)
set(SPIRV_TOOLS_USE_MIMALLOC_IN_STATIC_BUILD_DEFAULT_VALUE OFF)
endif()
# To avoid unexpected side effects on users of the static library, mimalloc
# must be explicitly enabled when building static libraries.
include(CMakeDependentOption)
cmake_dependent_option(SPIRV_TOOLS_USE_MIMALLOC
"Executables and shared libraries use mimalloc instead of the default allocator"
${SPIRV_TOOLS_USE_MIMALLOC_DEFAULT_VALUE} "MIMALLOC_DIR" OFF)
cmake_dependent_option(SPIRV_TOOLS_USE_MIMALLOC_IN_STATIC_BUILD
"Static libraries use mimalloc instead of the default allocator"
${SPIRV_TOOLS_USE_MIMALLOC_IN_STATIC_BUILD_DEFAULT_VALUE} SPIRV_TOOLS_USE_MIMALLOC OFF)
if (SPIRV_TOOLS_USE_MIMALLOC)
if (NOT WIN32)
push_variable(MI_OVERRIDE 0)
endif()
push_variable(MI_BUILD_TESTS 0)
add_subdirectory(${MIMALLOC_DIR} ${CMAKE_BINARY_DIR}/external/mimalloc EXCLUDE_FROM_ALL)
if (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
target_compile_options(mimalloc-static PRIVATE -Wno-int-conversion)
endif()
if (NOT WIN32)
pop_variable(MI_OVERRIDE)
endif()
pop_variable(MI_BUILD_TESTS)
endif()
if (DEFINED SPIRV-Headers_SOURCE_DIR)
# This allows flexible position of the SPIRV-Headers repo.
set(SPIRV_HEADER_DIR ${SPIRV-Headers_SOURCE_DIR})
else()
set(SPIRV_HEADER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/spirv-headers)
endif()
if (IS_DIRECTORY ${SPIRV_HEADER_DIR})
# TODO(dneto): We should not be modifying the parent scope.
set(SPIRV_HEADER_INCLUDE_DIR ${SPIRV_HEADER_DIR}/include PARENT_SCOPE)
# Add SPIRV-Headers as a sub-project if it isn't already defined.
# Do this so enclosing projects can use SPIRV-Headers_SOURCE_DIR to find
# headers to include.
if (NOT DEFINED SPIRV-Headers_SOURCE_DIR)
add_subdirectory(${SPIRV_HEADER_DIR})
endif()
else()
message(FATAL_ERROR
"SPIRV-Headers was not found - please checkout a copy at external/spirv-headers.")
endif()
if (NOT ${SPIRV_SKIP_TESTS})
# Find gmock if we can. If it's not already configured, then try finding
# it in external/googletest.
if (TARGET gmock)
message(STATUS "Google Mock already configured")
else()
if (NOT GMOCK_DIR)
set(GMOCK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
endif()
if(EXISTS ${GMOCK_DIR})
if(MSVC)
# Our tests use ::testing::Combine. Work around a compiler
# detection problem in googletest, where that template is
# accidentally disabled for VS 2017.
# See https://github.com/google/googletest/issues/1352
add_definitions(-DGTEST_HAS_COMBINE=1)
endif()
if(WIN32)
option(gtest_force_shared_crt
"Use shared (DLL) run-time lib even when Google Test is built as static lib."
ON)
endif()
# gtest requires special defines for building as a shared
# library, simply always build as static.
push_variable(BUILD_SHARED_LIBS 0)
add_subdirectory(${GMOCK_DIR} ${CMAKE_CURRENT_BINARY_DIR}/googletest EXCLUDE_FROM_ALL)
pop_variable(BUILD_SHARED_LIBS)
endif()
endif()
if (TARGET gmock)
set(GTEST_TARGETS
gtest
gtest_main
gmock
gmock_main
)
foreach(target ${GTEST_TARGETS})
set_property(TARGET ${target} PROPERTY FOLDER GoogleTest)
endforeach()
endif()
# Find Effcee and RE2, for testing.
# RE2 depends on Abseil. We set absl_SOURCE_DIR if it is not already set, so
# that effcee can find abseil.
if(NOT TARGET absl::base)
if (NOT absl_SOURCE_DIR)
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/abseil_cpp)
set(absl_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/abseil_cpp" CACHE STRING "Abseil source dir" )
endif()
endif()
endif()
# First find RE2, since Effcee depends on it.
# If already configured, then use that. Otherwise, prefer to find it under 're2'
# in this directory.
if (NOT TARGET re2)
# If we are configuring RE2, then turn off its testing. It takes a long time and
# does not add much value for us. If an enclosing project configured RE2, then it
# has already chosen whether to enable RE2 testing.
set(RE2_BUILD_TESTING OFF CACHE STRING "Run RE2 Tests")
if (NOT RE2_SOURCE_DIR)
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/re2)
set(RE2_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/re2" CACHE STRING "RE2 source dir" )
endif()
endif()
endif()
if (NOT TARGET effcee)
# Expect to find effcee in this directory.
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/effcee)
# If we're configuring RE2 (via Effcee), then turn off RE2 testing.
if (NOT TARGET re2)
set(RE2_BUILD_TESTING OFF)
endif()
if (MSVC)
# SPIRV-Tools uses the shared CRT with MSVC. Tell Effcee to do the same.
set(EFFCEE_ENABLE_SHARED_CRT ON)
endif()
set(EFFCEE_BUILD_SAMPLES OFF CACHE BOOL "Do not build Effcee examples")
if (NOT TARGET effcee)
set(EFFCEE_BUILD_TESTING OFF CACHE BOOL "Do not build Effcee test suite")
endif()
push_variable(BUILD_SHARED_LIBS 0) # effcee does not export any symbols for building as a DLL. Always build as static.
add_subdirectory(effcee EXCLUDE_FROM_ALL)
pop_variable(BUILD_SHARED_LIBS)
set_property(TARGET effcee PROPERTY FOLDER Effcee)
# Turn off warnings for effcee and re2
set_property(TARGET effcee APPEND PROPERTY COMPILE_OPTIONS -w)
set_property(TARGET re2 APPEND PROPERTY COMPILE_OPTIONS -w)
endif()
endif()
endif()
if(SPIRV_BUILD_FUZZER)
function(backup_compile_options)
get_property(
SPIRV_TOOLS_BACKUP_EXTERNAL_COMPILE_OPTIONS
DIRECTORY
PROPERTY COMPILE_OPTIONS
)
endfunction()
function(restore_compile_options)
set_property(
DIRECTORY
PROPERTY COMPILE_OPTIONS
${SPIRV_TOOLS_BACKUP_EXTERNAL_COMPILE_OPTIONS}
)
endfunction()
if(NOT TARGET protobuf::libprotobuf OR NOT TARGET protobuf::protoc)
set(SPIRV_TOOLS_PROTOBUF_DIR ${CMAKE_CURRENT_SOURCE_DIR}/protobuf)
if (NOT IS_DIRECTORY ${SPIRV_TOOLS_PROTOBUF_DIR})
message(
FATAL_ERROR
"protobuf not found - please checkout a copy under external/.")
endif()
set(protobuf_BUILD_TESTS OFF CACHE BOOL "Disable protobuf tests")
set(protobuf_MSVC_STATIC_RUNTIME OFF CACHE BOOL "Do not build protobuf static runtime")
backup_compile_options()
if (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
add_compile_options(-Wno-inconsistent-missing-override)
endif()
add_subdirectory(${SPIRV_TOOLS_PROTOBUF_DIR} EXCLUDE_FROM_ALL)
restore_compile_options()
endif()
endif()
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,432 @@
// Copyright (c) 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef INCLUDE_SPIRV_TOOLS_LIBSPIRV_HPP_
#define INCLUDE_SPIRV_TOOLS_LIBSPIRV_HPP_
#include <functional>
#include <memory>
#include <string>
#include <vector>
#include "libspirv.h"
namespace spvtools {
// Message consumer. The C strings for source and message are only alive for the
// specific invocation.
using MessageConsumer = std::function<void(
spv_message_level_t /* level */, const char* /* source */,
const spv_position_t& /* position */, const char* /* message */
)>;
using HeaderParser = std::function<spv_result_t(
const spv_endianness_t endianess, const spv_parsed_header_t& instruction)>;
using InstructionParser =
std::function<spv_result_t(const spv_parsed_instruction_t& instruction)>;
// C++ RAII wrapper around the C context object spv_context.
class SPIRV_TOOLS_EXPORT Context {
public:
// Constructs a context targeting the given environment |env|.
//
// See specific API calls for how the target environment is interpreted
// (particularly assembly and validation).
//
// The constructed instance will have an empty message consumer, which just
// ignores all messages from the library. Use SetMessageConsumer() to supply
// one if messages are of concern.
explicit Context(spv_target_env env);
// Enables move constructor/assignment operations.
Context(Context&& other);
Context& operator=(Context&& other);
// Disables copy constructor/assignment operations.
Context(const Context&) = delete;
Context& operator=(const Context&) = delete;
// Destructs this instance.
~Context();
// Sets the message consumer to the given |consumer|. The |consumer| will be
// invoked once for each message communicated from the library.
void SetMessageConsumer(MessageConsumer consumer);
// Returns the underlying spv_context.
spv_context& CContext();
const spv_context& CContext() const;
private:
spv_context context_;
};
// A RAII wrapper around a validator options object.
class SPIRV_TOOLS_EXPORT ValidatorOptions {
public:
ValidatorOptions() : options_(spvValidatorOptionsCreate()) {}
~ValidatorOptions() { spvValidatorOptionsDestroy(options_); }
// Allow implicit conversion to the underlying object.
operator spv_validator_options() const { return options_; }
// Sets a limit.
void SetUniversalLimit(spv_validator_limit limit_type, uint32_t limit) {
spvValidatorOptionsSetUniversalLimit(options_, limit_type, limit);
}
void SetRelaxStructStore(bool val) {
spvValidatorOptionsSetRelaxStoreStruct(options_, val);
}
// Enables VK_KHR_relaxed_block_layout when validating standard
// uniform/storage buffer/push-constant layout. If true, disables
// scalar block layout rules.
void SetRelaxBlockLayout(bool val) {
spvValidatorOptionsSetRelaxBlockLayout(options_, val);
}
// Enables VK_KHR_uniform_buffer_standard_layout when validating standard
// uniform layout. If true, disables scalar block layout rules.
void SetUniformBufferStandardLayout(bool val) {
spvValidatorOptionsSetUniformBufferStandardLayout(options_, val);
}
// Enables VK_EXT_scalar_block_layout when validating standard
// uniform/storage buffer/push-constant layout. If true, disables
// relaxed block layout rules.
void SetScalarBlockLayout(bool val) {
spvValidatorOptionsSetScalarBlockLayout(options_, val);
}
// Enables scalar layout when validating Workgroup blocks. See
// VK_KHR_workgroup_memory_explicit_layout.
void SetWorkgroupScalarBlockLayout(bool val) {
spvValidatorOptionsSetWorkgroupScalarBlockLayout(options_, val);
}
// Skips validating standard uniform/storage buffer/push-constant layout.
void SetSkipBlockLayout(bool val) {
spvValidatorOptionsSetSkipBlockLayout(options_, val);
}
// Enables LocalSizeId decorations where the environment would not otherwise
// allow them.
void SetAllowLocalSizeId(bool val) {
spvValidatorOptionsSetAllowLocalSizeId(options_, val);
}
// Allow Offset (in addition to ConstOffset) for texture
// operations. Was added for VK_KHR_maintenance8
void SetAllowOffsetTextureOperand(bool val) {
spvValidatorOptionsSetAllowOffsetTextureOperand(options_, val);
}
// Allow base operands of some bit operations to be non-32-bit wide.
// Was added for VK_KHR_maintenance9
void SetAllowVulkan32BitBitwise(bool val) {
spvValidatorOptionsSetAllowVulkan32BitBitwise(options_, val);
}
// Sets custom size and alignment for buffer and acceleration structure
// descriptor heap resources.
void SetBufferDescriptorLayout(uint32_t size, uint32_t alignment) {
spvValidatorOptionsSetBufferDescriptorLayout(options_, size, alignment);
}
// Sets custom size and alignment for image and sampled image descriptor heap
// resources.
void SetImageDescriptorLayout(uint32_t size, uint32_t alignment) {
spvValidatorOptionsSetImageDescriptorLayout(options_, size, alignment);
}
// Sets custom size and alignment for sampler descriptor heap resources.
void SetSamplerDescriptorLayout(uint32_t size, uint32_t alignment) {
spvValidatorOptionsSetSamplerDescriptorLayout(options_, size, alignment);
}
// Sets custom size and alignment for tensor descriptor heap resources.
void SetTensorDescriptorLayout(uint32_t size, uint32_t alignment) {
spvValidatorOptionsSetTensorDescriptorLayout(options_, size, alignment);
}
// Records whether or not the validator should relax the rules on pointer
// usage in logical addressing mode.
//
// When relaxed, it will allow the following usage cases of pointers:
// 1) OpVariable allocating an object whose type is a pointer type
// 2) OpReturnValue returning a pointer value
void SetRelaxLogicalPointer(bool val) {
spvValidatorOptionsSetRelaxLogicalPointer(options_, val);
}
// Records whether or not the validator should relax the rules because it is
// expected that the optimizations will make the code legal.
//
// When relaxed, it will allow the following:
// 1) It will allow relaxed logical pointers. Setting this option will also
// set that option.
// 2) Pointers that are pass as parameters to function calls do not have to
// match the storage class of the formal parameter.
// 3) Pointers that are actual parameters on function calls do not have to
// point to the same type pointed as the formal parameter. The types just
// need to logically match.
// 4) GLSLstd450 Interpolate* instructions can have a load of an interpolant
// for a first argument.
void SetBeforeHlslLegalization(bool val) {
spvValidatorOptionsSetBeforeHlslLegalization(options_, val);
}
// Whether friendly names should be used in validation error messages.
void SetFriendlyNames(bool val) {
spvValidatorOptionsSetFriendlyNames(options_, val);
}
private:
spv_validator_options options_;
};
// A C++ wrapper around an optimization options object.
class SPIRV_TOOLS_EXPORT OptimizerOptions {
public:
OptimizerOptions() : options_(spvOptimizerOptionsCreate()) {}
~OptimizerOptions() { spvOptimizerOptionsDestroy(options_); }
// Allow implicit conversion to the underlying object.
operator spv_optimizer_options() const { return options_; }
// Records whether or not the optimizer should run the validator before
// optimizing. If |run| is true, the validator will be run.
void set_run_validator(bool run) {
spvOptimizerOptionsSetRunValidator(options_, run);
}
// Records the validator options that should be passed to the validator if it
// is run.
void set_validator_options(const ValidatorOptions& val_options) {
spvOptimizerOptionsSetValidatorOptions(options_, val_options);
}
// Records the maximum possible value for the id bound.
void set_max_id_bound(uint32_t new_bound) {
spvOptimizerOptionsSetMaxIdBound(options_, new_bound);
}
// Records whether all bindings within the module should be preserved.
void set_preserve_bindings(bool preserve_bindings) {
spvOptimizerOptionsSetPreserveBindings(options_, preserve_bindings);
}
// Records whether all specialization constants within the module
// should be preserved.
void set_preserve_spec_constants(bool preserve_spec_constants) {
spvOptimizerOptionsSetPreserveSpecConstants(options_,
preserve_spec_constants);
}
private:
spv_optimizer_options options_;
};
// A C++ wrapper around a reducer options object.
class SPIRV_TOOLS_EXPORT ReducerOptions {
public:
ReducerOptions() : options_(spvReducerOptionsCreate()) {}
~ReducerOptions() { spvReducerOptionsDestroy(options_); }
// Allow implicit conversion to the underlying object.
operator spv_reducer_options() const { // NOLINT(google-explicit-constructor)
return options_;
}
// See spvReducerOptionsSetStepLimit.
void set_step_limit(uint32_t step_limit) {
spvReducerOptionsSetStepLimit(options_, step_limit);
}
// See spvReducerOptionsSetFailOnValidationError.
void set_fail_on_validation_error(bool fail_on_validation_error) {
spvReducerOptionsSetFailOnValidationError(options_,
fail_on_validation_error);
}
// See spvReducerOptionsSetTargetFunction.
void set_target_function(uint32_t target_function) {
spvReducerOptionsSetTargetFunction(options_, target_function);
}
private:
spv_reducer_options options_;
};
// A C++ wrapper around a fuzzer options object.
class SPIRV_TOOLS_EXPORT FuzzerOptions {
public:
FuzzerOptions() : options_(spvFuzzerOptionsCreate()) {}
~FuzzerOptions() { spvFuzzerOptionsDestroy(options_); }
// Allow implicit conversion to the underlying object.
operator spv_fuzzer_options() const { // NOLINT(google-explicit-constructor)
return options_;
}
// See spvFuzzerOptionsEnableReplayValidation.
void enable_replay_validation() {
spvFuzzerOptionsEnableReplayValidation(options_);
}
// See spvFuzzerOptionsSetRandomSeed.
void set_random_seed(uint32_t seed) {
spvFuzzerOptionsSetRandomSeed(options_, seed);
}
// See spvFuzzerOptionsSetReplayRange.
void set_replay_range(int32_t replay_range) {
spvFuzzerOptionsSetReplayRange(options_, replay_range);
}
// See spvFuzzerOptionsSetShrinkerStepLimit.
void set_shrinker_step_limit(uint32_t shrinker_step_limit) {
spvFuzzerOptionsSetShrinkerStepLimit(options_, shrinker_step_limit);
}
// See spvFuzzerOptionsEnableFuzzerPassValidation.
void enable_fuzzer_pass_validation() {
spvFuzzerOptionsEnableFuzzerPassValidation(options_);
}
// See spvFuzzerOptionsEnableAllPasses.
void enable_all_passes() { spvFuzzerOptionsEnableAllPasses(options_); }
private:
spv_fuzzer_options options_;
};
// C++ interface for SPIRV-Tools functionalities. It wraps the context
// (including target environment and the corresponding SPIR-V grammar) and
// provides methods for assembling, disassembling, and validating.
//
// Instances of this class provide basic thread-safety guarantee.
class SPIRV_TOOLS_EXPORT SpirvTools {
public:
enum {
// Default assembling option used by assemble():
kDefaultAssembleOption = SPV_TEXT_TO_BINARY_OPTION_NONE,
// Default disassembling option used by Disassemble():
// * Avoid prefix comments from decoding the SPIR-V module header, and
// * Use friendly names for variables.
kDefaultDisassembleOption = SPV_BINARY_TO_TEXT_OPTION_NO_HEADER |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES
};
// Constructs an instance targeting the given environment |env|.
//
// The constructed instance will have an empty message consumer, which just
// ignores all messages from the library. Use SetMessageConsumer() to supply
// one if messages are of concern.
explicit SpirvTools(spv_target_env env);
// Disables copy/move constructor/assignment operations.
SpirvTools(const SpirvTools&) = delete;
SpirvTools(SpirvTools&&) = delete;
SpirvTools& operator=(const SpirvTools&) = delete;
SpirvTools& operator=(SpirvTools&&) = delete;
// Destructs this instance.
~SpirvTools();
// Sets the message consumer to the given |consumer|. The |consumer| will be
// invoked once for each message communicated from the library.
void SetMessageConsumer(MessageConsumer consumer);
// Assembles the given assembly |text| and writes the result to |binary|.
// Returns true on successful assembling. |binary| will be kept untouched if
// assembling is unsuccessful.
// The SPIR-V binary version is set to the highest version of SPIR-V supported
// by the target environment with which this SpirvTools object was created.
bool Assemble(const std::string& text, std::vector<uint32_t>* binary,
uint32_t options = kDefaultAssembleOption) const;
// |text_size| specifies the number of bytes in |text|. A terminating null
// character is not required to present in |text| as long as |text| is valid.
// The SPIR-V binary version is set to the highest version of SPIR-V supported
// by the target environment with which this SpirvTools object was created.
bool Assemble(const char* text, size_t text_size,
std::vector<uint32_t>* binary,
uint32_t options = kDefaultAssembleOption) const;
// Disassembles the given SPIR-V |binary| with the given |options| and writes
// the assembly to |text|. Returns true on successful disassembling. |text|
// will be kept untouched if diassembling is unsuccessful.
bool Disassemble(const std::vector<uint32_t>& binary, std::string* text,
uint32_t options = kDefaultDisassembleOption) const;
// |binary_size| specifies the number of words in |binary|.
bool Disassemble(const uint32_t* binary, size_t binary_size,
std::string* text,
uint32_t options = kDefaultDisassembleOption) const;
// Parses a SPIR-V binary, specified as counted sequence of 32-bit words.
// Parsing feedback is provided via two callbacks provided as std::function.
// In a valid parse the parsed-header callback is called once, and
// then the parsed-instruction callback is called once for each instruction
// in the stream.
// Returns true on successful parsing.
// If diagnostic is non-null, a diagnostic is emitted on failed parsing.
// If diagnostic is null the context's message consumer
// will be used to emit any errors. If a callback returns anything other than
// SPV_SUCCESS, then that status code is returned, no further callbacks are
// issued, and no additional diagnostics are emitted.
// This is a wrapper around the C API spvBinaryParse.
bool Parse(const std::vector<uint32_t>& binary,
const HeaderParser& header_parser,
const InstructionParser& instruction_parser,
spv_diagnostic* diagnostic = nullptr);
// Validates the given SPIR-V |binary|. Returns true if no issues are found.
// Otherwise, returns false and communicates issues via the message consumer
// registered.
// Validates for SPIR-V spec rules for the SPIR-V version named in the
// binary's header (at word offset 1). Additionally, if the target
// environment is a client API (such as Vulkan 1.1), then validate for that
// client API version, to the extent that it is verifiable from data in the
// binary itself.
bool Validate(const std::vector<uint32_t>& binary) const;
// Like the previous overload, but provides the binary as a pointer and size:
// |binary_size| specifies the number of words in |binary|.
// Validates for SPIR-V spec rules for the SPIR-V version named in the
// binary's header (at word offset 1). Additionally, if the target
// environment is a client API (such as Vulkan 1.1), then validate for that
// client API version, to the extent that it is verifiable from data in the
// binary itself.
bool Validate(const uint32_t* binary, size_t binary_size) const;
// Like the previous overload, but takes an options object.
// Validates for SPIR-V spec rules for the SPIR-V version named in the
// binary's header (at word offset 1). Additionally, if the target
// environment is a client API (such as Vulkan 1.1), then validate for that
// client API version, to the extent that it is verifiable from data in the
// binary itself, or in the validator options.
bool Validate(const uint32_t* binary, size_t binary_size,
spv_validator_options options) const;
// Was this object successfully constructed.
bool IsValid() const;
private:
struct SPIRV_TOOLS_LOCAL
Impl; // Opaque struct for holding the data fields used by this class.
std::unique_ptr<Impl> impl_; // Unique pointer to implementation data.
};
} // namespace spvtools
#endif // INCLUDE_SPIRV_TOOLS_LIBSPIRV_HPP_
@@ -0,0 +1,128 @@
// Copyright (c) 2017 Pierre Moreau
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef INCLUDE_SPIRV_TOOLS_LINKER_HPP_
#define INCLUDE_SPIRV_TOOLS_LINKER_HPP_
#include <cstdint>
#include <memory>
#include <vector>
#include "libspirv.hpp"
namespace spvtools {
class SPIRV_TOOLS_EXPORT LinkerOptions {
public:
// Returns whether a library or an executable should be produced by the
// linking phase.
//
// All exported symbols are kept when creating a library, whereas they will
// be removed when creating an executable.
// The returned value will be true if creating a library, and false if
// creating an executable.
bool GetCreateLibrary() const { return create_library_; }
// Sets whether a library or an executable should be produced.
void SetCreateLibrary(bool create_library) {
create_library_ = create_library;
}
// Returns whether to verify the uniqueness of the unique ids in the merged
// context.
bool GetVerifyIds() const { return verify_ids_; }
// Sets whether to verify the uniqueness of the unique ids in the merged
// context.
void SetVerifyIds(bool verify_ids) { verify_ids_ = verify_ids; }
// Returns whether to allow for imported symbols to have no corresponding
// exported symbols
bool GetAllowPartialLinkage() const { return allow_partial_linkage_; }
// Sets whether to allow for imported symbols to have no corresponding
// exported symbols
void SetAllowPartialLinkage(bool allow_partial_linkage) {
allow_partial_linkage_ = allow_partial_linkage;
}
bool GetUseHighestVersion() const { return use_highest_version_; }
void SetUseHighestVersion(bool use_highest_vers) {
use_highest_version_ = use_highest_vers;
}
bool GetAllowPtrTypeMismatch() const { return allow_ptr_type_mismatch_; }
void SetAllowPtrTypeMismatch(bool allow_ptr_type_mismatch) {
allow_ptr_type_mismatch_ = allow_ptr_type_mismatch;
}
std::string GetFnVarTargetsCsv() const { return fnvar_targets_csv_; }
void SetFnVarTargetsCsv(std::string fnvar_targets_csv) {
fnvar_targets_csv_ = fnvar_targets_csv;
}
std::string GetFnVarArchitecturesCsv() const {
return fnvar_architectures_csv_;
}
void SetFnVarArchitecturesCsv(std::string fnvar_architectures_csv) {
fnvar_architectures_csv_ = fnvar_architectures_csv;
}
bool GetHasFnVarCapabilities() const { return has_fnvar_capabilities_; }
void SetHasFnVarCapabilities(bool fnvar_capabilities) {
has_fnvar_capabilities_ = fnvar_capabilities;
}
std::vector<std::string> GetInFiles() const { return in_files_; }
void SetInFiles(std::vector<std::string> in_files) { in_files_ = in_files; }
private:
bool create_library_{false};
bool verify_ids_{false};
bool allow_partial_linkage_{false};
bool use_highest_version_{false};
bool allow_ptr_type_mismatch_{false};
std::string fnvar_targets_csv_{""};
std::string fnvar_architectures_csv_{""};
bool has_fnvar_capabilities_ = false;
std::vector<std::string> in_files_{{}};
};
// Links one or more SPIR-V modules into a new SPIR-V module. That is, combine
// several SPIR-V modules into one, resolving link dependencies between them.
//
// At least one binary has to be provided in |binaries|. Those binaries do not
// have to be valid, but they should be at least parseable.
// The functions can fail due to the following:
// * The given context was not initialised using `spvContextCreate()`;
// * No input modules were given;
// * One or more of those modules were not parseable;
// * The input modules used different addressing or memory models;
// * The ID or global variable number limit were exceeded;
// * Some entry points were defined multiple times;
// * Some imported symbols did not have an exported counterpart;
// * Possibly other reasons.
SPIRV_TOOLS_EXPORT spv_result_t
Link(const Context& context, const std::vector<std::vector<uint32_t>>& binaries,
std::vector<uint32_t>* linked_binary,
const LinkerOptions& options = LinkerOptions());
SPIRV_TOOLS_EXPORT spv_result_t
Link(const Context& context, const uint32_t* const* binaries,
const size_t* binary_sizes, size_t num_binaries,
std::vector<uint32_t>* linked_binary,
const LinkerOptions& options = LinkerOptions());
} // namespace spvtools
#endif // INCLUDE_SPIRV_TOOLS_LINKER_HPP_
@@ -0,0 +1,48 @@
// Copyright (c) 2021 Google LLC.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef INCLUDE_SPIRV_TOOLS_LINTER_HPP_
#define INCLUDE_SPIRV_TOOLS_LINTER_HPP_
#include "libspirv.hpp"
namespace spvtools {
// C++ interface for SPIR-V linting functionalities. It wraps the context
// (including target environment and the corresponding SPIR-V grammar) and
// provides a method for linting.
//
// Instances of this class provides basic thread-safety guarantee.
class SPIRV_TOOLS_EXPORT Linter {
public:
explicit Linter(spv_target_env env);
~Linter();
// Sets the message consumer to the given |consumer|. The |consumer| will be
// invoked once for each message communicated from the library.
void SetMessageConsumer(MessageConsumer consumer);
// Returns a reference to the registered message consumer.
const MessageConsumer& Consumer() const;
bool Run(const uint32_t* binary, size_t binary_size);
private:
struct SPIRV_TOOLS_LOCAL Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace spvtools
#endif // INCLUDE_SPIRV_TOOLS_LINTER_HPP_
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,24 @@
#!/bin/bash
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Android Build Script.
# Fail on any error.
set -e
# Display commands being run.
set -x
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
source $SCRIPT_DIR/../scripts/linux/build.sh ASAN clang cmake-android-ndk
@@ -0,0 +1,17 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Continuous build configuration.
#
build_file: "SPIRV-Tools/kokoro/android/build.sh"
@@ -0,0 +1,16 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Presubmit build configuration.
build_file: "SPIRV-Tools/kokoro/android/build.sh"
@@ -0,0 +1,26 @@
#!/bin/bash
# Copyright (c) 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Fail on any error.
set -e
# This is required to run any git command in the docker since owner will
# have changed between the clone environment, and the docker container.
# Marking the root of the repo as safe for ownership changes.
git config --global --add safe.directory "$PWD"
echo $(date): Check formatting...
./utils/check_code_format.sh ${1:-main}
echo $(date): check completed.
@@ -0,0 +1,27 @@
#!/bin/bash
# Copyright (c) 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Fail on any error.
set -e
SCRIPT_DIR="$( cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
SRC_ROOT="$( cd "${SCRIPT_DIR}/../.." >/dev/null 2>&1 && pwd )"
TARGET_BRANCH="${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH-main}"
docker run --rm -i \
--volume "${SRC_ROOT}:${SRC_ROOT}" \
--workdir "${SRC_ROOT}" \
"us-east4-docker.pkg.dev/shaderc-build/radial-docker/ubuntu-24.04-amd64/formatter" \
"${SCRIPT_DIR}/build-docker.sh" "${TARGET_BRANCH}"
@@ -0,0 +1,15 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
build_file: "SPIRV-Tools/kokoro/check-format/build.sh"
@@ -0,0 +1,15 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
build_file: "SPIRV-Tools/kokoro/check-format/build.sh"
@@ -0,0 +1,22 @@
#!/bin/bash
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Fail on any error.
set -e
# Display commands being run.
set -x
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
source $SCRIPT_DIR/../scripts/linux/build.sh RELEASE gcc cmake-dxc-smoketest
@@ -0,0 +1,17 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Continuous build configuration.
build_file: "SPIRV-Tools/kokoro/dxc-smoketest/build.sh"
@@ -0,0 +1,17 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Presubmit build configuration.
build_file: "SPIRV-Tools/kokoro/dxc-smoketest/build.sh"
Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

@@ -0,0 +1,24 @@
#!/bin/bash
# Copyright (c) 2019 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Linux Build Script.
# Fail on any error.
set -e
# Display commands being run.
set -x
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
source $SCRIPT_DIR/../scripts/linux/build.sh ASAN clang cmake
@@ -0,0 +1,16 @@
# Copyright (c) 2019 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Continuous build configuration.
build_file: "SPIRV-Tools/kokoro/linux-clang-asan/build.sh"
@@ -0,0 +1,16 @@
# Copyright (c) 2019 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Presubmit build configuration.
build_file: "SPIRV-Tools/kokoro/linux-clang-asan/build.sh"
@@ -0,0 +1,24 @@
#!/bin/bash
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Linux Build Script.
# Fail on any error.
set -e
# Display commands being run.
set -x
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
source $SCRIPT_DIR/../scripts/linux/build.sh DEBUG clang cmake
@@ -0,0 +1,22 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Continuous build configuration.
build_file: "SPIRV-Tools/kokoro/linux-clang-debug/build.sh"
action {
define_artifacts {
regex: "install.tgz"
}
}
@@ -0,0 +1,16 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Presubmit build configuration.
build_file: "SPIRV-Tools/kokoro/linux-clang-debug/build.sh"
@@ -0,0 +1,24 @@
#!/bin/bash
# Copyright (c) 2019 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Linux Build Script.
# Fail on any error.
set -e
# Display commands being run.
set -x
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
source $SCRIPT_DIR/../scripts/linux/build.sh RELEASE clang bazel
@@ -0,0 +1,16 @@
# Copyright (c) 2019 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Continuous build configuration.
build_file: "SPIRV-Tools/kokoro/linux-clang-release-bazel/build.sh"
@@ -0,0 +1,16 @@
# Copyright (c) 2019 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Presubmit build configuration.
build_file: "SPIRV-Tools/kokoro/linux-clang-release-bazel/build.sh"
@@ -0,0 +1,24 @@
#!/bin/bash
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Linux Build Script.
# Fail on any error.
set -e
# Display commands being run.
set -x
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
source $SCRIPT_DIR/../scripts/linux/build.sh RELEASE clang cmake
@@ -0,0 +1,22 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Continuous build configuration.
build_file: "SPIRV-Tools/kokoro/linux-clang-release/build.sh"
action {
define_artifacts {
regex: "install.tgz"
}
}
@@ -0,0 +1,16 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Presubmit build configuration.
build_file: "SPIRV-Tools/kokoro/linux-clang-release/build.sh"
@@ -0,0 +1,24 @@
#!/bin/bash
# Copyright (c) 2021 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Linux Build Script.
# Fail on any error.
set -e
# Display commands being run.
set -x
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
source $SCRIPT_DIR/../scripts/linux/build.sh UBSAN clang cmake
@@ -0,0 +1,16 @@
# Copyright (c) 2021 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Continuous build configuration.
build_file: "SPIRV-Tools/kokoro/linux-clang-ubsan/build.sh"
@@ -0,0 +1,16 @@
# Copyright (c) 2021 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Presubmit build configuration.
build_file: "SPIRV-Tools/kokoro/linux-clang-ubsan/build.sh"
@@ -0,0 +1,24 @@
#!/bin/bash
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Linux Build Script.
# Fail on any error.
set -e
# Display commands being run.
set -x
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
source $SCRIPT_DIR/../scripts/linux/build.sh DEBUG gcc cmake
@@ -0,0 +1,22 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Continuous build configuration.
build_file: "SPIRV-Tools/kokoro/linux-gcc-debug/build.sh"
action {
define_artifacts {
regex: "install.tgz"
}
}
@@ -0,0 +1,17 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Presubmit build configuration.
build_file: "SPIRV-Tools/kokoro/linux-gcc-debug/build.sh"
@@ -0,0 +1,24 @@
#!/bin/bash
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Linux Build Script.
# Fail on any error.
set -e
# Display commands being run.
set -x
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
source $SCRIPT_DIR/../scripts/linux/build.sh RELEASE gcc cmake
@@ -0,0 +1,22 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Continuous build configuration.
build_file: "SPIRV-Tools/kokoro/linux-gcc-release/build.sh"
action {
define_artifacts {
regex: "install.tgz"
}
}
@@ -0,0 +1,16 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Presubmit build configuration.
build_file: "SPIRV-Tools/kokoro/linux-gcc-release/build.sh"
@@ -0,0 +1,24 @@
#!/bin/bash
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# MacOS Build Script.
# Fail on any error.
set -e
# Display commands being run.
set -x
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
source $SCRIPT_DIR/../scripts/macos/build.sh Debug
@@ -0,0 +1,22 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Continuous build configuration.
build_file: "SPIRV-Tools/kokoro/macos-clang-debug/build.sh"
action {
define_artifacts {
regex: "install.tgz"
}
}
@@ -0,0 +1,16 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Presubmit build configuration.
build_file: "SPIRV-Tools/kokoro/macos-clang-debug/build.sh"
@@ -0,0 +1,47 @@
#!/bin/bash
# Copyright (c) 2019 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Linux Build Script.
# Fail on any error.
set -e
# Display commands being run.
set -x
CC=clang
CXX=clang++
SRC=$PWD/github/SPIRV-Tools
# This is required to run any git command in the docker since owner will
# have changed between the clone environment, and the docker container.
# Marking the root of the repo as safe for ownership changes.
git config --global --add safe.directory $SRC
cd $SRC
/usr/bin/python3 utils/git-sync-deps --treeless
# Get bazel 7.4.0
BAZEL_VER=7.4.0
gcloud config set auth/disable_credentials True
gcloud storage cp gs://bazel/$BAZEL_VER/release/bazel-$BAZEL_VER-darwin-x86_64 .
chmod +x bazel-$BAZEL_VER-darwin-x86_64
echo $(date): Build everything...
./bazel-$BAZEL_VER-darwin-x86_64 build --cxxopt=-std=c++17 :all
echo $(date): Build completed.
echo $(date): Starting bazel test...
./bazel-$BAZEL_VER-darwin-x86_64 test --cxxopt=-std=c++17 :all
echo $(date): Bazel test completed.
@@ -0,0 +1,16 @@
# Copyright (c) 2019 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Continuous build configuration.
build_file: "SPIRV-Tools/kokoro/macos-clang-release-bazel/build.sh"
@@ -0,0 +1,16 @@
# Copyright (c) 2019 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Presubmit build configuration.
build_file: "SPIRV-Tools/kokoro/macos-clang-release-bazel/build.sh"
@@ -0,0 +1,24 @@
#!/bin/bash
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# MacOS Build Script.
# Fail on any error.
set -e
# Display commands being run.
set -x
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
source $SCRIPT_DIR/../scripts/macos/build.sh RelWithDebInfo
@@ -0,0 +1,22 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Continuous build configuration.
build_file: "SPIRV-Tools/kokoro/macos-clang-release/build.sh"
action {
define_artifacts {
regex: "install.tgz"
}
}
@@ -0,0 +1,16 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Presubmit build configuration.
build_file: "SPIRV-Tools/kokoro/macos-clang-release/build.sh"
@@ -0,0 +1,24 @@
#!/bin/bash
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Linux Build Script.
# Fail on any error.
set -e
# Display commands being run.
set -x
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
source $SCRIPT_DIR/../scripts/linux/build.sh ASAN clang android-ndk-build
@@ -0,0 +1,17 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Continuous build configuration.
#
build_file: "SPIRV-Tools/kokoro/ndk-build/build.sh"
@@ -0,0 +1,16 @@
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Presubmit build configuration.
build_file: "SPIRV-Tools/kokoro/ndk-build/build.sh"
@@ -0,0 +1,247 @@
#!/bin/bash
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Linux Build Script.
# Fail on any error.
set -e
# Display commands being run.
set -x
# This is required to run any git command in the docker since owner will
# have changed between the clone environment, and the docker container.
# Mark all repositories as safe for ownership changes.
git config --global --add safe.directory '*'
. /bin/using.sh # Declare the bash `using` function for configuring toolchains.
using python-3.12
if [ $COMPILER = "clang" ]; then
using clang-18
elif [ $COMPILER = "gcc" ]; then
using gcc-15
fi
cd $ROOT_DIR
function clean_dir() {
dir=$1
if [[ -d "$dir" ]]; then
rm -fr "$dir"
fi
mkdir "$dir"
}
if [ $TOOL != "cmake-shaderc-smoketest" ] && [ $TOOL != "cmake-dxc-smoketest" ]; then
# Get source for dependencies, as specified in the DEPS file
/usr/bin/python3 utils/git-sync-deps --treeless
fi
if [ $TOOL = "cmake" ]; then
using cmake-3.31.2
using ninja-1.10.0
# Possible configurations are:
# ASAN, UBSAN, COVERAGE, RELEASE, DEBUG, DEBUG_EXCEPTION, RELEASE_MINGW
BUILD_TYPE="Debug"
if [ $CONFIG = "RELEASE" ] || [ $CONFIG = "RELEASE_MINGW" ]; then
BUILD_TYPE="Release"
fi
SKIP_TESTS="False"
ADDITIONAL_CMAKE_FLAGS=""
if [ $CONFIG = "ASAN" ]; then
ADDITIONAL_CMAKE_FLAGS="-DSPIRV_USE_SANITIZER=address,bounds,null"
[ $COMPILER = "clang" ] || { echo "$CONFIG requires clang"; exit 1; }
elif [ $CONFIG = "UBSAN" ]; then
# UBSan requires RTTI, and by default UBSan does not exit when errors are
# encountered - additional compiler options are required to force this.
# The -DSPIRV_USE_SANITIZER=undefined option instructs SPIR-V Tools to be
# built with UBSan enabled.
ADDITIONAL_CMAKE_FLAGS="-DSPIRV_USE_SANITIZER=undefined -DENABLE_RTTI=ON -DCMAKE_C_FLAGS=-fno-sanitize-recover=all -DCMAKE_CXX_FLAGS=-fno-sanitize-recover=all"
[ $COMPILER = "clang" ] || { echo "$CONFIG requires clang"; exit 1; }
elif [ $CONFIG = "COVERAGE" ]; then
ADDITIONAL_CMAKE_FLAGS="-DENABLE_CODE_COVERAGE=ON"
SKIP_TESTS="True"
elif [ $CONFIG = "DEBUG_EXCEPTION" ]; then
ADDITIONAL_CMAKE_FLAGS="-DDISABLE_EXCEPTIONS=ON -DDISABLE_RTTI=ON"
elif [ $CONFIG = "RELEASE_MINGW" ]; then
ADDITIONAL_CMAKE_FLAGS="-Dgtest_disable_pthreads=ON -DCMAKE_TOOLCHAIN_FILE=$SRC/cmake/linux-mingw-toolchain.cmake"
SKIP_TESTS="True"
fi
# Build fuzzers on selected configurations.
if [ $COMPILER-$CONFIG = "clang-RELEASE" ]; then
# Build targets that fuzz the assembler, binary parser, disassembler,
# optimizer, and validator.
ADDITIONAL_CMAKE_FLAGS="$ADDITIONAL_CMAKE_FLAGS -DSPIRV_BUILD_LIBFUZZER_TARGETS=ON"
# Build spirv-fuzz, including its protobuf dependency
ADDITIONAL_CMAKE_FLAGS="$ADDITIONAL_CMAKE_FLAGS -DSPIRV_BUILD_FUZZER=ON"
fi
clean_dir "$ROOT_DIR/build"
cd "$ROOT_DIR/build"
# Invoke the build.
BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT}
echo $(date): Starting build...
cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/python3 -GNinja -DCMAKE_INSTALL_PREFIX=$KOKORO_ARTIFACTS_DIR/install -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DRE2_BUILD_TESTING=OFF -DSPIRV_BUILD_FUZZER=ON $ADDITIONAL_CMAKE_FLAGS ..
echo $(date): Build everything...
ninja
echo $(date): Build completed.
if [ $CONFIG = "COVERAGE" ]; then
echo $(date): Check coverage...
ninja report-coverage
echo $(date): Check coverage completed.
fi
echo $(date): Starting ctest...
if [ $SKIP_TESTS = "False" ]; then
ctest -j4 --output-on-failure --timeout 300
fi
echo $(date): ctest completed.
# Package the build.
ninja install
cd $KOKORO_ARTIFACTS_DIR
tar czf install.tgz install
elif [ $TOOL = "cmake-shaderc-smoketest" ]; then
using cmake-3.31.2
using ninja-1.10.0
# Get shaderc.
SHADERC_DIR=/tmp/shaderc
clean_dir "$SHADERC_DIR"
cd $SHADERC_DIR
git clone https://github.com/google/shaderc.git .
cd $SHADERC_DIR/third_party
# Get shaderc dependencies. Link the appropriate SPIRV-Tools.
git clone https://github.com/google/googletest.git
git clone https://github.com/KhronosGroup/glslang.git
ln -s $ROOT_DIR spirv-tools
git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-headers
git clone https://github.com/google/re2
git clone https://github.com/google/effcee
git clone https://github.com/abseil/abseil-cpp abseil_cpp
cd $SHADERC_DIR
mkdir build
cd $SHADERC_DIR/build
# Invoke the build.
echo $(date): Starting build...
cmake -GNinja -DRE2_BUILD_TESTING=OFF -DCMAKE_BUILD_TYPE="Release" ..
echo $(date): Build glslang...
ninja glslang-standalone
echo $(date): Build everything...
ninja
echo $(date): Build completed.
echo $(date): Check Shaderc for copyright notices...
ninja check-copyright
echo $(date): Starting ctest...
ctest --output-on-failure -j4
echo $(date): ctest completed.
elif [ $TOOL = "cmake-dxc-smoketest" ]; then
using cmake-3.31.2
using ninja-1.10.0
# Get shaderc.
DXC_DIR=/tmp/dxc
clean_dir "$DXC_DIR"
cd $DXC_DIR
git clone https://github.com/microsoft/DirectXShaderCompiler.git .
cd $DXC_DIR/external
# Get DXC dependencies. Link the appropriate SPIRV-Tools.
git submodule update --init DirectX-Headers
rm -rf SPIRV-Tools
ln -s $ROOT_DIR SPIRV-Tools
git clone https://github.com/KhronosGroup/SPIRV-Headers.git SPIRV-Headers
cd $DXC_DIR
mkdir build
cd $DXC_DIR/build
# Invoke the build.
echo $(date): Configuring build...
cmake $DXC_DIR \
-C $DXC_DIR/cmake/caches/PredefinedParams.cmake \
-DCMAKE_BUILD_TYPE="Release" \
-G Ninja
echo $(date): Building ClangSPIRVTests...
ninja ClangSPIRVTests
echo $(date): Testing ClangSPIRVTests...
tools/clang/unittests/SPIRV/ClangSPIRVTests
echo $(date): Testing check-clang-codegenspirv...
ninja check-clang-codegenspirv
elif [ $TOOL = "cmake-android-ndk" ]; then
using cmake-3.31.2
using ndk-r29
using ninja-1.10.0
clean_dir "$ROOT_DIR/build"
cd "$ROOT_DIR/build"
echo $(date): Starting build...
cmake -DCMAKE_BUILD_TYPE=Release \
-DANDROID_NATIVE_API_LEVEL=android-24 \
-DANDROID_ABI="armeabi-v7a with NEON" \
-DSPIRV_SKIP_TESTS=ON \
-DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \
-GNinja \
-DANDROID_NDK=$ANDROID_NDK \
..
echo $(date): Build everything...
ninja
echo $(date): Build completed.
elif [ $TOOL = "android-ndk-build" ]; then
using ndk-r29
clean_dir "$ROOT_DIR/build"
cd "$ROOT_DIR/build"
echo $(date): Starting ndk-build ...
$ANDROID_NDK_HOME/ndk-build \
-C $ROOT_DIR/android_test \
NDK_PROJECT_PATH=. \
NDK_LIBS_OUT=./libs \
NDK_APP_OUT=./app \
-j4
echo $(date): ndk-build completed.
elif [ $TOOL = "bazel" ]; then
using bazel-7.4.0
echo $(date): Build everything...
bazel build --cxxopt=-std=c++17 :all
echo $(date): Build completed.
echo $(date): Starting bazel test...
bazel test --cxxopt=-std=c++17 :all
echo $(date): Bazel test completed.
fi
@@ -0,0 +1,63 @@
#!/bin/bash
# Copyright (c) 2021 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Linux Build Script.
# Fail on any error.
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
ROOT_DIR="$( cd "${SCRIPT_DIR}/../../.." >/dev/null 2>&1 && pwd )"
CONFIG=$1
COMPILER=$2
TOOL=$3
BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT}
# chown the given directory to the current user, if it exists.
# Docker creates files with the root user - this can upset the Kokoro artifact copier.
function chown_dir() {
dir=$1
if [[ -d "$dir" ]]; then
sudo chown -R "$(id -u):$(id -g)" "$dir"
fi
}
set +e
# Allow build failures
# "--privileged" is required to run ptrace in the asan builds.
docker run --rm -i \
--privileged \
--volume "${ROOT_DIR}:${ROOT_DIR}" \
--volume "${KOKORO_ARTIFACTS_DIR}:${KOKORO_ARTIFACTS_DIR}" \
--workdir "${ROOT_DIR}" \
--env SCRIPT_DIR=${SCRIPT_DIR} \
--env ROOT_DIR=${ROOT_DIR} \
--env CONFIG=${CONFIG} \
--env COMPILER=${COMPILER} \
--env TOOL=${TOOL} \
--env KOKORO_ARTIFACTS_DIR="${KOKORO_ARTIFACTS_DIR}" \
--env BUILD_SHA="${BUILD_SHA}" \
--entrypoint "${SCRIPT_DIR}/build-docker.sh" \
us-east4-docker.pkg.dev/shaderc-build/radial-docker/ubuntu-24.04-amd64/cpp-builder
RESULT=$?
# This is important. If the permissions are not fixed, kokoro will fail
# to pull build artifacts, and put the build in tool-failure state, which
# blocks the logs.
chown_dir "${ROOT_DIR}/build"
chown_dir "${ROOT_DIR}/external"
exit $RESULT
@@ -0,0 +1,67 @@
#!/bin/bash
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# MacOS Build Script.
# Fail on any error.
set -e
# Display commands being run.
set -x
BUILD_ROOT=$PWD
SRC=$PWD/github/SPIRV-Tools
BUILD_TYPE=$1
# This is required to run any git command in the docker since owner will
# have changed between the clone environment, and the docker container.
# Marking the root of the repo as safe for ownership changes.
git config --global --add safe.directory $SRC
# Get NINJA.
wget -q https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-mac.zip
unzip -q ninja-mac.zip
chmod +x ninja
export PATH="$PWD:$PATH"
cd $SRC
python3 utils/git-sync-deps --treeless
mkdir build && cd $SRC/build
# Invoke the build.
BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT}
echo $(date): Starting build...
cmake \
-GNinja \
-DCMAKE_INSTALL_PREFIX=$KOKORO_ARTIFACTS_DIR/install \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DSPIRV_BUILD_FUZZER=ON \
..
echo $(date): Build everything...
ninja
echo $(date): Build completed.
echo $(date): Starting ctest...
ctest -j4 --output-on-failure --timeout 300
echo $(date): ctest completed.
# Package the build.
ninja install
cd $KOKORO_ARTIFACTS_DIR
tar czf install.tgz install
@@ -0,0 +1,94 @@
:: Copyright (c) 2018 Google LLC.
::
:: Licensed under the Apache License, Version 2.0 (the "License");
:: you may not use this file except in compliance with the License.
:: You may obtain a copy of the License at
::
:: http://www.apache.org/licenses/LICENSE-2.0
::
:: Unless required by applicable law or agreed to in writing, software
:: distributed under the License is distributed on an "AS IS" BASIS,
:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
:: See the License for the specific language governing permissions and
:: limitations under the License.
::
:: Windows Build Script.
@echo on
set BUILD_ROOT=%cd%
set SRC=%cd%\github\SPIRV-Tools
set BUILD_TYPE=%1
set VS_VERSION=%2
:: Force usage of python 3.12, cmake 3.31.2
set PATH=C:\python312;c:\cmake-3.31.2\bin;%PATH%
:: #########################################
:: set up msvc build env
:: #########################################
if %VS_VERSION% == 2022 (
call "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\vcvarsall.bat" x64
echo "Using VS 2022..."
)
cd %SRC%
python utils/git-sync-deps --treeless
mkdir build
cd build
:: #########################################
:: Start building.
:: #########################################
echo "Starting build... %DATE% %TIME%"
if "%KOKORO_GITHUB_COMMIT%." == "." (
set BUILD_SHA=%KOKORO_GITHUB_PULL_REQUEST_COMMIT%
) else (
set BUILD_SHA=%KOKORO_GITHUB_COMMIT%
)
set CMAKE_FLAGS=-DCMAKE_INSTALL_PREFIX=%KOKORO_ARTIFACTS_DIR%\install -GNinja -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DRE2_BUILD_TESTING=OFF -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe
:: Build spirv-fuzz
set CMAKE_FLAGS=%CMAKE_FLAGS% -DSPIRV_BUILD_FUZZER=ON
if "%BUILD_TESTS%" == "NO" (
set CMAKE_FLAGS=-DSPIRV_SKIP_TESTS=ON %CMAKE_FLAGS%
)
cmake --version
cmake %CMAKE_FLAGS% ..
if %ERRORLEVEL% NEQ 0 exit /b %ERRORLEVEL%
echo "Build everything... %DATE% %TIME%"
ninja
if %ERRORLEVEL% NEQ 0 exit /b %ERRORLEVEL%
echo "Build Completed %DATE% %TIME%"
:: This lets us use !ERRORLEVEL! inside an IF ... () and get the actual error at that point.
setlocal ENABLEDELAYEDEXPANSION
:: ################################################
:: Run the tests
:: ################################################
if "%BUILD_TESTS%" NEQ "NO" (
echo "Running Tests... %DATE% %TIME%"
ctest -C %BUILD_TYPE% --output-on-failure --timeout 300
if !ERRORLEVEL! NEQ 0 exit /b !ERRORLEVEL!
echo "Tests Completed %DATE% %TIME%"
)
:: ################################################
:: Install and package.
:: ################################################
ninja install
cd %KOKORO_ARTIFACTS_DIR%
zip -r install.zip install
:: Clean up some directories.
rm -rf %SRC%\build
rm -rf %SRC%\external
exit /b 0
@@ -0,0 +1,22 @@
#!/bin/bash
# Copyright (c) 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Fail on any error.
set -e
# Display commands being run.
set -x
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
source $SCRIPT_DIR/../scripts/linux/build.sh RELEASE gcc cmake-shaderc-smoketest

Some files were not shown because too many files have changed in this diff Show More