├── .clang-format ├── .github └── workflows │ └── autoroll.yml ├── .gitignore ├── AUTHORS ├── Android.mk ├── BUILD.gn ├── CHANGES ├── CMakeLists.txt ├── CONTRIBUTING.md ├── CONTRIBUTORS ├── DEPS ├── DEVELOPMENT.howto.md ├── Dockerfile ├── LICENSE ├── README.md ├── android_test ├── Android.mk ├── jni │ ├── Android.mk │ └── Application.mk └── test.cpp ├── build_overrides ├── build.gni └── shaderc.gni ├── cmake ├── linux-mingw-toolchain.cmake ├── setup_build.cmake ├── shaderc.pc.in ├── shaderc_combined.pc.in ├── shaderc_static.pc.in ├── utils.cmake └── write_pkg_config.cmake ├── downloads.md ├── examples ├── CMakeLists.txt └── online-compile │ ├── CMakeLists.txt │ └── main.cc ├── glslc ├── CMakeLists.txt ├── README.asciidoc ├── src │ ├── dependency_info.cc │ ├── dependency_info.h │ ├── file.cc │ ├── file.h │ ├── file_compiler.cc │ ├── file_compiler.h │ ├── file_includer.cc │ ├── file_includer.h │ ├── file_test.cc │ ├── main.cc │ ├── resource_parse.cc │ ├── resource_parse.h │ ├── resource_parse_test.cc │ ├── shader_stage.cc │ ├── shader_stage.h │ └── stage_test.cc └── test │ ├── CMakeLists.txt │ ├── assembly.py │ ├── environment.py │ ├── error_no_object.py │ ├── expect.py │ ├── expect_unittest.py │ ├── file_extensions.py │ ├── glslc_test_framework.py │ ├── glslc_test_framework_unittest.py │ ├── include.py │ ├── line.py │ ├── messages_tests.py │ ├── option_dash_D.py │ ├── option_dash_E.py │ ├── option_dash_M.py │ ├── option_dash_S.py │ ├── option_dash_c.py │ ├── option_dash_cap_O.py │ ├── option_dash_fhlsl_offsets.py │ ├── option_dash_fnan_clamp.py │ ├── option_dash_g.py │ ├── option_dash_o.py │ ├── option_dash_x.py │ ├── option_dashdash_version.py │ ├── option_fauto_bind_uniforms.py │ ├── option_fauto_combined_image_sampler.py │ ├── option_fauto_map_locations.py │ ├── option_fentry_point.py │ ├── option_fhlsl_16bit_types.py │ ├── option_fhlsl_functionality1.py │ ├── option_flimit.py │ ├── option_fpreserve_bindings.py │ ├── option_fresource_set_binding.py │ ├── option_mfmt.py │ ├── option_shader_stage.py │ ├── option_std.py │ ├── option_target_env.py │ ├── option_target_spv.py │ ├── parameter_tests.py │ ├── placeholder.py │ ├── pragma_shader_stage.py │ ├── stdin_out.py │ └── working_directory.py ├── kokoro ├── android-release │ ├── build-docker.sh │ ├── build.sh │ ├── build_arm.sh │ ├── build_x86.sh │ ├── continuous_arm.cfg │ ├── continuous_x86.cfg │ ├── presubmit_arm.cfg │ └── presubmit_x86.cfg ├── img │ ├── linux.png │ ├── macos.png │ └── windows.png ├── linux │ ├── build-docker.sh │ ├── build.sh │ ├── build_clang_asan.sh │ ├── build_clang_debug.sh │ ├── build_clang_release.sh │ ├── build_gcc_coverage.sh │ ├── build_gcc_debug.sh │ ├── build_gcc_debug_exception.sh │ ├── build_gcc_release.sh │ ├── build_mingw_release.sh │ ├── continuous_clang_asan.cfg │ ├── continuous_clang_debug.cfg │ ├── continuous_clang_release.cfg │ ├── continuous_gcc_debug.cfg │ ├── continuous_gcc_debug_exception.cfg │ ├── continuous_gcc_release.cfg │ ├── continuous_license_check.cfg │ ├── continuous_mingw_release.cfg │ ├── license_check.sh │ ├── presubmit_clang_asan.cfg │ ├── presubmit_clang_debug.cfg │ ├── presubmit_clang_release.cfg │ ├── presubmit_gcc_debug.cfg │ ├── presubmit_gcc_release.cfg │ ├── presubmit_license_check.cfg │ └── presubmit_mingw_release.cfg ├── macos │ ├── build.sh │ ├── build_clang_debug.sh │ ├── build_clang_release.sh │ ├── continuous_clang_debug.cfg │ ├── continuous_clang_release.cfg │ ├── presubmit_clang_debug.cfg │ └── presubmit_clang_release.cfg ├── ndk-build │ ├── build-docker.sh │ ├── build.sh │ ├── build_khronos.sh │ ├── continuous_khronos.cfg │ └── presubmit_khronos.cfg └── windows │ ├── build.bat │ ├── build_2019_amd64_release.bat │ ├── build_2022_amd64_debug.bat │ ├── build_2022_amd64_release.bat │ ├── continuous_release_2019.cfg │ ├── presubmit_release_2019.cfg │ ├── vs2022_amd64_debug_continuous.cfg │ ├── vs2022_amd64_debug_presubmit.cfg │ ├── vs2022_amd64_release_continuous.cfg │ └── vs2022_amd64_release_presubmit.cfg ├── libshaderc ├── Android.mk ├── CMakeLists.txt ├── README.md ├── include │ └── shaderc │ │ ├── env.h │ │ ├── shaderc.h │ │ ├── shaderc.hpp │ │ ├── status.h │ │ └── visibility.h └── src │ ├── common_shaders_for_test.h │ ├── shaderc.cc │ ├── shaderc_c_smoke_test.c │ ├── shaderc_cpp_test.cc │ ├── shaderc_private.h │ ├── shaderc_private_test.cc │ └── shaderc_test.cc ├── libshaderc_util ├── Android.mk ├── CMakeLists.txt ├── include │ └── libshaderc_util │ │ ├── args.h │ │ ├── compiler.h │ │ ├── counting_includer.h │ │ ├── exceptions.h │ │ ├── file_finder.h │ │ ├── format.h │ │ ├── io_shaderc.h │ │ ├── message.h │ │ ├── mutex.h │ │ ├── resources.h │ │ ├── resources.inc │ │ ├── shader_stage.h │ │ ├── spirv_tools_wrapper.h │ │ ├── string_piece.h │ │ ├── universal_unistd.h │ │ └── version_profile.h ├── src │ ├── args.cc │ ├── compiler.cc │ ├── compiler_test.cc │ ├── counting_includer_test.cc │ ├── death_test.h │ ├── file_finder.cc │ ├── file_finder_test.cc │ ├── format_test.cc │ ├── io_shaderc.cc │ ├── io_shaderc_test.cc │ ├── message.cc │ ├── message_test.cc │ ├── mutex_test.cc │ ├── resources.cc │ ├── shader_stage.cc │ ├── spirv_tools_wrapper.cc │ ├── string_piece_test.cc │ ├── version_profile.cc │ └── version_profile_test.cc └── testdata │ ├── copy-to-build.cmake │ ├── dir │ └── subdir │ │ └── include_file.2 │ └── include_file.1 ├── license-checker.cfg ├── third_party ├── Android.mk ├── CMakeLists.txt ├── LICENSE.glslang └── LICENSE.spirv-tools └── utils ├── add_copyright.py ├── git-sync-deps ├── remove-file-by-suffix.py ├── roll-deps └── update_build_version.py /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | # Use Google code formatting rules. 3 | Language: Cpp 4 | BasedOnStyle: Google 5 | ... 6 | -------------------------------------------------------------------------------- /.github/workflows/autoroll.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2023 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,s either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Update dependencies 16 | permissions: 17 | contents: read 18 | 19 | on: 20 | schedule: 21 | - cron: '0 2 * * *' 22 | workflow_dispatch: 23 | 24 | jobs: 25 | update-dependencies: 26 | permissions: 27 | contents: write 28 | pull-requests: write 29 | name: Update dependencies 30 | runs-on: ubuntu-latest 31 | 32 | steps: 33 | - uses: actions/checkout@v3 34 | 35 | # Checkout the depot tools they are needed by roll_deps.sh 36 | - name: Checkout depot tools 37 | run: git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git 38 | 39 | - name: Update PATH 40 | run: echo "$(pwd)/depot_tools" >> $GITHUB_PATH 41 | 42 | - name: Download dependencies 43 | run: python3 utils/git-sync-deps 44 | 45 | - name: Setup git user information 46 | run: | 47 | git config user.name "GitHub Actions[bot]" 48 | git config user.email "<>" 49 | git checkout -b roll_deps 50 | 51 | - name: Update dependencies 52 | run: | 53 | utils/roll-deps 54 | if [[ `git diff HEAD..origin/main --name-only | wc -l` == 0 ]]; then 55 | echo "changed=false" >> $GITHUB_OUTPUT 56 | else 57 | echo "changed=true" >> $GITHUB_OUTPUT 58 | fi 59 | id: update_dependencies 60 | - name: Push changes and create PR 61 | if: steps.update_dependencies.outputs.changed == 'true' 62 | run: | 63 | git push --force --set-upstream origin roll_deps 64 | gh pr create --label 'kokoro:run' --base main -f || true 65 | env: 66 | GITHUB_TOKEN: ${{ github.token }} 67 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | build-*/ 3 | out/ 4 | *.pyc 5 | *.swp 6 | compile_commands.json 7 | .ycm_extra_conf.py 8 | cscope.* 9 | third_party/abseil_cpp 10 | third_party/effcee 11 | third_party/glslang 12 | third_party/googletest 13 | third_party/re2 14 | third_party/spirv-tools 15 | third_party/spirv-headers 16 | third_party/spirv-cross 17 | third_party/tint 18 | android_test/libs 19 | android_test/include 20 | .DS_Store 21 | .vscode/ 22 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of shaderc authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | 5 | # Names should be added to this file as: 6 | # Name or Organization 7 | # The email address is not required for organizations. 8 | 9 | Google Inc. 10 | -------------------------------------------------------------------------------- /Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | ROOT_SHADERC_PATH := $(call my-dir) 16 | 17 | include $(ROOT_SHADERC_PATH)/third_party/Android.mk 18 | include $(ROOT_SHADERC_PATH)/libshaderc_util/Android.mk 19 | include $(ROOT_SHADERC_PATH)/libshaderc/Android.mk 20 | 21 | ALL_LIBS:=libglslang.a \ 22 | libshaderc.a \ 23 | libshaderc_util.a \ 24 | libSPIRV.a \ 25 | libSPIRV-Tools.a \ 26 | libSPIRV-Tools-opt.a 27 | 28 | SHADERC_HEADERS=shaderc.hpp shaderc.h env.h status.h visibility.h 29 | SHADERC_HEADERS_IN_OUT_DIR=$(foreach H,$(SHADERC_HEADERS),$(NDK_APP_LIBS_OUT)/../include/shaderc/$(H)) 30 | 31 | define gen_libshaderc_header 32 | $(call generate-file-dir,$(NDK_APP_LIBS_OUT)/../include/shaderc/$(1)) 33 | $(NDK_APP_LIBS_OUT)/../include/shaderc/$(1) : \ 34 | $(ROOT_SHADERC_PATH)/libshaderc/include/shaderc/$(1) 35 | $(call host-cp,$(ROOT_SHADERC_PATH)/libshaderc/include/shaderc/$(1) \ 36 | ,$(NDK_APP_LIBS_OUT)/../include/shaderc/$(1)) 37 | 38 | endef 39 | # Generate headers 40 | $(eval $(foreach H,$(SHADERC_HEADERS),$(call gen_libshaderc_header,$(H)))) 41 | libshaderc_headers: $(SHADERC_HEADERS_IN_OUT_DIR) 42 | .PHONY: libshaderc_headers 43 | 44 | 45 | # Rules for combining library files to form a single libshader_combined.a. 46 | # It always goes into $(TARGET_OUT) 47 | $(call generate-file-dir,$(TARGET_OUT)/combine.ar) 48 | $(TARGET_OUT)/combine.ar: $(TARGET_OUT) $(addprefix $(TARGET_OUT)/, $(ALL_LIBS)) 49 | $(file >$(TARGET_OUT)/combine.ar,create libshaderc_combined.a) 50 | $(foreach lib,$(ALL_LIBS),$(file >>$(TARGET_OUT)/combine.ar,addlib $(lib))) 51 | $(file >>$(TARGET_OUT)/combine.ar,save) 52 | $(file >>$(TARGET_OUT)/combine.ar,end) 53 | 54 | $(TARGET_OUT)/libshaderc_combined.a: $(addprefix $(TARGET_OUT)/, $(ALL_LIBS)) $(TARGET_OUT)/combine.ar 55 | @echo "[$(TARGET_ARCH_ABI)] Combine: libshaderc_combined.a <= $(ALL_LIBS)" 56 | @cd $(TARGET_OUT) && $(TARGET_AR) -M < combine.ar && cd $(ROOT_SHADERC_PATH) 57 | @$(TARGET_STRIP) --strip-debug $(TARGET_OUT)/libshaderc_combined.a 58 | 59 | $(call generate-file-dir,$(NDK_APP_LIBS_OUT)/$(APP_STL)/$(TARGET_ARCH_ABI)/libshaderc.a) 60 | $(NDK_APP_LIBS_OUT)/$(APP_STL)/$(TARGET_ARCH_ABI)/libshaderc.a: \ 61 | $(TARGET_OUT)/libshaderc_combined.a 62 | $(call host-cp,$(TARGET_OUT)/libshaderc_combined.a \ 63 | ,$(NDK_APP_LIBS_OUT)/$(APP_STL)/$(TARGET_ARCH_ABI)/libshaderc.a) 64 | 65 | libshaderc_combined: libshaderc_headers \ 66 | $(NDK_APP_LIBS_OUT)/$(APP_STL)/$(TARGET_ARCH_ABI)/libshaderc.a 67 | -------------------------------------------------------------------------------- /BUILD.gn: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import("//build_overrides/build.gni") 16 | import("//build_overrides/shaderc.gni") 17 | 18 | glslang_dir = shaderc_glslang_dir 19 | spirv_tools_dir = shaderc_spirv_tools_dir 20 | 21 | config("shaderc_util_public") { 22 | include_dirs = [ "libshaderc_util/include" ] 23 | } 24 | 25 | source_set("shaderc_util_sources") { 26 | sources = [ 27 | "libshaderc_util/include/libshaderc_util/counting_includer.h", 28 | "libshaderc_util/include/libshaderc_util/exceptions.h", 29 | "libshaderc_util/include/libshaderc_util/file_finder.h", 30 | "libshaderc_util/include/libshaderc_util/format.h", 31 | "libshaderc_util/include/libshaderc_util/io_shaderc.h", 32 | "libshaderc_util/include/libshaderc_util/message.h", 33 | "libshaderc_util/include/libshaderc_util/mutex.h", 34 | "libshaderc_util/include/libshaderc_util/resources.h", 35 | "libshaderc_util/include/libshaderc_util/spirv_tools_wrapper.h", 36 | "libshaderc_util/include/libshaderc_util/string_piece.h", 37 | "libshaderc_util/include/libshaderc_util/universal_unistd.h", 38 | "libshaderc_util/include/libshaderc_util/version_profile.h", 39 | "libshaderc_util/src/compiler.cc", 40 | "libshaderc_util/src/file_finder.cc", 41 | "libshaderc_util/src/io_shaderc.cc", 42 | "libshaderc_util/src/message.cc", 43 | "libshaderc_util/src/resources.cc", 44 | "libshaderc_util/src/shader_stage.cc", 45 | "libshaderc_util/src/spirv_tools_wrapper.cc", 46 | "libshaderc_util/src/version_profile.cc", 47 | ] 48 | 49 | # Configure Glslang's interface to include HLSL-related entry points. 50 | defines = [ "ENABLE_HLSL=1" ] 51 | 52 | public_configs = [ ":shaderc_util_public" ] 53 | 54 | deps = [ 55 | "${glslang_dir}:glslang_sources", 56 | "${spirv_tools_dir}:spvtools", 57 | ] 58 | 59 | if (build_with_chromium) { 60 | configs -= [ "//build/config/compiler:chromium_code" ] 61 | configs += [ "//build/config/compiler:no_chromium_code" ] 62 | } 63 | } 64 | 65 | config("shaderc_public") { 66 | include_dirs = [ "libshaderc/include" ] 67 | if (is_component_build) { 68 | defines = [ "SHADERC_SHAREDLIB" ] 69 | } 70 | } 71 | 72 | component("libshaderc") { 73 | public_configs = [ 74 | ":shaderc_public", 75 | ":shaderc_util_public", 76 | ] 77 | 78 | defines = [ "SHADERC_IMPLEMENTATION" ] 79 | 80 | sources = [ 81 | "libshaderc/include/shaderc/env.h", 82 | "libshaderc/include/shaderc/shaderc.h", 83 | "libshaderc/include/shaderc/shaderc.hpp", 84 | "libshaderc/include/shaderc/status.h", 85 | "libshaderc/include/shaderc/visibility.h", 86 | "libshaderc/src/shaderc.cc", 87 | "libshaderc/src/shaderc_private.h", 88 | ] 89 | 90 | deps = [ 91 | ":shaderc_util_sources", 92 | "${spirv_tools_dir}:spvtools", 93 | "${spirv_tools_dir}:spvtools_val", 94 | "${glslang_dir}:glslang_sources", 95 | ] 96 | 97 | if (build_with_chromium) { 98 | configs -= [ "//build/config/compiler:chromium_code" ] 99 | configs += [ "//build/config/compiler:no_chromium_code" ] 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Want to contribute? Great! First, read this page (including the small print at 2 | the end). Then, have a look at [`DEVELOPMENT.howto.md`](DEVELOPMENT.howto.md), 3 | which contains useful info to guide you along the way. 4 | 5 | ## Before you contribute 6 | 7 | Before we can use your code, you must sign the 8 | [Google Individual Contributor License Agreement](https://developers.google.com/open-source/cla/individual?csw=1) 9 | (CLA), which you can do online. The CLA is necessary mainly because you own the 10 | copyright to your changes, even after your contribution becomes part of our 11 | codebase, so we need your permission to use and distribute your code. We also 12 | need to be sure of various other things -- for instance that you'll tell us if 13 | you know that your code infringes on other people's patents. You don't have to 14 | sign the CLA until after you've submitted your code for review and a member has 15 | approved it, but you must do it before we can put your code into our codebase. 16 | 17 | Before you start working on a larger contribution, you should get in touch with 18 | us first through the issue tracker with your idea so that we can help out and 19 | possibly guide you. Coordinating up front makes it much easier to avoid 20 | frustration later on. 21 | 22 | ## The small print 23 | 24 | Contributions made by corporations are covered by a different agreement than 25 | the one above, the Software Grant and Corporate Contributor License Agreement. 26 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # People who have agreed to one of the CLAs and can contribute patches. 2 | # The AUTHORS file lists the copyright holders; this file 3 | # lists people. For example, Google employees are listed here 4 | # but not in AUTHORS, because Google holds the copyright. 5 | # 6 | # https://developers.google.com/open-source/cla/individual 7 | # https://developers.google.com/open-source/cla/corporate 8 | # 9 | # Names should be added to this file as: 10 | # Name 11 | 12 | Lei Zhang 13 | David Neto 14 | Andrew Woloszyn 15 | Stefanus Du Toit 16 | Dejan Mircevski 17 | Mark Adams 18 | Jason Ekstrand 19 | Damien Mabin 20 | Qining Lu 21 | Jakob Vogel 22 | David Yen 23 | Adam Chainz 24 | Robin Quint 25 | -------------------------------------------------------------------------------- /DEPS: -------------------------------------------------------------------------------- 1 | use_relative_paths = True 2 | 3 | vars = { 4 | 'abseil_git': 'https://github.com/abseil', 5 | 'google_git': 'https://github.com/google', 6 | 'khronos_git': 'https://github.com/KhronosGroup', 7 | 8 | 'abseil_revision': '1315c900e1ddbb08a23e06eeb9a06450052ccb5e', 9 | 'effcee_revision': '08da24ec245a274fea3a128ba50068f163390565', 10 | 'glslang_revision': '697683e6b8871420d7d942b1a2fe233242ab5608', 11 | 'googletest_revision': '1d17ea141d2c11b8917d2c7d029f1c4e2b9769b2', 12 | 're2_revision': '4a8cee3dd3c3d81b6fe8b867811e193d5819df07', 13 | 'spirv_headers_revision': 'aa6cef192b8e693916eb713e7a9ccadf06062ceb', 14 | 'spirv_tools_revision': 'a62abcb402009b9ca5975e6167c09f237f630e0e', 15 | } 16 | 17 | deps = { 18 | 'third_party/abseil_cpp': 19 | Var('abseil_git') + '/abseil-cpp.git@' + Var('abseil_revision'), 20 | 21 | 'third_party/effcee': Var('google_git') + '/effcee.git@' + 22 | Var('effcee_revision'), 23 | 24 | 'third_party/googletest': Var('google_git') + '/googletest.git@' + 25 | Var('googletest_revision'), 26 | 27 | 'third_party/glslang': Var('khronos_git') + '/glslang.git@' + 28 | Var('glslang_revision'), 29 | 30 | 'third_party/re2': Var('google_git') + '/re2.git@' + 31 | Var('re2_revision'), 32 | 33 | 'third_party/spirv-headers': Var('khronos_git') + '/SPIRV-Headers.git@' + 34 | Var('spirv_headers_revision'), 35 | 36 | 'third_party/spirv-tools': Var('khronos_git') + '/SPIRV-Tools.git@' + 37 | Var('spirv_tools_revision'), 38 | } 39 | -------------------------------------------------------------------------------- /DEVELOPMENT.howto.md: -------------------------------------------------------------------------------- 1 | Thank you for considering Shaderc development! Please make sure you review 2 | [`CONTRIBUTING.md`](CONTRIBUTING.md) for important preliminary info. 3 | 4 | ## Building 5 | 6 | Instructions for first-time building can be found in [`README.md`](README.md). 7 | Incremental build after a source change can be done using `ninja` (or 8 | `cmake --build`) and `ctest` exactly as in the first-time procedure. 9 | 10 | ## Code reviews 11 | 12 | (Terminology: we consider everyone with write access to our GitHub repo a 13 | project _member_.) 14 | 15 | All submissions, including submissions by project members, require review. We 16 | use GitHub pull requests to facilitate the review process. A submission may be 17 | accepted by any project member (other than the submitter), who will then squash 18 | the changes into a single commit and cherry-pick them into the repository. 19 | 20 | Before accepting, there may be some review feedback prompting changes in the 21 | submission. You should expect reviewers to strictly insist on the 22 | [commenting](https://google.github.io/styleguide/cppguide.html#Comments) 23 | guidelines -- in particular, every file, class, method, data member, and global 24 | will require a comment. Reviewers will also expect to see test coverage for 25 | every code change. _How much_ coverage will be a judgment call on a 26 | case-by-case basis, balancing the required effort against the incremental 27 | benefit. Coverage will be expected. As a matter of development philosophy, 28 | we will strive to engineer the code to make writing tests easy. 29 | 30 | ## Coding style 31 | 32 | For our C++ files, we use the 33 | [Google C++ style guide](https://google.github.io/styleguide/cppguide.html). 34 | (Conveniently, the formatting rules it specifies can be achieved using 35 | `clang-format -style=google`.) 36 | 37 | For our Python files, we use the 38 | [Google Python style guide](https://google.github.io/styleguide/pyguide.html). 39 | 40 | ## Supported platforms 41 | 42 | We expect Shaderc to always build and test successfully on the platforms listed 43 | below. Please keep that in mind when offering contributions. This list will 44 | likely grow over time. 45 | 46 | | Platform | Build Status | 47 | |:--------:|:------------:| 48 | | Android (ARMv7) | Not Automated | 49 | | Linux (x86_64) | [![Linux Build Status](https://travis-ci.org/google/shaderc.svg)](https://travis-ci.org/google/shaderc "Linux Build Status") | 50 | | Mac OS X | [![Mac Build Status](https://travis-ci.org/google/shaderc.svg)](https://travis-ci.org/google/shaderc "Mac Build Status") | 51 | | Windows (x86_64) | [![Windows Build status](https://ci.appveyor.com/api/projects/status/g6c372blna7vnk1l?svg=true)](https://ci.appveyor.com/project/dneto0/shaderc "Windows Build Status") | 52 | 53 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2016 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | FROM alpine 16 | 17 | MAINTAINER Google Shaderc Team 18 | 19 | RUN apk add --update \ 20 | build-base \ 21 | cmake \ 22 | git \ 23 | ninja \ 24 | python3 \ 25 | py-pip \ 26 | && rm -rf /var/cache/apk/* 27 | 28 | WORKDIR /root 29 | RUN git clone https://github.com/google/shaderc 30 | 31 | WORKDIR shaderc 32 | RUN ./utils/git-sync-deps 33 | 34 | WORKDIR build 35 | RUN cmake -GNinja \ 36 | -DCMAKE_BUILD_TYPE=Release \ 37 | -DCMAKE_INSTALL_PREFIX=/usr/local \ 38 | .. \ 39 | && ninja install 40 | 41 | WORKDIR /root 42 | RUN rm -rf shaderc 43 | 44 | RUN adduser -s /bin/sh -D shaderc 45 | USER shaderc 46 | 47 | VOLUME /code 48 | WORKDIR /code 49 | 50 | CMD ["/bin/sh"] 51 | -------------------------------------------------------------------------------- /android_test/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH:= $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | LOCAL_CPP_EXTENSION := .cc .cpp .cxx 19 | LOCAL_SRC_FILES:=test.cpp 20 | LOCAL_MODULE:=shaderc_test 21 | LOCAL_LDLIBS:=-landroid 22 | LOCAL_STATIC_LIBRARIES=shaderc android_native_app_glue 23 | include $(BUILD_SHARED_LIBRARY) 24 | 25 | include $(LOCAL_PATH)/../Android.mk 26 | $(call import-module,android/native_app_glue) 27 | -------------------------------------------------------------------------------- /android_test/jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | include $(LOCAL_PATH)/../Android.mk 17 | -------------------------------------------------------------------------------- /android_test/jni/Application.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | APP_ABI := all 16 | APP_BUILD_SCRIPT := Android.mk 17 | APP_STL := c++_static 18 | # Vulkan was added at API level 24. 19 | # Android NDK 26 will drop support for APIs before 21. 20 | APP_PLATFORM := android-24 21 | -------------------------------------------------------------------------------- /android_test/test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "shaderc/shaderc.hpp" 16 | #include 17 | 18 | void android_main(struct android_app* state) { 19 | shaderc::Compiler compiler; 20 | const char* test_program = "void main() {}"; 21 | compiler.CompileGlslToSpv(test_program, strlen(test_program), 22 | shaderc_glsl_vertex_shader, "shader"); 23 | } 24 | -------------------------------------------------------------------------------- /build_overrides/build.gni: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # These are variables that are overridable by projects that include shaderc. 16 | 17 | # Set to true when building shaderc as part of Chromium. 18 | build_with_chromium = false 19 | -------------------------------------------------------------------------------- /build_overrides/shaderc.gni: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # These are variables that are overridable by projects that include shaderc. 16 | 17 | # The path to shaderc dependencies. 18 | shaderc_glslang_dir = "//third_party/glslang" 19 | shaderc_spirv_tools_dir = "//third_party/spirv-tools" 20 | shaderc_spirv_headers_dir = "//third_party/spirv-headers" 21 | 22 | -------------------------------------------------------------------------------- /cmake/linux-mingw-toolchain.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | SET(CMAKE_SYSTEM_NAME Windows) 16 | 17 | set(MINGW_COMPILER_PREFIX "i686-w64-mingw32" CACHE STRING 18 | "What compiler prefix to use for mingw") 19 | 20 | set(MINGW_SYSROOT "/usr/${MINGW_COMPILER_PREFIX}" CACHE STRING 21 | "What sysroot to use for mingw") 22 | 23 | # Which compilers to use for C and C++ 24 | find_program(CMAKE_RC_COMPILER NAMES ${MINGW_COMPILER_PREFIX}-windres) 25 | find_program(CMAKE_C_COMPILER NAMES 26 | ${MINGW_COMPILER_PREFIX}-gcc-posix 27 | ${MINGW_COMPILER_PREFIX}-gcc) 28 | find_program(CMAKE_CXX_COMPILER NAMES 29 | ${MINGW_COMPILER_PREFIX}-g++-posix 30 | ${MINGW_COMPILER_PREFIX}-g++) 31 | 32 | SET(CMAKE_FIND_ROOT_PATH ${MINGW_SYSROOT}) 33 | 34 | # Adjust the default behaviour of the FIND_XXX() commands: 35 | # Search headers and libraries in the target environment; search 36 | # programs in the host environment. 37 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 38 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 39 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 40 | -------------------------------------------------------------------------------- /cmake/setup_build.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | if(NOT COMMAND find_host_package) 16 | macro(find_host_package) 17 | find_package(${ARGN}) 18 | endmacro() 19 | endif() 20 | if(NOT COMMAND find_host_program) 21 | macro(find_host_program) 22 | find_program(${ARGN}) 23 | endmacro() 24 | endif() 25 | 26 | # Find asciidoctor; see shaderc_add_asciidoc() from utils.cmake for 27 | # adding documents. 28 | find_program(ASCIIDOCTOR_EXE NAMES asciidoctor) 29 | if (NOT ASCIIDOCTOR_EXE) 30 | message(STATUS "asciidoctor was not found - no documentation will be" 31 | " generated") 32 | endif() 33 | 34 | # On Windows, CMake by default compiles with the shared CRT. 35 | # Ensure that gmock compiles the same, otherwise failures will occur. 36 | if(WIN32) 37 | # TODO(awoloszyn): Once we support selecting CRT versions, 38 | # make sure this matches correctly. 39 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 40 | endif(WIN32) 41 | 42 | if (ANDROID) 43 | # For android let's preemptively find the correct packages so that 44 | # child projects (glslang, googletest) do not fail to find them. 45 | 46 | # Tests in glslc and SPIRV-Tools tests require Python 3, or a Python 2 47 | # with the "future" package. Require Python 3 because we can't force 48 | # developers to manually install the "future" package. 49 | find_host_package(PythonInterp 3 REQUIRED) 50 | find_host_package(BISON) 51 | else() 52 | find_package(Python COMPONENTS Interpreter REQUIRED) 53 | endif() 54 | 55 | option(DISABLE_RTTI "Disable RTTI in builds") 56 | if(DISABLE_RTTI) 57 | if(UNIX) 58 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") 59 | endif(UNIX) 60 | endif(DISABLE_RTTI) 61 | 62 | option(DISABLE_EXCEPTIONS "Disables exceptions in builds") 63 | if(DISABLE_EXCEPTIONS) 64 | if(UNIX) 65 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") 66 | endif(UNIX) 67 | endif(DISABLE_EXCEPTIONS) 68 | -------------------------------------------------------------------------------- /cmake/shaderc.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ 4 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 5 | 6 | Name: shaderc 7 | Description: Tools and libraries for Vulkan shader compilation 8 | Version: @CURRENT_VERSION@ 9 | URL: https://github.com/google/shaderc 10 | 11 | Libs: -L${libdir} @LIBS@ 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /cmake/shaderc_combined.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ 4 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 5 | 6 | Name: shaderc 7 | Description: Tools and libraries for Vulkan shader compilation 8 | Version: @CURRENT_VERSION@ 9 | URL: https://github.com/google/shaderc 10 | 11 | Libs: -L${libdir} @LIBS@ 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /cmake/shaderc_static.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ 4 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 5 | 6 | Name: shaderc 7 | Description: Tools and libraries for Vulkan shader compilation 8 | Version: @CURRENT_VERSION@ 9 | URL: https://github.com/google/shaderc 10 | 11 | Libs: -L${libdir} @LIBS@ 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /cmake/write_pkg_config.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Pierre Moreau 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # First, retrieve the current version from CHANGES 16 | file(STRINGS ${CHANGES_FILE} CHANGES_CONTENT) 17 | string( 18 | REGEX 19 | MATCH "v[0-9]+(.[0-9]+)?(-dev)? [0-9]+-[0-9]+-[0-9]+" 20 | FIRST_VERSION_LINE 21 | ${CHANGES_CONTENT}) 22 | string( 23 | REGEX 24 | REPLACE "^v([^ ]+) .+$" "\\1" 25 | CURRENT_VERSION 26 | "${FIRST_VERSION_LINE}") 27 | # If this is a development version, replace "-dev" by ".0" as pkg-config nor 28 | # CMake support "-dev" in the version. 29 | # If it's not a "-dev" version then ensure it ends with ".1" 30 | string(REGEX REPLACE "-dev.1" ".0" CURRENT_VERSION "${CURRENT_VERSION}.1") 31 | configure_file(${TEMPLATE_FILE} ${OUT_FILE} @ONLY) 32 | -------------------------------------------------------------------------------- /downloads.md: -------------------------------------------------------------------------------- 1 | # Downloads 2 | Download the latest builds. 3 | 4 | **Note: These binaries are just the artifacts of the builders and have not 5 | undergone any QA, thus they should be considered unsupported.** 6 | 7 | ## Release 8 | | Windows | Linux | MacOS | 9 | | --- | --- | --- | 10 | | [MSVC 2019](https://storage.googleapis.com/shaderc/badges/build_link_windows_vs2019_release.html) | [clang](https://storage.googleapis.com/shaderc/badges/build_link_linux_clang_release.html) | [clang](https://storage.googleapis.com/shaderc/badges/build_link_macos_clang_release.html) | 11 | | | [gcc](https://storage.googleapis.com/shaderc/badges/build_link_linux_gcc_release.html) | | 12 | 13 | ## Debug 14 | | Windows | Linux | MacOS | 15 | | --- | --- | --- | 16 | | [MSVC 2019](https://storage.googleapis.com/shaderc/badges/build_link_windows_vs2019_debug.html) | [clang](https://storage.googleapis.com/shaderc/badges/build_link_linux_clang_debug.html) | [clang](https://storage.googleapis.com/shaderc/badges/build_link_macos_clang_debug.html) | 17 | | | [gcc](https://storage.googleapis.com/shaderc/badges/build_link_linux_gcc_debug.html) | | 18 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_subdirectory(online-compile) 16 | -------------------------------------------------------------------------------- /examples/online-compile/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_executable(shaderc-online-compile main.cc) 16 | shaderc_default_compile_options(shaderc-online-compile) 17 | target_include_directories(shaderc-online-compile PUBLIC ${shaderc_SOURCE_DIR}/libshaderc_util/include) 18 | target_link_libraries(shaderc-online-compile PRIVATE shaderc) 19 | -------------------------------------------------------------------------------- /glslc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | find_package(Threads) 16 | 17 | add_library(glslc STATIC 18 | src/file_compiler.cc 19 | src/file_compiler.h 20 | src/file.cc 21 | src/file.h 22 | src/file_includer.cc 23 | src/file_includer.h 24 | src/resource_parse.h 25 | src/resource_parse.cc 26 | src/shader_stage.cc 27 | src/shader_stage.h 28 | src/dependency_info.cc 29 | src/dependency_info.h 30 | ) 31 | 32 | shaderc_default_compile_options(glslc) 33 | target_include_directories(glslc PUBLIC ${glslang_SOURCE_DIR}) 34 | 35 | if (SHADERC_ENABLE_WGSL_OUTPUT) 36 | if (IS_DIRECTORY "${tint_SOURCE_DIR}/include") 37 | target_include_directories(glslc PRIVATE "${tint_SOURCE_DIR}/include") 38 | target_include_directories(glslc PRIVATE "${tint_SOURCE_DIR}") 39 | endif() 40 | # Turn on features in the tint/tint.h header 41 | add_definitions(-DTINT_BUILD_SPV_READER=1 -DTINT_BUILD_WGSL_WRITER=1) 42 | add_definitions(-DSHADERC_ENABLE_WGSL_OUTPUT=1) 43 | endif(SHADERC_ENABLE_WGSL_OUTPUT) 44 | 45 | target_link_libraries(glslc PRIVATE 46 | glslang SPIRV # Glslang libraries 47 | $<$:libtint> # Tint libraries, optional 48 | shaderc_util shaderc # internal Shaderc libraries 49 | ${CMAKE_THREAD_LIBS_INIT}) 50 | 51 | add_executable(glslc_exe src/main.cc) 52 | shaderc_default_compile_options(glslc_exe) 53 | target_include_directories(glslc_exe PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/.. ${spirv-tools_SOURCE_DIR}/include) 54 | set_target_properties(glslc_exe PROPERTIES OUTPUT_NAME glslc) 55 | target_link_libraries(glslc_exe PRIVATE glslc shaderc_util shaderc) 56 | add_dependencies(glslc_exe build-version) 57 | 58 | shaderc_add_tests( 59 | TEST_PREFIX glslc 60 | LINK_LIBS glslc shaderc_util shaderc 61 | TEST_NAMES 62 | file 63 | resource_parse 64 | stage) 65 | 66 | shaderc_add_asciidoc(glslc_doc_README README) 67 | 68 | if(SHADERC_ENABLE_INSTALL) 69 | install(TARGETS glslc_exe 70 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 71 | BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}) 72 | endif(SHADERC_ENABLE_INSTALL) 73 | 74 | add_subdirectory(test) 75 | -------------------------------------------------------------------------------- /glslc/src/file.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "file.h" 16 | 17 | namespace glslc { 18 | 19 | shaderc_util::string_piece GetFileExtension( 20 | const shaderc_util::string_piece& filename) { 21 | size_t dot_pos = filename.find_last_of("."); 22 | if (dot_pos == shaderc_util::string_piece::npos) return ""; 23 | return filename.substr(dot_pos + 1); 24 | } 25 | 26 | } // namespace glslc 27 | -------------------------------------------------------------------------------- /glslc/src/file.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef GLSLC_FILE_H_ 16 | #define GLSLC_FILE_H_ 17 | 18 | #include "libshaderc_util/string_piece.h" 19 | 20 | namespace glslc { 21 | 22 | // Given a file name, returns its extension. If no extension exists, 23 | // returns an empty string_piece. 24 | shaderc_util::string_piece GetFileExtension( 25 | const shaderc_util::string_piece& filename); 26 | 27 | // Returns true if the given file name ends with a known shader file extension. 28 | inline bool IsStageFile(const shaderc_util::string_piece& filename) { 29 | const shaderc_util::string_piece extension = 30 | glslc::GetFileExtension(filename); 31 | return extension == "vert" || extension == "frag" || extension == "tesc" || 32 | extension == "tese" || extension == "geom" || extension == "comp"; 33 | } 34 | 35 | // Returns the file extension if is either "glsl" or "hlsl", or an empty 36 | // string otherwise. 37 | inline std::string GetGlslOrHlslExtension( 38 | const shaderc_util::string_piece& filename) { 39 | auto extension = glslc::GetFileExtension(filename); 40 | if ((extension == "glsl") || (extension == "hlsl")) return extension.str(); 41 | return ""; 42 | } 43 | 44 | } // namespace glslc 45 | 46 | #endif // GLSLC_FILE_H_ 47 | -------------------------------------------------------------------------------- /glslc/src/file_includer.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "file_includer.h" 16 | 17 | #include 18 | #include 19 | 20 | #include "libshaderc_util/io_shaderc.h" 21 | 22 | namespace glslc { 23 | 24 | shaderc_include_result* MakeErrorIncludeResult(const char* message) { 25 | return new shaderc_include_result{"", 0, message, strlen(message)}; 26 | } 27 | 28 | FileIncluder::~FileIncluder() = default; 29 | 30 | shaderc_include_result* FileIncluder::GetInclude( 31 | const char* requested_source, shaderc_include_type include_type, 32 | const char* requesting_source, size_t) { 33 | 34 | const std::string full_path = 35 | (include_type == shaderc_include_type_relative) 36 | ? file_finder_.FindRelativeReadableFilepath(requesting_source, 37 | requested_source) 38 | : file_finder_.FindReadableFilepath(requested_source); 39 | 40 | if (full_path.empty()) 41 | return MakeErrorIncludeResult("Cannot find or open include file."); 42 | 43 | // In principle, several threads could be resolving includes at the same 44 | // time. Protect the included_files. 45 | 46 | // Read the file and save its full path and contents into stable addresses. 47 | FileInfo* new_file_info = new FileInfo{full_path, {}}; 48 | if (!shaderc_util::ReadFile(full_path, &(new_file_info->contents))) { 49 | return MakeErrorIncludeResult("Cannot read file"); 50 | } 51 | 52 | included_files_.insert(full_path); 53 | 54 | return new shaderc_include_result{ 55 | new_file_info->full_path.data(), new_file_info->full_path.length(), 56 | new_file_info->contents.data(), new_file_info->contents.size(), 57 | new_file_info}; 58 | } 59 | 60 | void FileIncluder::ReleaseInclude(shaderc_include_result* include_result) { 61 | FileInfo* info = static_cast(include_result->user_data); 62 | delete info; 63 | delete include_result; 64 | } 65 | 66 | } // namespace glslc 67 | -------------------------------------------------------------------------------- /glslc/src/file_includer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef GLSLC_FILE_INCLUDER_H_ 16 | #define GLSLC_FILE_INCLUDER_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "libshaderc_util/file_finder.h" 27 | #include "shaderc/shaderc.hpp" 28 | 29 | namespace glslc { 30 | 31 | // An includer for files implementing shaderc's includer interface. It responds 32 | // to the file including query from the compiler with the full path and content 33 | // of the file to be included. In the case that the file is not found or cannot 34 | // be opened, the full path field of in the response will point to an empty 35 | // string, and error message will be passed to the content field. 36 | // This class provides the basic thread-safety guarantee. 37 | class FileIncluder : public shaderc::CompileOptions::IncluderInterface { 38 | public: 39 | explicit FileIncluder(const shaderc_util::FileFinder* file_finder) 40 | : file_finder_(*file_finder) {} 41 | 42 | ~FileIncluder() override; 43 | 44 | // Resolves a requested source file of a given type from a requesting 45 | // source into a shaderc_include_result whose contents will remain valid 46 | // until it's released. 47 | shaderc_include_result* GetInclude(const char* requested_source, 48 | shaderc_include_type type, 49 | const char* requesting_source, 50 | size_t include_depth) override; 51 | // Releases an include result. 52 | void ReleaseInclude(shaderc_include_result* include_result) override; 53 | 54 | // Returns a reference to the member storing the set of included files. 55 | const std::unordered_set& file_path_trace() const { 56 | return included_files_; 57 | } 58 | 59 | private: 60 | // Used by GetInclude() to get the full filepath. 61 | const shaderc_util::FileFinder& file_finder_; 62 | // The full path and content of a source file. 63 | struct FileInfo { 64 | const std::string full_path; 65 | std::vector contents; 66 | }; 67 | 68 | // The set of full paths of included files. 69 | std::unordered_set included_files_; 70 | }; 71 | 72 | } // namespace glslc 73 | 74 | #endif // GLSLC_FILE_INCLUDER_H_ 75 | -------------------------------------------------------------------------------- /glslc/src/resource_parse.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "resource_parse.h" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace { 24 | 25 | // Converts a limit string to a limit enum. Returns true on successful 26 | // conversion. 27 | bool StringToLimit(const std::string& str, shaderc_limit* limit) { 28 | const char* cstr = str.c_str(); 29 | #define RESOURCE(NAME, FIELD, ENUM) \ 30 | if (0 == std::strcmp(#NAME, cstr)) { \ 31 | *limit = shaderc_limit_##ENUM; \ 32 | return true; \ 33 | } 34 | #include "libshaderc_util/resources.inc" 35 | #undef RESOURCE 36 | return false; 37 | } 38 | 39 | // Returns true if we should ignore the setting. 40 | bool IgnoreSetting(const std::string& str) { 41 | const std::string ignore_list[] = { 42 | "nonInductiveForLoops", 43 | "whileLoops", 44 | "doWhileLoops", 45 | "generalUniformIndexing", 46 | "generalAttributeMatrixVectorIndexing", 47 | "generalVaryingIndexing", 48 | "generalSamplerIndexing", 49 | "generalVariableIndexing", 50 | "generalConstantMatrixVectorIndexing", 51 | }; 52 | return std::find(std::begin(ignore_list), std::end(ignore_list), str) != 53 | std::end(ignore_list); 54 | } 55 | 56 | } // anonymous namespace 57 | 58 | namespace glslc { 59 | 60 | bool ParseResourceSettings(const std::string& input, 61 | std::vector* limits, 62 | std::string* err) { 63 | auto failure = [err, limits](std::string msg) { 64 | *err = msg; 65 | limits->clear(); 66 | return false; 67 | }; 68 | std::istringstream input_stream(input); 69 | std::istream_iterator pos((input_stream)); 70 | limits->clear(); 71 | 72 | while (pos != std::istream_iterator()) { 73 | const std::string limit_name = *pos++; 74 | shaderc_limit limit = static_cast(0); 75 | bool ignore = IgnoreSetting(limit_name); 76 | if (!ignore) { 77 | if (!StringToLimit(limit_name, &limit)) 78 | return failure(std::string("invalid resource limit: " + limit_name)); 79 | } 80 | 81 | if (pos == std::istream_iterator()) 82 | return failure(std::string("missing value after limit: ") + limit_name); 83 | 84 | const std::string value_str = *pos; 85 | int value; 86 | std::istringstream value_stream(value_str); 87 | value_stream >> value; 88 | if (value_stream.bad() || !value_stream.eof() || value_stream.fail()) 89 | return failure(std::string("invalid integer: ") + value_str); 90 | 91 | if (!ignore) limits->push_back({limit, value}); 92 | ++pos; 93 | } 94 | 95 | return true; 96 | } 97 | } // anonymous namespace 98 | -------------------------------------------------------------------------------- /glslc/src/resource_parse.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef GLSLC_RESOURCE_PARSE_H 16 | #define GLSLC_RESOURCE_PARSE_H 17 | 18 | #include 19 | #include 20 | 21 | #include "shaderc/shaderc.h" 22 | 23 | namespace glslc { 24 | 25 | // A resource limit setting. 26 | struct ResourceSetting { 27 | shaderc_limit limit; 28 | int value; 29 | }; 30 | 31 | 32 | // Returns true when two resource setting structures are equal. 33 | inline bool operator==(const ResourceSetting& lhs, const ResourceSetting& rhs) { 34 | return (lhs.limit == rhs.limit) && (lhs.value == rhs.value); 35 | } 36 | 37 | 38 | // Parses a resource limit setting string. On success, returns true and populates 39 | // the limits parameter. On failure returns failure and emits a message to err. 40 | // The setting string should be a seqeuence of pairs, where each pair 41 | // is a limit name followed by a decimal integer. Tokens should be separated 42 | // by whitespace. In particular, this function accepts Glslang's configuration 43 | // file syntax. If a limit is mentioned multiple times, then the last setting 44 | // takes effect. Ignore settings for: 45 | // nonInductiveForLoops 46 | // whileLoops 47 | // doWhileLoops 48 | // generalUniformIndexing 49 | // generalAttributeMatrixVectorIndexing 50 | // generalVaryingIndexing 51 | // generalSamplerIndexing 52 | // generalVariableIndexing 53 | // generalConstantMatrixVectorIndexing 54 | bool ParseResourceSettings(const std::string& input, 55 | std::vector* limits, 56 | std::string* err); 57 | } // namespace glslc 58 | 59 | 60 | #endif // GLSLC_FILE_H_ 61 | -------------------------------------------------------------------------------- /glslc/src/resource_parse_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "resource_parse.h" 16 | 17 | #include 18 | 19 | namespace { 20 | 21 | using glslc::ParseResourceSettings; 22 | using glslc::ResourceSetting; 23 | using testing::Eq; 24 | 25 | struct ResourceSettingsCase { 26 | std::string input; 27 | bool success; 28 | std::vector settings; 29 | std::string message; 30 | }; 31 | 32 | using ParseResourceSettingsTest = ::testing::TestWithParam; 33 | 34 | TEST_P(ParseResourceSettingsTest, Sample) { 35 | std::vector settings; 36 | std::string err; 37 | const bool succeeded = ParseResourceSettings(GetParam().input, &settings, &err); 38 | EXPECT_THAT(succeeded, Eq(GetParam().success)); 39 | EXPECT_THAT(settings, Eq(GetParam().settings)); 40 | EXPECT_THAT(err, Eq(GetParam().message)); 41 | } 42 | 43 | INSTANTIATE_TEST_SUITE_P(ParseResources, ParseResourceSettingsTest, 44 | ::testing::ValuesIn(std::vector{ 45 | {"", true, {}, ""}, 46 | {" \t \t \n ", true, {}, ""}, 47 | {" blorp blam", false, {}, "invalid resource limit: blorp"}, 48 | {"MaxLightsxyz", false, {}, "invalid resource limit: MaxLightsxyz"}, 49 | {"MaxLights", false, {}, "missing value after limit: MaxLights"}, 50 | {"MaxLights x", false, {}, "invalid integer: x"}, 51 | {"MaxLights 99x", false, {}, "invalid integer: 99x"}, 52 | {"MaxLights 12 blam", false, {}, "invalid resource limit: blam"}, 53 | {"MaxLights 12", true, {{shaderc_limit_max_lights, 12}}, ""}, 54 | // Test negative number 55 | {"MinProgramTexelOffset -9", true, {{shaderc_limit_min_program_texel_offset, -9}}, ""}, 56 | // Test leading, intervening, and trailing whitespace 57 | {" \tMaxLights \n 12 \t ", true, {{shaderc_limit_max_lights, 12}}, ""}, 58 | // Test more than one limit setting. 59 | {"MinProgramTexelOffset -10 MaxLights 4", true, {{shaderc_limit_min_program_texel_offset, -10}, {shaderc_limit_max_lights, 4}}, ""}, 60 | // Check ignore cases. 61 | {"nonInductiveForLoops", false, {}, "missing value after limit: nonInductiveForLoops"}, 62 | {"nonInductiveForLoops 1", true, {}, ""}, 63 | {"whileLoops 1", true, {}, ""}, 64 | {"doWhileLoops 1", true, {}, ""}, 65 | {"generalUniformIndexing 1", true, {}, ""}, 66 | {"generalAttributeMatrixVectorIndexing 1", true, {}, ""}, 67 | {"generalVaryingIndexing 1", true, {}, ""}, 68 | {"generalSamplerIndexing 1", true, {}, ""}, 69 | {"generalVariableIndexing 1", true, {}, ""}, 70 | {"generalConstantMatrixVectorIndexing 1", true, {}, ""}, 71 | // Check an ignore case with a regular case 72 | {"whileLoops 1 MaxLights 99", true, {{shaderc_limit_max_lights, 99}}, ""}, 73 | })); 74 | 75 | } // anonymous namespace 76 | -------------------------------------------------------------------------------- /glslc/src/shader_stage.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef GLSLC_SHADER_STAGE_H_ 16 | #define GLSLC_SHADER_STAGE_H_ 17 | 18 | #include 19 | 20 | #include "libshaderc_util/string_piece.h" 21 | #include "shaderc/shaderc.h" 22 | 23 | namespace glslc { 24 | 25 | // Maps a shader stage name to a forced shader stage enum value. Returns 26 | // 'shaderc_glsl_infer_from_source' if the stage name is unrecognized. 27 | shaderc_shader_kind MapStageNameToForcedKind( 28 | const shaderc_util::string_piece& f_shader_stage_str); 29 | 30 | // Parse the string piece from command line to get the force shader stage. 31 | // If the 'f_shader_stage_str' cannot be parsed to a valid force shader stage, 32 | // returns 'shaderc_glsl_infer_from_source'. Requires the string to begin with 33 | // '='. 34 | shaderc_shader_kind GetForcedShaderKindFromCmdLine( 35 | const shaderc_util::string_piece& f_shader_stage_str); 36 | 37 | // Parse the file name extension to get the default shader kind. 38 | shaderc_shader_kind DeduceDefaultShaderKindFromFileName( 39 | shaderc_util::string_piece file_name); 40 | } // namespace glslc 41 | 42 | #endif // GLSLC_SHADER_STAGE_H_ 43 | -------------------------------------------------------------------------------- /glslc/src/stage_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Some of the tests here check code paths that are not checked by 16 | // integration tests. 17 | // Generally, these would be conditions not generated by the Glslang 18 | // compiler. It's easier to write these unit tests than to inject 19 | // a dependency on a fake compiler. 20 | 21 | #include 22 | 23 | #include 24 | #include "shaderc/shaderc.h" 25 | 26 | #include "shader_stage.h" 27 | 28 | using shaderc_util::string_piece; 29 | 30 | namespace { 31 | 32 | TEST(DeduceDefaultShaderKindFromFileName, ValidStage) { 33 | std::stringstream error_stream; 34 | EXPECT_EQ(shaderc_glsl_default_vertex_shader, 35 | glslc::DeduceDefaultShaderKindFromFileName("a.vert")); 36 | 37 | EXPECT_EQ(shaderc_glsl_default_fragment_shader, 38 | glslc::DeduceDefaultShaderKindFromFileName("a.frag")); 39 | 40 | EXPECT_EQ(shaderc_glsl_default_geometry_shader, 41 | glslc::DeduceDefaultShaderKindFromFileName("a.geom")); 42 | 43 | EXPECT_EQ(shaderc_glsl_default_tess_control_shader, 44 | glslc::DeduceDefaultShaderKindFromFileName("a.tesc")); 45 | 46 | EXPECT_EQ(shaderc_glsl_default_tess_evaluation_shader, 47 | glslc::DeduceDefaultShaderKindFromFileName("a.tese")); 48 | 49 | EXPECT_EQ(shaderc_glsl_default_compute_shader, 50 | glslc::DeduceDefaultShaderKindFromFileName("a.comp")); 51 | 52 | EXPECT_EQ(shaderc_glsl_default_raygen_shader, 53 | glslc::DeduceDefaultShaderKindFromFileName("a.rgen")); 54 | 55 | EXPECT_EQ(shaderc_glsl_default_anyhit_shader, 56 | glslc::DeduceDefaultShaderKindFromFileName("a.rahit")); 57 | 58 | EXPECT_EQ(shaderc_glsl_default_closesthit_shader, 59 | glslc::DeduceDefaultShaderKindFromFileName("a.rchit")); 60 | 61 | EXPECT_EQ(shaderc_glsl_default_miss_shader, 62 | glslc::DeduceDefaultShaderKindFromFileName("a.rmiss")); 63 | 64 | EXPECT_EQ(shaderc_glsl_default_intersection_shader, 65 | glslc::DeduceDefaultShaderKindFromFileName("a.rint")); 66 | 67 | EXPECT_EQ(shaderc_glsl_default_callable_shader, 68 | glslc::DeduceDefaultShaderKindFromFileName("a.rcall")); 69 | 70 | EXPECT_EQ(shaderc_glsl_default_task_shader, 71 | glslc::DeduceDefaultShaderKindFromFileName("a.task")); 72 | 73 | EXPECT_EQ(shaderc_glsl_default_mesh_shader, 74 | glslc::DeduceDefaultShaderKindFromFileName("a.mesh")); 75 | } 76 | 77 | TEST(DeduceDefaultShaderKindFromFileName, InvalidStage) { 78 | std::stringstream error_stream; 79 | EXPECT_EQ(shaderc_glsl_infer_from_source, 80 | glslc::DeduceDefaultShaderKindFromFileName("a.glsl")); 81 | 82 | EXPECT_EQ(shaderc_glsl_infer_from_source, 83 | glslc::DeduceDefaultShaderKindFromFileName("-")); 84 | 85 | EXPECT_EQ(shaderc_glsl_infer_from_source, 86 | glslc::DeduceDefaultShaderKindFromFileName("a.foo")); 87 | 88 | EXPECT_EQ(shaderc_glsl_infer_from_source, 89 | glslc::DeduceDefaultShaderKindFromFileName("no-file-extension")); 90 | } 91 | 92 | } // anonymous namespace 93 | -------------------------------------------------------------------------------- /glslc/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_test(NAME shaderc_expect_unittests 16 | COMMAND ${Python_EXECUTABLE} -m unittest expect_unittest.py 17 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 18 | add_test(NAME shaderc_glslc_test_framework_unittests 19 | COMMAND ${Python_EXECUTABLE} -m unittest glslc_test_framework_unittest.py 20 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 21 | 22 | if(${SHADERC_ENABLE_TESTS}) 23 | add_test(NAME glslc_tests 24 | COMMAND ${Python_EXECUTABLE} 25 | ${CMAKE_CURRENT_SOURCE_DIR}/glslc_test_framework.py 26 | $ $ 27 | --test-dir ${CMAKE_CURRENT_SOURCE_DIR}) 28 | endif() 29 | -------------------------------------------------------------------------------- /glslc/test/environment.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Classes for conveniently specifying a test environment. 16 | 17 | These classes have write() methods that create objects in a test's environment. 18 | For instance, File creates a file, and Directory creates a directory with some 19 | files or subdirectories in it. 20 | 21 | Example: 22 | test.environment = Directory('.', [ 23 | File('a.vert', 'void main(){}'), 24 | Directory('subdir', [ 25 | File('b', 'b content'), 26 | File('c', 'c content') 27 | ]) 28 | ]) 29 | 30 | In general, these classes don't clean up the disk content they create. They 31 | were written in a test framework that handles clean-up at a higher level. 32 | 33 | """ 34 | 35 | import os 36 | 37 | class Directory: 38 | """Specifies a directory or a subdirectory.""" 39 | def __init__(self, name, content): 40 | """content is a list of File or Directory objects.""" 41 | self.name = name 42 | self.content = content 43 | 44 | @staticmethod 45 | def create(path): 46 | """Creates a directory path if it doesn't already exist.""" 47 | try: 48 | os.makedirs(path) 49 | except OSError: # Handles both pre-existence and a racing creation. 50 | if not os.path.isdir(path): 51 | raise 52 | 53 | def write(self, parent): 54 | """Creates a self.name directory within parent (which is a string path) and 55 | recursively writes the content in it. 56 | 57 | """ 58 | full_path = os.path.join(parent, self.name) 59 | Directory.create(full_path) 60 | for c in self.content: 61 | c.write(full_path) 62 | 63 | class File: 64 | """Specifies a file by name and content.""" 65 | def __init__(self, name, content): 66 | self.name = name 67 | self.content = content 68 | 69 | def write(self, directory): 70 | """Writes content to directory/name.""" 71 | with open(os.path.join(directory, self.name), 'w') as f: 72 | f.write(self.content) 73 | -------------------------------------------------------------------------------- /glslc/test/error_no_object.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import expect 16 | import os.path 17 | from glslc_test_framework import inside_glslc_testsuite 18 | from placeholder import FileShader 19 | 20 | 21 | @inside_glslc_testsuite('ErrorNoObject') 22 | class ErrorGeneratesNoObjectFile(expect.NoObjectFile, 23 | expect.NoOutputOnStdout, 24 | expect.ErrorMessageSubstr): 25 | """Tests that on error, no object file is generated.""" 26 | 27 | shader = FileShader('#version 150\nBad', '.frag') 28 | glslc_args = ['-c', shader] 29 | expected_error_substr = ['syntax error'] 30 | 31 | 32 | @inside_glslc_testsuite('ErrorNoObject') 33 | class FailureToMakeOutputFileIsErrorWithNoOutputFile( 34 | expect.NoNamedOutputFiles, 35 | expect.NoOutputOnStdout, 36 | expect.ErrorMessageSubstr): 37 | """Tests that if we fail to make an output file, no file is generated, 38 | and we have certain error messages.""" 39 | 40 | shader = FileShader('#version 150\nvoid main() {}', '.frag') 41 | bad_file = '/file/should/not/exist/today' 42 | glslc_args = ['-c', shader, '-o', bad_file] 43 | expected_output_filenames = [bad_file] 44 | expected_error_substr = ['cannot open output file'] 45 | 46 | 47 | @inside_glslc_testsuite('ErrorNoObject') 48 | class FailureToMakeOutputFileAsCurrentDirIsErrorWithNoOutputFile( 49 | expect.NoNamedOutputFiles, 50 | expect.NoOutputOnStdout, 51 | expect.ErrorMessageSubstr): 52 | """Tests that if we fail to make an output file because it is the current 53 | directory, then no file is generated, and we have certain error messages.""" 54 | 55 | shader = FileShader('#version 150\nvoid main() {}', '.frag') 56 | bad_file = '.' # Current directory 57 | glslc_args = ['-c', shader, '-o', bad_file] 58 | expected_output_filenames = [bad_file] 59 | expected_error_substr = ['cannot open output file'] 60 | -------------------------------------------------------------------------------- /glslc/test/expect_unittest.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Tests for the expect module.""" 15 | 16 | 17 | import expect 18 | from glslc_test_framework import TestStatus 19 | import re 20 | import unittest 21 | 22 | 23 | class TestStdoutMatchADotC(expect.StdoutMatch): 24 | expected_stdout = re.compile('a.c') 25 | 26 | 27 | class TestExpect(unittest.TestCase): 28 | def test_get_object_name(self): 29 | """Tests get_object_filename().""" 30 | source_and_object_names = [('a.vert', 'a.vert.spv'), 31 | ('b.frag', 'b.frag.spv'), 32 | ('c.tesc', 'c.tesc.spv'), 33 | ('d.tese', 'd.tese.spv'), 34 | ('e.geom', 'e.geom.spv'), 35 | ('f.comp', 'f.comp.spv'), 36 | ('file', 'file.spv'), ('file.', 'file.spv'), 37 | ('file.uk', 38 | 'file.spv'), ('file.vert.', 39 | 'file.vert.spv'), 40 | ('file.vert.bla', 41 | 'file.vert.spv')] 42 | actual_object_names = [ 43 | expect.get_object_filename(f[0]) for f in source_and_object_names 44 | ] 45 | expected_object_names = [f[1] for f in source_and_object_names] 46 | 47 | self.assertEqual(actual_object_names, expected_object_names) 48 | 49 | def test_stdout_match_regex_has_match(self): 50 | test = TestStdoutMatchADotC() 51 | status = TestStatus( 52 | test_manager=None, 53 | returncode=0, 54 | stdout=b'0abc1', 55 | stderr=None, 56 | directory=None, 57 | inputs=None, 58 | input_filenames=None) 59 | self.assertTrue(test.check_stdout_match(status)[0]) 60 | 61 | def test_stdout_match_regex_no_match(self): 62 | test = TestStdoutMatchADotC() 63 | status = TestStatus( 64 | test_manager=None, 65 | returncode=0, 66 | stdout=b'ab', 67 | stderr=None, 68 | directory=None, 69 | inputs=None, 70 | input_filenames=None) 71 | self.assertFalse(test.check_stdout_match(status)[0]) 72 | 73 | def test_stdout_match_regex_empty_stdout(self): 74 | test = TestStdoutMatchADotC() 75 | status = TestStatus( 76 | test_manager=None, 77 | returncode=0, 78 | stdout=b'', 79 | stderr=None, 80 | directory=None, 81 | inputs=None, 82 | input_filenames=None) 83 | self.assertFalse(test.check_stdout_match(status)[0]) 84 | -------------------------------------------------------------------------------- /glslc/test/file_extensions.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import expect 16 | from glslc_test_framework import GlslCTest, inside_glslc_testsuite 17 | from placeholder import FileShader 18 | 19 | 20 | def empty_es_310_shader(): 21 | return '#version 310 es\n void main() {}\n' 22 | 23 | 24 | @inside_glslc_testsuite('FileExtension') 25 | class VerifyVertExtension(expect.ValidObjectFile): 26 | """Tests glslc accepts vertex shader extension (.vert).""" 27 | 28 | shader = FileShader(empty_es_310_shader(), '.vert') 29 | glslc_args = ['-c', shader] 30 | 31 | 32 | @inside_glslc_testsuite('FileExtension') 33 | class VerifyFragExtension(expect.ValidObjectFile): 34 | """Tests glslc accepts fragment shader extension (.frag).""" 35 | 36 | shader = FileShader(empty_es_310_shader(), '.frag') 37 | glslc_args = ['-c', shader] 38 | 39 | 40 | @inside_glslc_testsuite('FileExtension') 41 | class VerifyTescExtension(expect.ValidObjectFile): 42 | """Tests glslc accepts tessellation control shader extension (.tesc).""" 43 | 44 | shader = FileShader( 45 | '#version 440 core\n layout(vertices = 3) out;\n void main() {}', 46 | '.tesc') 47 | glslc_args = ['-c', shader] 48 | 49 | 50 | @inside_glslc_testsuite('FileExtension') 51 | class VerifyTeseExtension(expect.ValidObjectFile): 52 | """Tests glslc accepts tessellation evaluation shader extension (.tese).""" 53 | 54 | shader = FileShader( 55 | '#version 440 core\n layout(triangles) in;\n void main() {}', '.tese') 56 | glslc_args = ['-c', shader] 57 | 58 | 59 | @inside_glslc_testsuite('FileExtension') 60 | class VerifyGeomExtension(expect.ValidObjectFile): 61 | """Tests glslc accepts geomtry shader extension (.geom).""" 62 | 63 | shader = FileShader( 64 | '#version 150 core\n layout (triangles) in;\n' 65 | 'layout (line_strip, max_vertices = 4) out;\n void main() {}', 66 | '.geom') 67 | glslc_args = ['-c', shader] 68 | 69 | 70 | @inside_glslc_testsuite('FileExtension') 71 | class VerifyCompExtension(expect.ValidObjectFile): 72 | """Tests glslc accepts compute shader extension (.comp).""" 73 | 74 | shader = FileShader(empty_es_310_shader(), '.comp') 75 | glslc_args = ['-c', shader] 76 | 77 | 78 | @inside_glslc_testsuite('FileExtension') 79 | class InvalidExtension(expect.ErrorMessage): 80 | """Tests the error message if a file extension cannot be determined.""" 81 | 82 | shader = FileShader('#version 150\n', '.fraga') 83 | glslc_args = ['-c', shader] 84 | expected_error = [ 85 | "glslc: error: '", shader, 86 | "': file not recognized: File format not recognized\n"] 87 | -------------------------------------------------------------------------------- /glslc/test/option_dash_c.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import expect 16 | from glslc_test_framework import inside_glslc_testsuite 17 | from placeholder import FileShader 18 | 19 | 20 | def empty_es_310_shader(): 21 | return '#version 310 es\n void main() {}\n' 22 | 23 | 24 | @inside_glslc_testsuite('OptionC') 25 | class TestSingleDashCSingleFile(expect.ValidObjectFile): 26 | """Tests that glslc accepts -c [filename].""" 27 | 28 | shader = FileShader(empty_es_310_shader(), '.vert') 29 | glslc_args = ['-c', shader] 30 | 31 | 32 | @inside_glslc_testsuite('OptionC') 33 | class TestSingleFileSingleDashC(expect.ValidObjectFile): 34 | """Tests that glslc accepts [filename] -c.""" 35 | 36 | shader = FileShader(empty_es_310_shader(), '.vert') 37 | glslc_args = [shader, '-c'] 38 | 39 | 40 | @inside_glslc_testsuite('OptionC') 41 | class TestMultipleFiles(expect.ValidObjectFile): 42 | """Tests that glslc accepts -c and multiple source files.""" 43 | 44 | shader1 = FileShader(empty_es_310_shader(), '.vert') 45 | shader2 = FileShader(empty_es_310_shader(), '.frag') 46 | glslc_args = ['-c', shader1, shader2] 47 | 48 | 49 | @inside_glslc_testsuite('OptionC') 50 | class TestMultipleDashC(expect.ValidObjectFile): 51 | """Tests that glslc accepts multiple -c and treated them as one.""" 52 | 53 | shader1 = FileShader(empty_es_310_shader(), '.vert') 54 | shader2 = FileShader(empty_es_310_shader(), '.vert') 55 | glslc_args = ['-c', shader1, '-c', '-c', shader2] 56 | -------------------------------------------------------------------------------- /glslc/test/option_dash_fhlsl_offsets.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import expect 16 | from glslc_test_framework import inside_glslc_testsuite 17 | from placeholder import FileShader 18 | 19 | 20 | # A GLSL shader with uniforms without explicit bindings. 21 | GLSL_SHADER = """#version 450 22 | layout(set=0, binding=0) 23 | buffer B { float x; vec3 y; } my_ssbo; 24 | void main() { 25 | my_ssbo.x = 1.0; 26 | }""" 27 | 28 | 29 | @inside_glslc_testsuite('OptionFHlslOffsets') 30 | class StandardOffsetsByDefault(expect.ValidAssemblyFileWithSubstr): 31 | """Tests that standard GLSL packign is used by default.""" 32 | 33 | shader = FileShader(GLSL_SHADER, '.vert') 34 | glslc_args = ['-S', shader] 35 | expected_assembly_substr = "OpMemberDecorate %B 1 Offset 16" 36 | 37 | 38 | @inside_glslc_testsuite('OptionFHlslOffsets') 39 | class HlslOffsetsWhenRequested(expect.ValidAssemblyFileWithSubstr): 40 | """Tests that standard GLSL packign is used by default.""" 41 | 42 | shader = FileShader(GLSL_SHADER, '.vert') 43 | glslc_args = ['-S', '-fhlsl-offsets', shader] 44 | expected_assembly_substr = "OpMemberDecorate %B 1 Offset 4" 45 | -------------------------------------------------------------------------------- /glslc/test/option_dash_fnan_clamp.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import expect 16 | from glslc_test_framework import inside_glslc_testsuite 17 | from placeholder import FileShader 18 | 19 | # A GLSL shader using the clamp, max, and min builtin functions. 20 | GLSL_FRAG_SHADER_WITH_CLAMP = """#version 450 21 | layout(location=0) in vec4 i; 22 | layout(location=0) out vec4 o; 23 | void main() { 24 | o = clamp(i, vec4(0.5), vec4(1.0)) 25 | + max(i, vec4(0.5)) 26 | + min(i, vec4(0.5)); 27 | } 28 | """ 29 | 30 | 31 | @inside_glslc_testsuite('OptionFNanClamp') 32 | class TestClampMapsToFClampByDefault(expect.ValidAssemblyFileWithSubstr): 33 | shader = FileShader(GLSL_FRAG_SHADER_WITH_CLAMP, '.frag') 34 | glslc_args = ['-S', shader] 35 | expected_assembly_substr = 'OpExtInst %v4float %1 FClamp' 36 | 37 | 38 | @inside_glslc_testsuite('OptionFNanClamp') 39 | class TestMaxMapsToFMaxByDefault(expect.ValidAssemblyFileWithSubstr): 40 | shader = FileShader(GLSL_FRAG_SHADER_WITH_CLAMP, '.frag') 41 | glslc_args = ['-S', shader] 42 | expected_assembly_substr = 'OpExtInst %v4float %1 FMax' 43 | 44 | 45 | @inside_glslc_testsuite('OptionFNanClamp') 46 | class TestMinMapsToFMinByDefault(expect.ValidAssemblyFileWithSubstr): 47 | shader = FileShader(GLSL_FRAG_SHADER_WITH_CLAMP, '.frag') 48 | glslc_args = ['-S', shader] 49 | expected_assembly_substr = 'OpExtInst %v4float %1 FMin' 50 | 51 | 52 | @inside_glslc_testsuite('OptionFNanClamp') 53 | class TestClampMapsToNClampWithFlag(expect.ValidAssemblyFileWithSubstr): 54 | shader = FileShader(GLSL_FRAG_SHADER_WITH_CLAMP, '.frag') 55 | glslc_args = ['-S', '-fnan-clamp', shader] 56 | expected_assembly_substr = 'OpExtInst %v4float %1 NClamp' 57 | 58 | @inside_glslc_testsuite('OptionFNanClamp') 59 | class TestMaxMapsToNMaxWithFlag(expect.ValidAssemblyFileWithSubstr): 60 | shader = FileShader(GLSL_FRAG_SHADER_WITH_CLAMP, '.frag') 61 | glslc_args = ['-S', '-fnan-clamp', shader] 62 | expected_assembly_substr = 'OpExtInst %v4float %1 NMax' 63 | 64 | 65 | @inside_glslc_testsuite('OptionFNanClamp') 66 | class TestMinMapsToNMinWithFlag(expect.ValidAssemblyFileWithSubstr): 67 | shader = FileShader(GLSL_FRAG_SHADER_WITH_CLAMP, '.frag') 68 | glslc_args = ['-S', '-fnan-clamp', shader] 69 | expected_assembly_substr = 'OpExtInst %v4float %1 NMin' 70 | -------------------------------------------------------------------------------- /glslc/test/option_dash_g.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import expect 16 | from glslc_test_framework import inside_glslc_testsuite 17 | from placeholder import FileShader 18 | 19 | 20 | def empty_es_310_shader(): 21 | return '#version 310 es\n void main() {}\n' 22 | 23 | 24 | @inside_glslc_testsuite('OptionG') 25 | class TestSingleDashGSingleFile(expect.ValidObjectFile): 26 | """Tests that glslc accepts -g [filename]. Need -c for now too.""" 27 | 28 | shader = FileShader(empty_es_310_shader(), '.vert') 29 | glslc_args = ['-c', '-g', shader] 30 | 31 | 32 | @inside_glslc_testsuite('OptionG') 33 | class TestSingleFileSingleDashG(expect.ValidObjectFile): 34 | """Tests that glslc accepts [filename] -g -c.""" 35 | 36 | shader = FileShader(empty_es_310_shader(), '.vert') 37 | glslc_args = [shader, '-g', '-c'] 38 | 39 | 40 | @inside_glslc_testsuite('OptionG') 41 | class TestMultipleFiles(expect.ValidObjectFile): 42 | """Tests that glslc accepts -g and multiple source files.""" 43 | 44 | shader1 = FileShader(empty_es_310_shader(), '.vert') 45 | shader2 = FileShader(empty_es_310_shader(), '.frag') 46 | glslc_args = ['-c', shader1, '-g', shader2] 47 | 48 | 49 | @inside_glslc_testsuite('OptionG') 50 | class TestMultipleDashG(expect.ValidObjectFile): 51 | """Tests that glslc accepts multiple -g and treated them as one.""" 52 | 53 | shader1 = FileShader(empty_es_310_shader(), '.vert') 54 | shader2 = FileShader(empty_es_310_shader(), '.vert') 55 | glslc_args = ['-c', '-g', shader1, '-g', '-g', shader2] 56 | -------------------------------------------------------------------------------- /glslc/test/option_dashdash_version.py: -------------------------------------------------------------------------------- 1 | # Copyright 2016 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import expect 16 | from glslc_test_framework import inside_glslc_testsuite 17 | import re 18 | 19 | @inside_glslc_testsuite('OptionDashDashVersion') 20 | class TestVersionContainsShaderc(expect.StdoutMatch, expect.ReturnCodeIsZero): 21 | """Tests --version output contains 'shaderc'.""" 22 | glslc_args = ['--version'] 23 | expected_stdout = re.compile('^shaderc') 24 | 25 | 26 | @inside_glslc_testsuite('OptionDashDashVersion') 27 | class TestVersionContainsSpirvTools(expect.StdoutMatch, expect.ReturnCodeIsZero): 28 | """Tests --version output contains 'spirv-tools'.""" 29 | glslc_args = ['--version'] 30 | expected_stdout = re.compile('\nspirv-tools') 31 | 32 | 33 | @inside_glslc_testsuite('OptionDashDashVersion') 34 | class TestVersionContainsGlslang(expect.StdoutMatch, expect.ReturnCodeIsZero): 35 | """Tests --version output contains 'glslang'.""" 36 | glslc_args = ['--version'] 37 | expected_stdout = re.compile('\nglslang') 38 | 39 | 40 | @inside_glslc_testsuite('OptionDashDashVersion') 41 | class TestVersionContainsTarget(expect.StdoutMatch, expect.ReturnCodeIsZero): 42 | """Tests --version output contains 'Target:'.""" 43 | glslc_args = ['--version'] 44 | expected_stdout = re.compile('\nTarget: SPIR-V \d+\.\d+') 45 | -------------------------------------------------------------------------------- /glslc/test/option_fauto_combined_image_sampler.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import expect 16 | from glslc_test_framework import inside_glslc_testsuite 17 | from placeholder import FileShader 18 | 19 | # A GLSL shader with a separate sampler and texture2D object 20 | GLSL_SHADER_SEPARATE_IMAGE_SAMPLER = """#version 460 21 | layout (location=0) in vec2 in_UV; 22 | layout (location=0) out vec4 out_Color; 23 | layout (set=0,binding=0) uniform sampler u_Sampler; 24 | layout (set=0,binding=0) uniform texture2D u_Tex; 25 | void main() { 26 | out_Color = texture(sampler2D(u_Tex, u_Sampler), in_UV); 27 | }""" 28 | 29 | 30 | # An HLSL fragment shader with the usual Texture2D and SamplerState pair 31 | HLSL_SHADER_SEPARATE_IMAGE_SAMPLER = """ 32 | Texture2D u_Tex; 33 | SamplerState u_Sampler; 34 | float4 Frag(float2 uv) : COLOR0 { 35 | return u_Tex.Sample(u_Sampler, uv); 36 | }""" 37 | 38 | 39 | @inside_glslc_testsuite('OptionFAutoCombinedImageSampler') 40 | class FAutoCombinedImageSamplerCheckGLSL(expect.ValidAssemblyFileWithSubstr): 41 | """Tests that the compiler combines GLSL sampler and texture2D objects.""" 42 | shader = FileShader(GLSL_SHADER_SEPARATE_IMAGE_SAMPLER, '.frag') 43 | glslc_args = ['-S', '-fauto-combined-image-sampler', shader] 44 | expected_assembly_substr = """%10 = OpTypeImage %float 2D 0 0 0 1 Unknown 45 | %11 = OpTypeSampledImage %10 46 | %_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11 47 | %u_Tex = OpVariable %_ptr_UniformConstant_11 UniformConstant""" 48 | 49 | @inside_glslc_testsuite('OptionFAutoCombinedImageSampler') 50 | class FAutoCombinedImageSamplerCheckHLSL(expect.ValidAssemblyFileWithSubstr): 51 | """Tests that the HLSL compiler combines HLSL Texture2D and SamplerState objects into SPIRV SampledImage.""" 52 | 53 | shader = FileShader(HLSL_SHADER_SEPARATE_IMAGE_SAMPLER, '.hlsl') 54 | glslc_args = ['-S', '-fshader-stage=frag', '-fentry-point=Frag', '-fauto-combined-image-sampler', shader] 55 | expected_assembly_substr = """%14 = OpTypeImage %float 2D 0 0 0 1 Unknown 56 | %15 = OpTypeSampledImage %14 57 | %_ptr_UniformConstant_15 = OpTypePointer UniformConstant %15 58 | %u_Tex = OpVariable %_ptr_UniformConstant_15 UniformConstant""" 59 | 60 | -------------------------------------------------------------------------------- /glslc/test/option_fauto_map_locations.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import expect 16 | from glslc_test_framework import inside_glslc_testsuite 17 | from placeholder import FileShader 18 | 19 | # A GLSL shader with inputs and outputs explicit locations. 20 | GLSL_SHADER_IO_WITHOUT_LOCATIONS = """#version 310 es 21 | in vec4 m_in; 22 | in vec4 m_in1; 23 | out vec4 m_out; 24 | out vec4 m_out1; 25 | void main() { 26 | m_out = m_in; 27 | m_out1 = m_in1; 28 | }""" 29 | 30 | 31 | # An HLSL fragment shader with inputs and outputs explicit locations. 32 | HLSL_SHADER_IO_WITHOUT_LOCATIONS = """ 33 | float4 Foo(float4 a, float4 b) : COLOR0 { 34 | return a + b; 35 | }""" 36 | 37 | 38 | @inside_glslc_testsuite('OptionFAutoMapLocations') 39 | class MissingLocationsResultsInError(expect.ErrorMessageSubstr): 40 | """Tests that compilation fails when inputs or outputs have no location.""" 41 | 42 | shader = FileShader(GLSL_SHADER_IO_WITHOUT_LOCATIONS, '.vert') 43 | glslc_args = ['-S', shader] 44 | expected_error_substr = "SPIR-V requires location for user input/output" 45 | 46 | 47 | @inside_glslc_testsuite('OptionFAutoMapLocations') 48 | class FAutoMapLocationsGeneratesLocationsCheckInput(expect.ValidAssemblyFileWithSubstr): 49 | """Tests that the compiler generates locations upon request: Input 0""" 50 | 51 | shader = FileShader(GLSL_SHADER_IO_WITHOUT_LOCATIONS, '.vert') 52 | glslc_args = ['-S', shader, '-fauto-map-locations'] 53 | expected_assembly_substr = "OpDecorate %m_in Location 0" 54 | 55 | 56 | @inside_glslc_testsuite('OptionFAutoMapLocations') 57 | class FAutoMapLocationsGeneratesLocationsCheckOutput0(expect.ValidAssemblyFileWithSubstr): 58 | """Tests that the compiler generates locations upon request: Output 0""" 59 | 60 | shader = FileShader(GLSL_SHADER_IO_WITHOUT_LOCATIONS, '.vert') 61 | glslc_args = ['-S', shader, '-fauto-map-locations'] 62 | expected_assembly_substr = "OpDecorate %m_out Location 0" 63 | 64 | 65 | # Currently Glslang only generates Location 0. 66 | # See https://github.com/KhronosGroup/glslang/issues/1261 67 | # TODO(dneto): Write tests that check Location 1 is generated for inputs and 68 | # outputs. 69 | 70 | 71 | # Glslang's HLSL compiler automatically assigns locations inptus and outputs. 72 | @inside_glslc_testsuite('OptionFAutoMapLocations') 73 | class HLSLCompilerGeneratesLocationsCheckInput0(expect.ValidAssemblyFileWithSubstr): 74 | """Tests that the HLSL compiler generates locations automatically: Input 0.""" 75 | 76 | shader = FileShader(HLSL_SHADER_IO_WITHOUT_LOCATIONS, '.hlsl') 77 | glslc_args = ['-S', '-fshader-stage=frag', '-fentry-point=Foo', shader] 78 | expected_assembly_substr = "OpDecorate %a Location 0" 79 | 80 | 81 | @inside_glslc_testsuite('OptionFAutoMapLocations') 82 | class HLSLCompilerGeneratesLocationsCheckOutput(expect.ValidAssemblyFileWithSubstr): 83 | """Tests that the HLSL compiler generates locations automatically: Output.""" 84 | 85 | shader = FileShader(HLSL_SHADER_IO_WITHOUT_LOCATIONS, '.hlsl') 86 | glslc_args = ['-S', '-fshader-stage=frag', '-fentry-point=Foo', shader] 87 | expected_assembly_substr = "OpDecorate %_entryPointOutput Location 0" 88 | -------------------------------------------------------------------------------- /glslc/test/option_fhlsl_16bit_types.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import expect 16 | from glslc_test_framework import inside_glslc_testsuite 17 | from placeholder import FileShader 18 | 19 | HLSL_SHADER_WITH_HALF_TYPE = """ 20 | float4 main() : SV_Target0 { 21 | half h0 = (half)0.0; 22 | half h1 = (half)1.0; 23 | half h2 = (half)2.0; 24 | half h3 = (half)3.0; 25 | half4 v = (half4)(h0,h1,h2,h3) * (half)2.0; 26 | return (float4)(v); 27 | } 28 | """ 29 | 30 | 31 | @inside_glslc_testsuite('OptionFHlsl16BitTypes') 32 | class TestHlsl16BitTypes_EnablesCapability(expect.ValidAssemblyFileWithSubstr): 33 | """Tests that -fhlsl_16bit_types enables the 16bit floating point capability.""" 34 | 35 | shader = FileShader(HLSL_SHADER_WITH_HALF_TYPE, '.frag') 36 | glslc_args = ['-S', '-x', 'hlsl', '-fhlsl-16bit-types', '-fauto-bind-uniforms', shader] 37 | expected_assembly_substr = 'OpCapability Float16'; 38 | 39 | 40 | @inside_glslc_testsuite('OptionFHlsl16BitTypes') 41 | class TestHlsl16BitTypes_CreatesType(expect.ValidAssemblyFileWithSubstr): 42 | """Tests that -fhlsl_16bit_types creates the 16bit floating point capability.""" 43 | 44 | shader = FileShader(HLSL_SHADER_WITH_HALF_TYPE, '.frag') 45 | glslc_args = ['-S', '-x', 'hlsl', '-fhlsl-16bit-types', '-fauto-bind-uniforms', shader] 46 | expected_assembly_substr = '= OpTypeFloat 16'; 47 | -------------------------------------------------------------------------------- /glslc/test/option_fhlsl_functionality1.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import expect 16 | from glslc_test_framework import inside_glslc_testsuite 17 | from placeholder import FileShader 18 | 19 | # An HLSL shader with a counter buffer with a counter increment. 20 | # Glslang doesn't automatically assign a binding to the counter, and 21 | # it doesn't understand [[vk::counter_binding(n)]], so compile this 22 | # with --auto-bind-uniforms. 23 | # See https://github.com/KhronosGroup/glslang/issues/1616 24 | HLSL_VERTEX_SHADER_WITH_COUNTER_BUFFER = """ 25 | RWStructuredBuffer Ainc; 26 | float4 main() : SV_Target0 { 27 | return float4(Ainc.IncrementCounter(), 0, 1, 2); 28 | } 29 | """ 30 | 31 | 32 | @inside_glslc_testsuite('OptionFHlslFunctionality1') 33 | class TestHlslFunctionality1MentionsExtension(expect.ValidAssemblyFileWithSubstr): 34 | """Tests that -fhlsl_functionality1 enabled SPV_GOOGLE_hlsl_functionality1.""" 35 | 36 | shader = FileShader(HLSL_VERTEX_SHADER_WITH_COUNTER_BUFFER, '.frag') 37 | glslc_args = ['-S', '-x', 'hlsl', '-fhlsl_functionality1', 38 | '-fauto-bind-uniforms', shader] 39 | expected_assembly_substr = 'OpExtension "SPV_GOOGLE_hlsl_functionality1"' 40 | 41 | 42 | @inside_glslc_testsuite('OptionFHlslFunctionality1') 43 | class TestHlslFunctionality1DecoratesCounter(expect.ValidAssemblyFileWithSubstr): 44 | """Tests that -fhlsl_functionality1 decorates the output target""" 45 | 46 | shader = FileShader(HLSL_VERTEX_SHADER_WITH_COUNTER_BUFFER, '.frag') 47 | glslc_args = ['-S', '-x', 'hlsl', '-fhlsl_functionality1', 48 | '-fauto-bind-uniforms', shader] 49 | expected_assembly_substr = 'OpDecorateString' 50 | 51 | 52 | ## Next tests use the option with the hypen instead of underscore. 53 | 54 | @inside_glslc_testsuite('OptionFHlslFunctionality1') 55 | class TestHlslHyphenFunctionality1MentionsExtension(expect.ValidAssemblyFileWithSubstr): 56 | """Tests that -fhlsl-functionality1 enabled SPV_GOOGLE_hlsl_functionality1.""" 57 | 58 | shader = FileShader(HLSL_VERTEX_SHADER_WITH_COUNTER_BUFFER, '.frag') 59 | glslc_args = ['-S', '-x', 'hlsl', '-fhlsl_functionality1', 60 | '-fauto-bind-uniforms', shader] 61 | expected_assembly_substr = 'OpExtension "SPV_GOOGLE_hlsl_functionality1"' 62 | 63 | 64 | @inside_glslc_testsuite('OptionFHlslFunctionality1') 65 | class TestHlslHyphenFunctionality1DecoratesCounter(expect.ValidAssemblyFileWithSubstr): 66 | """Tests that -fhlsl-functionality1 decorates the output target""" 67 | 68 | shader = FileShader(HLSL_VERTEX_SHADER_WITH_COUNTER_BUFFER, '.frag') 69 | glslc_args = ['-S', '-x', 'hlsl', '-fhlsl_functionality1', 70 | '-fauto-bind-uniforms', shader] 71 | expected_assembly_substr = 'OpDecorateString' 72 | -------------------------------------------------------------------------------- /glslc/test/option_fpreserve_bindings.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import expect 16 | from glslc_test_framework import inside_glslc_testsuite 17 | from placeholder import FileShader 18 | 19 | # A GLSL shader with unused bindings. 20 | GLSL_SHADER_WITH_UNUSED_BINDINGS = """#version 450 21 | layout(binding=0) buffer InputA { vec4 x[]; } inputA; 22 | layout(binding=1) buffer InputB { vec4 x[]; } inputB; 23 | layout(binding=2) buffer Output { vec4 x[]; } outputO; 24 | 25 | void main() {} 26 | """ 27 | 28 | 29 | @inside_glslc_testsuite('OptionFPreserveBindings') 30 | class TestFPreserveBindingsInputA(expect.ValidAssemblyFileWithSubstr): 31 | """Tests that the compiler preserves bindings when optimizations are 32 | enabled.""" 33 | 34 | shader = FileShader(GLSL_SHADER_WITH_UNUSED_BINDINGS, '.comp') 35 | glslc_args = ['-S', '-O', shader, '-fpreserve-bindings'] 36 | # Check the first buffer. 37 | expected_assembly_substr = "Binding 0" 38 | 39 | 40 | @inside_glslc_testsuite('OptionFPreserveBindings') 41 | class TestFPreserveBindingsInputB(expect.ValidAssemblyFileWithSubstr): 42 | """Tests that the compiler preserves bindings when optimizations are 43 | enabled.""" 44 | 45 | shader = FileShader(GLSL_SHADER_WITH_UNUSED_BINDINGS, '.comp') 46 | glslc_args = ['-S', '-O', shader, '-fpreserve-bindings'] 47 | # Check the first buffer. 48 | expected_assembly_substr = "Binding 1" 49 | 50 | 51 | @inside_glslc_testsuite('OptionFPreserveBindings') 52 | class TestFPreserveBindingsOutputO(expect.ValidAssemblyFileWithSubstr): 53 | """Tests that the compiler preserves bindings when optimizations are 54 | enabled.""" 55 | 56 | shader = FileShader(GLSL_SHADER_WITH_UNUSED_BINDINGS, '.comp') 57 | glslc_args = ['-S', '-O', shader, '-fpreserve-bindings'] 58 | # Check the first buffer. 59 | expected_assembly_substr = "Binding 2" 60 | 61 | 62 | @inside_glslc_testsuite('OptionFPreserveBindings') 63 | class TestFNoPreserveBindings(expect.ValidAssemblyFileWithoutSubstr): 64 | """Tests that the compiler removes bindings when -fpreserve-bindings is not 65 | set.""" 66 | 67 | shader = FileShader(GLSL_SHADER_WITH_UNUSED_BINDINGS, '.comp') 68 | glslc_args = ['-S', '-O', shader] 69 | # Check that all binding decorations are gone. 70 | unexpected_assembly_substr = "OpDecorate" 71 | -------------------------------------------------------------------------------- /glslc/test/stdin_out.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import expect 16 | from glslc_test_framework import inside_glslc_testsuite 17 | from placeholder import FileShader, StdinShader 18 | 19 | 20 | @inside_glslc_testsuite('StdInOut') 21 | class VerifyStdinWorks(expect.ValidObjectFile): 22 | """Tests glslc accepts vertex shader extension (.vert).""" 23 | 24 | shader = StdinShader('#version 140\nvoid main() { }') 25 | glslc_args = ['-c', '-fshader-stage=vertex', shader] 26 | 27 | 28 | @inside_glslc_testsuite('StdInOut') 29 | class VerifyStdoutWorks( 30 | expect.ReturnCodeIsZero, expect.StdoutMatch, expect.StderrMatch): 31 | 32 | shader = FileShader('#version 140\nvoid main() {}', '.vert') 33 | glslc_args = [shader, '-o', '-'] 34 | 35 | # We expect SOME stdout, we just do not care what. 36 | expected_stdout = True 37 | expected_stderr = '' 38 | -------------------------------------------------------------------------------- /kokoro/android-release/build-docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017-2022 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Android Build Script. 18 | 19 | 20 | # Fail on any error. 21 | set -e 22 | 23 | . /bin/using.sh # Declare the bash `using` function for configuring toolchains. 24 | 25 | # Display commands being run. 26 | set -x 27 | 28 | using cmake-3.31.2 29 | using ninja-1.10.0 30 | using ndk-r27c # Sets ANDROID_NDK_HOME, pointing at the NDK's root dir 31 | 32 | cd $ROOT_DIR 33 | ./utils/git-sync-deps 34 | 35 | mkdir build 36 | cd $ROOT_DIR/build 37 | 38 | # Invoke the build. 39 | BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT} 40 | echo $(date): Starting build... 41 | cmake \ 42 | -GNinja \ 43 | -DCMAKE_MAKE_PROGRAM=ninja \ 44 | -DCMAKE_BUILD_TYPE=Release \ 45 | -DANDROID_ABI="$TARGET_ARCH" \ 46 | -DSHADERC_SKIP_TESTS=ON \ 47 | -DSPIRV_SKIP_TESTS=ON \ 48 | -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \ 49 | -DANDROID_NDK=$ANDROID_NDK_HOME .. 50 | 51 | echo $(date): Build glslang library... 52 | ninja glslang 53 | 54 | echo $(date): Build everything... 55 | ninja 56 | 57 | echo $(date): Check Shaderc for copyright notices... 58 | ninja check-copyright 59 | 60 | echo $(date): Build completed. 61 | -------------------------------------------------------------------------------- /kokoro/android-release/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2020-2022 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Linux Build Script. 18 | 19 | set -e # Fail on any error. 20 | 21 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )" 22 | ROOT_DIR="$( cd "${SCRIPT_DIR}/../.." >/dev/null 2>&1 && pwd )" 23 | 24 | TARGET_ARCH="$1" 25 | 26 | # --privileged is required for some sanitizer builds, as they seem to require 27 | # PTRACE privileges 28 | docker run --rm -i \ 29 | --privileged \ 30 | --volume "${ROOT_DIR}:${ROOT_DIR}" \ 31 | --volume "${KOKORO_ARTIFACTS_DIR}:${KOKORO_ARTIFACTS_DIR}" \ 32 | --workdir "${ROOT_DIR}" \ 33 | --env ROOT_DIR="${ROOT_DIR}" \ 34 | --env SCRIPT_DIR="${SCRIPT_DIR}" \ 35 | --env TARGET_ARCH="${TARGET_ARCH}" \ 36 | --env KOKORO_ARTIFACTS_DIR="${KOKORO_ARTIFACTS_DIR}" \ 37 | --entrypoint "${SCRIPT_DIR}/build-docker.sh" \ 38 | us-east4-docker.pkg.dev/shaderc-build/radial-docker/ubuntu-24.04-amd64/cpp-builder 39 | -------------------------------------------------------------------------------- /kokoro/android-release/build_arm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Android Build Script. 18 | 19 | # Fail on any error. 20 | set -e 21 | # Display commands being run. 22 | set -x 23 | 24 | SCRIPT_DIR=`dirname "$BASH_SOURCE"` 25 | source $SCRIPT_DIR/build.sh "armeabi-v7a with NEON" 26 | -------------------------------------------------------------------------------- /kokoro/android-release/build_x86.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Android Build Script. 18 | 19 | # Fail on any error. 20 | set -e 21 | # Display commands being run. 22 | set -x 23 | 24 | SCRIPT_DIR=`dirname "$BASH_SOURCE"` 25 | source $SCRIPT_DIR/build.sh x86 26 | 27 | -------------------------------------------------------------------------------- /kokoro/android-release/continuous_arm.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | # 17 | build_file: "shaderc/kokoro/android-release/build_arm.sh" 18 | -------------------------------------------------------------------------------- /kokoro/android-release/continuous_x86.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | # 17 | build_file: "shaderc/kokoro/android-release/build_x86.sh" 18 | -------------------------------------------------------------------------------- /kokoro/android-release/presubmit_arm.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Presubmit build configuration. 16 | build_file: "shaderc/kokoro/android-release/build_arm.sh" 17 | -------------------------------------------------------------------------------- /kokoro/android-release/presubmit_x86.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Presubmit build configuration. 16 | build_file: "shaderc/kokoro/android-release/build_x86.sh" 17 | -------------------------------------------------------------------------------- /kokoro/img/linux.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/shaderc/a5a8caa1951b3f893a08f63cab2dc877087dc05b/kokoro/img/linux.png -------------------------------------------------------------------------------- /kokoro/img/macos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/shaderc/a5a8caa1951b3f893a08f63cab2dc877087dc05b/kokoro/img/macos.png -------------------------------------------------------------------------------- /kokoro/img/windows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/shaderc/a5a8caa1951b3f893a08f63cab2dc877087dc05b/kokoro/img/windows.png -------------------------------------------------------------------------------- /kokoro/linux/build-docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Linux Build Script run inside docker container. 18 | 19 | set -e # Fail on any error. 20 | 21 | . /bin/using.sh # Declare the bash `using` function for configuring toolchains. 22 | 23 | set -x # Display commands being run. 24 | 25 | SKIP_TESTS="False" 26 | BUILD_TYPE="Debug" 27 | 28 | using cmake-3.31.2 29 | using ninja-1.10.0 30 | using python-3.12 31 | 32 | if [ ! -z "$COMPILER" ]; then 33 | using "$COMPILER" 34 | fi 35 | 36 | # Possible configurations are: 37 | # ASAN, COVERAGE, RELEASE, DEBUG, DEBUG_EXCEPTION, RELEASE_MINGW 38 | 39 | if [ $CONFIG = "RELEASE" ] || [ $CONFIG = "RELEASE_MINGW" ] 40 | then 41 | BUILD_TYPE="RelWithDebInfo" 42 | fi 43 | 44 | ADDITIONAL_CMAKE_FLAGS="" 45 | if [ $CONFIG = "ASAN" ] 46 | then 47 | ADDITIONAL_CMAKE_FLAGS="-DCMAKE_CXX_FLAGS=-fsanitize=address -DCMAKE_C_FLAGS=-fsanitize=address" 48 | elif [ $CONFIG = "COVERAGE" ] 49 | then 50 | ADDITIONAL_CMAKE_FLAGS="-DENABLE_CODE_COVERAGE=ON" 51 | SKIP_TESTS="True" 52 | elif [ $CONFIG = "DEBUG_EXCEPTION" ] 53 | then 54 | ADDITIONAL_CMAKE_FLAGS="-DDISABLE_EXCEPTIONS=ON -DDISABLE_RTTI=ON" 55 | elif [ $CONFIG = "RELEASE_MINGW" ] 56 | then 57 | ADDITIONAL_CMAKE_FLAGS="-DCMAKE_TOOLCHAIN_FILE=$ROOT_DIR/cmake/linux-mingw-toolchain.cmake" 58 | SKIP_TESTS="True" 59 | fi 60 | 61 | cd $ROOT_DIR 62 | ./utils/git-sync-deps 63 | 64 | mkdir build 65 | cd $ROOT_DIR/build 66 | 67 | # Invoke the build. 68 | BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT} 69 | echo $(date): Starting build... 70 | cmake -GNinja -DCMAKE_INSTALL_PREFIX=$KOKORO_ARTIFACTS_DIR/install -DRE2_BUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=$BUILD_TYPE $ADDITIONAL_CMAKE_FLAGS .. 71 | 72 | echo $(date): Build glslang... 73 | ninja glslang-standalone 74 | 75 | echo $(date): Build everything... 76 | ninja 77 | echo $(date): Build completed. 78 | 79 | echo $(date): Check Shaderc for copyright notices... 80 | ninja check-copyright 81 | 82 | if [ $CONFIG = "COVERAGE" ] 83 | then 84 | echo $(date): Check coverage... 85 | ninja report-coverage 86 | echo $(date): Check coverage completed. 87 | fi 88 | 89 | echo $(date): Starting ctest... 90 | if [ $SKIP_TESTS = "False" ] 91 | then 92 | ctest --output-on-failure -j4 93 | fi 94 | echo $(date): ctest completed. 95 | 96 | # libshaderc_util/core is generated by the death test in shaderc_util_file_finder_test 97 | rm -f libshaderc_util/core 98 | 99 | # Package the build. 100 | ninja install 101 | cd $KOKORO_ARTIFACTS_DIR 102 | tar czf install.tgz install 103 | -------------------------------------------------------------------------------- /kokoro/linux/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2020 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Linux Build Script. 18 | 19 | set -e # Fail on any error. 20 | 21 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )" 22 | ROOT_DIR="$( cd "${SCRIPT_DIR}/../.." >/dev/null 2>&1 && pwd )" 23 | 24 | CONFIG=$1 25 | COMPILER=$2 26 | 27 | # --privileged is required for some sanitizer builds, as they seem to require 28 | # PTRACE privileges 29 | docker run --rm -i \ 30 | --privileged \ 31 | --volume "${ROOT_DIR}:${ROOT_DIR}" \ 32 | --volume "${KOKORO_ARTIFACTS_DIR}:${KOKORO_ARTIFACTS_DIR}" \ 33 | --workdir "${ROOT_DIR}" \ 34 | --env ROOT_DIR="${ROOT_DIR}" \ 35 | --env SCRIPT_DIR="${SCRIPT_DIR}" \ 36 | --env CONFIG="${CONFIG}" \ 37 | --env COMPILER="${COMPILER}" \ 38 | --env KOKORO_ARTIFACTS_DIR="${KOKORO_ARTIFACTS_DIR}" \ 39 | --entrypoint "${SCRIPT_DIR}/build-docker.sh" \ 40 | us-east4-docker.pkg.dev/shaderc-build/radial-docker/ubuntu-24.04-amd64/cpp-builder 41 | -------------------------------------------------------------------------------- /kokoro/linux/build_clang_asan.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Linux Build Script. 18 | 19 | # Fail on any error. 20 | set -e 21 | # Display commands being run. 22 | set -x 23 | 24 | SCRIPT_DIR=`dirname "$BASH_SOURCE"` 25 | source $SCRIPT_DIR/build.sh ASAN "clang-13.0.1" 26 | -------------------------------------------------------------------------------- /kokoro/linux/build_clang_debug.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Linux Build Script. 18 | 19 | # Fail on any error. 20 | set -e 21 | # Display commands being run. 22 | set -x 23 | 24 | SCRIPT_DIR=`dirname "$BASH_SOURCE"` 25 | source $SCRIPT_DIR/build.sh DEBUG "clang-13.0.1" 26 | -------------------------------------------------------------------------------- /kokoro/linux/build_clang_release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Linux Build Script. 18 | 19 | # Fail on any error. 20 | set -e 21 | # Display commands being run. 22 | set -x 23 | 24 | SCRIPT_DIR=`dirname "$BASH_SOURCE"` 25 | source $SCRIPT_DIR/build.sh RELEASE "clang-13.0.1" 26 | -------------------------------------------------------------------------------- /kokoro/linux/build_gcc_coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Linux Build Script. 18 | 19 | # Fail on any error. 20 | set -e 21 | # Display commands being run. 22 | set -x 23 | 24 | SCRIPT_DIR=`dirname "$BASH_SOURCE"` 25 | source $SCRIPT_DIR/build.sh COVERAGE "gcc-7" # gcc-8+ has issues with lcov 26 | -------------------------------------------------------------------------------- /kokoro/linux/build_gcc_debug.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Linux Build Script. 18 | 19 | # Fail on any error. 20 | set -e 21 | # Display commands being run. 22 | set -x 23 | 24 | SCRIPT_DIR=`dirname "$BASH_SOURCE"` 25 | source $SCRIPT_DIR/build.sh DEBUG "gcc-13" 26 | -------------------------------------------------------------------------------- /kokoro/linux/build_gcc_debug_exception.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Linux Build Script. 18 | 19 | # Fail on any error. 20 | set -e 21 | # Display commands being run. 22 | set -x 23 | 24 | SCRIPT_DIR=`dirname "$BASH_SOURCE"` 25 | source $SCRIPT_DIR/build.sh DEBUG_EXCEPTION "gcc-13" 26 | -------------------------------------------------------------------------------- /kokoro/linux/build_gcc_release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Linux Build Script. 18 | 19 | # Fail on any error. 20 | set -e 21 | # Display commands being run. 22 | set -x 23 | 24 | SCRIPT_DIR=`dirname "$BASH_SOURCE"` 25 | source $SCRIPT_DIR/build.sh RELEASE "gcc-13" 26 | -------------------------------------------------------------------------------- /kokoro/linux/build_mingw_release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Linux Build Script. 18 | 19 | # Fail on any error. 20 | set -e 21 | # Display commands being run. 22 | set -x 23 | 24 | SCRIPT_DIR=`dirname "$BASH_SOURCE"` 25 | source $SCRIPT_DIR/build.sh RELEASE_MINGW 26 | -------------------------------------------------------------------------------- /kokoro/linux/continuous_clang_asan.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | build_file: "shaderc/kokoro/linux/build_clang_asan.sh" 17 | -------------------------------------------------------------------------------- /kokoro/linux/continuous_clang_debug.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | build_file: "shaderc/kokoro/linux/build_clang_debug.sh" 17 | 18 | action { 19 | define_artifacts { 20 | regex: "install.tgz" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /kokoro/linux/continuous_clang_release.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | build_file: "shaderc/kokoro/linux/build_clang_release.sh" 17 | 18 | action { 19 | define_artifacts { 20 | regex: "install.tgz" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /kokoro/linux/continuous_gcc_debug.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | build_file: "shaderc/kokoro/linux/build_gcc_debug.sh" 17 | 18 | action { 19 | define_artifacts { 20 | regex: "install.tgz" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /kokoro/linux/continuous_gcc_debug_exception.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | build_file: "shaderc/kokoro/linux/build_gcc_debug_exception.sh" 17 | -------------------------------------------------------------------------------- /kokoro/linux/continuous_gcc_release.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | build_file: "shaderc/kokoro/linux/build_gcc_release.sh" 17 | 18 | action { 19 | define_artifacts { 20 | regex: "install.tgz" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /kokoro/linux/continuous_license_check.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | build_file: "shaderc/kokoro/linux/license_check.sh" 17 | -------------------------------------------------------------------------------- /kokoro/linux/continuous_mingw_release.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | build_file: "shaderc/kokoro/linux/build_mingw_release.sh" 17 | -------------------------------------------------------------------------------- /kokoro/linux/license_check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2020 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e # Fail on any error. 18 | 19 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )" 20 | ROOT_DIR="$( cd "${SCRIPT_DIR}/../.." >/dev/null 2>&1 && pwd )" 21 | 22 | docker run --rm -i \ 23 | --volume "${ROOT_DIR}:${ROOT_DIR}:ro" \ 24 | --workdir "${ROOT_DIR}" \ 25 | us-east4-docker.pkg.dev/shaderc-build/radial-docker/ubuntu-24.04-amd64/license-checker 26 | -------------------------------------------------------------------------------- /kokoro/linux/presubmit_clang_asan.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Presubmit build configuration. 16 | build_file: "shaderc/kokoro/linux/build_clang_asan.sh" 17 | -------------------------------------------------------------------------------- /kokoro/linux/presubmit_clang_debug.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Presubmit build configuration. 16 | build_file: "shaderc/kokoro/linux/build_clang_debug.sh" 17 | -------------------------------------------------------------------------------- /kokoro/linux/presubmit_clang_release.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Presubmit build configuration. 16 | build_file: "shaderc/kokoro/linux/build_clang_release.sh" 17 | -------------------------------------------------------------------------------- /kokoro/linux/presubmit_gcc_debug.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Presubmit build configuration. 16 | build_file: "shaderc/kokoro/linux/build_gcc_debug.sh" 17 | 18 | -------------------------------------------------------------------------------- /kokoro/linux/presubmit_gcc_release.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Presubmit build configuration. 16 | build_file: "shaderc/kokoro/linux/build_gcc_release.sh" 17 | -------------------------------------------------------------------------------- /kokoro/linux/presubmit_license_check.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Presubmit build configuration. 16 | build_file: "shaderc/kokoro/linux/license_check.sh" 17 | -------------------------------------------------------------------------------- /kokoro/linux/presubmit_mingw_release.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Presubmit build configuration. 16 | build_file: "shaderc/kokoro/linux/build_mingw_release.sh" 17 | -------------------------------------------------------------------------------- /kokoro/macos/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # MacOS Build Script. 18 | 19 | # Fail on any error. 20 | set -e 21 | # Display commands being run. 22 | set -x 23 | 24 | BUILD_ROOT=$PWD 25 | SRC=$PWD/github/shaderc 26 | BUILD_TYPE=$1 27 | 28 | # Get NINJA. 29 | wget -q https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-mac.zip 30 | unzip -q ninja-mac.zip 31 | chmod +x ninja 32 | export PATH="$PWD:$PATH" 33 | 34 | cd $SRC 35 | ./utils/git-sync-deps 36 | 37 | mkdir build 38 | cd $SRC/build 39 | 40 | # Invoke the build. 41 | BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT} 42 | echo $(date): Starting build... 43 | cmake -GNinja -DCMAKE_INSTALL_PREFIX=$KOKORO_ARTIFACTS_DIR/install -DRE2_BUILD_TESTING=OFF -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=$BUILD_TYPE .. 44 | 45 | echo $(date): Build glslang... 46 | ninja glslang-standalone 47 | 48 | echo $(date): Build everything... 49 | ninja 50 | 51 | echo $(date): Check Shaderc for copyright notices... 52 | ninja check-copyright 53 | 54 | echo $(date): Build completed. 55 | 56 | echo $(date): Starting ctest... 57 | ctest --output-on-failure -j4 58 | echo $(date): ctest completed. 59 | 60 | # Package the build. 61 | ninja install 62 | cd $KOKORO_ARTIFACTS_DIR 63 | tar czf install.tgz install 64 | -------------------------------------------------------------------------------- /kokoro/macos/build_clang_debug.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # MacOS Build Script. 18 | 19 | # Fail on any error. 20 | set -e 21 | # Display commands being run. 22 | set -x 23 | 24 | SCRIPT_DIR=`dirname "$BASH_SOURCE"` 25 | source $SCRIPT_DIR/build.sh Debug 26 | 27 | -------------------------------------------------------------------------------- /kokoro/macos/build_clang_release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # MacOS Build Script. 18 | 19 | # Fail on any error. 20 | set -e 21 | # Display commands being run. 22 | set -x 23 | 24 | SCRIPT_DIR=`dirname "$BASH_SOURCE"` 25 | source $SCRIPT_DIR/build.sh RelWithDebInfo 26 | 27 | -------------------------------------------------------------------------------- /kokoro/macos/continuous_clang_debug.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | build_file: "shaderc/kokoro/macos/build_clang_debug.sh" 17 | 18 | action { 19 | define_artifacts { 20 | regex: "install.tgz" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /kokoro/macos/continuous_clang_release.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | build_file: "shaderc/kokoro/macos/build_clang_release.sh" 17 | 18 | action { 19 | define_artifacts { 20 | regex: "install.tgz" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /kokoro/macos/presubmit_clang_debug.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Presubmit build configuration. 16 | build_file: "shaderc/kokoro/macos/build_clang_debug.sh" 17 | -------------------------------------------------------------------------------- /kokoro/macos/presubmit_clang_release.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Presubmit build configuration. 16 | build_file: "shaderc/kokoro/macos/build_clang_release.sh" 17 | -------------------------------------------------------------------------------- /kokoro/ndk-build/build-docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2018 Google LLC. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # Linux Build Script. 17 | 18 | # Fail on any error. 19 | set -e 20 | # Display commands being run. 21 | set -x 22 | 23 | # This is required to run any git command in the docker since owner will 24 | # have changed between the clone environment, and the docker container. 25 | # Marking the root of the repo as safe for ownership changes. 26 | git config --global --add safe.directory $ROOT_DIR 27 | 28 | . /bin/using.sh # Declare the bash `using` function for configuring toolchains. 29 | 30 | cd $ROOT_DIR 31 | 32 | function clean_dir() { 33 | dir=$1 34 | if [[ -d "$dir" ]]; then 35 | rm -fr "$dir" 36 | fi 37 | mkdir "$dir" 38 | } 39 | 40 | # Get source for dependencies, as specified in the DEPS file 41 | /usr/bin/python3 utils/git-sync-deps --treeless 42 | 43 | using ndk-r27c 44 | 45 | clean_dir "$ROOT_DIR/build" 46 | cd "$ROOT_DIR/build" 47 | 48 | function do_ndk_build () { 49 | echo $(date): Starting ndk-build $@... 50 | $ANDROID_NDK_HOME/ndk-build \ 51 | -C $ROOT_DIR/android_test \ 52 | NDK_PROJECT_PATH=. \ 53 | NDK_LIBS_OUT=./libs \ 54 | NDK_APP_OUT=./app \ 55 | V=1 \ 56 | SPVTOOLS_LOCAL_PATH=$ROOT_DIR/third_party/spirv-tools \ 57 | SPVHEADERS_LOCAL_PATH=$ROOT_DIR/third_party/spirv-headers \ 58 | -j8 $@ 59 | } 60 | 61 | # Builds all the ABIs (see APP_ABI in jni/Application.mk) 62 | do_ndk_build 63 | 64 | # Check that libshaderc_combined builds 65 | # Explicitly set each ABI, otherwise it will only pick x86. 66 | # It seems to be the behaviour when specifying an explicit target. 67 | for abi in x86 x86_64 armeabi-v7a arm64-v8a; do 68 | do_ndk_build APP_ABI=$abi libshaderc_combined 69 | done 70 | 71 | echo $(date): ndk-build completed. 72 | -------------------------------------------------------------------------------- /kokoro/ndk-build/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2021 Google LLC. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # Linux Build Script. 17 | 18 | # Fail on any error. 19 | set -e 20 | 21 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )" 22 | ROOT_DIR="$( cd "${SCRIPT_DIR}/../.." >/dev/null 2>&1 && pwd )" 23 | 24 | BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT} 25 | 26 | # chown the given directory to the current user, if it exists. 27 | # Docker creates files with the root user - this can upset the Kokoro artifact copier. 28 | function chown_dir() { 29 | dir=$1 30 | if [[ -d "$dir" ]]; then 31 | sudo chown -R "$(id -u):$(id -g)" "$dir" 32 | fi 33 | } 34 | 35 | set +e 36 | # Allow build failures 37 | 38 | # "--privileged" is required to run ptrace in the asan builds. 39 | docker run --rm -i \ 40 | --privileged \ 41 | --volume "${ROOT_DIR}:${ROOT_DIR}" \ 42 | --volume "${KOKORO_ARTIFACTS_DIR}:${KOKORO_ARTIFACTS_DIR}" \ 43 | --workdir "${ROOT_DIR}" \ 44 | --env SCRIPT_DIR=${SCRIPT_DIR} \ 45 | --env ROOT_DIR=${ROOT_DIR} \ 46 | --env KOKORO_ARTIFACTS_DIR="${KOKORO_ARTIFACTS_DIR}" \ 47 | --env BUILD_SHA="${BUILD_SHA}" \ 48 | --entrypoint "${SCRIPT_DIR}/build-docker.sh" \ 49 | us-east4-docker.pkg.dev/shaderc-build/radial-docker/ubuntu-24.04-amd64/cpp-builder 50 | RESULT=$? 51 | 52 | # This is important. If the permissions are not fixed, kokoro will fail 53 | # to pull build artifacts, and put the build in tool-failure state, which 54 | # blocks the logs. 55 | chown_dir "${ROOT_DIR}/build" 56 | exit $RESULT 57 | -------------------------------------------------------------------------------- /kokoro/ndk-build/build_khronos.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2017 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Linux Build Script. 18 | 19 | # Fail on any error. 20 | set -e 21 | # Display commands being run. 22 | set -x 23 | 24 | SCRIPT_DIR=`dirname "$BASH_SOURCE"` 25 | source $SCRIPT_DIR/build.sh 26 | -------------------------------------------------------------------------------- /kokoro/ndk-build/continuous_khronos.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | # 17 | build_file: "shaderc/kokoro/ndk-build/build_khronos.sh" 18 | -------------------------------------------------------------------------------- /kokoro/ndk-build/presubmit_khronos.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Presubmit build configuration. 16 | # 17 | build_file: "shaderc/kokoro/ndk-build/build_khronos.sh" 18 | -------------------------------------------------------------------------------- /kokoro/windows/build.bat: -------------------------------------------------------------------------------- 1 | :: Copyright (C) 2017 Google Inc. 2 | :: 3 | :: Licensed under the Apache License, Version 2.0 (the "License"); 4 | :: you may not use this file except in compliance with the License. 5 | :: You may obtain a copy of the License at 6 | :: 7 | :: http://www.apache.org/licenses/LICENSE-2.0 8 | :: 9 | :: Unless required by applicable law or agreed to in writing, software 10 | :: distributed under the License is distributed on an "AS IS" BASIS, 11 | :: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | :: See the License for the specific language governing permissions and 13 | :: limitations under the License. 14 | :: 15 | :: Windows Build Script. 16 | 17 | @echo on 18 | 19 | set BUILD_ROOT=%cd% 20 | set SRC=%cd%\github\shaderc 21 | set BUILD_TYPE=%1 22 | set VS_VERSION=%2 23 | set ARCH=%3 24 | 25 | :: Force usage of python 3.12 26 | set PATH=C:\python312;%PATH% 27 | :: Glslang requires cmake 3.27 or later 28 | set PATH=C:\cmake-3.31.2\bin;%PATH% 29 | 30 | cd %SRC% 31 | python utils\git-sync-deps 32 | 33 | cmake --version 34 | 35 | mkdir build 36 | cd %SRC%\build 37 | 38 | :: ######################################### 39 | :: set up msvc build env 40 | :: ######################################### 41 | if %VS_VERSION% == 2019 ( 42 | call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" %ARCH% 43 | ) else if %VS_VERSION% == 2022 ( 44 | call "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\vcvarsall.bat" %ARCH% 45 | ) 46 | 47 | :: ######################################### 48 | :: Start building. 49 | :: ######################################### 50 | echo "Starting build... %DATE% %TIME%" 51 | if "%KOKORO_GITHUB_COMMIT%." == "." ( 52 | set BUILD_SHA=%KOKORO_GITHUB_PULL_REQUEST_COMMIT% 53 | ) else ( 54 | set BUILD_SHA=%KOKORO_GITHUB_COMMIT% 55 | ) 56 | 57 | set CMAKE_FLAGS=-DCMAKE_INSTALL_PREFIX=%KOKORO_ARTIFACTS_DIR%\install -DRE2_BUILD_TESTING=OFF -GNinja -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe 58 | 59 | cmake %CMAKE_FLAGS% .. 60 | if %ERRORLEVEL% NEQ 0 exit /b %ERRORLEVEL% 61 | 62 | echo "Build glslang... %DATE% %TIME%" 63 | ninja glslang-standalone 64 | if %ERRORLEVEL% NEQ 0 exit /b %ERRORLEVEL% 65 | 66 | echo "Build everything... %DATE% %TIME%" 67 | ninja 68 | if %ERRORLEVEL% NEQ 0 exit /b %ERRORLEVEL% 69 | 70 | echo "Check Shaderc for copyright notices... %DATE% %TIME%" 71 | ninja check-copyright 72 | if %ERRORLEVEL% NEQ 0 exit /b %ERRORLEVEL% 73 | echo "Build Completed %DATE% %TIME%" 74 | 75 | :: This lets us use !ERRORLEVEL! inside an IF ... () and get the actual error at that point. 76 | setlocal ENABLEDELAYEDEXPANSION 77 | 78 | :: ################################################ 79 | :: Run the tests 80 | :: ################################################ 81 | echo "Running tests... %DATE% %TIME%" 82 | ctest -C %BUILD_TYPE% --output-on-failure -j4 83 | if !ERRORLEVEL! NEQ 0 exit /b !ERRORLEVEL! 84 | echo "Tests passed %DATE% %TIME%" 85 | 86 | :: ################################################ 87 | :: Install and package. 88 | :: ################################################ 89 | ninja install 90 | cd %KOKORO_ARTIFACTS_DIR% 91 | zip -r install.zip install 92 | 93 | :: Clean up some directories. 94 | rm -rf %SRC%\build 95 | rm -rf %SRC%\install 96 | rm -rf %SRC%\third_party 97 | 98 | exit /b 0 99 | -------------------------------------------------------------------------------- /kokoro/windows/build_2019_amd64_release.bat: -------------------------------------------------------------------------------- 1 | :: Copyright (C) 2023 Google Inc. 2 | :: 3 | :: Licensed under the Apache License, Version 2.0 (the "License"); 4 | :: you may not use this file except in compliance with the License. 5 | :: You may obtain a copy of the License at 6 | :: 7 | :: http://www.apache.org/licenses/LICENSE-2.0 8 | :: 9 | :: Unless required by applicable law or agreed to in writing, software 10 | :: distributed under the License is distributed on an "AS IS" BASIS, 11 | :: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | :: See the License for the specific language governing permissions and 13 | :: limitations under the License. 14 | :: 15 | :: Windows Build Script. 16 | 17 | @echo on 18 | 19 | :: Find out the directory of the common build script. 20 | set SCRIPT_DIR=%~dp0 21 | 22 | :: Call with correct parameter 23 | call %SCRIPT_DIR%\build.bat RelWithDebInfo 2019 amd64 24 | -------------------------------------------------------------------------------- /kokoro/windows/build_2022_amd64_debug.bat: -------------------------------------------------------------------------------- 1 | :: Copyright (C) 2025 Google Inc. 2 | :: 3 | :: Licensed under the Apache License, Version 2.0 (the "License"); 4 | :: you may not use this file except in compliance with the License. 5 | :: You may obtain a copy of the License at 6 | :: 7 | :: http://www.apache.org/licenses/LICENSE-2.0 8 | :: 9 | :: Unless required by applicable law or agreed to in writing, software 10 | :: distributed under the License is distributed on an "AS IS" BASIS, 11 | :: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | :: See the License for the specific language governing permissions and 13 | :: limitations under the License. 14 | :: 15 | :: Windows Build Script. 16 | 17 | @echo on 18 | 19 | :: Find out the directory of the common build script. 20 | set SCRIPT_DIR=%~dp0 21 | 22 | :: Call with correct parameter 23 | call %SCRIPT_DIR%\build.bat Debug 2022 amd64 24 | -------------------------------------------------------------------------------- /kokoro/windows/build_2022_amd64_release.bat: -------------------------------------------------------------------------------- 1 | :: Copyright (C) 2025 Google Inc. 2 | :: 3 | :: Licensed under the Apache License, Version 2.0 (the "License"); 4 | :: you may not use this file except in compliance with the License. 5 | :: You may obtain a copy of the License at 6 | :: 7 | :: http://www.apache.org/licenses/LICENSE-2.0 8 | :: 9 | :: Unless required by applicable law or agreed to in writing, software 10 | :: distributed under the License is distributed on an "AS IS" BASIS, 11 | :: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | :: See the License for the specific language governing permissions and 13 | :: limitations under the License. 14 | :: 15 | :: Windows Build Script. 16 | 17 | @echo on 18 | 19 | :: Find out the directory of the common build script. 20 | set SCRIPT_DIR=%~dp0 21 | 22 | :: Call with correct parameter 23 | call %SCRIPT_DIR%\build.bat RelWithDebInfo 2022 amd64 24 | -------------------------------------------------------------------------------- /kokoro/windows/continuous_release_2019.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2023 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | build_file: "shaderc/kokoro/windows/build_2019_amd64_release.bat" 17 | 18 | action { 19 | define_artifacts { 20 | regex: "install.zip" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /kokoro/windows/presubmit_release_2019.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2023 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Presubmit build configuration. 16 | build_file: "shaderc/kokoro/windows/build_2019_amd64_release.bat" 17 | -------------------------------------------------------------------------------- /kokoro/windows/vs2022_amd64_debug_continuous.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2025 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | build_file: "shaderc/kokoro/windows/build_2022_amd64_debug.bat" 17 | 18 | action { 19 | define_artifacts { 20 | regex: "install.zip" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /kokoro/windows/vs2022_amd64_debug_presubmit.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2025 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Presubmit build configuration. 16 | build_file: "shaderc/kokoro/windows/build_2022_amd64_debug.bat" 17 | 18 | action { 19 | define_artifacts { 20 | regex: "install.zip" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /kokoro/windows/vs2022_amd64_release_continuous.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2025 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Continuous build configuration. 16 | build_file: "shaderc/kokoro/windows/build_2022_amd64_release.bat" 17 | 18 | action { 19 | define_artifacts { 20 | regex: "install.zip" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /kokoro/windows/vs2022_amd64_release_presubmit.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2025 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Presubmit build configuration. 16 | build_file: "shaderc/kokoro/windows/build_2022_amd64_release.bat" 17 | 18 | action { 19 | define_artifacts { 20 | regex: "install.zip" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /libshaderc/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | LOCAL_CPP_EXTENSION := .cc .cpp .cxx 19 | LOCAL_MODULE:=shaderc 20 | LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)/include 21 | LOCAL_SRC_FILES:=src/shaderc.cc 22 | # The Shaderc third_party/Android.mk deduces SPVHEADERS_LOCAL_PATH, 23 | # or delegates that responsibility to SPIRV-Tools' Android.mk. 24 | LOCAL_C_INCLUDES:=$(LOCAL_PATH)/include $(SPVHEADERS_LOCAL_PATH)/include 25 | LOCAL_STATIC_LIBRARIES:=shaderc_util SPIRV-Tools-opt 26 | LOCAL_CXXFLAGS:=-std=c++17 -fno-exceptions -fno-rtti -DENABLE_HLSL=1 27 | LOCAL_EXPORT_CPPFLAGS:=-std=c++17 28 | LOCAL_EXPORT_LDFLAGS:=-latomic 29 | include $(BUILD_STATIC_LIBRARY) 30 | -------------------------------------------------------------------------------- /libshaderc/README.md: -------------------------------------------------------------------------------- 1 | # libshaderc 2 | 3 | A library for compiling shader strings into SPIR-V. 4 | 5 | ## Build Artifacts 6 | 7 | There are two main shaderc libraries that are created during a CMake 8 | compilation. The first is `libshaderc`, which is a static library 9 | containing just the functionality exposed by libshaderc. It depends 10 | on other compilation targets `glslang`, `shaderc_util`, `SPIRV`, 11 | `SPIRV-Tools`, and `SPIRV-Tools-opt`. 12 | 13 | The other is `libshaderc_combined`, which is a static library containing 14 | libshaderc and all of its dependencies. 15 | 16 | 17 | ## Integrating libshaderc 18 | 19 | There are several ways of integrating libshaderc into external projects. 20 | 21 | 1. If the external project uses CMake, then `shaderc/CMakeLists.txt` can be 22 | included into the external project's CMake configuration and shaderc can be used 23 | as a link target. 24 | This is the simplest way to use libshaderc in an external project. 25 | 26 | 2. If the external project uses CMake and is building for Linux or Android, 27 | `target_link_libraries(shaderc_combined)` can instead be specified. This is 28 | functionally identical to the previous option. 29 | 30 | 3. If the external project does not use CMake, then the external project can 31 | instead directly use the generated libraries. `shaderc/libshaderc/include` 32 | should be added to the include path, and 33 | `build/libshaderc/libshaderc_combined.a` should be linked. Note that on some 34 | platforms `-lpthread` should also be specified. 35 | 36 | 4. If the external project does not use CMake and cannot use 37 | `libshaderc_combined`, the following libraries or their platform-dependent 38 | counterparts should be linked in the order specified. 39 | * `build/libshaderc/libshaderc.a` 40 | * `build/third_party/glslang/glslang/glslang.a` 41 | * `build/third_party/glslang/libglslang.a` 42 | * `build/shaderc_util/libshaderc_util.a` 43 | * `build/third_party/glslang/SPIRV/libSPIRV.a` 44 | * `build/third_party/spirv-tools/libSPIRV-Tools-opt.a` 45 | * `build/third_party/spirv-tools/libSPIRV-Tools.a` 46 | 47 | 5. If building for Android using the Android NDK, `shaderc/Android.mk` can be 48 | included in the application's `Android.mk` and `LOCAL_STATIC_LIBRARIES:=shaderc` 49 | can be specified. See `shaderc/android_test` for an example. 50 | -------------------------------------------------------------------------------- /libshaderc/include/shaderc/env.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef SHADERC_ENV_H_ 16 | #define SHADERC_ENV_H_ 17 | 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | typedef enum { 25 | shaderc_target_env_vulkan, // SPIR-V under Vulkan semantics 26 | shaderc_target_env_opengl, // SPIR-V under OpenGL semantics 27 | // NOTE: SPIR-V code generation is not supported for shaders under OpenGL 28 | // compatibility profile. 29 | shaderc_target_env_opengl_compat, // SPIR-V under OpenGL semantics, 30 | // including compatibility profile 31 | // functions 32 | shaderc_target_env_webgpu, // Deprecated, SPIR-V under WebGPU 33 | // semantics 34 | shaderc_target_env_default = shaderc_target_env_vulkan 35 | } shaderc_target_env; 36 | 37 | typedef enum { 38 | // For Vulkan, use Vulkan's mapping of version numbers to integers. 39 | // See vulkan.h 40 | shaderc_env_version_vulkan_1_0 = ((1u << 22)), 41 | shaderc_env_version_vulkan_1_1 = ((1u << 22) | (1 << 12)), 42 | shaderc_env_version_vulkan_1_2 = ((1u << 22) | (2 << 12)), 43 | shaderc_env_version_vulkan_1_3 = ((1u << 22) | (3 << 12)), 44 | shaderc_env_version_vulkan_1_4 = ((1u << 22) | (4 << 12)), 45 | // For OpenGL, use the number from #version in shaders. 46 | // TODO(dneto): Currently no difference between OpenGL 4.5 and 4.6. 47 | // See glslang/Standalone/Standalone.cpp 48 | // TODO(dneto): Glslang doesn't accept a OpenGL client version of 460. 49 | shaderc_env_version_opengl_4_5 = 450, 50 | shaderc_env_version_webgpu, // Deprecated, WebGPU env never defined versions 51 | } shaderc_env_version; 52 | 53 | // The known versions of SPIR-V. 54 | typedef enum { 55 | // Use the values used for word 1 of a SPIR-V binary: 56 | // - bits 24 to 31: zero 57 | // - bits 16 to 23: major version number 58 | // - bits 8 to 15: minor version number 59 | // - bits 0 to 7: zero 60 | shaderc_spirv_version_1_0 = 0x010000u, 61 | shaderc_spirv_version_1_1 = 0x010100u, 62 | shaderc_spirv_version_1_2 = 0x010200u, 63 | shaderc_spirv_version_1_3 = 0x010300u, 64 | shaderc_spirv_version_1_4 = 0x010400u, 65 | shaderc_spirv_version_1_5 = 0x010500u, 66 | shaderc_spirv_version_1_6 = 0x010600u 67 | } shaderc_spirv_version; 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif // __cplusplus 72 | 73 | #endif // SHADERC_ENV_H_ 74 | -------------------------------------------------------------------------------- /libshaderc/include/shaderc/status.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef SHADERC_STATUS_H_ 16 | #define SHADERC_STATUS_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | // Indicate the status of a compilation. 23 | typedef enum { 24 | shaderc_compilation_status_success = 0, 25 | shaderc_compilation_status_invalid_stage = 1, // error stage deduction 26 | shaderc_compilation_status_compilation_error = 2, 27 | shaderc_compilation_status_internal_error = 3, // unexpected failure 28 | shaderc_compilation_status_null_result_object = 4, 29 | shaderc_compilation_status_invalid_assembly = 5, 30 | shaderc_compilation_status_validation_error = 6, 31 | shaderc_compilation_status_transformation_error = 7, 32 | shaderc_compilation_status_configuration_error = 8, 33 | } shaderc_compilation_status; 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif // __cplusplus 38 | 39 | #endif // SHADERC_STATUS_H_ 40 | -------------------------------------------------------------------------------- /libshaderc/include/shaderc/visibility.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef SHADERC_VISIBILITY_H_ 16 | #define SHADERC_VISIBILITY_H_ 17 | 18 | // SHADERC_EXPORT tags symbol that will be exposed by the shared libraries. 19 | #if defined(SHADERC_SHAREDLIB) 20 | #if defined(_WIN32) 21 | #if defined(SHADERC_IMPLEMENTATION) 22 | #define SHADERC_EXPORT __declspec(dllexport) 23 | #else 24 | #define SHADERC_EXPORT __declspec(dllimport) 25 | #endif 26 | #else 27 | #if defined(SHADERC_IMPLEMENTATION) 28 | #define SHADERC_EXPORT __attribute__((visibility("default"))) 29 | #else 30 | #define SHADERC_EXPORT 31 | #endif 32 | #endif 33 | #else 34 | #define SHADERC_EXPORT 35 | #endif 36 | 37 | #endif // SHADERC_VISIBILITY_H_ 38 | -------------------------------------------------------------------------------- /libshaderc/src/shaderc_c_smoke_test.c: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "shaderc/shaderc.h" 16 | #include 17 | #include 18 | 19 | // Because we want to test this as a plain old C file, we cannot use 20 | // gtest, so just run a simple smoke test. 21 | 22 | int main() { 23 | const char* test_program = 24 | "#version 310 es\n" 25 | "layout(location = 0) in highp vec4 vtxColor;\n" 26 | "layout(location = 0) out highp vec4 outColor;\n" 27 | "void main() {\n" 28 | " outColor = vtxColor;" 29 | "}\n"; 30 | shaderc_compiler_t compiler; 31 | shaderc_compilation_result_t result; 32 | shaderc_compile_options_t options; 33 | 34 | compiler = shaderc_compiler_initialize(); 35 | options = shaderc_compile_options_initialize(); 36 | shaderc_compile_options_add_macro_definition(options, "FOO", 3, "1", 1); 37 | result = shaderc_compile_into_spv( 38 | compiler, test_program, strlen(test_program), 39 | shaderc_glsl_fragment_shader, "a.glsl", "main", options); 40 | 41 | assert(result); 42 | 43 | if (shaderc_result_get_compilation_status(result) != 44 | shaderc_compilation_status_success) { 45 | // Early exit on failure. 46 | return -1; 47 | } 48 | shaderc_result_release(result); 49 | shaderc_compile_options_release(options); 50 | shaderc_compiler_release(compiler); 51 | 52 | return 0; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /libshaderc/src/shaderc_private_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include "shaderc_private.h" 17 | 18 | namespace { 19 | 20 | TEST(ConvertSpecificStage, Exhaustive) { 21 | EXPECT_EQ(shaderc_util::Compiler::Stage::Vertex, 22 | shaderc_convert_specific_stage(shaderc_vertex_shader)); 23 | EXPECT_EQ(shaderc_util::Compiler::Stage::Fragment, 24 | shaderc_convert_specific_stage(shaderc_fragment_shader)); 25 | EXPECT_EQ(shaderc_util::Compiler::Stage::TessControl, 26 | shaderc_convert_specific_stage(shaderc_tess_control_shader)); 27 | EXPECT_EQ(shaderc_util::Compiler::Stage::TessEval, 28 | shaderc_convert_specific_stage(shaderc_tess_evaluation_shader)); 29 | EXPECT_EQ(shaderc_util::Compiler::Stage::Geometry, 30 | shaderc_convert_specific_stage(shaderc_geometry_shader)); 31 | EXPECT_EQ(shaderc_util::Compiler::Stage::Compute, 32 | shaderc_convert_specific_stage(shaderc_compute_shader)); 33 | EXPECT_EQ(shaderc_util::Compiler::Stage::RayGenNV, 34 | shaderc_convert_specific_stage(shaderc_raygen_shader)); 35 | EXPECT_EQ(shaderc_util::Compiler::Stage::AnyHitNV, 36 | shaderc_convert_specific_stage(shaderc_anyhit_shader)); 37 | EXPECT_EQ(shaderc_util::Compiler::Stage::ClosestHitNV, 38 | shaderc_convert_specific_stage(shaderc_closesthit_shader)); 39 | EXPECT_EQ(shaderc_util::Compiler::Stage::IntersectNV, 40 | shaderc_convert_specific_stage(shaderc_intersection_shader)); 41 | EXPECT_EQ(shaderc_util::Compiler::Stage::MissNV, 42 | shaderc_convert_specific_stage(shaderc_miss_shader)); 43 | EXPECT_EQ(shaderc_util::Compiler::Stage::CallableNV, 44 | shaderc_convert_specific_stage(shaderc_callable_shader)); 45 | EXPECT_EQ(shaderc_util::Compiler::Stage::TaskNV, 46 | shaderc_convert_specific_stage(shaderc_task_shader)); 47 | EXPECT_EQ(shaderc_util::Compiler::Stage::MeshNV, 48 | shaderc_convert_specific_stage(shaderc_mesh_shader)); 49 | } 50 | } // anonymous namespace 51 | -------------------------------------------------------------------------------- /libshaderc_util/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | LOCAL_MODULE:=shaderc_util 19 | LOCAL_CXXFLAGS:=-std=c++17 -fno-exceptions -fno-rtti -DENABLE_HLSL=1 20 | LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)/include 21 | LOCAL_SRC_FILES:=src/args.cc \ 22 | src/compiler.cc \ 23 | src/file_finder.cc \ 24 | src/io_shaderc.cc \ 25 | src/message.cc \ 26 | src/resources.cc \ 27 | src/shader_stage.cc \ 28 | src/spirv_tools_wrapper.cc \ 29 | src/version_profile.cc 30 | LOCAL_STATIC_LIBRARIES:=SPIRV SPIRV-Tools-opt glslang 31 | LOCAL_C_INCLUDES:=$(LOCAL_PATH)/include 32 | include $(BUILD_STATIC_LIBRARY) 33 | -------------------------------------------------------------------------------- /libshaderc_util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | project(libshaderc_util) 16 | 17 | add_library(shaderc_util STATIC 18 | include/libshaderc_util/counting_includer.h 19 | include/libshaderc_util/file_finder.h 20 | include/libshaderc_util/format.h 21 | include/libshaderc_util/io_shaderc.h 22 | include/libshaderc_util/mutex.h 23 | include/libshaderc_util/message.h 24 | include/libshaderc_util/resources.h 25 | include/libshaderc_util/spirv_tools_wrapper.h 26 | include/libshaderc_util/string_piece.h 27 | include/libshaderc_util/universal_unistd.h 28 | include/libshaderc_util/version_profile.h 29 | src/args.cc 30 | src/compiler.cc 31 | src/file_finder.cc 32 | src/io_shaderc.cc 33 | src/message.cc 34 | src/resources.cc 35 | src/shader_stage.cc 36 | src/spirv_tools_wrapper.cc 37 | src/version_profile.cc 38 | ) 39 | 40 | shaderc_default_compile_options(shaderc_util) 41 | target_include_directories(shaderc_util 42 | PUBLIC include PRIVATE ${glslang_SOURCE_DIR}) 43 | # We use parts of Glslang's HLSL compilation interface, which 44 | # now requires this preprocessor definition. 45 | add_definitions(-DENABLE_HLSL) 46 | 47 | find_package(Threads) 48 | target_link_libraries(shaderc_util PRIVATE 49 | glslang SPIRV 50 | SPIRV-Tools-opt ${CMAKE_THREAD_LIBS_INIT}) 51 | 52 | shaderc_add_tests( 53 | TEST_PREFIX shaderc_util 54 | LINK_LIBS shaderc_util 55 | TEST_NAMES 56 | counting_includer 57 | string_piece 58 | format 59 | file_finder 60 | io_shaderc 61 | message 62 | mutex 63 | version_profile) 64 | 65 | if(${SHADERC_ENABLE_TESTS}) 66 | target_include_directories(shaderc_util_counting_includer_test 67 | PRIVATE ${glslang_SOURCE_DIR}) 68 | target_include_directories(shaderc_util_version_profile_test 69 | PRIVATE ${glslang_SOURCE_DIR}) 70 | endif() 71 | 72 | shaderc_add_tests( 73 | TEST_PREFIX shaderc_util 74 | LINK_LIBS shaderc_util 75 | INCLUDE_DIRS 76 | ${glslang_SOURCE_DIR} 77 | ${spirv-tools_SOURCE_DIR}/include 78 | TEST_NAMES 79 | compiler) 80 | 81 | # This target copies content of testdata into the build directory. 82 | add_custom_target(testdata COMMAND 83 | ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/testdata/copy-to-build.cmake 84 | COMMENT "Copy testdata into build directory") 85 | 86 | if(${SHADERC_ENABLE_TESTS}) 87 | add_dependencies(shaderc_util_file_finder_test testdata) 88 | add_dependencies(shaderc_util_io_shaderc_test testdata) 89 | endif() 90 | -------------------------------------------------------------------------------- /libshaderc_util/include/libshaderc_util/args.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LIBSHADERC_UTIL_INC_ARGS_H 16 | #define LIBSHADERC_UTIL_INC_ARGS_H 17 | 18 | #include 19 | #include 20 | 21 | #include "libshaderc_util/string_piece.h" 22 | 23 | namespace shaderc_util { 24 | 25 | // Gets the option argument for the option at *index in argv in a way consistent 26 | // with clang/gcc. On success, returns true and writes the parsed argument into 27 | // *option_argument. Returns false if any errors occur. After calling this 28 | // function, *index will be the index of the last command line argument 29 | // consumed. 30 | bool GetOptionArgument(int argc, char** argv, int* index, 31 | const std::string& option, 32 | string_piece* option_argument); 33 | 34 | // Parses the given string as a number of the specified type. Returns true 35 | // if parsing succeeded, and stores the parsed value via |value|. 36 | // (I've worked out the general case for this in 37 | // SPIRV-Tools source/util/parse_number.h. -- dneto) 38 | bool ParseUint32(const std::string& str, uint32_t* value); 39 | 40 | } // namespace shaderc_util 41 | #endif // LIBSHADERC_UTIL_INC_ARGS_H 42 | -------------------------------------------------------------------------------- /libshaderc_util/include/libshaderc_util/exceptions.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LIBSHADERC_UTIL_EXCEPTIONS_H_ 16 | #define LIBSHADERC_UTIL_EXCEPTIONS_H_ 17 | 18 | #if (defined(_MSC_VER) && !defined(_CPPUNWIND)) || !defined(__EXCEPTIONS) 19 | #define TRY_IF_EXCEPTIONS_ENABLED 20 | #define CATCH_IF_EXCEPTIONS_ENABLED(X) if (0) 21 | #else 22 | #define TRY_IF_EXCEPTIONS_ENABLED try 23 | #define CATCH_IF_EXCEPTIONS_ENABLED(X) catch (X) 24 | #endif 25 | 26 | #endif // LIBSHADERC_UTIL_EXCEPTIONS_H_ 27 | -------------------------------------------------------------------------------- /libshaderc_util/include/libshaderc_util/file_finder.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LIBSHADERC_UTIL_SRC_FILE_FINDER_H_ 16 | #define LIBSHADERC_UTIL_SRC_FILE_FINDER_H_ 17 | 18 | #include 19 | #include 20 | 21 | namespace shaderc_util { 22 | 23 | // Finds files within a search path. 24 | class FileFinder { 25 | public: 26 | // Searches for a read-openable file based on filename, which must be 27 | // non-empty. The search is attempted on filename prefixed by each element of 28 | // search_path() in turn. The first hit is returned, or an empty string if 29 | // there are no hits. Search attempts treat their argument the way 30 | // std::fopen() treats its filename argument, ignoring whether the path is 31 | // absolute or relative. 32 | // 33 | // If a search_path() element is non-empty and not ending in a slash, then a 34 | // slash is inserted between it and filename before its search attempt. An 35 | // empty string in search_path() means that the filename is tried as-is. 36 | std::string FindReadableFilepath(const std::string& filename) const; 37 | 38 | // Searches for a read-openable file based on filename, which must be 39 | // non-empty. The search is first attempted as a path relative to 40 | // the requesting_file parameter. If no file is found relative to the 41 | // requesting_file then this acts as FindReadableFilepath does. If 42 | // requesting_file does not contain a '/' or a '\' character then it is 43 | // assumed to be a filename and the request will be relative to the 44 | // current directory. 45 | std::string FindRelativeReadableFilepath(const std::string& requesting_file, 46 | const std::string& filename) const; 47 | 48 | // Search path for Find(). Users may add/remove elements as desired. 49 | std::vector& search_path() { return search_path_; } 50 | 51 | private: 52 | std::vector search_path_; 53 | }; 54 | 55 | } // namespace shaderc_util 56 | 57 | #endif // LIBSHADERC_UTIL_SRC_FILE_FINDER_H_ 58 | -------------------------------------------------------------------------------- /libshaderc_util/include/libshaderc_util/format.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LIBSHADERC_UTIL_FORMAT_H_ 16 | #define LIBSHADERC_UTIL_FORMAT_H_ 17 | 18 | #include 19 | 20 | namespace shaderc_util { 21 | 22 | // Returns a string containing for every 23 | // key-value entry in map. 24 | template 25 | std::string format(const Map& map, const std::string& prefix, 26 | const std::string& infix, const std::string& postfix) { 27 | std::stringstream s; 28 | for (const auto& pair : map) { 29 | s << prefix << pair.first << infix << pair.second << postfix; 30 | } 31 | return s.str(); 32 | } 33 | 34 | } // namespace shaderc_util 35 | 36 | #endif // LIBSHADERC_UTIL_FORMAT_H_ 37 | -------------------------------------------------------------------------------- /libshaderc_util/include/libshaderc_util/io_shaderc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LIBSHADERC_UTIL_IO_H_ 16 | #define LIBSHADERC_UTIL_IO_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "string_piece.h" 22 | 23 | namespace shaderc_util { 24 | 25 | // Returns true if the given path is an absolute path. 26 | bool IsAbsolutePath(const std::string& path); 27 | 28 | // A helper function to return the base file name from either absolute path or 29 | // relative path representation of a file. It keeps the component from the last 30 | // '/' or '\' to the end of the given string. If the component is '..' or '.', 31 | // returns an empty string. If '/' or '\' is the last char of the given string, 32 | // also returns an empty string. 33 | // e.g.: dir_a/dir_b/file_c.vert => file_c.vert 34 | // dir_a/dir_b/.. => 35 | // dir_a/dir_b/. => 36 | // dir_a/dirb/c/ => 37 | // Note that this method doesn't check whether the given path is a valid one or 38 | // not. 39 | std::string GetBaseFileName(const std::string& file_path); 40 | 41 | // Reads all of the characters in a given file into input_data. Outputs an 42 | // error message to std::cerr if the file could not be read and returns false if 43 | // there was an error. If the input_file is "-", then input is read from 44 | // std::cin. 45 | bool ReadFile(const std::string& input_file_name, 46 | std::vector* input_data); 47 | 48 | // Returns and initializes the file_stream parameter if the output_filename 49 | // refers to a file, or returns &std::cout if the output_filename is "-". 50 | // Returns nullptr and emits an error message to err if the file could 51 | // not be opened for writing. If the output refers to a file, and the open 52 | // failed for writing, file_stream is left with its fail_bit set. 53 | std::ostream* GetOutputStream(const string_piece& output_filename, 54 | std::ofstream* file_stream, std::ostream* err); 55 | 56 | // Writes output_data to a file, overwriting if it exists. If output_file_name 57 | // is "-", writes to std::cout. 58 | bool WriteFile(std::ostream* output_stream, const string_piece& output_data); 59 | 60 | // Flush the standard output stream and set it to binary mode. Subsequent 61 | // output will not translate newlines to carriage-return newline pairs. 62 | void FlushAndSetBinaryModeOnStdout(); 63 | // Flush the standard output stream and set it to text mode. Subsequent 64 | // output will translate newlines to carriage-return newline pairs. 65 | void FlushAndSetTextModeOnStdout(); 66 | 67 | } // namespace shaderc_util 68 | 69 | #endif // LIBSHADERC_UTIL_IO_H_ 70 | -------------------------------------------------------------------------------- /libshaderc_util/include/libshaderc_util/resources.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LIBSHADERC_UTIL_RESOURCES_H_ 16 | #define LIBSHADERC_UTIL_RESOURCES_H_ 17 | 18 | // We want TBuiltInResource 19 | #include "glslang/Include/ResourceLimits.h" 20 | 21 | namespace shaderc_util { 22 | 23 | using TBuiltInResource = ::TBuiltInResource; 24 | 25 | // A set of suitable defaults. 26 | extern const TBuiltInResource kDefaultTBuiltInResource; 27 | 28 | } // namespace shaderc_util 29 | 30 | #endif // LIBSHADERC_UTIL_RESOURCES_H_ 31 | -------------------------------------------------------------------------------- /libshaderc_util/include/libshaderc_util/shader_stage.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LIBSHADERC_UTIL_SHADER_STAGE_H_ 16 | #define LIBSHADERC_UTIL_SHADER_STAGE_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "glslang/Public/ShaderLang.h" 24 | 25 | #include "libshaderc_util/string_piece.h" 26 | 27 | namespace shaderc_util { 28 | 29 | // Given a string representing a stage, returns the glslang EShLanguage for it. 30 | // If the stage string is not recognized, returns EShLangCount. 31 | EShLanguage MapStageNameToLanguage( 32 | const shaderc_util::string_piece& stage_name); 33 | 34 | } // namespace shaderc_util 35 | 36 | #endif // LIBSHADERC_UTIL_SHADER_STAGE_H_ 37 | -------------------------------------------------------------------------------- /libshaderc_util/include/libshaderc_util/spirv_tools_wrapper.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LIBSHADERC_UTIL_INC_SPIRV_TOOLS_WRAPPER_H 16 | #define LIBSHADERC_UTIL_INC_SPIRV_TOOLS_WRAPPER_H 17 | 18 | #include 19 | #include 20 | 21 | #include "spirv-tools/libspirv.hpp" 22 | 23 | #include "libshaderc_util/compiler.h" 24 | #include "libshaderc_util/string_piece.h" 25 | 26 | namespace shaderc_util { 27 | // Assembles the given assembly. On success, returns true, writes the assembled 28 | // binary to *binary, and clears *errors. Otherwise, writes the error message 29 | // into *errors. 30 | bool SpirvToolsAssemble(Compiler::TargetEnv env, 31 | Compiler::TargetEnvVersion version, 32 | const string_piece assembly, spv_binary* binary, 33 | std::string* errors); 34 | 35 | // Disassembles the given binary. Returns true and writes the disassembled text 36 | // to *text_or_error if successful. Otherwise, writes the error message to 37 | // *text_or_error. 38 | bool SpirvToolsDisassemble(Compiler::TargetEnv env, 39 | Compiler::TargetEnvVersion version, 40 | const std::vector& binary, 41 | std::string* text_or_error); 42 | 43 | // The ids of a list of supported optimization passes. 44 | enum class PassId { 45 | // SPIRV-Tools standard recipes 46 | kLegalizationPasses, 47 | kPerformancePasses, 48 | kSizePasses, 49 | 50 | // SPIRV-Tools specific passes 51 | kNullPass, 52 | kStripDebugInfo, 53 | kCompactIds, 54 | }; 55 | 56 | // Optimizes the given binary. Passes are registered in the exact order as shown 57 | // in enabled_passes, without de-duplication. Returns true and writes the 58 | // optimized binary back to *binary if successful. Otherwise, writes errors to 59 | // *errors and the content of binary may be in an invalid state. 60 | bool SpirvToolsOptimize(Compiler::TargetEnv env, 61 | Compiler::TargetEnvVersion version, 62 | const std::vector& enabled_passes, 63 | spvtools::OptimizerOptions& optimizer_options, 64 | std::vector* binary, std::string* errors); 65 | 66 | } // namespace shaderc_util 67 | 68 | #endif // LIBSHADERC_UTIL_INC_SPIRV_TOOLS_WRAPPER_H 69 | -------------------------------------------------------------------------------- /libshaderc_util/include/libshaderc_util/universal_unistd.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LIBSHADERC_UTIL_UNIVERSAL_UNISTD_H_ 16 | #define LIBSHADERC_UTIL_UNIVERSAL_UNISTD_H_ 17 | 18 | #ifndef _MSC_VER 19 | #include 20 | #else 21 | // Minimal set of needed to compile on windows. 22 | 23 | #include 24 | #define access _access 25 | 26 | // https://msdn.microsoft.com/en-us/library/1w06ktdy.aspx 27 | // Defines these constants. 28 | #define R_OK 4 29 | #define W_OK 2 30 | #endif //_MSC_VER 31 | 32 | #endif // LIBSHADERC_UTIL_UNIVERSAL_UNISTD_H_ 33 | -------------------------------------------------------------------------------- /libshaderc_util/include/libshaderc_util/version_profile.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LIBSHADERC_UTIL_INC_VERSION_PROFILE_H_ 16 | #define LIBSHADERC_UTIL_INC_VERSION_PROFILE_H_ 17 | 18 | #include 19 | 20 | #include "glslang/MachineIndependent/Versions.h" 21 | 22 | namespace shaderc_util { 23 | 24 | // Returns true if the given version is an accepted GLSL (ES) version. 25 | inline bool IsKnownVersion(int version) { 26 | switch (version) { 27 | case 100: 28 | case 110: 29 | case 120: 30 | case 130: 31 | case 140: 32 | case 150: 33 | case 300: 34 | case 310: 35 | case 320: 36 | case 330: 37 | case 400: 38 | case 410: 39 | case 420: 40 | case 430: 41 | case 440: 42 | case 450: 43 | case 460: 44 | return true; 45 | default: 46 | break; 47 | } 48 | return false; 49 | } 50 | 51 | // Given a string version_profile containing both version and profile, decodes 52 | // it and puts the decoded version in version, decoded profile in profile. 53 | // Returns true if decoding is successful and version and profile are accepted. 54 | // This does not validate the version number against the profile. For example, 55 | // "460es" doesn't make sense (yet), but is still accepted. 56 | bool ParseVersionProfile(const std::string& version_profile, int* version, 57 | EProfile* profile); 58 | 59 | } // namespace shaderc_util 60 | 61 | #endif // LIBSHADERC_UTIL_INC_VERSION_PROFILE_H_ 62 | -------------------------------------------------------------------------------- /libshaderc_util/src/args.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "libshaderc_util/args.h" 16 | 17 | #include 18 | #include 19 | 20 | namespace shaderc_util { 21 | 22 | bool GetOptionArgument(int argc, char** argv, int* index, 23 | const std::string& option, 24 | string_piece* option_argument) { 25 | const string_piece arg = argv[*index]; 26 | assert(arg.starts_with(option)); 27 | if (arg.size() != option.size()) { 28 | *option_argument = arg.substr(option.size()); 29 | return true; 30 | } 31 | 32 | if (option.back() == '=') { 33 | *option_argument = ""; 34 | return true; 35 | } 36 | 37 | if (++(*index) >= argc) return false; 38 | *option_argument = argv[*index]; 39 | return true; 40 | } 41 | 42 | bool ParseUint32(const std::string& str, uint32_t* value) { 43 | std::istringstream iss(str); 44 | 45 | iss >> std::setbase(0); 46 | iss >> *value; 47 | 48 | // We should have read something. 49 | bool ok = !str.empty() && !iss.bad(); 50 | // It should have been all the text. 51 | ok = ok && iss.eof(); 52 | // It should have been in range. 53 | ok = ok && !iss.fail(); 54 | 55 | // Work around a bugs in various C++ standard libraries. 56 | // Count any negative number as an error, including "-0". 57 | ok = ok && (str[0] != '-'); 58 | 59 | return ok; 60 | } 61 | 62 | } // namespace shaderc_util 63 | -------------------------------------------------------------------------------- /libshaderc_util/src/counting_includer_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "libshaderc_util/counting_includer.h" 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | namespace { 23 | 24 | // A trivial implementation of CountingIncluder's virtual methods, so tests can 25 | // instantiate. 26 | class ConcreteCountingIncluder : public shaderc_util::CountingIncluder { 27 | public: 28 | using IncludeResult = glslang::TShader::Includer::IncludeResult; 29 | ~ConcreteCountingIncluder() { 30 | // Avoid leaks. 31 | for (auto result : results_) { 32 | release_delegate(result); 33 | } 34 | } 35 | virtual IncludeResult* include_delegate( 36 | const char* requested, const char* requestor, IncludeType, 37 | size_t) override { 38 | const char kError[] = "Unexpected #include"; 39 | results_.push_back(new IncludeResult{"", kError, strlen(kError), nullptr}); 40 | return results_.back(); 41 | } 42 | virtual void release_delegate(IncludeResult* include_result) override { 43 | delete include_result; 44 | } 45 | 46 | private: 47 | // All the results we've returned so far. 48 | std::vector results_; 49 | }; 50 | 51 | TEST(CountingIncluderTest, InitialCount) { 52 | EXPECT_EQ(0, ConcreteCountingIncluder().num_include_directives()); 53 | } 54 | 55 | TEST(CountingIncluderTest, OneIncludeLocal) { 56 | ConcreteCountingIncluder includer; 57 | includer.includeLocal("random file name", "from me", 0); 58 | EXPECT_EQ(1, includer.num_include_directives()); 59 | } 60 | 61 | TEST(CountingIncluderTest, TwoIncludesAnyIncludeType) { 62 | ConcreteCountingIncluder includer; 63 | includer.includeSystem("name1", "from me", 0); 64 | includer.includeLocal("name2", "me", 0); 65 | EXPECT_EQ(2, includer.num_include_directives()); 66 | } 67 | 68 | TEST(CountingIncluderTest, ManyIncludes) { 69 | ConcreteCountingIncluder includer; 70 | for (int i = 0; i < 100; ++i) { 71 | includer.includeLocal("filename", "from me", i); 72 | includer.includeSystem("filename", "from me", i); 73 | } 74 | EXPECT_EQ(200, includer.num_include_directives()); 75 | } 76 | 77 | #ifndef SHADERC_DISABLE_THREADED_TESTS 78 | TEST(CountingIncluderTest, ThreadedIncludes) { 79 | ConcreteCountingIncluder includer; 80 | std::thread t1( 81 | [&includer]() { includer.includeLocal("name1", "me", 0); }); 82 | std::thread t2( 83 | [&includer]() { includer.includeSystem("name2", "me", 1); }); 84 | std::thread t3( 85 | [&includer]() { includer.includeLocal("name3", "me", 2); }); 86 | t1.join(); 87 | t2.join(); 88 | t3.join(); 89 | EXPECT_EQ(3, includer.num_include_directives()); 90 | } 91 | #endif // SHADERC_DISABLE_THREADED_TESTS 92 | 93 | } // anonymous namespace 94 | -------------------------------------------------------------------------------- /libshaderc_util/src/death_test.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LIBSHADERC_UTIL_SRC_DEATH_TEST_H 16 | #define LIBSHADERC_UTIL_SRC_DEATH_TEST_H 17 | 18 | #ifdef NDEBUG 19 | #define EXPECT_DEBUG_DEATH_IF_SUPPORTED(statement, regexp) 20 | #else 21 | #define EXPECT_DEBUG_DEATH_IF_SUPPORTED(statement, regexp) \ 22 | EXPECT_DEATH_IF_SUPPORTED(statement, regexp) 23 | #endif 24 | 25 | #endif // LIBSHADERC_UTIL_SRC_DEATH_TEST_H 26 | -------------------------------------------------------------------------------- /libshaderc_util/src/file_finder.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "libshaderc_util/file_finder.h" 16 | #include "libshaderc_util/string_piece.h" 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | namespace { 23 | 24 | // Returns "" if path is empty or ends in '/'. Otherwise, returns "/". 25 | std::string MaybeSlash(const shaderc_util::string_piece& path) { 26 | return (path.empty() || path.back() == '/') ? "" : "/"; 27 | } 28 | 29 | } // anonymous namespace 30 | 31 | namespace shaderc_util { 32 | 33 | std::string FileFinder::FindReadableFilepath( 34 | const std::string& filename) const { 35 | assert(!filename.empty()); 36 | static const auto for_reading = std::ios_base::in; 37 | std::filebuf opener; 38 | for (const auto& prefix : search_path_) { 39 | const std::string prefixed_filename = 40 | prefix + MaybeSlash(prefix) + filename; 41 | if (opener.open(prefixed_filename, for_reading)) return prefixed_filename; 42 | } 43 | return ""; 44 | } 45 | 46 | std::string FileFinder::FindRelativeReadableFilepath( 47 | const std::string& requesting_file, const std::string& filename) const { 48 | assert(!filename.empty()); 49 | 50 | string_piece dir_name(requesting_file); 51 | 52 | size_t last_slash = requesting_file.find_last_of("/\\"); 53 | if (last_slash != std::string::npos) { 54 | dir_name = string_piece(requesting_file.c_str(), 55 | requesting_file.c_str() + last_slash); 56 | } 57 | 58 | if (dir_name.size() == requesting_file.size()) { 59 | dir_name.clear(); 60 | } 61 | 62 | static const auto for_reading = std::ios_base::in; 63 | std::filebuf opener; 64 | const std::string relative_filename = 65 | dir_name.str() + MaybeSlash(dir_name) + filename; 66 | if (opener.open(relative_filename, for_reading)) return relative_filename; 67 | 68 | return FindReadableFilepath(filename); 69 | } 70 | 71 | } // namespace shaderc_util 72 | -------------------------------------------------------------------------------- /libshaderc_util/src/mutex_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "libshaderc_util/mutex.h" 16 | 17 | #include 18 | #include 19 | 20 | namespace { 21 | 22 | TEST(MutexTest, CanCreateMutex) { 23 | shaderc_util::mutex mutex; 24 | mutex.lock(); 25 | mutex.unlock(); 26 | } 27 | 28 | #ifndef SHADERC_DISABLE_THREADED_TESTS 29 | 30 | void increment_by_1000(shaderc_util::mutex& mut, int& i) { 31 | for(size_t j = 0; j < 1000; ++j) { 32 | mut.lock(); 33 | i = i + 1; 34 | mut.unlock(); 35 | } 36 | } 37 | 38 | TEST(MutexTest, MutexLocks) { 39 | shaderc_util::mutex mutex; 40 | int i = 0; 41 | std::thread t1([&mutex, &i]() { increment_by_1000(mutex, i); }); 42 | std::thread t2([&mutex, &i]() { increment_by_1000(mutex, i); }); 43 | std::thread t3([&mutex, &i]() { increment_by_1000(mutex, i); }); 44 | t1.join(); 45 | t2.join(); 46 | t3.join(); 47 | EXPECT_EQ(3000, i); 48 | } 49 | #endif // SHADERC_DISABLE_THREADED_TESTS 50 | 51 | } // anonymous namespace 52 | -------------------------------------------------------------------------------- /libshaderc_util/src/shader_stage.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "libshaderc_util/shader_stage.h" 16 | 17 | namespace { 18 | 19 | // Maps an identifier to a language. 20 | struct LanguageMapping { 21 | const char* id; 22 | EShLanguage language; 23 | }; 24 | 25 | } // anonymous namespace 26 | 27 | namespace shaderc_util { 28 | 29 | EShLanguage MapStageNameToLanguage(const string_piece& stage_name) { 30 | const LanguageMapping string_to_stage[] = { 31 | {"vertex", EShLangVertex}, 32 | {"fragment", EShLangFragment}, 33 | {"tesscontrol", EShLangTessControl}, 34 | {"tesseval", EShLangTessEvaluation}, 35 | {"geometry", EShLangGeometry}, 36 | {"compute", EShLangCompute}, 37 | {"raygen", EShLangRayGenNV}, 38 | {"intersect", EShLangIntersectNV}, 39 | {"anyhit", EShLangAnyHitNV}, 40 | {"closest", EShLangClosestHitNV}, 41 | {"miss", EShLangMissNV}, 42 | {"callable", EShLangCallableNV}, 43 | {"task", EShLangTaskNV}, 44 | {"mesh", EShLangMeshNV}, 45 | }; 46 | 47 | for (const auto& entry : string_to_stage) { 48 | if (stage_name == entry.id) return entry.language; 49 | } 50 | return EShLangCount; 51 | } 52 | 53 | } // namespace shaderc_util 54 | -------------------------------------------------------------------------------- /libshaderc_util/src/version_profile.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Shaderc Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "libshaderc_util/version_profile.h" 16 | 17 | #include 18 | #include 19 | 20 | namespace { 21 | 22 | const int kVersionNumberLength = 3; 23 | const int kMaxProfileLength = 13; // strlen(compatibility) 24 | const int kMaxVersionProfileLength = kVersionNumberLength + kMaxProfileLength; 25 | const int kMinVersionProfileLength = kVersionNumberLength; 26 | 27 | } // anonymous namespace 28 | 29 | namespace shaderc_util { 30 | 31 | bool ParseVersionProfile(const std::string& version_profile, int* version, 32 | EProfile* profile) { 33 | if (version_profile.size() < kMinVersionProfileLength || 34 | version_profile.size() > kMaxVersionProfileLength || 35 | !::isdigit(version_profile.front())) 36 | return false; 37 | 38 | std::string profile_string; 39 | std::istringstream(version_profile) >> *version >> profile_string; 40 | 41 | if (!IsKnownVersion(*version)) { 42 | return false; 43 | } 44 | if (profile_string.empty()) { 45 | *profile = ENoProfile; 46 | } else if (profile_string == "core") { 47 | *profile = ECoreProfile; 48 | } else if (profile_string == "es") { 49 | *profile = EEsProfile; 50 | } else if (profile_string == "compatibility") { 51 | *profile = ECompatibilityProfile; 52 | } else { 53 | return false; 54 | } 55 | 56 | return true; 57 | } 58 | 59 | } // namespace shaderc_util 60 | -------------------------------------------------------------------------------- /libshaderc_util/testdata/copy-to-build.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2020 The Shaderc Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | file(GLOB all_files ${CMAKE_CURRENT_LIST_DIR}/*) 16 | file(COPY ${all_files} DESTINATION .) -------------------------------------------------------------------------------- /libshaderc_util/testdata/dir/subdir/include_file.2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/shaderc/a5a8caa1951b3f893a08f63cab2dc877087dc05b/libshaderc_util/testdata/dir/subdir/include_file.2 -------------------------------------------------------------------------------- /libshaderc_util/testdata/include_file.1: -------------------------------------------------------------------------------- 1 | The quick brown fox jumps over a lazy dog. -------------------------------------------------------------------------------- /license-checker.cfg: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "licenses": [ "Apache-2.0" ], 4 | "paths": [ 5 | { 6 | "exclude": [ 7 | "**.md", 8 | "**.png", 9 | "**/README.asciidoc", 10 | 11 | ".*", 12 | "AUTHORS", 13 | "CHANGES", 14 | "CONTRIBUTORS", 15 | "DEPS", 16 | "LICENSE", 17 | 18 | "cmake/*.pc.in", 19 | "libshaderc_util/testdata/dir/subdir/include_file.2", 20 | "libshaderc_util/testdata/include_file.1", 21 | 22 | "utils/git-sync-deps", 23 | 24 | "third_party/**" 25 | ] 26 | } 27 | ] 28 | }, 29 | { 30 | "licenses": [ "BSD-3-Clause" ], 31 | "paths": [ 32 | { "exclude": [ "**" ] }, 33 | { "include": [ "utils/git-sync-deps" ] } 34 | ] 35 | } 36 | ] 37 | -------------------------------------------------------------------------------- /third_party/Android.mk: -------------------------------------------------------------------------------- 1 | THIRD_PARTY_PATH := $(call my-dir) 2 | 3 | # Set the location of glslang 4 | ifeq ($(GLSLANG_LOCAL_PATH),) 5 | GLSLANG_LOCAL_PATH:=$(THIRD_PARTY_PATH)/glslang 6 | endif 7 | include $(GLSLANG_LOCAL_PATH)/Android.mk 8 | 9 | # Set the location of SPIRV-Tools. 10 | # Allow the user to override it, but default it to under our third_party directory. 11 | ifeq ($(SPVTOOLS_LOCAL_PATH),) 12 | SPVTOOLS_LOCAL_PATH:=$(THIRD_PARTY_PATH)/spirv-tools 13 | endif 14 | ifeq ($(SPVHEADERS_LOCAL_PATH),) 15 | # Use the third party dir if it exists. 16 | ifneq ($(wildcard $(THIRD_PARTY_PATH)/spirv-headers/include/spirv/spir-v.xml),) 17 | SPVHEADERS_LOCAL_PATH:=$(THIRD_PARTY_PATH)/spirv-headers 18 | else 19 | # Let SPIRV-Tools find its own headers and hope for the best. 20 | endif 21 | endif 22 | 23 | # Now include the SPIRV-Tools dependency 24 | include $(SPVTOOLS_LOCAL_PATH)/Android.mk 25 | 26 | ifeq ($(SHADERC_ENABLE_SPVC),1) 27 | # Set the location of SPIRV-Cross. 28 | # Allow the user to override it, but default it to under our third_party directory. 29 | ifeq ($(SPVCROSS_LOCAL_PATH),) 30 | SPVCROSS_LOCAL_PATH:=$(THIRD_PARTY_PATH)/spirv-cross 31 | endif 32 | 33 | # Now include the SPIRV-Cross dependency 34 | include $(SPVCROSS_LOCAL_PATH)/jni/Android.mk 35 | endif 36 | -------------------------------------------------------------------------------- /utils/remove-file-by-suffix.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Copyright 2015 The Shaderc Authors. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Removes all files with a certain suffix in a given path recursively. 18 | 19 | # Arguments: path suffix 20 | 21 | import os 22 | import sys 23 | 24 | 25 | def main(): 26 | path = sys.argv[1] 27 | suffix = sys.argv[2] 28 | for root, _, filenames in os.walk(path): 29 | for filename in filenames: 30 | if filename.endswith(suffix): 31 | os.remove(os.path.join(root, filename)) 32 | 33 | 34 | if __name__ == '__main__': 35 | main() 36 | -------------------------------------------------------------------------------- /utils/roll-deps: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2019 The Shaderc Authors. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Attempts to roll all entries in DEPS to tip-of-tree and create a commit. 18 | # 19 | # Depends on roll-dep from depot_path being in PATH. 20 | 21 | set -eo pipefail 22 | 23 | function ExitIfIsInterestingError() { 24 | local return_code=$1 25 | if [[ ${return_code} -ne 0 && ${return_code} -ne 2 ]]; then 26 | exit ${return_code} 27 | fi 28 | return 0 29 | } 30 | 31 | dependencies=("third_party/effcee/" 32 | "third_party/glslang/" 33 | "third_party/googletest/" 34 | "third_party/re2/" 35 | "third_party/spirv-headers/" 36 | "third_party/spirv-tools/") 37 | branch="origin/main" 38 | 39 | # This script assumes it's parent directory is the repo root. 40 | repo_path=$(dirname "$0")/.. 41 | 42 | cd "$repo_path" 43 | 44 | if [[ $(git diff --stat) != '' ]]; then 45 | echo "Working tree is dirty, commit changes before attempting to roll DEPS" 46 | exit 1 47 | fi 48 | 49 | echo "*** Ignore messages about running 'git cl upload' ***" 50 | 51 | set +e 52 | 53 | for dep in ${dependencies[@]}; do 54 | echo "Rolling $dep" 55 | roll-dep --ignore-dirty-tree --roll-to="${branch}" "${dep}" 56 | ExitIfIsInterestingError $? 57 | done 58 | --------------------------------------------------------------------------------