aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Neto <dneto@google.com>2020-12-02 13:44:02 -0500
committerDavid Neto <dneto@google.com>2020-12-02 20:36:38 -0500
commit2e9aa5c5283b859603e8c5755204fd9b0f6bf7ae (patch)
tree2c1cf155af2f0a2ad3881ac6df0347cc9d8235bb
parenteb5d79cbc50581eb63a482107f0a4b5b198228a4 (diff)
parent6216d098d8abe3ccda8781016c4f69372c48afb9 (diff)
downloadshaderc-2e9aa5c5283b859603e8c5755204fd9b0f6bf7ae.tar.gz
Merge remote-tracking branch 'aosp/upstream-main' into update-shadercndk-r23-beta1
Supports non-provisional Vulkan raytracing extensions Includes: 6216d09 Roll dependencies to support Vulkan raytracing 46ea32f Roll third_party/glslang/ 142cb87f8..7f6559d28 (13 commits) 88f9156 Replace C-style cast with static_cast e258cf5 Roll back googletest to earlier version fcafd5b Roll 6 dependencies (#1144) 813ef3d Handle alias libraries in shaderc_combined to avoid duplicated symbols (#1141) 0111390 Adding back non-spvc BUILD.gn that I accidentally nuked (#1136) dbe8f66 Remove spvc (#1135) 00e17f2 Start SPIRV-Tools v2020.4 Testing: checkbuild.py on Linux; unit tests on Windows Change-Id: I309703d6ec2435986e3a05e38600b84c38de5def
-rw-r--r--BUILD.gn128
-rw-r--r--CHANGES3
-rw-r--r--CMakeLists.txt18
-rw-r--r--DEPS14
-rw-r--r--README.md22
-rw-r--r--build_overrides/shaderc.gni2
-rw-r--r--cmake/utils.cmake13
-rw-r--r--libshaderc/include/shaderc/shaderc.hpp6
-rw-r--r--libshaderc_spvc/Android.mk28
-rw-r--r--libshaderc_spvc/CMakeLists.txt139
-rw-r--r--libshaderc_spvc/README.md47
-rw-r--r--libshaderc_spvc/include/spvc/spvc.h681
-rw-r--r--libshaderc_spvc/include/spvc/spvc.hpp604
-rw-r--r--libshaderc_spvc/src/common_shaders_for_test.h110
-rw-r--r--libshaderc_spvc/src/spvc.cc1243
-rw-r--r--libshaderc_spvc/src/spvc_c_smoke_test.c20
-rw-r--r--libshaderc_spvc/src/spvc_cpp_test.cc115
-rw-r--r--libshaderc_spvc/src/spvc_log.cc88
-rw-r--r--libshaderc_spvc/src/spvc_log.h79
-rw-r--r--libshaderc_spvc/src/spvc_private.cc573
-rw-r--r--libshaderc_spvc/src/spvc_private.h158
-rw-r--r--libshaderc_spvc/src/spvc_smoke_test_util.c118
-rw-r--r--libshaderc_spvc/src/spvc_smoke_test_util.h17
-rw-r--r--libshaderc_spvc/src/spvc_test.cc162
-rw-r--r--libshaderc_spvc/src/spvc_webgpu_c_smoke_test.c20
-rw-r--r--libshaderc_spvc/src/spvc_webgpu_cpp_test.cc113
-rw-r--r--libshaderc_spvc/src/spvc_webgpu_test.cc105
-rw-r--r--libshaderc_spvc/src/spvcir_pass.cc1270
-rw-r--r--libshaderc_spvc/src/spvcir_pass.h120
-rw-r--r--libshaderc_spvc/src/spvcir_test.cc1572
-rw-r--r--license-checker.cfg6
-rw-r--r--shaderc_features.gni24
-rw-r--r--spvc/CMakeLists.txt31
-rw-r--r--spvc/README.asciidoc62
-rw-r--r--spvc/src/main.cc407
-rw-r--r--spvc/test/CMakeLists.txt35
-rw-r--r--spvc/test/known_failures153
-rw-r--r--spvc/test/known_invalids5
-rw-r--r--spvc/test/known_spvc_failures200
-rw-r--r--spvc/test/reference/shaders-hlsl-no-opt/asm/vert/spvc_OpSource.asm.vert8
-rw-r--r--spvc/test/reference/shaders-hlsl-no-opt/asm/vert/spvc_trivial_shader.asm.vert8
-rw-r--r--spvc/test/run_spirv_cross_tests.py683
-rwxr-xr-xspvc/test/run_spirv_cross_tests_wrapper.sh50
-rw-r--r--spvc/test/shaders-hlsl-no-opt/asm/vert/spvc_OpSource.asm.vert12
-rw-r--r--spvc/test/shaders-hlsl-no-opt/asm/vert/spvc_trivial_shader.asm.vert11
-rw-r--r--spvc/test/unconfirmed_invalids39
-rw-r--r--third_party/CMakeLists.txt23
-rwxr-xr-xutils/roll-deps3
48 files changed, 24 insertions, 9324 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 57368fe..7b40d1d 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -14,16 +14,9 @@
import("//build_overrides/build.gni")
import("//build_overrides/shaderc.gni")
-import("shaderc_features.gni")
glslang_dir = shaderc_glslang_dir
spirv_tools_dir = shaderc_spirv_tools_dir
-spirv_cross_dir = shaderc_spirv_cross_dir
-spirv_headers_dir = shaderc_spirv_headers_dir
-use_direct_logging = shaderc_spvc_enable_direct_logging
-use_context_logging = !shaderc_spvc_disable_context_logging
-
-is_msvc = is_win && !is_clang
config("shaderc_util_public") {
include_dirs = [ "libshaderc_util/include" ]
@@ -106,124 +99,3 @@ component("libshaderc") {
configs += [ "//build/config/compiler:no_chromium_code" ]
}
}
-
-config("spirv_cross_public") {
- include_dirs = [
- "${spirv_cross_dir}",
- "${spirv_cross_dir}/..",
- ]
- defines = [ "SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS" ]
-}
-
-config("spirv_cross_internal") {
- if (!is_msvc) {
- cflags_cc = [
- "-Wno-implicit-fallthrough",
- "-Wno-return-type",
- "-Wno-sign-compare",
- ]
- } else {
- # Disable "not all control paths return a value" warning.
- cflags_cc = [ "/wd4715" ]
- }
-}
-
-source_set("spirv_cross") {
- public_configs = [ ":spirv_cross_public" ]
- configs += [ ":spirv_cross_internal" ]
-
- sources = [
- "${spirv_cross_dir}/GLSL.std.450.h",
- "${spirv_cross_dir}/spirv.hpp",
- "${spirv_cross_dir}/spirv_cfg.cpp",
- "${spirv_cross_dir}/spirv_cfg.hpp",
- "${spirv_cross_dir}/spirv_common.hpp",
- "${spirv_cross_dir}/spirv_cross.cpp",
- "${spirv_cross_dir}/spirv_cross.hpp",
- "${spirv_cross_dir}/spirv_cross_containers.hpp",
- "${spirv_cross_dir}/spirv_cross_error_handling.hpp",
- "${spirv_cross_dir}/spirv_cross_parsed_ir.cpp",
- "${spirv_cross_dir}/spirv_cross_parsed_ir.hpp",
- "${spirv_cross_dir}/spirv_glsl.cpp",
- "${spirv_cross_dir}/spirv_glsl.hpp",
- "${spirv_cross_dir}/spirv_hlsl.cpp",
- "${spirv_cross_dir}/spirv_hlsl.hpp",
- "${spirv_cross_dir}/spirv_msl.cpp",
- "${spirv_cross_dir}/spirv_msl.hpp",
- "${spirv_cross_dir}/spirv_parser.cpp",
- "${spirv_cross_dir}/spirv_parser.hpp",
- "${spirv_cross_dir}/spirv_reflect.cpp",
- "${spirv_cross_dir}/spirv_reflect.hpp",
- ]
-}
-
-config("shaderc_spvc_public") {
- include_dirs = [
- "libshaderc/include",
- "libshaderc_spvc/include",
- "${spirv_headers_dir}/include",
- # Accessing a private spirv-tools headers.
- "${spirv_tools_dir}",
- # Accessing auto-generated spirv-tools headers. The headers are generated by
- # actions in ${spirv_tools_dir}/BUILD.gn, hence locate the action outputs
- # using the generated file directory corresponding to that build file.
- get_path_info("${spirv_tools_dir}/BUILD.gn", "gen_dir"),
- ]
-
- if (is_component_build) {
- defines = [ "SHADERC_SHAREDLIB" ]
- }
-}
-
-component("libshaderc_spvc") {
- public_deps = [ ":libshaderc_spvc_sources" ]
-}
-
-source_set("libshaderc_spvc_sources") {
- public_configs = [
- ":shaderc_spvc_public",
- ]
-
- defines = [
- "SHADERC_IMPLEMENTATION",
- "SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS"
- ]
-
- if (use_direct_logging) {
- defines += [ "SHADERC_SPVC_ENABLE_DIRECT_LOGGING", ]
- }
-
- if (!use_context_logging) {
- defines += [ "SHADERC_SPVC_DISABLE_CONTEXT_LOGGING", ]
- }
-
- sources = [
- "libshaderc/include/shaderc/env.h",
- "libshaderc/include/shaderc/status.h",
- "libshaderc/include/shaderc/visibility.h",
- "libshaderc_spvc/include/spvc/spvc.h",
- "libshaderc_spvc/include/spvc/spvc.hpp",
- "libshaderc_spvc/src/spvc.cc",
- "libshaderc_spvc/src/spvc_log.cc",
- "libshaderc_spvc/src/spvc_log.h",
- "libshaderc_spvc/src/spvc_private.cc",
- "libshaderc_spvc/src/spvc_private.h",
- "libshaderc_spvc/src/spvcir_pass.cc",
- "libshaderc_spvc/src/spvcir_pass.h",
- ]
-
- public_deps = [ ":spirv_cross" ]
-
- deps = [
- ":spirv_cross",
- "${spirv_tools_dir}:spvtools",
- "${spirv_tools_dir}:spvtools_core_enums_unified1",
- "${spirv_tools_dir}:spvtools_opt",
- "${spirv_tools_dir}:spvtools_val",
- ]
-
- if (build_with_chromium) {
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [ "//build/config/compiler:no_chromium_code" ]
- }
-}
diff --git a/CHANGES b/CHANGES
index 3aa4b00..b6b97c7 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,8 @@
Revision history for Shaderc
+v2020.4-dev 2020-09-02
+ - Start v2020.4-dev
+
v2020.3 2020-09-02
- General:
- Last release with spvc
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6392d2b..5c74cd8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,7 +23,6 @@ endif()
message(STATUS "Shaderc: build type is \"${CMAKE_BUILD_TYPE}\".")
-option(SHADERC_ENABLE_SPVC "Enable libshaderc_spvc" OFF)
option(SHADERC_ENABLE_WGSL_OUTPUT "Enable WGSL output" OFF)
option(SHADERC_SKIP_INSTALL "Skip installation" ${SHADERC_SKIP_INSTALL})
@@ -41,16 +40,6 @@ else()
message(STATUS "Configuring Shaderc to avoid building tests.")
endif()
-option(SHADERC_SPVC_ENABLE_DIRECT_LOGGING "Send logging messages from spvc directly to stdout/err" OFF)
-if (${SHADERC_SPVC_ENABLE_DIRECT_LOGGING})
- add_definitions(-DSHADERC_SPVC_ENABLE_DIRECT_LOGGING)
-endif()
-
-option(SHADERC_SPVC_DISABLE_CONTEXT_LOGGING "Send logging messages from spvc to context object" OFF)
-if (${SHADERC_SPVC_DISABLE_CONTEXT_LOGGING})
- add_definitions(-DSHADERC_SPVC_DISABLE_CONTEXT_LOGGING)
-endif()
-
option(SHADERC_ENABLE_WERROR_COMPILE "Enable passing -Werror to compiler, if available" ON)
set (CMAKE_CXX_STANDARD 11)
@@ -115,10 +104,6 @@ endif(MSVC)
# We depend on these for later projects, so they should come first.
add_subdirectory(third_party)
-if(SHADERC_ENABLE_SPVC)
-add_subdirectory(libshaderc_spvc)
-add_subdirectory(spvc)
-endif()
add_subdirectory(libshaderc_util)
add_subdirectory(libshaderc)
add_subdirectory(glslc)
@@ -152,9 +137,6 @@ function(define_pkg_config_file NAME LIBS)
endif()
endfunction()
-if(SHADERC_ENABLE_SPVC)
- set(EXTRA_STATIC_PKGCONFIG_LIBS -lshaderc_spvc)
-endif()
define_pkg_config_file(shaderc -lshaderc_shared)
define_pkg_config_file(shaderc_static "-lshaderc ${EXTRA_STATIC_PKGCONFIG_LIBS} -lshaderc_util")
define_pkg_config_file(shaderc_combined -lshaderc_combined)
diff --git a/DEPS b/DEPS
index ea7f54a..d334a28 100644
--- a/DEPS
+++ b/DEPS
@@ -5,12 +5,11 @@ vars = {
'khronos_git': 'https://github.com/KhronosGroup',
'effcee_revision' : '2ec8f8738118cc483b67c04a759fee53496c5659',
- 'glslang_revision': '517f39eee46f27c83527117d831c4d7e2f7c9fe3',
- 'googletest_revision': 'df6b75949b1efab7606ba60c0f0a0125ac95c5af',
- 're2_revision': 'ca11026a032ce2a3de4b3c389ee53d2bdc8794d6',
- 'spirv_headers_revision': '3fdabd0da2932c276b25b9b4a988ba134eba1aa6',
- 'spirv_tools_revision': '8a0ebd40f86d1f18ad42ea96c6ac53915076c3c7',
- 'spirv_cross_revision': '685f86471e9d26b3eb7676695a2e2cefb4551ae9',
+ 'glslang_revision': 'ffccefddfd9a02ec0c0b6dd04ef5e1042279c97f',
+ 'googletest_revision': '36d8eb532022d3b543bf55aa8ffa01b6e9f03490',
+ 're2_revision': '9e5430536b59ad8a8aff8616a6e6b0f888594fac',
+ 'spirv_headers_revision': '104ecc356c1bea4476320faca64440cd1df655a3',
+ 'spirv_tools_revision': 'cd590fa3341284cd6d1ee82366155786cfd44c96',
}
deps = {
@@ -31,7 +30,4 @@ deps = {
'third_party/spirv-tools': Var('khronos_git') + '/SPIRV-Tools.git@' +
Var('spirv_tools_revision'),
-
- 'third_party/spirv-cross': Var('khronos_git') + '/SPIRV-Cross.git@' +
- Var('spirv_cross_revision'),
}
diff --git a/README.md b/README.md
index 5dc8b77..2262272 100644
--- a/README.md
+++ b/README.md
@@ -5,10 +5,6 @@ At the moment it includes:
- [`glslc`](glslc), a command line compiler for GLSL/HLSL to SPIR-V, and
- [`libshaderc`](libshaderc), a library API for accessing `glslc` functionality.
-- [`spvc`](spvc), a command line wrapper around the SPIR-V to GLSL/HLSL/MSL
- compiler [SPIRV-Cross][spirv-cross], and
-- [`libshaderc_spvc`](libshaderc_spvc), a library API for accessing `spvc`
- functionality.
**Note:** The fact that that `libshaderc` is not named `libshaderc_glslc` is a
quirk of history, and a known inconsistency. Changing it would require a
@@ -25,16 +21,6 @@ to provide:
operating systems
* increased functionality such as file `#include` support
-`spvc` wraps around core functionality in [spirv-cross][spirv-cross]
-and [SPIRV-Tools][spirv-tools]. `spirv` and its library aims to
-provide:
-
-* validation and transformation of inputs before cross-compiling
-* an API designed around integration with specific projects like [Dawn][dawn]
-
-**Note:** `spvc` and its library are WIP and optional artifacts that are by
-default disabled in the build. How to enabled is detailed below.
-
## Downloads
**Note: These binaries are just the artifacts of the builders and have not
@@ -234,14 +220,6 @@ test.vert
/code $ glslc -c -o - test.vert | spirv-dis
```
-### Building spvc
-
-The value `SHADERC_ENABLE_SPVC` in `CMakeLists.txt` must be set to `ON` to
-enable building `spvc`.
-
-This can be achieved by either editing the file in your checkout, or passing
-`-DSHADERC_ENABLE_SPVC=ON` to `cmake` to set the value.
-
## Bug tracking
We track bugs using GitHub -- click on the "Issues" button on
diff --git a/build_overrides/shaderc.gni b/build_overrides/shaderc.gni
index 4917c91..fea75fd 100644
--- a/build_overrides/shaderc.gni
+++ b/build_overrides/shaderc.gni
@@ -18,4 +18,4 @@
shaderc_glslang_dir = "//third_party/glslang"
shaderc_spirv_tools_dir = "//third_party/spirv-tools"
shaderc_spirv_headers_dir = "//third_party/spirv-headers"
-shaderc_spirv_cross_dir = "//third_party/spirv-cross"
+
diff --git a/cmake/utils.cmake b/cmake/utils.cmake
index ffa9336..d64757d 100644
--- a/cmake/utils.cmake
+++ b/cmake/utils.cmake
@@ -146,7 +146,18 @@ macro(shaderc_get_transitive_libs target out_list)
get_target_property(libtype ${target} TYPE)
# If this target is a static library, get anything it depends on.
if ("${libtype}" STREQUAL "STATIC_LIBRARY")
- list(INSERT ${out_list} 0 "${target}")
+ # Get the original library if this is an alias library. This is
+ # to avoid putting both the original library and the alias library
+ # in the list (given we are deduplicating according to target names).
+ # Otherwise, we may pack the same library twice, resulting in
+ # duplicated symbols.
+ get_target_property(aliased_target ${target} ALIASED_TARGET)
+ if (aliased_target)
+ list(INSERT ${out_list} 0 "${aliased_target}")
+ else()
+ list(INSERT ${out_list} 0 "${target}")
+ endif()
+
get_target_property(libs ${target} LINK_LIBRARIES)
if (libs)
foreach(lib ${libs})
diff --git a/libshaderc/include/shaderc/shaderc.hpp b/libshaderc/include/shaderc/shaderc.hpp
index c88b684..1588dfe 100644
--- a/libshaderc/include/shaderc/shaderc.hpp
+++ b/libshaderc/include/shaderc/shaderc.hpp
@@ -203,9 +203,9 @@ class CompileOptions {
[](void* user_data, const char* requested_source, int type,
const char* requesting_source, size_t include_depth) {
auto* sub_includer = static_cast<IncluderInterface*>(user_data);
- return sub_includer->GetInclude(requested_source,
- (shaderc_include_type)type,
- requesting_source, include_depth);
+ return sub_includer->GetInclude(
+ requested_source, static_cast<shaderc_include_type>(type),
+ requesting_source, include_depth);
},
[](void* user_data, shaderc_include_result* include_result) {
auto* sub_includer = static_cast<IncluderInterface*>(user_data);
diff --git a/libshaderc_spvc/Android.mk b/libshaderc_spvc/Android.mk
deleted file mode 100644
index a13e05b..0000000
--- a/libshaderc_spvc/Android.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-# Copyright 2020 The Shaderc Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-LOCAL_CPP_EXTENSION := .cc .cpp .cxx
-LOCAL_MODULE:=shaderc_spvc
-LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)/include
-LOCAL_SRC_FILES:=src/spvc.cc \
- src/spvc_private.cc
-LOCAL_C_INCLUDES:=$(LOCAL_PATH)/include
-LOCAL_STATIC_LIBRARIES:=shaderc_util SPIRV-Tools SPIRV-Tools-opt spirv-cross-glsl
-LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -DENABLE_HLSL=1
-LOCAL_EXPORT_CPPFLAGS:=-std=c++11
-LOCAL_EXPORT_LDFLAGS:=-latomic
-include $(BUILD_STATIC_LIBRARY)
diff --git a/libshaderc_spvc/CMakeLists.txt b/libshaderc_spvc/CMakeLists.txt
deleted file mode 100644
index 927375c..0000000
--- a/libshaderc_spvc/CMakeLists.txt
+++ /dev/null
@@ -1,139 +0,0 @@
-# Copyright 2020 The Shaderc Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-project(libshaderc)
-
-find_package(Threads)
-
-set(SPIRV_TOOLS "SPIRV-Tools")
-set(SPVC_LIBS
- ${CMAKE_THREAD_LIBS_INIT}
- SPIRV-Tools
- SPIRV-Tools-opt
- spirv-cross-glsl
- spirv-cross-hlsl
- spirv-cross-msl
- spirv-cross-reflect
-)
-
-set(SPVC_SOURCES
- include/spvc/spvc.h
- include/spvc/spvc.hpp
- src/spvc.cc
- src/spvc_log.cc
- src/spvc_private.cc
- src/spvcir_pass.cc
- src/spvcir_pass.h
-)
-
-add_library(shaderc_spvc STATIC ${SPVC_SOURCES})
-add_dependencies(shaderc_spvc ${SPIRV_TOOLS})
-shaderc_default_compile_options(shaderc_spvc)
-target_include_directories(shaderc_spvc
- PUBLIC include
- ${shaderc_SOURCE_DIR}/libshaderc/include
- ${spirv-tools_SOURCE_DIR}/include
- ${spirv-tools_SOURCE_DIR}
- ${spirv-tools_BINARY_DIR})
-target_link_libraries(shaderc_spvc PRIVATE ${SPVC_LIBS})
-
-add_library(shaderc_spvc_shared SHARED ${SPVC_SOURCES})
-add_dependencies(shaderc_spvc_shared ${SPIRV_TOOLS}-shared)
-shaderc_default_compile_options(shaderc_spvc_shared)
-target_include_directories(shaderc_spvc_shared
- PUBLIC include
- ${shaderc_SOURCE_DIR}/libshaderc/include
- ${spirv-tools_SOURCE_DIR}/include
- ${spirv-tools_SOURCE_DIR}
- ${spirv-tools_BINARY_DIR})
-target_link_libraries(shaderc_spvc_shared PRIVATE ${SPVC_LIBS})
-set_target_properties(shaderc_spvc_shared PROPERTIES SOVERSION 1)
-target_compile_definitions(shaderc_spvc_shared
- PRIVATE SHADERC_IMPLEMENTATION
- PUBLIC SHADERC_SHAREDLIB
-)
-
-target_compile_definitions(shaderc_spvc_shared
- PRIVATE SHADERC_IMPLEMENTATION
- PUBLIC SHADERC_SHAREDLIB
-)
-
-if(SHADERC_ENABLE_INSTALL)
- install(
- FILES
- include/spvc/spvc.h
- include/spvc/spvc.hpp
- DESTINATION
- ${CMAKE_INSTALL_INCLUDEDIR}/shaderc)
-
- install(TARGETS shaderc_spvc shaderc_spvc_shared
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
-endif(SHADERC_ENABLE_INSTALL)
-
-shaderc_add_tests(
- TEST_PREFIX shaderc
- LINK_LIBS shaderc_spvc ${SPVC_LIBS}
- INCLUDE_DIRS include ${shaderc_SOURCE_DIR}/libshaderc/include ${SPIRV-Cross_SOURCE_DIR}/..
- ${effcee_SOURCE_DIR}
- ${RE2_SOURCE_DIR}
- TEST_NAMES
- spvc
- spvc_cpp
- spvc_webgpu
- spvc_webgpu_cpp
- spvcir)
-
-
-shaderc_combine_static_lib(shaderc_spvc_combined shaderc_spvc)
-
-if(SHADERC_ENABLE_INSTALL)
- # Since shaderc_combined is defined as an imported library, we cannot use the
- # install() directive to install it. Install it like a normal file.
- get_target_property(generated_location shaderc_spvc_combined LOCATION)
- string(REGEX MATCH "Visual Studio .*" vs_generator "${CMAKE_GENERATOR}")
- if (NOT "${vs_generator}" STREQUAL "")
- # With Visual Studio generators, the LOCATION property is not properly
- # expanded according to the current build configuration. We need to work
- # around this problem by manually substitution.
- string(REPLACE "$(Configuration)" "\${CMAKE_INSTALL_CONFIG_NAME}"
- install_location "${generated_location}")
- install(FILES ${install_location} DESTINATION ${CMAKE_INSTALL_LIBDIR})
- else()
- install(FILES ${generated_location} DESTINATION ${CMAKE_INSTALL_LIBDIR})
- endif()
-endif(SHADERC_ENABLE_INSTALL)
-
-shaderc_add_tests(
- TEST_PREFIX shaderc_spvc_combined
- LINK_LIBS shaderc_spvc_combined ${SPVC_LIBS} ${CMAKE_THREAD_LIBS_INIT}
- INCLUDE_DIRS include ${shaderc_SOURCE_DIR}/libshaderc/include ${spirv-tools_SOURCE_DIR}/include
- TEST_NAMES
- spvc
- spvc_cpp)
-
-if(${SHADERC_ENABLE_TESTS})
- add_executable(spvc_c_smoke_test ./src/spvc_smoke_test_util.c ./src/spvc_c_smoke_test.c)
- target_include_directories(spvc_c_smoke_test PUBLIC include PRIVATE ${shaderc_SOURCE_DIR}/libshaderc/include)
- shaderc_default_c_compile_options(spvc_c_smoke_test)
- target_link_libraries(spvc_c_smoke_test PRIVATE shaderc_spvc shaderc)
- add_test(NAME spvc_c_smoke_test COMMAND spvc_c_smoke_test)
-
- add_executable(spvc_webgpu_c_smoke_test ./src/spvc_smoke_test_util.c ./src/spvc_webgpu_c_smoke_test.c)
- target_include_directories(spvc_webgpu_c_smoke_test PUBLIC include PRIVATE ${shaderc_SOURCE_DIR}/libshaderc/include)
- shaderc_default_c_compile_options(spvc_webgpu_c_smoke_test)
- target_link_libraries(spvc_webgpu_c_smoke_test PRIVATE shaderc_spvc shaderc)
- add_test(NAME spvc_webgpu_c_smoke_test COMMAND spvc_webgpu_c_smoke_test)
-endif()
diff --git a/libshaderc_spvc/README.md b/libshaderc_spvc/README.md
deleted file mode 100644
index 4cf98ec..0000000
--- a/libshaderc_spvc/README.md
+++ /dev/null
@@ -1,47 +0,0 @@
-# libshaderc_spvc
-
-A library for validating and translating SPIR-V, using SPIRV-Tools validation and the SPIRV-Cross compiler.
-
-## Build Artifacts
-
-There are two main shaderc libraries that are created during a CMake
-compilation. The first is `libshaderc_spvc`, which is a static library
-containing just the functionality exposed by libshaderc_spvc. It depends
-on other compilation targets `shaderc_util`, `SPIRV-Tools`, and `SPIRV-Cross`.
-
-The other is `libshaderc_spvc_combined`, which is a static library containing
-libshaderc_spvc and all of its dependencies.
-
-
-## Integrating libshaderc_spvc
-
-There are several ways of integrating libshaderc_spvc into external projects.
-
-1. If the external project uses CMake, then `shaderc/CMakeLists.txt` can be
-included into the external project's CMake configuration and shaderc_spvc can be used
-as a link target.
-This is the simplest way to use libshaderc_spvc in an external project.
-
-2. If the external project uses CMake and is building for Linux or Android,
-`target_link_libraries(shaderc_spvc_combined)` can instead be specified. This is
-functionally identical to the previous option.
-
-3. If the external project does not use CMake, then the external project can
-instead directly use the generated libraries. `shaderc/libshaderc_spvc/include`
-should be added to the include path, and
-`build/libshaderc_spvc/libshaderc_spvc_combined.a` should be linked. Note that on some
-platforms `-lpthread` should also be specified.
-
-4. If the external project does not use CMake and cannot use
-`libshaderc_spvc_combined`, the following libraries or their platform-dependent
-counterparts should be linked in the order specified.
- * `build/libshaderc_spvc/libshaderc_spvc.a`
- * `build/libshaderc_util/libshaderc_util.a`
- * `build/third_party/spirv-tools/libSPIRV-Tools-opt.a`
- * `build/third_party/spirv-tools/libSPIRV-Tools.a`
- * `build/third_party/SPIRV-Cross/libspirv-cross-core.a`
- * `build/third_party/SPIRV-Cross/libspirv-cross-glsl.a` etc.
-
-5. If building for Android using the Android NDK, `shaderc/Android.mk` can be
-included in the application's `Android.mk` and `LOCAL_STATIC_LIBRARIES:=shaderc_spvc`
-can be specified. See `shaderc/android_test` for an example.
diff --git a/libshaderc_spvc/include/spvc/spvc.h b/libshaderc_spvc/include/spvc/spvc.h
deleted file mode 100644
index e40b434..0000000
--- a/libshaderc_spvc/include/spvc/spvc.h
+++ /dev/null
@@ -1,681 +0,0 @@
-// Copyright 2018 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef SHADERC_SPVC_H_
-#define SHADERC_SPVC_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdint.h>
-
-#include "shaderc/env.h"
-#include "shaderc/status.h"
-#include "shaderc/visibility.h"
-
-// SPIR-V decorations supported by spvc. This is not an exhaustive list of all
-// of the values in the spec, but more can be added if needed.
-typedef enum {
- shaderc_spvc_decoration_specid,
- shaderc_spvc_decoration_block,
- shaderc_spvc_decoration_rowmajor,
- shaderc_spvc_decoration_colmajor,
- shaderc_spvc_decoration_arraystride,
- shaderc_spvc_decoration_matrixstride,
- shaderc_spvc_decoration_builtin,
- shaderc_spvc_decoration_noperspective,
- shaderc_spvc_decoration_flat,
- shaderc_spvc_decoration_centroid,
- shaderc_spvc_decoration_restrict,
- shaderc_spvc_decoration_aliased,
- shaderc_spvc_decoration_nonwritable,
- shaderc_spvc_decoration_nonreadable,
- shaderc_spvc_decoration_uniform,
- shaderc_spvc_decoration_location,
- shaderc_spvc_decoration_component,
- shaderc_spvc_decoration_index,
- shaderc_spvc_decoration_binding,
- shaderc_spvc_decoration_descriptorset,
- shaderc_spvc_decoration_offset,
- shaderc_spvc_decoration_nocontraction,
-} shaderc_spvc_decoration;
-
-// Backwards compatiblity enum for Dawn. This will be removed once Dawn no
-// longer depends on it.
-#define SHADERC_SPVC_DECORATION_BINDING shaderc_spvc_decoration_binding
-
-typedef enum {
- shaderc_spvc_msl_platform_ios,
- shaderc_spvc_msl_platform_macos,
-} shaderc_spvc_msl_platform;
-
-// Return code for spvc API calls. shaderc_spvc_status_success indicates success
-// completion of the operation, all others indicate some sort of failure.
-typedef enum {
- shaderc_spvc_status_success,
- shaderc_spvc_status_compilation_error,
- shaderc_spvc_status_internal_error,
- shaderc_spvc_status_validation_error,
- shaderc_spvc_status_transformation_error,
- shaderc_spvc_status_configuration_error,
- shaderc_spvc_status_uninitialized_compiler_error,
- shaderc_spvc_status_missing_context_error,
- shaderc_spvc_status_invalid_out_param,
- shaderc_spvc_status_missing_options_error,
- shaderc_spvc_status_invalid_in_param,
- shaderc_spvc_status_missing_result_error,
-} shaderc_spvc_status;
-
-typedef enum {
- shaderc_spvc_execution_model_vertex,
- shaderc_spvc_execution_model_fragment,
- shaderc_spvc_execution_model_glcompute,
- shaderc_spvc_execution_model_invalid,
-} shaderc_spvc_execution_model;
-
-typedef enum {
- shaderc_spvc_binding_type_uniform_buffer = 0x00000000,
- shaderc_spvc_binding_type_storage_buffer = 0x00000001,
- shaderc_spvc_binding_type_readonly_storage_buffer = 0x00000002,
- shaderc_spvc_binding_type_sampler = 0x00000003,
- shaderc_spvc_binding_type_comparison_sampler = 0x00000004,
- shaderc_spvc_binding_type_sampled_texture = 0x00000005,
- shaderc_spvc_binding_type_storage_texture = 0x00000006,
- shaderc_spvc_binding_type_readonly_storage_texture = 0x00000007,
- shaderc_spvc_binding_type_writeonly_storage_texture = 0x00000008,
-} shaderc_spvc_binding_type;
-
-typedef enum {
- shaderc_spvc_texture_view_dimension_undefined = 0x00000000,
- shaderc_spvc_texture_view_dimension_e1D = 0x00000001,
- shaderc_spvc_texture_view_dimension_e2D = 0x00000002,
- shaderc_spvc_texture_view_dimension_e2D_array = 0x00000003,
- shaderc_spvc_texture_view_dimension_cube = 0x00000004,
- shaderc_spvc_texture_view_dimension_cube_array = 0x00000005,
- shaderc_spvc_texture_view_dimension_e3D = 0x00000006,
-} shaderc_spvc_texture_view_dimension;
-
-typedef enum {
- shaderc_spvc_texture_format_type_float,
- shaderc_spvc_texture_format_type_sint,
- shaderc_spvc_texture_format_type_uint,
- shaderc_spvc_texture_format_type_other,
-} shaderc_spvc_texture_format_type;
-
-typedef enum {
- shaderc_spvc_shader_resource_uniform_buffers,
- shaderc_spvc_shader_resource_separate_images,
- shaderc_spvc_shader_resource_separate_samplers,
- shaderc_spvc_shader_resource_storage_buffers,
- shaderc_spvc_shader_resource_storage_images,
-} shaderc_spvc_shader_resource;
-
-typedef enum {
- shaderc_spvc_storage_texture_format_undefined = 0x00000000,
- shaderc_spvc_storage_texture_format_r8unorm = 0x00000001,
- shaderc_spvc_storage_texture_format_r8snorm = 0x00000002,
- shaderc_spvc_storage_texture_format_r8uint = 0x00000003,
- shaderc_spvc_storage_texture_format_r8sint = 0x00000004,
- shaderc_spvc_storage_texture_format_r16uint = 0x00000005,
- shaderc_spvc_storage_texture_format_r16sint = 0x00000006,
- shaderc_spvc_storage_texture_format_r16float = 0x00000007,
- shaderc_spvc_storage_texture_format_rg8unorm = 0x00000008,
- shaderc_spvc_storage_texture_format_rg8snorm = 0x00000009,
- shaderc_spvc_storage_texture_format_rg8uint = 0x0000000a,
- shaderc_spvc_storage_texture_format_rg8sint = 0x0000000b,
- shaderc_spvc_storage_texture_format_r32float = 0x0000000c,
- shaderc_spvc_storage_texture_format_r32uint = 0x0000000d,
- shaderc_spvc_storage_texture_format_r32sint = 0x0000000e,
- shaderc_spvc_storage_texture_format_rg16uint = 0x0000000f,
- shaderc_spvc_storage_texture_format_rg16sint = 0x00000010,
- shaderc_spvc_storage_texture_format_rg16float = 0x00000011,
- shaderc_spvc_storage_texture_format_rgba8unorm = 0x00000012,
- shaderc_spvc_storage_texture_format_rgba8unormsrgb = 0x00000013,
- shaderc_spvc_storage_texture_format_rgba8snorm = 0x00000014,
- shaderc_spvc_storage_texture_format_rgba8uint = 0x00000015,
- shaderc_spvc_storage_texture_format_rgba8sint = 0x00000016,
- shaderc_spvc_storage_texture_format_bgra8unorm = 0x00000017,
- shaderc_spvc_storage_texture_format_bgra8unormsrgb = 0x00000018,
- shaderc_spvc_storage_texture_format_rgb10a2unorm = 0x00000019,
- shaderc_spvc_storage_texture_format_rg11b10float = 0x0000001A,
- shaderc_spvc_storage_texture_format_rg32float = 0x0000001B,
- shaderc_spvc_storage_texture_format_rg32uint = 0x0000001C,
- shaderc_spvc_storage_texture_format_rg32sint = 0x0000001D,
- shaderc_spvc_storage_texture_format_rgba16uint = 0x0000001E,
- shaderc_spvc_storage_texture_format_rgba16sint = 0x0000001F,
- shaderc_spvc_storage_texture_format_rgba16float = 0x00000020,
- shaderc_spvc_storage_texture_format_rgba32float = 0x00000021,
- shaderc_spvc_storage_texture_format_rgba32uint = 0x00000022,
- shaderc_spvc_storage_texture_format_rgba32sint = 0x00000023,
- shaderc_spvc_storage_texture_format_depth32float = 0x00000024,
- shaderc_spvc_storage_texture_format_depth24plus = 0x00000025,
- shaderc_spvc_storage_texture_format_depth24plusstencil8 = 0x00000026,
- shaderc_spvc_storage_texture_format_bc1rgbaunorm = 0x00000027,
- shaderc_spvc_storage_texture_format_bc1rgbaunormsrgb = 0x00000028,
- shaderc_spvc_storage_texture_format_bc2rgbaunorm = 0x00000029,
- shaderc_spvc_storage_texture_format_bc2rgbaunormsrgb = 0x0000002A,
- shaderc_spvc_storage_texture_format_bc3rgbaunorm = 0x0000002B,
- shaderc_spvc_storage_texture_format_bc3rgbaunormsrgb = 0x0000002C,
- shaderc_spvc_storage_texture_format_bc4runorm = 0x0000002D,
- shaderc_spvc_storage_texture_format_bc4rsnorm = 0x0000002E,
- shaderc_spvc_storage_texture_format_bc5rgunorm = 0x0000002F,
- shaderc_spvc_storage_texture_format_bc5rgsnorm = 0x00000030,
- shaderc_spvc_storage_texture_format_bc6hrgbufloat = 0x00000031,
- shaderc_spvc_storage_texture_format_bc6hrgbsfloat = 0x00000032,
- shaderc_spvc_storage_texture_format_bc7rgbaunorm = 0x00000033,
- shaderc_spvc_storage_texture_format_bc7rgbaunormsrgb = 0x00000034,
-} shaderc_spvc_storage_texture_format;
-
-typedef enum {
- shaderc_spvc_spv_env_universal_1_0,
- shaderc_spvc_spv_env_vulkan_1_0,
- shaderc_spvc_spv_env_universal_1_1,
- shaderc_spvc_spv_env_opencl_2_1,
- shaderc_spvc_spv_env_opencl_2_2,
- shaderc_spvc_spv_env_opengl_4_0,
- shaderc_spvc_spv_env_opengl_4_1,
- shaderc_spvc_spv_env_opengl_4_2,
- shaderc_spvc_spv_env_opengl_4_3,
- shaderc_spvc_spv_env_opengl_4_5,
- shaderc_spvc_spv_env_universal_1_2,
- shaderc_spvc_spv_env_opencl_1_2,
- shaderc_spvc_spv_env_opencl_embedded_1_2,
- shaderc_spvc_spv_env_opencl_2_0,
- shaderc_spvc_spv_env_opencl_embedded_2_0,
- shaderc_spvc_spv_env_opencl_embedded_2_1,
- shaderc_spvc_spv_env_opencl_embedded_2_2,
- shaderc_spvc_spv_env_universal_1_3,
- shaderc_spvc_spv_env_vulkan_1_1,
- shaderc_spvc_spv_env_webgpu_0,
- shaderc_spvc_spv_env_universal_1_4,
- shaderc_spvc_spv_env_vulkan_1_1_spirv_1_4,
- shaderc_spvc_spv_env_universal_1_5,
- shaderc_spvc_spv_env_vulkan_1_2,
-} shaderc_spvc_spv_env;
-
-// An opaque handle to an object that manages all compiler state.
-typedef struct shaderc_spvc_context* shaderc_spvc_context_t;
-
-typedef struct {
- uint32_t combined_id;
- uint32_t image_id;
- uint32_t sampler_id;
-} shaderc_spvc_combined_image_sampler;
-
-typedef struct {
- shaderc_spvc_execution_model stage;
- uint32_t desc_set;
- uint32_t binding;
- uint32_t msl_buffer;
- uint32_t msl_texture;
- uint32_t msl_sampler;
-} shaderc_spvc_msl_resource_binding;
-
-typedef struct {
- uint32_t x;
- uint32_t y;
- uint32_t z;
- uint32_t constant;
-} shaderc_spvc_workgroup_size;
-
-typedef struct {
- uint32_t set;
- uint32_t binding;
- uint32_t id;
- uint32_t base_type_id;
- shaderc_spvc_binding_type binding_type;
- shaderc_spvc_texture_view_dimension texture_dimension;
- shaderc_spvc_texture_format_type texture_component_type;
- bool multisampled;
- shaderc_spvc_storage_texture_format storage_texture_format;
- uint64_t minimum_buffer_size;
-} shaderc_spvc_binding_info;
-
-typedef struct {
- uint32_t id;
- bool has_location;
- uint32_t location;
-} shaderc_spvc_resource_location_info;
-
-typedef struct {
- uint32_t location;
- shaderc_spvc_texture_format_type type;
-} shaderc_spvc_resource_type_info;
-
-// Create a spvc state handle. A return of NULL indicates that there was an
-// error. Any function operating on a *_context_t must offer the basic
-// thread-safety guarantee.
-// [http://herbsutter.com/2014/01/13/gotw-95-solution-thread-safety-and-synchronization/]
-// That is: concurrent invocation of these functions on DIFFERENT objects needs
-// no synchronization; concurrent invocation of these functions on the SAME
-// object requires synchronization IF AND ONLY IF some of them take a non-const
-// argument.
-SHADERC_EXPORT shaderc_spvc_context_t shaderc_spvc_context_create(void);
-
-// Release resources. After this the handle cannot be used.
-SHADERC_EXPORT void shaderc_spvc_context_destroy(
- shaderc_spvc_context_t context);
-
-// Get validation/compilation error or informational messages.
-SHADERC_EXPORT const char* shaderc_spvc_context_get_messages(
- const shaderc_spvc_context_t context);
-
-// EXPERIMENTAL
-// Get spirv_cross compiler reference, does NOT transfer ownership.
-// Return type is actually spirv_cross::Compiler*, but cannot have that in the
-// C API.
-// This is being exposed temporarily to ease integration of spvc into Dawn, but
-// this is will be removed in the future without warning.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_context_get_compiler(
- const shaderc_spvc_context_t context, void** compiler);
-
-// If true, use spvc built in parser to generate IR for spirv-cross, otherwise
-// use spirv-cross's implementation.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_context_set_use_spvc_parser(
- shaderc_spvc_context_t context, bool b);
-
-// An opaque handle to an object that manages options to a single compilation
-// result.
-typedef struct shaderc_spvc_compile_options* shaderc_spvc_compile_options_t;
-
-// Creates default compiler options.
-// A return of NULL indicates that there was an error initializing the options.
-// Any function operating on shaderc_spvc_compile_options_t must offer the
-// basic thread-safety guarantee.
-SHADERC_EXPORT shaderc_spvc_compile_options_t
-shaderc_spvc_compile_options_create(shaderc_spvc_spv_env source_env,
- shaderc_spvc_spv_env target_env);
-
-// Returns a copy of the given options.
-SHADERC_EXPORT shaderc_spvc_compile_options_t
-shaderc_spvc_compile_options_clone(
- const shaderc_spvc_compile_options_t options);
-
-// Destroys the compilation options. It is invalid to use the given
-// option object in any future calls. It is safe to pass
-// NULL to this function, and doing such will have no effect.
-SHADERC_EXPORT void shaderc_spvc_compile_options_destroy(
- shaderc_spvc_compile_options_t options);
-
-// DEPRECATED
-// Sets the source shader environment, affecting which warnings or errors will
-// be issued during validation.
-// Default value for environment is Vulkan 1.0.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_source_env(
- shaderc_spvc_compile_options_t options, shaderc_target_env env,
- shaderc_env_version version);
-
-// DEPRECATED
-// Sets the target shader environment, if this is different from the source
-// environment, then a transform between the environments will be performed if
-// possible. Currently only WebGPU <-> Vulkan 1.1 are defined.
-// Default value for environment is Vulkan 1.0.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_target_env(
- shaderc_spvc_compile_options_t options, shaderc_target_env env,
- shaderc_env_version version);
-
-// Sets the entry point.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_entry_point(
- shaderc_spvc_compile_options_t options, const char* entry_point);
-
-// If true, unused variables will not appear in the output.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_remove_unused_variables(
- shaderc_spvc_compile_options_t options, bool b);
-
-// If true, enable robust buffer access pass in the spirv-opt, meaning:
-// Inject code to clamp indexed accesses to buffers and internal
-// arrays, providing guarantees satisfying Vulkan's robustBufferAccess rules.
-// This is useful when an implementation does not support robust-buffer access
-// as a driver option.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_robust_buffer_access_pass(
- shaderc_spvc_compile_options_t options, bool b);
-
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_emit_line_directives(
- shaderc_spvc_compile_options_t options, bool b);
-
-// If true, Vulkan GLSL features are used instead of GL-compatible features.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_vulkan_semantics(
- shaderc_spvc_compile_options_t options, bool b);
-
-// If true, gl_PerVertex is explicitly redeclared in vertex, geometry and
-// tessellation shaders. The members of gl_PerVertex is determined by which
-// built-ins are declared by the shader.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_separate_shader_objects(
- shaderc_spvc_compile_options_t options, bool b);
-
-// Flatten uniform or push constant variable into (i|u)vec4 array.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_flatten_ubo(
- shaderc_spvc_compile_options_t options, bool b);
-
-// Set GLSL language version. Default is 450 (i.e. 4.5).
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_glsl_language_version(
- shaderc_spvc_compile_options_t options, uint32_t version);
-
-// If true, flatten multidimensional arrays, e.g. foo[a][b][c] -> foo[a*b*c].
-// Default is false.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_flatten_multidimensional_arrays(
- shaderc_spvc_compile_options_t options, bool b);
-
-// If true, initialize new variables from cross-compile to 0 if possible.
-// Default is false.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_force_zero_initialized_variables(
- shaderc_spvc_compile_options_t options, bool b);
-
-// Force interpretion as ES, or not. Default is to detect from source.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_es(
- shaderc_spvc_compile_options_t options, bool b);
-
-// If true, emit push constants as uniform buffer objects. Default is false.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_glsl_emit_push_constant_as_ubo(
- shaderc_spvc_compile_options_t options, bool b);
-
-// Set MSL language version. Default is 10200 (i.e. 1.2).
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_msl_language_version(
- shaderc_spvc_compile_options_t options, uint32_t version);
-
-// If true, swizzle MSL texture samples. Default is false.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_msl_swizzle_texture_samples(
- shaderc_spvc_compile_options_t options, bool b);
-
-// Choose MSL platform. Default is MacOS.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_msl_platform(
- shaderc_spvc_compile_options_t options, shaderc_spvc_msl_platform platform);
-
-// If true, pad MSL fragment output. Default is false.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_msl_pad_fragment_output(
- shaderc_spvc_compile_options_t options, bool b);
-
-// If true, capture MSL output to buffer. Default is false.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_msl_capture(
- shaderc_spvc_compile_options_t options, bool b);
-
-// If true, flip the Y-coord of the built-in "TessCoord." Default is top left.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_msl_domain_lower_left(
- shaderc_spvc_compile_options_t options, bool b);
-
-// Enable use of MSL 2.0 indirect argument buffers. Default is not to use them.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_msl_argument_buffers(
- shaderc_spvc_compile_options_t options, bool b);
-
-// When using MSL argument buffers, force "classic" MSL 1.0 binding for the
-// given descriptor sets. This corresponds to VK_KHR_push_descriptor in Vulkan.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_msl_discrete_descriptor_sets(
- shaderc_spvc_compile_options_t options, const uint32_t* descriptors,
- size_t num_descriptors);
-
-// Set whether or not PointSize builtin is used for MSL shaders
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_msl_enable_point_size_builtin(
- shaderc_spvc_compile_options_t options, bool b);
-
-// Set the index in the buffer size in the buffer for MSL
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_msl_buffer_size_buffer_index(
- shaderc_spvc_compile_options_t options, uint32_t index);
-
-// Set the additional fixed sample mask for MSL
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_msl_additional_fixed_sample_mask(
- shaderc_spvc_compile_options_t options, uint32_t mask);
-
-// Set HLSL shader model. Default is 30.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_hlsl_shader_model(
- shaderc_spvc_compile_options_t options, uint32_t model);
-
-// If true, ignore PointSize. Default is false.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_hlsl_point_size_compat(
- shaderc_spvc_compile_options_t options, bool b);
-
-// If true, ignore PointCoord. Default is false.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_hlsl_point_coord_compat(
- shaderc_spvc_compile_options_t options, bool b);
-
-// If true, enable 16-bit types. Default is false.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_hlsl_enable_16bit_types(
- shaderc_spvc_compile_options_t options, bool b);
-
-// If true, set non-writable storage images to be SRV, see spirv_hlsl.hpp in
-// SPIRV-Cross for more details.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_hlsl_nonwritable_uav_texture_as_srv(
- shaderc_spvc_compile_options_t options, bool b);
-
-// Set storage buffers to be always declared as UAV, even if the read-only
-// declaration is used, see spirv_hlsl.hpp in SPIRV-Cross for more details.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_set_hlsl_force_storage_buffer_as_uav(
- const shaderc_spvc_context_t context, uint32_t desc_set, uint32_t binding);
-
-// If true (default is false):
-// GLSL: map depth from Vulkan/D3D style to GL style, i.e. [ 0,w] -> [-w,w]
-// MSL : map depth from GL style to Vulkan/D3D style, i.e. [-w,w] -> [ 0,w]
-// HLSL: map depth from GL style to Vulkan/D3D style, i.e. [-w,w] -> [ 0,w]
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_options_set_fixup_clipspace(
- shaderc_spvc_compile_options_t options, bool b);
-
-// If true invert gl_Position.y or equivalent. Default is false.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_flip_vert_y(
- shaderc_spvc_compile_options_t options, bool b);
-
-// Set if validation should be performed. Default is true.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_validate(
- shaderc_spvc_compile_options_t options, bool b);
-
-// Set if optimization should be performed. Default is true.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_compile_options_set_optimize(
- shaderc_spvc_compile_options_t options, bool b);
-
-// Fill options with given data. Return amount of data used, or zero
-// if not enough data was given.
-SHADERC_EXPORT size_t shaderc_spvc_compile_options_set_for_fuzzing(
- shaderc_spvc_compile_options_t options, const uint8_t* data, size_t size);
-
-// An opaque handle to the results of a call to any
-// shaderc_spvc_*_compile_*() function.
-typedef struct shaderc_spvc_compilation_result*
- shaderc_spvc_compilation_result_t;
-
-// Takes SPIR-V as a sequence of 32-bit words, validates it, then creates the
-// internal compiler for translating to GLSL and performing reflection.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_initialize_for_glsl(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options);
-
-// Takes SPIR-V as a sequence of 32-bit words, validates it, then creates the
-// internal compiler for translating to HLSL and performing reflection.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_initialize_for_hlsl(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options);
-
-// Takes SPIR-V as a sequence of 32-bit words, validates it, then creates the
-// internal compiler for translating to MSL and performing reflection.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_initialize_for_msl(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options);
-
-// Takes SPIR-V as a sequence of 32-bit words, validates it, then creates the
-// internal compiler for translating to Vulkan and performing reflection.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_initialize_for_vulkan(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options);
-
-// Given an initialized compiler, generates a shader of the appropriate
-// language.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_compile_shader(const shaderc_spvc_context_t context,
- shaderc_spvc_compilation_result_t result);
-
-// Get spirv_cross decoration (added for GLSL API support in Dawn)
-// Given an id and a decoration, result is sent out through |argument|
-// if |id| does not exist, returns an error.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_decoration(
- const shaderc_spvc_context_t context, uint32_t id,
- shaderc_spvc_decoration decoration, uint32_t* value);
-
-// Unset spirv_cross decoration (added for GLSL API support in Dawn)
-// Given an id and a decoration. Assuming |id| is valid.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_unset_decoration(const shaderc_spvc_context_t context, uint32_t id,
- shaderc_spvc_decoration decoration);
-
-// Set |name| on a given |id| (added for GLSL API support in Dawn)
-// Assuming |id| is valid.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_set_name(
- const shaderc_spvc_context_t context, uint32_t id, const char* name);
-
-// spirv-cross comment:
-// Analyzes all separate image and samplers used from the currently selected
-// entry point, and re-routes them all to a combined image sampler instead.
-// (added for GLSL API support in Dawn)
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_build_combined_image_samplers(
- const shaderc_spvc_context_t context);
-
-// Returns the combined image samplers.
-
-// If |samples| is NULL, then num_samplers is set, and no data is copied.
-// The caller is responsible for |samplers| being large enough to
-// contain all of the data.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_combined_image_samplers(
- const shaderc_spvc_context_t context,
- shaderc_spvc_combined_image_sampler* samplers, size_t* num_samplers);
-
-// Set spirv_cross decoration (added for HLSL support in Dawn)
-// Given an id, decoration and argument, the decoration flag on the id is set
-// Assuming id is valid.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_set_decoration(
- const shaderc_spvc_context_t context, uint32_t id,
- shaderc_spvc_decoration decoration, uint32_t argument);
-
-// Adds a binding to indicate the MSL buffer, texture or sampler index to use
-// for a particular SPIR-V description set and binding.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_add_msl_resource_binding(
- const shaderc_spvc_context_t context,
- const shaderc_spvc_msl_resource_binding binding);
-
-// Gets workgroup size for an entry point defined by a given execution model and
-// function name.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_workgroup_size(
- const shaderc_spvc_context_t context, const char* function_name,
- shaderc_spvc_execution_model execution_model,
- shaderc_spvc_workgroup_size* workgroup_size);
-
-// Gets whether or not the shader needes a buffer of buffer sizes.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_needs_buffer_size_buffer(
- const shaderc_spvc_context_t context, bool* b);
-
-// Gets the execution model for the shader parsed by the compiler.
-SHADERC_EXPORT shaderc_spvc_status
-shaderc_spvc_get_execution_model(const shaderc_spvc_context_t context,
- shaderc_spvc_execution_model* execution_model);
-
-// Gets the number of push constants buffers used by the shader.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_push_constant_buffer_count(
- const shaderc_spvc_context_t context, size_t* count);
-
-// Fetches all of the binding info for a given shader resource.
-// If |bindings| is null, then |binding_count| is populated with the number of
-// entries that would have been written out.
-// The caller is responsible for ensuring that |bindings| has enough space
-// allocated to contain all of the entries.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_binding_info(
- const shaderc_spvc_context_t context, shaderc_spvc_shader_resource resource,
- shaderc_spvc_binding_type binding_type, shaderc_spvc_binding_info* bindings,
- size_t* binding_count);
-
-// Fetches the Location decoration information for the stage inputs.
-// If |locations| is null, then |location_count| is populated with the number of
-// entries that would have been written out.
-// The caller is responsible for ensuring that |locations| has enough space
-// allocated to contain all of the entries.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_input_stage_location_info(
- const shaderc_spvc_context_t context,
- shaderc_spvc_resource_location_info* locations, size_t* location_count);
-
-// Fetches the Location decoration information for the stage outputs.
-// If |locations| is null, then |location_count| is populated with the number of
-// entries that would have been written out.
-// The caller is responsible for ensuring that |locations| has enough space
-// allocated to contain all of the entries.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_output_stage_location_info(
- const shaderc_spvc_context_t context,
- shaderc_spvc_resource_location_info* locations, size_t* location_count);
-
-// Fetches the type information for the stage outputs.
-// If |types| is null, then |type_count| is populated with the number of
-// entries that would have been written out.
-// The caller is responsible for ensuring that |types| has enough space
-// allocated to contain all of the entries.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_get_output_stage_type_info(
- const shaderc_spvc_context_t context,
- shaderc_spvc_resource_type_info* types, size_t* type_count);
-
-// The following functions, operating on shaderc_spvc_compilation_result_t
-// objects, offer only the basic thread-safety guarantee.
-
-// Creates an instant of compiliation result data structure.
-// A return of NULL indicates that there was an error creating the structure.
-// Any function operating on shaderc_spvc_compilation_result_t must offer the
-// basic thread-safety guarantee.
-SHADERC_EXPORT shaderc_spvc_compilation_result_t
-shaderc_spvc_result_create(void);
-
-// Destroys the resources held by the result object. It is invalid to use the
-// result object for any further operations.
-SHADERC_EXPORT void shaderc_spvc_result_destroy(
- shaderc_spvc_compilation_result_t result);
-
-// Get validation/compilation result as a string. This is only supported
-// compiling to GLSL, HSL, and MSL.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_result_get_string_output(
- const shaderc_spvc_compilation_result_t result, const char** str);
-
-// Get validation/compilation result as a binary buffer. This is only supported
-// compiling to Vulkan.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_result_get_binary_output(
- const shaderc_spvc_compilation_result_t result, const uint32_t** data);
-
-// Get length of validation/compilation result as a binary buffer. This is only
-// supported compiling to Vulkan.
-SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_result_get_binary_length(
- const shaderc_spvc_compilation_result_t result, uint32_t* len);
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-
-#endif // SHADERC_SPVC_H_
diff --git a/libshaderc_spvc/include/spvc/spvc.hpp b/libshaderc_spvc/include/spvc/spvc.hpp
deleted file mode 100644
index 33e717d..0000000
--- a/libshaderc_spvc/include/spvc/spvc.hpp
+++ /dev/null
@@ -1,604 +0,0 @@
-// Copyright 2018 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef SHADERC_SPVC_HPP_
-#define SHADERC_SPVC_HPP_
-
-#include <functional>
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "spvc.h"
-
-namespace shaderc_spvc {
-
-// A CompilationResult contains the compiler output, compilation status,
-// and messages.
-//
-// The compiler output is stored as an array of elements and accessed
-// via random access iterators provided by cbegin() and cend(). The iterators
-// are contiguous in the sense of "Contiguous Iterators: A Refinement of
-// Random Access Iterators", Nevin Liber, C++ Library Evolution Working
-// Group Working Paper N3884.
-// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3884.pdf
-//
-// Methods begin() and end() are also provided to enable range-based for.
-// They are synonyms to cbegin() and cend(), respectively.
-class CompilationResult {
- public:
- // Upon creation, the CompilationResult takes ownership of the
- // shaderc_spvc_compilation_result instance. During destruction of the
- // CompilationResult, the shaderc_spvc_compilation_result will be released.
- explicit CompilationResult()
- : result_(shaderc_spvc_result_create(), shaderc_spvc_result_destroy) {}
- ~CompilationResult() {}
-
- CompilationResult(CompilationResult&& other)
- : result_(nullptr, shaderc_spvc_result_destroy) {
- *this = std::move(other);
- }
-
- CompilationResult& operator=(CompilationResult&& other) {
- result_.reset(other.result_.release());
- return *this;
- }
-
- shaderc_spvc_status GetStringOutput(std::string* str) const {
- if (!str) return shaderc_spvc_status_invalid_out_param;
- const char* inner_str;
- shaderc_spvc_status status =
- shaderc_spvc_result_get_string_output(result_.get(), &inner_str);
- if (status != shaderc_spvc_status_success) {
- return status;
- }
- *str = std::string(inner_str);
- return shaderc_spvc_status_success;
- }
-
- shaderc_spvc_status GetBinaryOutput(std::vector<uint32_t>* data) const {
- if (!data) return shaderc_spvc_status_invalid_out_param;
- const uint32_t* binary_output;
- shaderc_spvc_status status =
- shaderc_spvc_result_get_binary_output(result_.get(), &binary_output);
- if (status != shaderc_spvc_status_success) {
- return status;
- }
- uint32_t binary_length;
- status =
- shaderc_spvc_result_get_binary_length(result_.get(), &binary_length);
- if (status != shaderc_spvc_status_success) {
- return status;
- }
- if (!binary_output || !binary_length) {
- *data = std::vector<uint32_t>();
- } else {
- *data =
- std::vector<uint32_t>(binary_output, binary_output + binary_length);
- }
- return shaderc_spvc_status_success;
- }
-
- private:
- friend class Context;
-
- CompilationResult(const CompilationResult& other) = delete;
- CompilationResult& operator=(const CompilationResult& other) = delete;
-
- std::unique_ptr<shaderc_spvc_compilation_result,
- void (*)(shaderc_spvc_compilation_result_t)>
- result_;
-};
-
-// Contains any options that can have default values for a compilation.
-class CompileOptions {
- public:
- CompileOptions(shaderc_spvc_spv_env source_env,
- shaderc_spvc_spv_env target_env)
- : options_(shaderc_spvc_compile_options_create(source_env, target_env),
- shaderc_spvc_compile_options_destroy) {}
- // DEPRECATED
- CompileOptions()
- : CompileOptions(shaderc_spvc_spv_env_universal_1_0,
- shaderc_spvc_spv_env_universal_1_0) {}
- CompileOptions(const CompileOptions& other)
- : options_(nullptr, shaderc_spvc_compile_options_destroy) {
- options_.reset(shaderc_spvc_compile_options_clone(other.options_.get()));
- }
-
- CompileOptions(CompileOptions&& other)
- : options_(nullptr, shaderc_spvc_compile_options_destroy) {
- options_.reset(other.options_.release());
- }
-
- // DEPRECATED
- // Set the environment for the input SPIR-V. Default is Vulkan 1.0.
- shaderc_spvc_status SetSourceEnvironment(shaderc_target_env env,
- shaderc_env_version version) {
- return shaderc_spvc_compile_options_set_source_env(options_.get(), env,
- version);
- }
-
- // DEPRECATED
- // Set the target environment for the SPIR-V to be cross-compiled. If this is
- // different then the source a transformation will need to be applied.
- // Currently only Vulkan 1.1 <-> WebGPU transforms are defined. Default is
- // Vulkan 1.0.
- shaderc_spvc_status SetTargetEnvironment(shaderc_target_env env,
- shaderc_env_version version) {
- return shaderc_spvc_compile_options_set_target_env(options_.get(), env,
- version);
- }
-
- // Set the entry point.
- shaderc_spvc_status SetEntryPoint(const std::string& entry_point) {
- return shaderc_spvc_compile_options_set_entry_point(options_.get(),
- entry_point.c_str());
- }
-
- // If true, unused variables will not appear in the output.
- shaderc_spvc_status SetRemoveUnusedVariables(bool b) {
- return shaderc_spvc_compile_options_set_remove_unused_variables(
- options_.get(), b);
- }
-
- // If true, enable robust buffer access pass in the spirv-opt, meaning:
- // Inject code to clamp indexed accesses to buffers and internal
- // arrays, providing guarantees satisfying Vulkan's robustBufferAccess rules.
- // This is useful when an implementation does not support robust-buffer access
- // as a driver option.
- shaderc_spvc_status SetRobustBufferAccessPass(bool b) {
- return shaderc_spvc_compile_options_set_robust_buffer_access_pass(
- options_.get(), b);
- }
-
- shaderc_spvc_status SetEmitLineDirectives(bool b) {
- return shaderc_spvc_compile_options_set_emit_line_directives(options_.get(),
- b);
- }
- // If true, Vulkan GLSL features are used instead of GL-compatible features.
- shaderc_spvc_status SetVulkanSemantics(bool b) {
- return shaderc_spvc_compile_options_set_vulkan_semantics(options_.get(), b);
- }
-
- // If true, gl_PerVertex is explicitly redeclared in vertex, geometry and
- // tessellation shaders. The members of gl_PerVertex is determined by which
- // built-ins are declared by the shader.
- shaderc_spvc_status SetSeparateShaderObjects(bool b) {
- return shaderc_spvc_compile_options_set_separate_shader_objects(
- options_.get(), b);
- }
-
- // Flatten uniform or push constant variable into (i|u)vec4 array.
- shaderc_spvc_status SetFlattenUbo(bool b) {
- return shaderc_spvc_compile_options_set_flatten_ubo(options_.get(), b);
- }
-
- // Which GLSL version should be produced. Default is 450 (i.e. 4.5).
- shaderc_spvc_status SetGLSLLanguageVersion(uint32_t version) {
- return shaderc_spvc_compile_options_set_glsl_language_version(
- options_.get(), version);
- }
-
- // If true, flatten multidimensional arrays, e.g. foo[a][b][c] -> foo[a*b*c].
- // Default is false.
- shaderc_spvc_status SetFlattenMultidimensionalArrays(bool b) {
- return shaderc_spvc_compile_options_set_flatten_multidimensional_arrays(
- options_.get(), b);
- }
-
- // If true, initialize new variables from cross-compile to 0 if possible.
- // Default is false.
- shaderc_spvc_status SetForceZeroInitializedVariables(bool b) {
- return shaderc_spvc_compile_options_set_force_zero_initialized_variables(
- options_.get(), b);
- }
-
- // Force interpretion as ES, or not. Default is to detect from source.
- shaderc_spvc_status SetES(bool b) {
- return shaderc_spvc_compile_options_set_es(options_.get(), b);
- }
-
- // If true, emit push constants as uniform buffer objects. Default is false.
- shaderc_spvc_status SetGLSLEmitPushConstantAsUBO(bool b) {
- return shaderc_spvc_compile_options_set_glsl_emit_push_constant_as_ubo(
- options_.get(), b);
- }
-
- // Which MSL version should be produced. Default is 10200 (i.e. 1.2).
- shaderc_spvc_status SetMSLLanguageVersion(uint32_t version) {
- return shaderc_spvc_compile_options_set_msl_language_version(options_.get(),
- version);
- }
-
- // If true, swizzle MSL texture samples. Default is false.
- shaderc_spvc_status SetMSLSwizzleTextureSamples(bool b) {
- return shaderc_spvc_compile_options_set_msl_swizzle_texture_samples(
- options_.get(), b);
- }
-
- // Choose MSL platform. Default is MacOS.
- shaderc_spvc_status SetMSLPlatform(shaderc_spvc_msl_platform platform) {
- return shaderc_spvc_compile_options_set_msl_platform(options_.get(),
- platform);
- }
-
- // If true, pad MSL fragment output. Default is false.
- shaderc_spvc_status SetMSLPadFragmentOutput(bool b) {
- return shaderc_spvc_compile_options_set_msl_pad_fragment_output(
- options_.get(), b);
- }
-
- // If true, capture MSL output to buffer. Default is false.
- shaderc_spvc_status SetMSLCapture(bool b) {
- return shaderc_spvc_compile_options_set_msl_capture(options_.get(), b);
- }
-
- // If true, flip the Y-coord of the built-in "TessCoord." Default is top
- // left.
- shaderc_spvc_status SetMSLDomainLowerLeft(bool b) {
- return shaderc_spvc_compile_options_set_msl_domain_lower_left(
- options_.get(), b);
- }
-
- // Enable use of MSL 2.0 indirect argument buffers. Default is not to use
- // them.
- shaderc_spvc_status SetMSLArgumentBuffers(bool b) {
- return shaderc_spvc_compile_options_set_msl_argument_buffers(options_.get(),
- b);
- }
-
- // When using MSL argument buffers, force "classic" MSL 1.0 binding for the
- // given descriptor sets. This corresponds to VK_KHR_push_descriptor in
- // Vulkan.
- shaderc_spvc_status SetMSLDiscreteDescriptorSets(
- const std::vector<uint32_t> descriptors) {
- return shaderc_spvc_compile_options_set_msl_discrete_descriptor_sets(
- options_.get(), descriptors.data(), descriptors.size());
- }
-
- // Set whether or not PointSize builtin is used for MSL shaders
- shaderc_spvc_status SetMSLEnablePointSizeBuiltIn(bool b) {
- return shaderc_spvc_compile_options_set_msl_enable_point_size_builtin(
- options_.get(), b);
- }
-
- // Set the index in the buffer size in the buffer for MSL
- shaderc_spvc_status SetMSLBufferSizeBufferIndex(uint32_t index) {
- return shaderc_spvc_compile_options_set_msl_buffer_size_buffer_index(
- options_.get(), index);
- }
-
- // Set the additional fixed sample mask for MSL
- shaderc_spvc_status SetMSLAdditionalFixedSampleMask(uint32_t mask) {
- return shaderc_spvc_compile_options_set_msl_additional_fixed_sample_mask(
- options_.get(), mask);
- }
-
- // Which HLSL shader model should be used. Default is 30.
- shaderc_spvc_status SetHLSLShaderModel(uint32_t model) {
- return shaderc_spvc_compile_options_set_hlsl_shader_model(options_.get(),
- model);
- }
-
- // If true, ignore PointSize. Default is false.
- shaderc_spvc_status SetHLSLPointSizeCompat(bool b) {
- return shaderc_spvc_compile_options_set_hlsl_point_size_compat(
- options_.get(), b);
- }
-
- // If true, ignore PointCoord. Default is false.
- shaderc_spvc_status SetHLSLPointCoordCompat(bool b) {
- return shaderc_spvc_compile_options_set_hlsl_point_coord_compat(
- options_.get(), b);
- }
-
- // If true, enable 16-bit types. Default is false.
- shaderc_spvc_status SetHLSLEnable16BitTypes(bool b) {
- return shaderc_spvc_compile_options_set_hlsl_enable_16bit_types(
- options_.get(), b);
- }
-
- // If true, set non-writable storage images to be SRV, see spirv_hlsl.hpp in
- // SPIRV-Cross for more details.
- shaderc_spvc_status SetHLSLNonWritableUAVTextureAsSRV(bool b) {
- return shaderc_spvc_compile_options_set_hlsl_nonwritable_uav_texture_as_srv(
- options_.get(), b);
- }
-
- // If true (default is false):
- // GLSL: map depth from Vulkan/D3D style to GL style, i.e. [ 0,w] -> [-w,w]
- // MSL : map depth from GL style to Vulkan/D3D style, i.e. [-w,w] -> [ 0,w]
- // HLSL: map depth from GL style to Vulkan/D3D style, i.e. [-w,w] -> [ 0,w]
- shaderc_spvc_status SetFixupClipspace(bool b) {
- return shaderc_spvc_compile_options_set_fixup_clipspace(options_.get(), b);
- }
-
- // If true invert gl_Position.y or equivalent. Default is false.
- shaderc_spvc_status SetFlipVertY(bool b) {
- return shaderc_spvc_compile_options_set_flip_vert_y(options_.get(), b);
- }
-
- // If true validate input and intermediate source. Default is true.
- shaderc_spvc_status SetValidate(bool b) {
- return shaderc_spvc_compile_options_set_validate(options_.get(), b);
- }
-
- // If true optimize input and intermediate source. Default is true.
- shaderc_spvc_status SetOptimize(bool b) {
- return shaderc_spvc_compile_options_set_optimize(options_.get(), b);
- }
-
- // Fill options with given data. Return amount of data used, or zero
- // if not enough data was given.
- size_t SetForFuzzing(const uint8_t* data, size_t size) {
- return shaderc_spvc_compile_options_set_for_fuzzing(options_.get(), data,
- size);
- }
-
- private:
- CompileOptions& operator=(const CompileOptions& other) = delete;
- std::unique_ptr<shaderc_spvc_compile_options,
- void (*)(shaderc_spvc_compile_options_t)>
- options_;
-
- friend class Context;
-};
-
-// The compilation context for compiling SPIR-V.
-class Context {
- public:
- Context()
- : context_(shaderc_spvc_context_create(), shaderc_spvc_context_destroy) {}
-
- Context(Context&& other) : context_(nullptr, shaderc_spvc_context_destroy) {
- context_.reset(other.context_.release());
- }
-
- bool IsValid() const { return context_ != nullptr; }
-
- // Returns logged messages from operations
- const std::string GetMessages() const {
- return shaderc_spvc_context_get_messages(context_.get());
- }
-
- // EXPERIMENTAL
- // Returns the internal spirv_cross compiler reference, does NOT transfer
- // ownership.
- // This is being exposed temporarily to ease integration of spvc into Dawn,
- // but this is will be removed in the future without warning.
- shaderc_spvc_status GetCompiler(void** compiler) {
- return shaderc_spvc_context_get_compiler(context_.get(), compiler);
- }
-
- shaderc_spvc_status SetUseSpvcParser(bool b) {
- return shaderc_spvc_context_set_use_spvc_parser(context_.get(), b);
- }
-
- // Initializes state for compiling SPIR-V to GLSL.
- shaderc_spvc_status InitializeForGlsl(const uint32_t* source,
- size_t source_len,
- const CompileOptions& options) const {
- return shaderc_spvc_initialize_for_glsl(context_.get(), source, source_len,
- options.options_.get());
- }
-
- // Initializes state for compiling SPIR-V to HLSL.
- shaderc_spvc_status InitializeForHlsl(const uint32_t* source,
- size_t source_len,
- const CompileOptions& options) const {
- return shaderc_spvc_initialize_for_hlsl(context_.get(), source, source_len,
- options.options_.get());
- }
-
- // Initializes state for compiling SPIR-V to MSL.
- shaderc_spvc_status InitializeForMsl(const uint32_t* source,
- size_t source_len,
- const CompileOptions& options) const {
- return shaderc_spvc_initialize_for_msl(context_.get(), source, source_len,
- options.options_.get());
- }
-
- // Initializes state for compiling SPIR-V to Vulkan.
- shaderc_spvc_status InitializeForVulkan(const uint32_t* source,
- size_t source_len,
- const CompileOptions& options) const {
- return shaderc_spvc_initialize_for_vulkan(
- context_.get(), source, source_len, options.options_.get());
- }
-
- // After initialization compile the shader to desired language.
- shaderc_spvc_status CompileShader(CompilationResult* result) {
- return shaderc_spvc_compile_shader(context_.get(), result->result_.get());
- }
-
- // Set spirv_cross decoration (added for HLSL support in Dawn)
- // Given an id, decoration and argument, the decoration flag on the id is set,
- // assuming id is valid.
- shaderc_spvc_status SetDecoration(uint32_t id,
- shaderc_spvc_decoration decoration,
- uint32_t argument) {
- return shaderc_spvc_set_decoration(context_.get(), id, decoration, argument);
- }
-
- // Get spirv_cross decoration (added for GLSL API support in Dawn).
- // Given an id and a decoration, result is sent out through |argument|
- // if |id| does not exist, returns an error.
- shaderc_spvc_status GetDecoration(uint32_t id,
- shaderc_spvc_decoration decoration,
- uint32_t* argument) {
- return shaderc_spvc_get_decoration(context_.get(), id, decoration, argument);
- }
-
- // Unset spirv_cross decoration (added for GLSL API support in Dawn).
- // Given an id and a decoration. Assuming id is valid.
- shaderc_spvc_status UnsetDecoration(uint32_t id,
- shaderc_spvc_decoration decoration) {
- return shaderc_spvc_unset_decoration(context_.get(), id, decoration);
- }
-
- // spirv-cross comment:
- // Analyzes all separate image and samplers used from the currently selected
- // entry point, and re-routes them all to a combined image sampler instead.
- // (added for GLSL API support in Dawn)
- shaderc_spvc_status BuildCombinedImageSamplers(void) {
- return shaderc_spvc_build_combined_image_samplers(context_.get());
- }
-
- // After call to BuildCombinedImageSamplers, fetch the ids associated with the
- // combined image samplers.
- shaderc_spvc_status GetCombinedImageSamplers(
- std::vector<shaderc_spvc_combined_image_sampler>* samplers) {
- size_t count;
- shaderc_spvc_status status = shaderc_spvc_get_combined_image_samplers(
- context_.get(), nullptr, &count);
- if (status != shaderc_spvc_status_success) return status;
- samplers->resize(count);
- return shaderc_spvc_get_combined_image_samplers(context_.get(),
- samplers->data(), &count);
- }
-
- // set |name| on a given |id| (added for GLSL support in Dawn).
- // Assuming id is valid.
- shaderc_spvc_status SetName(uint32_t id, const std::string& name) {
- return shaderc_spvc_set_name(context_.get(), id, name.c_str());
- }
-
- // Adds a binding to indicate the MSL buffer, texture or sampler index to use
- // for a particular SPIR-V description set and binding.
- shaderc_spvc_status AddMSLResourceBinding(
- const shaderc_spvc_msl_resource_binding binding) {
- return shaderc_spvc_add_msl_resource_binding(context_.get(), binding);
- }
-
- // Gets workgroup size for an entry point defined by a given execution model
- // and function name.
- shaderc_spvc_status GetWorkgroupSize(
- const std::string& function_name,
- shaderc_spvc_execution_model execution_model,
- shaderc_spvc_workgroup_size* workgroup_size) {
- return shaderc_spvc_get_workgroup_size(
- context_.get(), function_name.c_str(), execution_model, workgroup_size);
- }
-
- // Gets whether or not the shader needes a buffer of buffer sizes.
- shaderc_spvc_status NeedsBufferSizeBuffer(bool* b) {
- return shaderc_spvc_needs_buffer_size_buffer(context_.get(), b);
- }
-
- // Gets the execution model for the shader.
- shaderc_spvc_status GetExecutionModel(shaderc_spvc_execution_model* model) {
- return shaderc_spvc_get_execution_model(context_.get(), model);
- }
-
- // Gets the number of push constant buffers used by the shader.
- shaderc_spvc_status GetPushConstantBufferCount(size_t* count) {
- return shaderc_spvc_get_push_constant_buffer_count(context_.get(), count);
- }
-
- // Gets all of the binding info for a given shader resource.
- shaderc_spvc_status GetBindingInfo(
- shaderc_spvc_shader_resource resource,
- shaderc_spvc_binding_type binding_type,
- std::vector<shaderc_spvc_binding_info>* bindings) {
- if (!bindings) {
- return shaderc_spvc_status_invalid_out_param;
- }
-
- size_t binding_count;
- shaderc_spvc_status status = shaderc_spvc_get_binding_info(
- context_.get(), resource, binding_type, nullptr, &binding_count);
- if (status != shaderc_spvc_status_success) {
- return status;
- }
-
- bindings->resize(binding_count);
- return shaderc_spvc_get_binding_info(context_.get(), resource, binding_type,
- bindings->data(), &binding_count);
- }
-
- // Gets the Location decoration information for the stage inputs.
- shaderc_spvc_status GetInputStageLocationInfo(
- std::vector<shaderc_spvc_resource_location_info>* locations) {
- if (!locations) {
- return shaderc_spvc_status_invalid_out_param;
- }
-
- size_t location_count;
- shaderc_spvc_status status = shaderc_spvc_get_input_stage_location_info(
- context_.get(), nullptr, &location_count);
- if (status != shaderc_spvc_status_success) {
- return status;
- }
-
- locations->resize(location_count);
- return shaderc_spvc_get_input_stage_location_info(
- context_.get(), locations->data(), &location_count);
- }
-
- // Gets the Location decoration information for the stage output.
- shaderc_spvc_status GetOutputStageLocationInfo(
- std::vector<shaderc_spvc_resource_location_info>* locations) {
- if (!locations) {
- return shaderc_spvc_status_invalid_out_param;
- }
-
- size_t location_count;
- shaderc_spvc_status status = shaderc_spvc_get_output_stage_location_info(
- context_.get(), nullptr, &location_count);
- if (status != shaderc_spvc_status_success) {
- return status;
- }
-
- locations->resize(location_count);
- return shaderc_spvc_get_output_stage_location_info(
- context_.get(), locations->data(), &location_count);
- }
-
- // Gets the type information for the stage output.
- shaderc_spvc_status GetOutputStageTypeInfo(
- std::vector<shaderc_spvc_resource_type_info>* types) {
- if (!types) {
- return shaderc_spvc_status_invalid_out_param;
- }
-
- size_t type_count;
- shaderc_spvc_status status = shaderc_spvc_get_output_stage_type_info(
- context_.get(), nullptr, &type_count);
- if (status != shaderc_spvc_status_success) {
- return status;
- }
-
- types->resize(type_count);
- return shaderc_spvc_get_output_stage_type_info(context_.get(),
- types->data(), &type_count);
- }
-
- // Set storage buffers to be always declared as UAV, even if the read-only
- // declaration is used, see spirv_hlsl.hpp in SPIRV-Cross for more details.
- shaderc_spvc_status SetHLSLForceStorageBufferAsUAV(uint32_t desc_set, uint32_t binding) {
- return shaderc_spvc_set_hlsl_force_storage_buffer_as_uav(context_.get(), desc_set, binding);
- }
-
- private:
- Context(const Context&) = delete;
- Context& operator=(const Context& other) = delete;
-
- std::unique_ptr<shaderc_spvc_context, void (*)(shaderc_spvc_context_t)>
- context_;
-};
-
-} // namespace shaderc_spvc
-
-#endif // SHADERC_SPVC_HPP_
diff --git a/libshaderc_spvc/src/common_shaders_for_test.h b/libshaderc_spvc/src/common_shaders_for_test.h
deleted file mode 100644
index de514e1..0000000
--- a/libshaderc_spvc/src/common_shaders_for_test.h
+++ /dev/null
@@ -1,110 +0,0 @@
-// Copyright 2018 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef COMMON_SHADERS_FOR_TESTS_H_
-#define COMMON_SHADERS_FOR_TESTS_H_
-
-#ifdef __cplusplus
-#include <cstdint>
-#else
-#include <stdint.h>
-#endif // __cplusplus
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-const char* kSmokeShader =
- " OpCapability Shader\n"
- " %1 = OpExtInstImport \"GLSL.std.450\"\n"
- " OpMemoryModel Logical GLSL450\n"
- " OpEntryPoint Vertex %main \"main\" %outColor %vtxColor\n"
- " OpSource ESSL 310\n"
- " OpSourceExtension "
- "\"GL_GOOGLE_cpp_style_line_directive\"\n"
- " OpSourceExtension \"GL_GOOGLE_include_directive\"\n"
- " OpName %main \"main\"\n"
- " OpName %outColor \"outColor\"\n"
- " OpName %vtxColor \"vtxColor\"\n"
- " OpDecorate %outColor Location 0\n"
- " OpDecorate %vtxColor Location 0\n"
- " %void = OpTypeVoid\n"
- " %3 = OpTypeFunction %void\n"
- " %float = OpTypeFloat 32\n"
- " %v4float = OpTypeVector %float 4\n"
- "%_ptr_Output_v4float = OpTypePointer Output %v4float\n"
- " %outColor = OpVariable %_ptr_Output_v4float Output\n"
- "%_ptr_Input_v4float = OpTypePointer Input %v4float\n"
- " %vtxColor = OpVariable %_ptr_Input_v4float Input\n"
- " %main = OpFunction %void None %3\n"
- " %5 = OpLabel\n"
- " %12 = OpLoad %v4float %vtxColor\n"
- " OpStore %outColor %12\n"
- " OpReturn\n"
- " OpFunctionEnd\n";
-
-const uint32_t kSmokeShaderBinary[] = {
- 0x07230203, 0x00010000, 0x000d0007, 0x0000000d, 0x00000000, 0x00020011,
- 0x00000001, 0x0006000b, 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e,
- 0x00000000, 0x0003000e, 0x00000000, 0x00000001, 0x0007000f, 0x00000000,
- 0x00000004, 0x6e69616d, 0x00000000, 0x00000009, 0x0000000b, 0x00030003,
- 0x00000001, 0x00000136, 0x000a0004, 0x475f4c47, 0x4c474f4f, 0x70635f45,
- 0x74735f70, 0x5f656c79, 0x656e696c, 0x7269645f, 0x69746365, 0x00006576,
- 0x00080004, 0x475f4c47, 0x4c474f4f, 0x6e695f45, 0x64756c63, 0x69645f65,
- 0x74636572, 0x00657669, 0x00040005, 0x00000004, 0x6e69616d, 0x00000000,
- 0x00050005, 0x00000009, 0x4374756f, 0x726f6c6f, 0x00000000, 0x00050005,
- 0x0000000b, 0x43787476, 0x726f6c6f, 0x00000000, 0x00040047, 0x00000009,
- 0x0000001e, 0x00000000, 0x00040047, 0x0000000b, 0x0000001e, 0x00000000,
- 0x00020013, 0x00000002, 0x00030021, 0x00000003, 0x00000002, 0x00030016,
- 0x00000006, 0x00000020, 0x00040017, 0x00000007, 0x00000006, 0x00000004,
- 0x00040020, 0x00000008, 0x00000003, 0x00000007, 0x0004003b, 0x00000008,
- 0x00000009, 0x00000003, 0x00040020, 0x0000000a, 0x00000001, 0x00000007,
- 0x0004003b, 0x0000000a, 0x0000000b, 0x00000001, 0x00050036, 0x00000002,
- 0x00000004, 0x00000000, 0x00000003, 0x000200f8, 0x00000005, 0x0004003d,
- 0x00000007, 0x0000000c, 0x0000000b, 0x0003003e, 0x00000009, 0x0000000c,
- 0x000100fd, 0x00010038,
-};
-
-const char* kWebGPUShader =
- " OpCapability Shader\n"
- " OpCapability VulkanMemoryModelKHR\n"
- " OpExtension \"SPV_KHR_vulkan_memory_model\"\n"
- " OpMemoryModel Logical VulkanKHR\n"
- " OpEntryPoint Vertex %func \"shader\"\n"
- "%void = OpTypeVoid\n"
- "%void_f = OpTypeFunction %void\n"
- "%func = OpFunction %void None %void_f\n"
- "%label = OpLabel\n"
- " OpReturn\n"
- " OpFunctionEnd\n";
-
-const uint32_t kWebGPUShaderBinary[] = {
- 0x07230203, 0x00010000, 0x00070000, 0x00000005, 0x00000000, 0x00020011,
- 0x00000001, 0x00020011, 0x000014E1, 0x0008000A, 0x5F565053, 0x5F52484B,
- 0x6B6C7576, 0x6D5F6E61, 0x726F6D65, 0x6F6D5F79, 0x006C6564, 0x0003000E,
- 0x00000000, 0x00000003, 0x0005000F, 0x00000000, 0x00000001, 0x64616873,
- 0x00007265, 0x00020013, 0x00000002, 0x00030021, 0x00000003, 0x00000002,
- 0x00050036, 0x00000002, 0x00000001, 0x00000000, 0x00000003, 0x000200F8,
- 0x00000004, 0x000100FD, 0x00010038,
-};
-
-const char* kInvalidShader = "";
-
-const uint32_t kInvalidShaderBinary[] = {0x07230203};
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-
-#endif // COMMON_SHADERS_FOR_TESTS_H_
diff --git a/libshaderc_spvc/src/spvc.cc b/libshaderc_spvc/src/spvc.cc
deleted file mode 100644
index 8ff4afb..0000000
--- a/libshaderc_spvc/src/spvc.cc
+++ /dev/null
@@ -1,1243 +0,0 @@
-// Copyright 2018 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <spvc/spvc.hpp>
-
-#include "spvc_log.h"
-#include "spvc_private.h"
-
-// MSVC 2013 doesn't define __func__
-#ifndef __func__
-#define __func__ __FUNCTION__
-#endif
-
-#define CHECK_CONTEXT(context) \
- do { \
- if (!context) { \
- shaderc_spvc::ErrorLog(nullptr) \
- << "Invoked " << __func__ << " without an initialized context"; \
- return shaderc_spvc_status_missing_context_error; \
- } \
- } while (0)
-
-#define CHECK_CROSS_COMPILER(context, cross_compiler) \
- do { \
- if (!cross_compiler) { \
- shaderc_spvc::ErrorLog(context) \
- << "Invoked " << __func__ \
- << " without an initialized cross compiler"; \
- return shaderc_spvc_status_uninitialized_compiler_error; \
- } \
- } while (0)
-
-#define CHECK_OPTIONS(context, options) \
- do { \
- if (!options) { \
- shaderc_spvc::ErrorLog(context) \
- << "Invoked " << __func__ << " without an initialized options"; \
- return shaderc_spvc_status_missing_options_error; \
- } \
- } while (0)
-
-#define CHECK_RESULT(context, result) \
- do { \
- if (!result) { \
- shaderc_spvc::ErrorLog(context) \
- << "Invoked " << __func__ << " without an initialized result"; \
- return shaderc_spvc_status_missing_result_error; \
- } \
- } while (0)
-
-#define CHECK_OUT_PARAM(context, param, param_str) \
- do { \
- if (!param) { \
- shaderc_spvc::ErrorLog(context) \
- << "Invoked " << __func__ << " with invalid out param, " \
- << param_str; \
- return shaderc_spvc_status_invalid_out_param; \
- } \
- } while (0)
-
-#define CHECK_IN_PARAM(context, param, param_str) \
- do { \
- if (!param) { \
- shaderc_spvc::ErrorLog(context) \
- << "Invoked " << __func__ << " with invalid in param, " \
- << param_str; \
- return shaderc_spvc_status_invalid_in_param; \
- } \
- } while (0)
-
-namespace {
-
-spv::ExecutionModel spvc_model_to_spv_model(
- shaderc_spvc_execution_model model) {
- switch (model) {
- case shaderc_spvc_execution_model_vertex:
- return spv::ExecutionModel::ExecutionModelVertex;
- case shaderc_spvc_execution_model_fragment:
- return spv::ExecutionModel::ExecutionModelFragment;
- case shaderc_spvc_execution_model_glcompute:
- return spv::ExecutionModel::ExecutionModelGLCompute;
- case shaderc_spvc_execution_model_invalid:
- return spv::ExecutionModel::ExecutionModelMax;
- }
-
- // Older gcc doesn't recognize that all of the possible cases are covered
- // above.
- assert(false);
- return spv::ExecutionModel::ExecutionModelMax;
-}
-
-shaderc_spvc_execution_model spv_model_to_spvc_model(
- spv::ExecutionModel model) {
- switch (model) {
- case spv::ExecutionModel::ExecutionModelVertex:
- return shaderc_spvc_execution_model_vertex;
- case spv::ExecutionModel::ExecutionModelFragment:
- return shaderc_spvc_execution_model_fragment;
- case spv::ExecutionModel::ExecutionModelGLCompute:
- return shaderc_spvc_execution_model_glcompute;
- default:
- return shaderc_spvc_execution_model_invalid;
- }
-}
-
-const spirv_cross::SmallVector<spirv_cross::Resource>* get_shader_resources(
- const spirv_cross::ShaderResources& resources,
- shaderc_spvc_shader_resource resource) {
- switch (resource) {
- case shaderc_spvc_shader_resource_uniform_buffers:
- return &(resources.uniform_buffers);
- case shaderc_spvc_shader_resource_separate_images:
- return &(resources.separate_images);
- case shaderc_spvc_shader_resource_separate_samplers:
- return &(resources.separate_samplers);
- case shaderc_spvc_shader_resource_storage_buffers:
- return &(resources.storage_buffers);
- case shaderc_spvc_shader_resource_storage_images:
- return &(resources.storage_images);
- }
-
- // Older gcc doesn't recognize that all of the possible cases are covered
- // above.
- assert(false);
- return nullptr;
-}
-
-shaderc_spvc_texture_view_dimension spirv_dim_to_texture_view_dimension(
- spv::Dim dim, bool arrayed) {
- switch (dim) {
- case spv::Dim::Dim1D:
- return shaderc_spvc_texture_view_dimension_e1D;
- case spv::Dim::Dim2D:
- if (arrayed) {
- return shaderc_spvc_texture_view_dimension_e2D_array;
- } else {
- return shaderc_spvc_texture_view_dimension_e2D;
- }
- case spv::Dim::Dim3D:
- return shaderc_spvc_texture_view_dimension_e3D;
- case spv::Dim::DimCube:
- if (arrayed) {
- return shaderc_spvc_texture_view_dimension_cube_array;
- } else {
- return shaderc_spvc_texture_view_dimension_cube;
- }
- default:
- return shaderc_spvc_texture_view_dimension_undefined;
- }
-}
-
-shaderc_spvc_texture_format_type spirv_cross_base_type_to_texture_format_type(
- spirv_cross::SPIRType::BaseType type) {
- switch (type) {
- case spirv_cross::SPIRType::Float:
- return shaderc_spvc_texture_format_type_float;
- case spirv_cross::SPIRType::Int:
- return shaderc_spvc_texture_format_type_sint;
- case spirv_cross::SPIRType::UInt:
- return shaderc_spvc_texture_format_type_uint;
- default:
- return shaderc_spvc_texture_format_type_other;
- }
-}
-
-shaderc_spvc_storage_texture_format spv_image_format_to_storage_texture_format(
- spv::ImageFormat format) {
- switch (format) {
- case spv::ImageFormatR8:
- return shaderc_spvc_storage_texture_format_r8unorm;
- case spv::ImageFormatR8Snorm:
- return shaderc_spvc_storage_texture_format_r8snorm;
- case spv::ImageFormatR8ui:
- return shaderc_spvc_storage_texture_format_r8uint;
- case spv::ImageFormatR8i:
- return shaderc_spvc_storage_texture_format_r8sint;
- case spv::ImageFormatR16ui:
- return shaderc_spvc_storage_texture_format_r16uint;
- case spv::ImageFormatR16i:
- return shaderc_spvc_storage_texture_format_r16sint;
- case spv::ImageFormatR16f:
- return shaderc_spvc_storage_texture_format_r16float;
- case spv::ImageFormatRg8:
- return shaderc_spvc_storage_texture_format_rg8unorm;
- case spv::ImageFormatRg8Snorm:
- return shaderc_spvc_storage_texture_format_rg8snorm;
- case spv::ImageFormatRg8ui:
- return shaderc_spvc_storage_texture_format_rg8uint;
- case spv::ImageFormatRg8i:
- return shaderc_spvc_storage_texture_format_rg8sint;
- case spv::ImageFormatR32f:
- return shaderc_spvc_storage_texture_format_r32float;
- case spv::ImageFormatR32ui:
- return shaderc_spvc_storage_texture_format_r32uint;
- case spv::ImageFormatR32i:
- return shaderc_spvc_storage_texture_format_r32sint;
- case spv::ImageFormatRg16ui:
- return shaderc_spvc_storage_texture_format_rg16uint;
- case spv::ImageFormatRg16i:
- return shaderc_spvc_storage_texture_format_rg16sint;
- case spv::ImageFormatRg16f:
- return shaderc_spvc_storage_texture_format_rg16float;
- case spv::ImageFormatRgba8:
- return shaderc_spvc_storage_texture_format_rgba8unorm;
- case spv::ImageFormatRgba8Snorm:
- return shaderc_spvc_storage_texture_format_rgba8snorm;
- case spv::ImageFormatRgba8ui:
- return shaderc_spvc_storage_texture_format_rgba8uint;
- case spv::ImageFormatRgba8i:
- return shaderc_spvc_storage_texture_format_rgba8sint;
- case spv::ImageFormatRgb10A2:
- return shaderc_spvc_storage_texture_format_rgb10a2unorm;
- case spv::ImageFormatR11fG11fB10f:
- return shaderc_spvc_storage_texture_format_rg11b10float;
- case spv::ImageFormatRg32f:
- return shaderc_spvc_storage_texture_format_rg32float;
- case spv::ImageFormatRg32ui:
- return shaderc_spvc_storage_texture_format_rg32uint;
- case spv::ImageFormatRg32i:
- return shaderc_spvc_storage_texture_format_rg32sint;
- case spv::ImageFormatRgba16ui:
- return shaderc_spvc_storage_texture_format_rgba16uint;
- case spv::ImageFormatRgba16i:
- return shaderc_spvc_storage_texture_format_rgba16sint;
- case spv::ImageFormatRgba16f:
- return shaderc_spvc_storage_texture_format_rgba16float;
- case spv::ImageFormatRgba32f:
- return shaderc_spvc_storage_texture_format_rgba32float;
- case spv::ImageFormatRgba32ui:
- return shaderc_spvc_storage_texture_format_rgba32uint;
- case spv::ImageFormatRgba32i:
- return shaderc_spvc_storage_texture_format_rgba32sint;
- default:
- return shaderc_spvc_storage_texture_format_undefined;
- }
-}
-
-spv_target_env shaderc_spvc_spv_env_to_spv_target_env(
- shaderc_spvc_spv_env env) {
- switch (env) {
- case shaderc_spvc_spv_env_universal_1_0:
- return SPV_ENV_UNIVERSAL_1_0;
- case shaderc_spvc_spv_env_vulkan_1_0:
- return SPV_ENV_VULKAN_1_0;
- case shaderc_spvc_spv_env_universal_1_1:
- return SPV_ENV_UNIVERSAL_1_1;
- case shaderc_spvc_spv_env_opencl_2_1:
- return SPV_ENV_OPENCL_2_1;
- case shaderc_spvc_spv_env_opencl_2_2:
- return SPV_ENV_OPENCL_2_2;
- case shaderc_spvc_spv_env_opengl_4_0:
- return SPV_ENV_OPENGL_4_0;
- case shaderc_spvc_spv_env_opengl_4_1:
- return SPV_ENV_OPENGL_4_1;
- case shaderc_spvc_spv_env_opengl_4_2:
- return SPV_ENV_OPENGL_4_2;
- case shaderc_spvc_spv_env_opengl_4_3:
- return SPV_ENV_OPENGL_4_3;
- case shaderc_spvc_spv_env_opengl_4_5:
- return SPV_ENV_OPENGL_4_5;
- case shaderc_spvc_spv_env_universal_1_2:
- return SPV_ENV_UNIVERSAL_1_2;
- case shaderc_spvc_spv_env_opencl_1_2:
- return SPV_ENV_OPENCL_1_2;
- case shaderc_spvc_spv_env_opencl_embedded_1_2:
- return SPV_ENV_OPENCL_EMBEDDED_1_2;
- case shaderc_spvc_spv_env_opencl_2_0:
- return SPV_ENV_OPENCL_2_0;
- case shaderc_spvc_spv_env_opencl_embedded_2_0:
- return SPV_ENV_OPENCL_EMBEDDED_2_0;
- case shaderc_spvc_spv_env_opencl_embedded_2_1:
- return SPV_ENV_OPENCL_EMBEDDED_2_1;
- case shaderc_spvc_spv_env_opencl_embedded_2_2:
- return SPV_ENV_OPENCL_EMBEDDED_2_2;
- case shaderc_spvc_spv_env_universal_1_3:
- return SPV_ENV_UNIVERSAL_1_3;
- case shaderc_spvc_spv_env_vulkan_1_1:
- return SPV_ENV_VULKAN_1_1;
- case shaderc_spvc_spv_env_webgpu_0:
- return SPV_ENV_WEBGPU_0;
- case shaderc_spvc_spv_env_universal_1_4:
- return SPV_ENV_UNIVERSAL_1_4;
- case shaderc_spvc_spv_env_vulkan_1_1_spirv_1_4:
- return SPV_ENV_VULKAN_1_1_SPIRV_1_4;
- case shaderc_spvc_spv_env_universal_1_5:
- return SPV_ENV_UNIVERSAL_1_5;
- case shaderc_spvc_spv_env_vulkan_1_2:
- return SPV_ENV_VULKAN_1_2;
- }
- shaderc_spvc::ErrorLog(nullptr)
- << "Attempted to convert unknown shaderc_spvc_spv_env value, " << env;
- assert(false);
- return SPV_ENV_UNIVERSAL_1_0;
-}
-
-shaderc_spvc_status get_location_info_impl(
- spirv_cross::Compiler* compiler,
- const spirv_cross::SmallVector<spirv_cross::Resource>& resources,
- shaderc_spvc_resource_location_info* locations, size_t* location_count) {
- *location_count = resources.size();
- if (!locations) return shaderc_spvc_status_success;
-
- for (const auto& resource : resources) {
- if (!compiler->get_decoration_bitset(resource.id)
- .get(spv::DecorationLocation)) {
- return shaderc_spvc_status_internal_error;
- }
- locations->id = resource.id;
- if (compiler->get_decoration_bitset(resource.id)
- .get(spv::DecorationLocation)) {
- locations->location =
- compiler->get_decoration(resource.id, spv::DecorationLocation);
- locations->has_location = true;
- } else {
- locations->has_location = false;
- }
- locations++;
- }
- return shaderc_spvc_status_success;
-}
-
-} // namespace
-
-shaderc_spvc_context_t shaderc_spvc_context_create() {
- return new (std::nothrow) shaderc_spvc_context;
-}
-
-void shaderc_spvc_context_destroy(shaderc_spvc_context_t context) {
- if (context) delete context;
-}
-
-const char* shaderc_spvc_context_get_messages(
- const shaderc_spvc_context_t context) {
- for (const auto& message : context->messages) {
- context->messages_string += message;
- }
- context->messages.clear();
- return context->messages_string.c_str();
-}
-
-shaderc_spvc_status shaderc_spvc_context_get_compiler(
- const shaderc_spvc_context_t context, void** compiler) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
- CHECK_OUT_PARAM(context, compiler, "compiler");
-
- *compiler = context->cross_compiler.get();
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_context_set_use_spvc_parser(
- shaderc_spvc_context_t context, bool b) {
- CHECK_CONTEXT(context);
-
- context->use_spvc_parser = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_compile_options_t shaderc_spvc_compile_options_create(
- shaderc_spvc_spv_env source_env, shaderc_spvc_spv_env target_env) {
- shaderc_spvc_compile_options_t options =
- new (std::nothrow) shaderc_spvc_compile_options;
- if (options) {
- options->glsl.version = 0;
- options->source_env = shaderc_spvc_spv_env_to_spv_target_env(source_env);
- options->target_env = shaderc_spvc_spv_env_to_spv_target_env(target_env);
- }
- return options;
-}
-
-shaderc_spvc_compile_options_t shaderc_spvc_compile_options_clone(
- shaderc_spvc_compile_options_t options) {
- if (options) return new (std::nothrow) shaderc_spvc_compile_options(*options);
- return nullptr;
-}
-
-void shaderc_spvc_compile_options_destroy(
- shaderc_spvc_compile_options_t options) {
- if (options) delete options;
-}
-
-// DEPRECATED
-shaderc_spvc_status shaderc_spvc_compile_options_set_source_env(
- shaderc_spvc_compile_options_t options, shaderc_target_env env,
- shaderc_env_version version) {
- CHECK_OPTIONS(nullptr, options);
-
- options->source_env = spvc_private::get_spv_target_env(env, version);
- return shaderc_spvc_status_success;
-}
-
-// DEPRECATED
-shaderc_spvc_status shaderc_spvc_compile_options_set_target_env(
- shaderc_spvc_compile_options_t options, shaderc_target_env env,
- shaderc_env_version version) {
- CHECK_OPTIONS(nullptr, options);
-
- options->target_env = spvc_private::get_spv_target_env(env, version);
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_entry_point(
- shaderc_spvc_compile_options_t options, const char* entry_point) {
- CHECK_OPTIONS(nullptr, options);
- CHECK_IN_PARAM(nullptr, entry_point, "entry_point");
-
- options->entry_point = entry_point;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_remove_unused_variables(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->remove_unused_variables = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_robust_buffer_access_pass(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->robust_buffer_access_pass = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_emit_line_directives(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->glsl.emit_line_directives = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_vulkan_semantics(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->glsl.vulkan_semantics = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_separate_shader_objects(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->glsl.separate_shader_objects = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_flatten_ubo(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->flatten_ubo = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_glsl_language_version(
- shaderc_spvc_compile_options_t options, uint32_t version) {
- CHECK_OPTIONS(nullptr, options);
-
- options->glsl.version = version;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status
-shaderc_spvc_compile_options_set_flatten_multidimensional_arrays(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->glsl.flatten_multidimensional_arrays = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status
-shaderc_spvc_compile_options_set_force_zero_initialized_variables(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->glsl.force_zero_initialized_variables = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_es(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->forced_es_setting = b;
- options->force_es = true;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status
-shaderc_spvc_compile_options_set_glsl_emit_push_constant_as_ubo(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->glsl.emit_push_constant_as_uniform_buffer = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_msl_language_version(
- shaderc_spvc_compile_options_t options, uint32_t version) {
- CHECK_OPTIONS(nullptr, options);
-
- options->msl.msl_version = version;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status
-shaderc_spvc_compile_options_set_msl_swizzle_texture_samples(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->msl.swizzle_texture_samples = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_msl_platform(
- shaderc_spvc_compile_options_t options,
- shaderc_spvc_msl_platform platform) {
- CHECK_OPTIONS(nullptr, options);
-
- switch (platform) {
- case shaderc_spvc_msl_platform_ios:
- options->msl.platform = spirv_cross::CompilerMSL::Options::iOS;
- break;
- case shaderc_spvc_msl_platform_macos:
- options->msl.platform = spirv_cross::CompilerMSL::Options::macOS;
- break;
- }
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_msl_pad_fragment_output(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->msl.pad_fragment_output_components = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_msl_capture(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->msl.capture_output_to_buffer = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_msl_domain_lower_left(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->msl.tess_domain_origin_lower_left = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_msl_argument_buffers(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->msl.argument_buffers = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status
-shaderc_spvc_compile_options_set_msl_discrete_descriptor_sets(
- shaderc_spvc_compile_options_t options, const uint32_t* descriptors,
- size_t num_descriptors) {
- CHECK_OPTIONS(nullptr, options);
-
- options->msl_discrete_descriptor_sets.resize(num_descriptors);
- std::copy_n(descriptors, num_descriptors,
- options->msl_discrete_descriptor_sets.begin());
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status
-shaderc_spvc_compile_options_set_msl_enable_point_size_builtin(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->msl.enable_point_size_builtin = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status
-shaderc_spvc_compile_options_set_msl_buffer_size_buffer_index(
- shaderc_spvc_compile_options_t options, uint32_t index) {
- CHECK_OPTIONS(nullptr, options);
-
- options->msl.buffer_size_buffer_index = index;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status
-shaderc_spvc_compile_options_set_msl_additional_fixed_sample_mask(
- shaderc_spvc_compile_options_t options, uint32_t mask) {
- CHECK_OPTIONS(nullptr, options);
-
- options->msl.additional_fixed_sample_mask = mask;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_hlsl_shader_model(
- shaderc_spvc_compile_options_t options, uint32_t model) {
- CHECK_OPTIONS(nullptr, options);
-
- options->hlsl.shader_model = model;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_hlsl_point_size_compat(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->hlsl.point_size_compat = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_hlsl_point_coord_compat(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->hlsl.point_coord_compat = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_hlsl_enable_16bit_types(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->hlsl.enable_16bit_types = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status
-shaderc_spvc_compile_options_set_hlsl_nonwritable_uav_texture_as_srv(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->hlsl.nonwritable_uav_texture_as_srv = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_set_hlsl_force_storage_buffer_as_uav(
- const shaderc_spvc_context_t context, uint32_t desc_set, uint32_t binding) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
-
- auto* hlsl_compiler = reinterpret_cast<spirv_cross::CompilerHLSL*>(
- context->cross_compiler.get());
- hlsl_compiler->set_hlsl_force_storage_buffer_as_uav(desc_set, binding);
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_fixup_clipspace(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->glsl.vertex.fixup_clipspace = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_flip_vert_y(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->glsl.vertex.flip_vert_y = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_validate(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->validate = b;
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_compile_options_set_optimize(
- shaderc_spvc_compile_options_t options, bool b) {
- CHECK_OPTIONS(nullptr, options);
-
- options->optimize = b;
- return shaderc_spvc_status_success;
-}
-
-size_t shaderc_spvc_compile_options_set_for_fuzzing(
- shaderc_spvc_compile_options_t options, const uint8_t* data, size_t size) {
- if (!options || !data || size < sizeof(*options)) return 0;
-
- memcpy(static_cast<void*>(options), data, sizeof(*options));
- return sizeof(*options);
-}
-
-shaderc_spvc_status shaderc_spvc_initialize_impl(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options,
- shaderc_spvc_status (*generator)(const shaderc_spvc_context_t,
- const uint32_t*, size_t,
- shaderc_spvc_compile_options_t)) {
- shaderc_spvc_status status = spvc_private::validate_and_translate_spirv(
- context, source, source_len, options, &context->intermediate_shader);
- if (status != shaderc_spvc_status_success) return status;
-
- status = generator(context, context->intermediate_shader.data(),
- context->intermediate_shader.size(), options);
- if (status != shaderc_spvc_status_success) return status;
-
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_initialize_for_glsl(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options) {
- CHECK_CONTEXT(context);
- CHECK_OPTIONS(context, options);
- CHECK_IN_PARAM(context, source, "source");
-
- context->target_lang = SPVC_TARGET_LANG_GLSL;
- return shaderc_spvc_initialize_impl(context, source, source_len, options,
- spvc_private::generate_glsl_compiler);
-}
-
-shaderc_spvc_status shaderc_spvc_initialize_for_hlsl(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options) {
- CHECK_CONTEXT(context);
- CHECK_OPTIONS(context, options);
- CHECK_IN_PARAM(context, source, "source");
-
- context->target_lang = SPVC_TARGET_LANG_HLSL;
- return shaderc_spvc_initialize_impl(context, source, source_len, options,
- spvc_private::generate_hlsl_compiler);
-}
-
-shaderc_spvc_status shaderc_spvc_initialize_for_msl(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options) {
- CHECK_CONTEXT(context);
- CHECK_OPTIONS(context, options);
- CHECK_IN_PARAM(context, source, "source");
-
- context->target_lang = SPVC_TARGET_LANG_MSL;
- return shaderc_spvc_initialize_impl(context, source, source_len, options,
- spvc_private::generate_msl_compiler);
-}
-
-shaderc_spvc_status shaderc_spvc_initialize_for_vulkan(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options) {
- CHECK_CONTEXT(context);
- CHECK_OPTIONS(context, options);
- CHECK_IN_PARAM(context, source, "source");
-
- context->target_lang = SPVC_TARGET_LANG_VULKAN;
- return shaderc_spvc_initialize_impl(context, source, source_len, options,
- spvc_private::generate_vulkan_compiler);
-}
-
-shaderc_spvc_status shaderc_spvc_compile_shader(
- const shaderc_spvc_context_t context,
- shaderc_spvc_compilation_result_t result) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
-
- if (context->target_lang == SPVC_TARGET_LANG_UNKNOWN) {
- shaderc_spvc::ErrorLog(context)
- << "Invoked compile_shader with unknown language";
- return shaderc_spvc_status_configuration_error;
- }
-
- if (context->target_lang == SPVC_TARGET_LANG_VULKAN) {
- // No actual cross compilation is needed, since the intermediate shader is
- // already in Vulkan SPIR->V.
- result->binary_output = context->intermediate_shader;
- return shaderc_spvc_status_success;
- } else {
- shaderc_spvc_status status =
- spvc_private::generate_shader(context->cross_compiler.get(), result);
- if (status != shaderc_spvc_status_success) {
- shaderc_spvc::ErrorLog(context) << "Compilation failed. Partial source:";
- if (context->target_lang == SPVC_TARGET_LANG_GLSL) {
- spirv_cross::CompilerGLSL* cast_compiler =
- reinterpret_cast<spirv_cross::CompilerGLSL*>(
- context->cross_compiler.get());
- shaderc_spvc::ErrorLog(context) << cast_compiler->get_partial_source();
- } else if (context->target_lang == SPVC_TARGET_LANG_HLSL) {
- spirv_cross::CompilerHLSL* cast_compiler =
- reinterpret_cast<spirv_cross::CompilerHLSL*>(
- context->cross_compiler.get());
- shaderc_spvc::ErrorLog(context) << cast_compiler->get_partial_source();
- } else if (context->target_lang == SPVC_TARGET_LANG_MSL) {
- spirv_cross::CompilerMSL* cast_compiler =
- reinterpret_cast<spirv_cross::CompilerMSL*>(
- context->cross_compiler.get());
- shaderc_spvc::ErrorLog(context) << cast_compiler->get_partial_source();
- } else {
- shaderc_spvc::ErrorLog(context)
- << "Unexpected target language in context";
- }
- context->cross_compiler.reset();
- }
- return status;
- }
-}
-
-shaderc_spvc_status shaderc_spvc_set_decoration(
- const shaderc_spvc_context_t context, uint32_t id,
- shaderc_spvc_decoration decoration, uint32_t argument) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
-
- spv::Decoration spirv_cross_decoration;
- shaderc_spvc_status status =
- spvc_private::shaderc_spvc_decoration_to_spirv_cross_decoration(
- decoration, &spirv_cross_decoration);
- if (status == shaderc_spvc_status_success) {
- context->cross_compiler->set_decoration(static_cast<spirv_cross::ID>(id),
- spirv_cross_decoration, argument);
- } else {
- shaderc_spvc::ErrorLog(context) << "Decoration Conversion failed. "
- "shaderc_spvc_decoration not supported.";
- }
- return status;
-}
-
-shaderc_spvc_status shaderc_spvc_get_decoration(
- const shaderc_spvc_context_t context, uint32_t id,
- shaderc_spvc_decoration decoration, uint32_t* value) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
- CHECK_OUT_PARAM(context, value, "value");
-
- spv::Decoration spirv_cross_decoration;
- shaderc_spvc_status status =
- spvc_private::shaderc_spvc_decoration_to_spirv_cross_decoration(
- decoration, &spirv_cross_decoration);
- if (status != shaderc_spvc_status_success) {
- shaderc_spvc::ErrorLog(context) << "Decoration conversion failed. "
- "shaderc_spvc_decoration not supported.";
-
- return status;
- }
-
- *value = context->cross_compiler->get_decoration(
- static_cast<spirv_cross::ID>(id), spirv_cross_decoration);
- if (*value == 0) {
- shaderc_spvc::ErrorLog(context)
- << "Getting decoration failed. id not found.";
- return shaderc_spvc_status_compilation_error;
- }
-
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_unset_decoration(
- const shaderc_spvc_context_t context, uint32_t id,
- shaderc_spvc_decoration decoration) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
-
- spv::Decoration spirv_cross_decoration;
- shaderc_spvc_status status =
- spvc_private::shaderc_spvc_decoration_to_spirv_cross_decoration(
- decoration, &spirv_cross_decoration);
- if (status == shaderc_spvc_status_success) {
- context->cross_compiler->unset_decoration(static_cast<spirv_cross::ID>(id),
- spirv_cross_decoration);
- } else {
- shaderc_spvc::ErrorLog(context) << "Decoration conversion failed. "
- "shaderc_spvc_decoration not supported.";
- }
-
- return status;
-}
-
-shaderc_spvc_status shaderc_spvc_get_combined_image_samplers(
- const shaderc_spvc_context_t context,
- shaderc_spvc_combined_image_sampler* samplers, size_t* num_samplers) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
- CHECK_OUT_PARAM(context, num_samplers, "num_samplers");
-
- *num_samplers = context->cross_compiler->get_combined_image_samplers().size();
- if (!samplers) return shaderc_spvc_status_success;
-
- for (const auto& combined :
- context->cross_compiler->get_combined_image_samplers()) {
- samplers->combined_id = combined.combined_id;
- samplers->image_id = combined.image_id;
- samplers->sampler_id = combined.sampler_id;
- samplers++;
- }
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_set_name(const shaderc_spvc_context_t context,
- uint32_t id, const char* name) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
- CHECK_IN_PARAM(context, name, "name");
-
- context->cross_compiler->set_name(id, name);
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_add_msl_resource_binding(
- const shaderc_spvc_context_t context,
- const shaderc_spvc_msl_resource_binding binding) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
- if (context->target_lang != SPVC_TARGET_LANG_MSL) {
- shaderc_spvc::ErrorLog(context)
- << "Invoked add_msl_resource_binding when target language was not MSL";
- return shaderc_spvc_status_configuration_error;
- }
-
- spirv_cross::MSLResourceBinding cross_binding;
- cross_binding.stage = spvc_model_to_spv_model(binding.stage);
- cross_binding.binding = binding.binding;
- cross_binding.desc_set = binding.desc_set;
- cross_binding.msl_buffer = binding.msl_buffer;
- cross_binding.msl_texture = binding.msl_texture;
- cross_binding.msl_sampler = binding.msl_sampler;
- reinterpret_cast<spirv_cross::CompilerMSL*>(context->cross_compiler.get())
- ->add_msl_resource_binding(cross_binding);
-
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_get_workgroup_size(
- const shaderc_spvc_context_t context, const char* function_name,
- shaderc_spvc_execution_model execution_model,
- shaderc_spvc_workgroup_size* workgroup_size) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
- CHECK_IN_PARAM(context, function_name, "function_name");
- CHECK_OUT_PARAM(context, workgroup_size, "workgroup_size");
-
- const auto& cross_size =
- context->cross_compiler
- ->get_entry_point(function_name,
- spvc_model_to_spv_model(execution_model))
- .workgroup_size;
- workgroup_size->x = cross_size.x;
- workgroup_size->y = cross_size.y;
- workgroup_size->z = cross_size.z;
- workgroup_size->constant = cross_size.constant;
-
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_needs_buffer_size_buffer(
- const shaderc_spvc_context_t context, bool* b) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
- CHECK_OUT_PARAM(context, b, "b");
- if (context->target_lang != SPVC_TARGET_LANG_MSL) {
- shaderc_spvc::ErrorLog(context)
- << "Invoked needs_buffer_size_buffer when target language was not MSL";
- return shaderc_spvc_status_configuration_error;
- }
-
- *b =
- reinterpret_cast<spirv_cross::CompilerMSL*>(context->cross_compiler.get())
- ->needs_buffer_size_buffer();
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_build_combined_image_samplers(
- const shaderc_spvc_context_t context) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
-
- context->cross_compiler->build_combined_image_samplers();
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_get_execution_model(
- const shaderc_spvc_context_t context,
- shaderc_spvc_execution_model* execution_model) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
- CHECK_OUT_PARAM(context, execution_model, "execution_model");
-
- auto spirv_model = context->cross_compiler->get_execution_model();
- *execution_model = spv_model_to_spvc_model(spirv_model);
- if (*execution_model == shaderc_spvc_execution_model_invalid) {
- shaderc_spvc::ErrorLog(context)
- << "Shader execution model appears to be of an unsupported type";
- return shaderc_spvc_status_internal_error;
- }
-
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_get_push_constant_buffer_count(
- const shaderc_spvc_context_t context, size_t* count) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
- CHECK_OUT_PARAM(context, count, "count");
-
- *count = context->cross_compiler->get_shader_resources()
- .push_constant_buffers.size();
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_get_binding_info(
- const shaderc_spvc_context_t context, shaderc_spvc_shader_resource resource,
- shaderc_spvc_binding_type binding_type, shaderc_spvc_binding_info* bindings,
- size_t* binding_count) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
- CHECK_OUT_PARAM(context, binding_count, "binding_count");
-
- auto* compiler = context->cross_compiler.get();
- const auto& resources = compiler->get_shader_resources();
- const auto* shader_resources = get_shader_resources(resources, resource);
- *binding_count = shader_resources->size();
- if (!bindings) return shaderc_spvc_status_success;
-
- for (const auto& shader_resource : *shader_resources) {
- bindings->texture_dimension = shaderc_spvc_texture_view_dimension_undefined;
- bindings->texture_component_type = shaderc_spvc_texture_format_type_float;
-
- if (!compiler->get_decoration_bitset(shader_resource.id)
- .get(spv::DecorationBinding)) {
- shaderc_spvc::ErrorLog(context)
- << "Unable to get binding decoration for shader resource";
- return shaderc_spvc_status_internal_error;
- }
- uint32_t binding_decoration =
- compiler->get_decoration(shader_resource.id, spv::DecorationBinding);
- bindings->binding = binding_decoration;
-
- if (!compiler->get_decoration_bitset(shader_resource.id)
- .get(spv::DecorationDescriptorSet)) {
- shaderc_spvc::ErrorLog(context)
- << "Unable to get descriptor set decoration for shader resource";
- return shaderc_spvc_status_internal_error;
- }
- uint32_t descriptor_set_decoration = compiler->get_decoration(
- shader_resource.id, spv::DecorationDescriptorSet);
- bindings->set = descriptor_set_decoration;
-
- bindings->id = shader_resource.id;
- bindings->base_type_id = shader_resource.base_type_id;
-
- if (binding_type == shaderc_spvc_binding_type_uniform_buffer ||
- binding_type == shaderc_spvc_binding_type_storage_buffer) {
- // Determine buffer size, with a minimum of 1 element in the runtime array
- spirv_cross::SPIRType type =
- compiler->get_type(shader_resource.base_type_id);
- bindings->minimum_buffer_size =
- compiler->get_declared_struct_size_runtime_array(type, 1);
- }
-
- switch (binding_type) {
- case shaderc_spvc_binding_type_sampled_texture: {
- spirv_cross::SPIRType::ImageType imageType =
- compiler->get_type(bindings->base_type_id).image;
- spirv_cross::SPIRType::BaseType textureComponentType =
- compiler->get_type(imageType.type).basetype;
- bindings->multisampled = imageType.ms;
- bindings->texture_dimension = spirv_dim_to_texture_view_dimension(
- imageType.dim, imageType.arrayed);
- bindings->texture_component_type =
- spirv_cross_base_type_to_texture_format_type(textureComponentType);
- bindings->binding_type = binding_type;
- } break;
- case shaderc_spvc_binding_type_storage_buffer: {
- // Differentiate between readonly storage bindings and writable ones
- // based on the NonWritable decoration
- spirv_cross::Bitset flags =
- compiler->get_buffer_block_flags(shader_resource.id);
- if (flags.get(spv::DecorationNonWritable)) {
- bindings->binding_type =
- shaderc_spvc_binding_type_readonly_storage_buffer;
- } else {
- bindings->binding_type = shaderc_spvc_binding_type_storage_buffer;
- }
- } break;
- case shaderc_spvc_binding_type_storage_texture: {
- spirv_cross::Bitset flags = compiler->get_decoration_bitset(shader_resource.id);
- if (flags.get(spv::DecorationNonReadable)) {
- bindings->binding_type = shaderc_spvc_binding_type_writeonly_storage_texture;
- } else if (flags.get(spv::DecorationNonWritable)) {
- bindings->binding_type = shaderc_spvc_binding_type_readonly_storage_texture;
- } else {
- bindings->binding_type = shaderc_spvc_binding_type_storage_texture;
- }
- spirv_cross::SPIRType::ImageType imageType =
- compiler->get_type(bindings->base_type_id).image;
- bindings->storage_texture_format =
- spv_image_format_to_storage_texture_format(imageType.format);
- bindings->texture_dimension = spirv_dim_to_texture_view_dimension(
- imageType.dim, imageType.arrayed);
- bindings->multisampled = imageType.ms;
- } break;
- case shaderc_spvc_binding_type_sampler: {
- // The inheritance hierarchy here is odd, it goes
- // Compiler->CompilerGLSL->CompilerHLSL/MSL/Reflection.
- // CompilerGLSL is an intermediate super class for all of the other leaf
- // classes. The method we need is defined on CompilerGLSL, not Compiler.
- // This cast is safe, since we only should ever have a
- // CompilerGLSL/HLSL/MSL/Reflection in |cross_compiler|.
- auto* glsl_compiler = reinterpret_cast<spirv_cross::CompilerGLSL*>(
- context->cross_compiler.get());
- if (glsl_compiler->variable_is_depth_or_compare(shader_resource.id)) {
- bindings->binding_type = shaderc_spvc_binding_type_comparison_sampler;
- } else {
- bindings->binding_type = shaderc_spvc_binding_type_sampler;
- }
- } break;
- default:
- bindings->binding_type = binding_type;
- }
- bindings++;
- }
-
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_get_input_stage_location_info(
- const shaderc_spvc_context_t context,
- shaderc_spvc_resource_location_info* locations, size_t* location_count) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
- CHECK_OUT_PARAM(context, location_count, "location_count");
-
- auto* compiler = context->cross_compiler.get();
- shaderc_spvc_status status = get_location_info_impl(
- compiler, compiler->get_shader_resources().stage_inputs, locations,
- location_count);
- if (status != shaderc_spvc_status_success) {
- shaderc_spvc::ErrorLog(context)
- << "Unable to get location decoration for stage input";
- }
-
- return status;
-}
-
-shaderc_spvc_status shaderc_spvc_get_output_stage_location_info(
- const shaderc_spvc_context_t context,
- shaderc_spvc_resource_location_info* locations, size_t* location_count) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
- CHECK_OUT_PARAM(context, location_count, "location_count");
-
- auto* compiler = context->cross_compiler.get();
- shaderc_spvc_status status = get_location_info_impl(
- compiler, compiler->get_shader_resources().stage_outputs, locations,
- location_count);
- if (status != shaderc_spvc_status_success) {
- shaderc_spvc::ErrorLog(context)
- << "Unable to get location decoration for stage output";
- }
-
- return status;
-}
-
-shaderc_spvc_status shaderc_spvc_get_output_stage_type_info(
- const shaderc_spvc_context_t context,
- shaderc_spvc_resource_type_info* types, size_t* type_count) {
- CHECK_CONTEXT(context);
- CHECK_CROSS_COMPILER(context, context->cross_compiler);
- CHECK_OUT_PARAM(context, type_count, "type_count");
-
- auto* compiler = context->cross_compiler.get();
- const auto& resources = compiler->get_shader_resources().stage_outputs;
-
- *type_count = resources.size();
- if (!types) return shaderc_spvc_status_success;
-
- for (const auto& resource : resources) {
- if (!compiler->get_decoration_bitset(resource.id)
- .get(spv::DecorationLocation)) {
- shaderc_spvc::ErrorLog(context)
- << "Unable to get location decoration for stage output";
- return shaderc_spvc_status_internal_error;
- }
-
- types->location =
- compiler->get_decoration(resource.id, spv::DecorationLocation);
- spirv_cross::SPIRType::BaseType base_type =
- compiler->get_type(resource.base_type_id).basetype;
- types->type = spirv_cross_base_type_to_texture_format_type(base_type);
- types++;
- }
-
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_compilation_result_t shaderc_spvc_result_create() {
- return new (std::nothrow) shaderc_spvc_compilation_result;
-}
-
-void shaderc_spvc_result_destroy(shaderc_spvc_compilation_result_t result) {
- if (result) delete result;
-}
-
-shaderc_spvc_status shaderc_spvc_result_get_string_output(
- const shaderc_spvc_compilation_result_t result, const char** str) {
- CHECK_RESULT(nullptr, result);
- CHECK_OUT_PARAM(nullptr, str, "str");
-
- *str = result->string_output.c_str();
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_result_get_binary_output(
- const shaderc_spvc_compilation_result_t result,
- const uint32_t** binary_output) {
- CHECK_RESULT(nullptr, result);
- CHECK_OUT_PARAM(nullptr, binary_output, "binary_output");
-
- *binary_output = result->binary_output.data();
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_result_get_binary_length(
- const shaderc_spvc_compilation_result_t result, uint32_t* len) {
- CHECK_RESULT(nullptr, result);
- CHECK_OUT_PARAM(nullptr, len, "len");
-
- *len = result->binary_output.size();
- return shaderc_spvc_status_success;
-}
diff --git a/libshaderc_spvc/src/spvc_c_smoke_test.c b/libshaderc_spvc/src/spvc_c_smoke_test.c
deleted file mode 100644
index fc667e5..0000000
--- a/libshaderc_spvc/src/spvc_c_smoke_test.c
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2018 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "common_shaders_for_test.h"
-#include "spvc_smoke_test_util.h"
-
-// This test is meant to be for the C API, so using a plain old C file, thus
-// gtest cannot be used, so running as a simple smoke test.
-int main() { return run_smoke_test(kSmokeShader, 0); }
diff --git a/libshaderc_spvc/src/spvc_cpp_test.cc b/libshaderc_spvc/src/spvc_cpp_test.cc
deleted file mode 100644
index 7bb426a..0000000
--- a/libshaderc_spvc/src/spvc_cpp_test.cc
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright 2018 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <gtest/gtest.h>
-
-#include "common_shaders_for_test.h"
-#include "spvc/spvc.hpp"
-
-using shaderc_spvc::CompilationResult;
-using shaderc_spvc::CompileOptions;
-using shaderc_spvc::Context;
-
-namespace {
-
-class CompileTest : public testing::Test {
- public:
- CompileTest()
- : options_(shaderc_spvc_spv_env_vulkan_1_1,
- shaderc_spvc_spv_env_vulkan_1_1) {}
-
- Context context_;
- CompileOptions options_;
- CompilationResult result_;
-};
-
-TEST_F(CompileTest, Glsl) {
- {
- shaderc_spvc_status status = context_.InitializeForGlsl(
- kSmokeShaderBinary, sizeof(kSmokeShaderBinary) / sizeof(uint32_t),
- options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
-
- {
- shaderc_spvc_status status = context_.CompileShader(&result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- std::string string_output;
- result_.GetStringOutput(&string_output);
- EXPECT_NE(0, string_output.size());
- std::vector<uint32_t> binary_output;
- result_.GetBinaryOutput(&binary_output);
- EXPECT_EQ(0, binary_output.size());
- }
-}
-
-TEST_F(CompileTest, Hlsl) {
- {
- shaderc_spvc_status status = context_.InitializeForHlsl(
- kSmokeShaderBinary, sizeof(kSmokeShaderBinary) / sizeof(uint32_t),
- options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
- {
- shaderc_spvc_status status = context_.CompileShader(&result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- std::string string_output;
- result_.GetStringOutput(&string_output);
- EXPECT_NE(0, string_output.size());
- std::vector<uint32_t> binary_output;
- result_.GetBinaryOutput(&binary_output);
- EXPECT_EQ(0, binary_output.size());
- }
-}
-
-TEST_F(CompileTest, Msl) {
- {
- shaderc_spvc_status status = context_.InitializeForMsl(
- kSmokeShaderBinary, sizeof(kSmokeShaderBinary) / sizeof(uint32_t),
- options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
-
- {
- shaderc_spvc_status status = context_.CompileShader(&result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- std::string string_output;
- result_.GetStringOutput(&string_output);
- EXPECT_NE(0, string_output.size());
- std::vector<uint32_t> binary_output;
- result_.GetBinaryOutput(&binary_output);
- EXPECT_EQ(0, binary_output.size());
- }
-}
-
-TEST_F(CompileTest, Vulkan) {
- {
- shaderc_spvc_status status = context_.InitializeForVulkan(
- kSmokeShaderBinary, sizeof(kSmokeShaderBinary) / sizeof(uint32_t),
- options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
- {
- shaderc_spvc_status status = context_.CompileShader(&result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- std::string string_output;
- result_.GetStringOutput(&string_output);
- EXPECT_EQ(0, string_output.size());
- std::vector<uint32_t> binary_output;
- result_.GetBinaryOutput(&binary_output);
- EXPECT_NE(0, binary_output.size());
- }
-}
-
-} // anonymous namespace
diff --git a/libshaderc_spvc/src/spvc_log.cc b/libshaderc_spvc/src/spvc_log.cc
deleted file mode 100644
index b382c4f..0000000
--- a/libshaderc_spvc/src/spvc_log.cc
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2020 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "spvc_log.h"
-
-#include <cstdio>
-
-#include "spvc_private.h"
-
-namespace shaderc_spvc {
-
-LogMessage::LogMessage(shaderc_spvc_context_t context, LogSeverity severity)
- : context_(context),
- severity_(severity) {
- switch (severity_) {
- case LogSeverity::Debug:
- stream_ << "Debug: ";
- break;
- case LogSeverity::Info:
- stream_ << "Info: ";
- break;
- case LogSeverity::Warning:
- stream_ << "Warning: ";
- break;
- case LogSeverity::Error:
- stream_ << "Error: ";
- break;
- }
-}
-
-LogMessage::~LogMessage() {
-#if defined(SHADERC_SPVC_ENABLE_DIRECT_LOGGING) || \
- !defined(SHADERC_SPVC_DISABLE_CONTEXT_LOGGING)
- std::string message = stream_.str();
-
- // If this message has been moved, its stream is empty.
- if (message.empty()) {
- return;
- }
-
-#if defined(SHADERC_SPVC_ENABLE_DIRECT_LOGGING)
- FILE* outputStream = stdout;
- if (severity_ == LogSeverity::Warning || severity_ == LogSeverity::Error) {
- outputStream = stderr;
- }
-
- // Note: we use fprintf because <iostream> includes static initializers.
- fprintf(outputStream, "%s\n", stream_.str().c_str());
- fflush(outputStream);
-#endif // defined(SHADERC_SPVC_ENABLE_DIRECT_LOGGING)
-
-#if !defined(SHADERC_SPVC_DISABLE_CONTEXT_LOGGING)
- if (context_) {
- context_->messages.push_back(stream_.str());
- }
-#endif // !defined(SHADERC_SPVC_DISABLE_CONTEXT_LOGGING)
-#endif // defined(SHADERC_SPVC_ENABLE_DIRECT_LOGGING) ||
- // !defined(SHADERC_SPVC_DISABLE_CONTEXT_LOGGING)
-}
-
-LogMessage DebugLog(shaderc_spvc_context_t context) {
- return {context, LogSeverity::Debug};
-}
-
-LogMessage InfoLog(shaderc_spvc_context_t context) {
- return {context, LogSeverity::Info};
-}
-
-LogMessage WarningLog(shaderc_spvc_context_t context) {
- return {context, LogSeverity::Warning};
-}
-
-LogMessage ErrorLog(shaderc_spvc_context_t context) {
- return {context, LogSeverity::Error};
-}
-
-} // namespace shaderc_spvc
diff --git a/libshaderc_spvc/src/spvc_log.h b/libshaderc_spvc/src/spvc_log.h
deleted file mode 100644
index 827fbd5..0000000
--- a/libshaderc_spvc/src/spvc_log.h
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright 2020 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// Interface inspired by src/common/Log.h from Dawn
-
-// Logging logging is done using the [Debug|Info|Warning|Error]Log() function
-// this way:
-//
-// InfoLog() << things << that << ostringstream << supports; // No need for a
-// std::endl or "\n"
-//
-// It creates a LogMessage object that isn't stored anywhere and gets its
-// destructor called immediately which outputs the stored ostringstream in the
-// right place.
-
-#ifndef LIBSHADERC_SPVC_SRC_SPVC_LOG_H_
-#define LIBSHADERC_SPVC_SRC_SPVC_LOG_H_
-
-#include <sstream>
-
-#include "spvc/spvc.h"
-
-namespace shaderc_spvc {
-
-// Log levels mostly used to signal intent where the log message is produced and
-// used to route the message to the correct output.
-enum class LogSeverity {
- Debug,
- Info,
- Warning,
- Error,
-};
-
-// Essentially an ostringstream that will print itself in its destructor.
-class LogMessage {
- public:
- LogMessage(shaderc_spvc_context_t context, LogSeverity severity);
- ~LogMessage();
-
- template <typename T>
- LogMessage& operator<<(T&& value) {
- stream_ << value;
- return *this;
- }
-
- private:
- // Disallow copy and assign
- LogMessage(const LogMessage& other) = delete;
- LogMessage& operator=(const LogMessage& other) = delete;
-
-#if defined(SHADERC_SPVC_DISABLE_CONTEXT_LOGGING)
- shaderc_spvc_context_t context_ __attribute__((unused));
-#else
- shaderc_spvc_context_t context_;
-#endif // defined(SHADERC_SPVC_DISABLE_CONTEXT_LOGGING)
- std::ostringstream stream_;
- LogSeverity severity_;
-};
-
-// Short-hands to create a LogMessage with the respective severity.
-LogMessage DebugLog(shaderc_spvc_context_t context);
-LogMessage InfoLog(shaderc_spvc_context_t context);
-LogMessage WarningLog(shaderc_spvc_context_t context);
-LogMessage ErrorLog(shaderc_spvc_context_t context);
-
-} // namespace shaderc_spvc
-
-#endif // LIBSHADERC_SPVC_SRC_SPVC_LOG_H_
diff --git a/libshaderc_spvc/src/spvc_private.cc b/libshaderc_spvc/src/spvc_private.cc
deleted file mode 100644
index 4884db6..0000000
--- a/libshaderc_spvc/src/spvc_private.cc
+++ /dev/null
@@ -1,573 +0,0 @@
-// Copyright 2019 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "spvc_private.h"
-
-#include "spirv-tools/optimizer.hpp"
-#include "spvc_log.h"
-#include "spvcir_pass.h"
-
-// Originally from libshaderc_utils/exceptions.h, copied here to avoid
-// needing to depend on libshaderc_utils and pull in its dependency on
-// glslang.
-#if (defined(_MSC_VER) && !defined(_CPPUNWIND)) || !defined(__EXCEPTIONS)
-#define TRY_IF_EXCEPTIONS_ENABLED
-#define CATCH_IF_EXCEPTIONS_ENABLED(X) if (0)
-#else
-#define TRY_IF_EXCEPTIONS_ENABLED try
-#define CATCH_IF_EXCEPTIONS_ENABLED(X) catch (X)
-#endif
-
-namespace {
-bool is_vulkan_env(spv_target_env env) {
- switch (env) {
- case SPV_ENV_VULKAN_1_0:
- case SPV_ENV_VULKAN_1_1:
- case SPV_ENV_VULKAN_1_1_SPIRV_1_4:
- case SPV_ENV_VULKAN_1_2:
- return true;
- default:
- return false;
- }
-}
-
-} // namespace
-
-namespace spvc_private {
-
-spv_target_env get_spv_target_env(shaderc_target_env env,
- shaderc_env_version version) {
- switch (env) {
- case shaderc_target_env_opengl:
- case shaderc_target_env_opengl_compat:
- switch (version) {
- case shaderc_env_version_opengl_4_5:
- return SPV_ENV_OPENGL_4_5;
- default:
- break;
- }
- break;
- case shaderc_target_env_vulkan:
- switch (version) {
- case shaderc_env_version_vulkan_1_0:
- return SPV_ENV_VULKAN_1_0;
- case shaderc_env_version_vulkan_1_1:
- return SPV_ENV_VULKAN_1_1;
- default:
- break;
- }
-
- break;
- case shaderc_target_env_webgpu:
- return SPV_ENV_WEBGPU_0;
- default:
- break;
- }
- return SPV_ENV_VULKAN_1_0;
-}
-
-void consume_spirv_tools_message(shaderc_spvc_context* context,
- spv_message_level_t level, const char* src,
- const spv_position_t& pos,
- const char* message) {
- switch (level) {
- case SPV_MSG_FATAL:
- shaderc_spvc::ErrorLog(context) << message;
- break;
- case SPV_MSG_INTERNAL_ERROR:
- shaderc_spvc::ErrorLog(context) << message;
- break;
- case SPV_MSG_ERROR:
- shaderc_spvc::ErrorLog(context) << message;
- break;
- case SPV_MSG_WARNING:
- shaderc_spvc::WarningLog(context) << message;
- break;
- case SPV_MSG_INFO:
- shaderc_spvc::InfoLog(context) << message;
- break;
- case SPV_MSG_DEBUG:
- shaderc_spvc::DebugLog(context) << message;
- break;
- }
-}
-
-shaderc_spvc_status validate_spirv(shaderc_spvc_context* context,
- spv_target_env env, const uint32_t* source,
- size_t source_len) {
- spvtools::SpirvTools tools(env);
- if (!tools.IsValid()) {
- shaderc_spvc::ErrorLog(context) << "Could not initialize SPIRV-Tools.";
- return shaderc_spvc_status_internal_error;
- }
-
- tools.SetMessageConsumer(std::bind(
- consume_spirv_tools_message, context, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
-
- if (!tools.Validate(source, source_len, spvtools::ValidatorOptions())) {
- shaderc_spvc::ErrorLog(context) << "Validation of shader failed.";
- return shaderc_spvc_status_validation_error;
- }
-
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status translate_spirv(shaderc_spvc_context* context,
- spv_target_env source_env,
- spv_target_env target_env,
- const uint32_t* source, size_t source_len,
- shaderc_spvc_compile_options_t options,
- std::vector<uint32_t>* target) {
- bool registered_pass = false;
- if (!target) {
- shaderc_spvc::ErrorLog(context)
- << "null provided for translation destination.";
- return shaderc_spvc_status_transformation_error;
- }
-
- spvtools::Optimizer opt(source_env);
- opt.SetValidateAfterAll(options->validate);
- opt.SetMessageConsumer(std::bind(
- consume_spirv_tools_message, context, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
-
- if (source_env == SPV_ENV_WEBGPU_0 && is_vulkan_env(target_env)) {
- registered_pass = true;
- opt.RegisterWebGPUToVulkanPasses();
- } else if (is_vulkan_env(source_env) && target_env == SPV_ENV_WEBGPU_0) {
- registered_pass = true;
- opt.RegisterVulkanToWebGPUPasses();
- } else if (source_env == SPV_ENV_UNIVERSAL_1_0 &&
- target_env == SPV_ENV_UNIVERSAL_1_0) {
- // Assuming that the default constructor in Dawn was used, thus the intent
- // was to perform WebGPU->Vulkan conversion.
- //
- // TODO: Remove this case once deprecated options constructor with defaults
- // is removed.
- registered_pass = true;
- opt.RegisterWebGPUToVulkanPasses();
- } else if (source_env != target_env) {
- shaderc_spvc::ErrorLog(context)
- << "No defined transformation between source and target execution "
- "environments.";
- return shaderc_spvc_status_transformation_error;
- }
-
- if (options->robust_buffer_access_pass) {
- registered_pass = true;
- opt.RegisterPass(spvtools::CreateGraphicsRobustAccessPass());
- }
-
- if (!registered_pass) {
- target->resize(source_len);
- memcpy(target->data(), source, source_len * sizeof(uint32_t));
- return shaderc_spvc_status_success;
- }
-
- if (!opt.Run(source, source_len, target, spvtools::ValidatorOptions(),
- options->validate)) {
- shaderc_spvc::ErrorLog(context) << "Transformations between source and "
- "target execution environments failed.";
- return shaderc_spvc_status_transformation_error;
- }
-
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status validate_and_translate_spirv(
- shaderc_spvc_context* context, const uint32_t* source, size_t source_len,
- shaderc_spvc_compile_options_t options, std::vector<uint32_t>* target) {
- shaderc_spvc_status status;
- if (options->validate) {
- status = validate_spirv(context, options->source_env, source, source_len);
- if (status != shaderc_spvc_status_success) {
- shaderc_spvc::ErrorLog(context) << "Validation of input source failed.";
- return status;
- }
- }
-
- status = translate_spirv(context, options->source_env, options->target_env,
- source, source_len, options, target);
- if (status != shaderc_spvc_status_success) return status;
-
- if (options->validate && (options->source_env != options->target_env)) {
- // Re-run validation on input if actually transformed.
- status = validate_spirv(context, options->target_env, target->data(),
- target->size());
- if (status != shaderc_spvc_status_success) {
- shaderc_spvc::ErrorLog(context)
- << "Validation of transformed source failed.";
- return status;
- }
- }
-
- return status;
-}
-
-shaderc_spvc_status generate_shader(spirv_cross::Compiler* compiler,
- shaderc_spvc_compilation_result_t result) {
- TRY_IF_EXCEPTIONS_ENABLED {
- result->string_output = compiler->compile();
- // An exception during compiling would crash (if exceptions off) or jump to
- // the catch block (if exceptions on) so if we're here we know the compile
- // worked.
- return shaderc_spvc_status_success;
- }
- CATCH_IF_EXCEPTIONS_ENABLED(...) {
- return shaderc_spvc_status_compilation_error;
- }
-}
-
-shaderc_spvc_status generate_glsl_compiler(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options) {
- spirv_cross::CompilerGLSL* cross_compiler;
- // spvc IR generation is under development, for now run spirv-cross
- // compiler, unless explicitly requested.
- // TODO (sarahM0): change the default to spvc IR generation when it's done
- if (context->use_spvc_parser) {
- shaderc_spvc_status status;
- spirv_cross::ParsedIR ir;
- status = generate_spvcir(context, &ir, source, source_len, options);
- if (status != shaderc_spvc_status_success) {
- shaderc_spvc::ErrorLog(context)
- << "Transformations between source and target execution environments "
- "failed (spvc-ir-pass).";
- return status;
- } else {
- cross_compiler = new (std::nothrow) spirv_cross::CompilerGLSL(ir);
- }
- } else {
- cross_compiler =
- new (std::nothrow) spirv_cross::CompilerGLSL(source, source_len);
- }
-
- if (!cross_compiler) {
- shaderc_spvc::ErrorLog(context)
- << "Unable to initialize SPIRV-Cross GLSL compiler.";
- return shaderc_spvc_status_compilation_error;
- }
- context->cross_compiler.reset(cross_compiler);
-
- if (options->glsl.version == 0) {
- // no version requested, was one detected in source?
- options->glsl.version = cross_compiler->get_common_options().version;
- if (options->glsl.version == 0) {
- // no version detected in source, use default
- options->glsl.version = DEFAULT_GLSL_VERSION;
- } else {
- // version detected implies ES also detected
- options->glsl.es = cross_compiler->get_common_options().es;
- }
- }
-
- // Override detected setting, if any.
- if (options->force_es) options->glsl.es = options->forced_es_setting;
-
- auto entry_points = cross_compiler->get_entry_points_and_stages();
- spv::ExecutionModel model = spv::ExecutionModelMax;
- if (!options->entry_point.empty()) {
- // Make sure there is just one entry point with this name, or the stage is
- // ambiguous.
- uint32_t stage_count = 0;
- for (auto& e : entry_points) {
- if (e.name == options->entry_point) {
- stage_count++;
- model = e.execution_model;
- }
- }
-
- if (stage_count != 1) {
- context->cross_compiler.reset();
- if (stage_count == 0) {
- shaderc_spvc::ErrorLog(context)
- << "There is no entry point with name: " << options->entry_point;
- } else {
- shaderc_spvc::ErrorLog(context)
- << "There is more than one entry point with name: "
- << options->entry_point << ". Use --stage.";
- }
- return shaderc_spvc_status_compilation_error;
- }
- }
-
- if (!options->entry_point.empty()) {
- cross_compiler->set_entry_point(options->entry_point, model);
- }
-
- if (!options->glsl.vulkan_semantics) {
- uint32_t sampler =
- cross_compiler->build_dummy_sampler_for_combined_images();
- if (sampler) {
- // Set some defaults to make validation happy.
- cross_compiler->set_decoration(sampler, spv::DecorationDescriptorSet, 0);
- cross_compiler->set_decoration(sampler, spv::DecorationBinding, 0);
- }
- }
-
- spirv_cross::ShaderResources res;
- if (options->remove_unused_variables) {
- auto active = cross_compiler->get_active_interface_variables();
- res = cross_compiler->get_shader_resources(active);
- cross_compiler->set_enabled_interface_variables(move(active));
- } else {
- res = cross_compiler->get_shader_resources();
- }
-
- if (options->flatten_ubo) {
- for (auto& ubo : res.uniform_buffers)
- cross_compiler->flatten_buffer_block(ubo.id);
- for (auto& ubo : res.push_constant_buffers)
- cross_compiler->flatten_buffer_block(ubo.id);
- }
-
- if (!options->glsl.vulkan_semantics) {
- cross_compiler->build_combined_image_samplers();
-
- // if (args.combined_samplers_inherit_bindings)
- // spirv_cross_util::inherit_combined_sampler_bindings(*compiler);
-
- // Give the remapped combined samplers new names.
- for (auto& remap : cross_compiler->get_combined_image_samplers()) {
- cross_compiler->set_name(
- remap.combined_id,
- spirv_cross::join("SPIRV_Cross_Combined",
- cross_compiler->get_name(remap.image_id),
- cross_compiler->get_name(remap.sampler_id)));
- }
- }
-
- cross_compiler->set_common_options(options->glsl);
-
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status generate_hlsl_compiler(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options) {
- spirv_cross::CompilerHLSL* cross_compiler;
- // spvc IR generation is under development, for now run spirv-cross
- // compiler, unless explicitly requested.
- // TODO (sarahM0): change the default to spvc IR generation when it's done
- if (context->use_spvc_parser) {
- shaderc_spvc_status status;
- spirv_cross::ParsedIR ir;
- status = generate_spvcir(context, &ir, source, source_len, options);
- if (status != shaderc_spvc_status_success) {
- shaderc_spvc::ErrorLog(context)
- << "Transformations between source and target execution environments "
- "failed (spvc-ir-pass).";
- return status;
- } else {
- cross_compiler = new (std::nothrow) spirv_cross::CompilerHLSL(ir);
- }
- } else {
- cross_compiler =
- new (std::nothrow) spirv_cross::CompilerHLSL(source, source_len);
- }
- if (!cross_compiler) {
- shaderc_spvc::ErrorLog(context)
- << "Unable to initialize SPIRV-Cross HLSL compiler.";
- return shaderc_spvc_status_compilation_error;
- }
- context->cross_compiler.reset(cross_compiler);
-
- cross_compiler->set_common_options(options->glsl);
- cross_compiler->set_hlsl_options(options->hlsl);
-
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status generate_msl_compiler(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options) {
- spirv_cross::CompilerMSL* cross_compiler;
- // spvc IR generation is under development, for now run spirv-cross
- // compiler, unless explicitly requested.
- // TODO (sarahM0): change the default to spvc IR generation when it's done
- if (context->use_spvc_parser) {
- shaderc_spvc_status status;
- spirv_cross::ParsedIR ir;
- status = generate_spvcir(context, &ir, source, source_len, options);
- if (status != shaderc_spvc_status_success) {
- shaderc_spvc::ErrorLog(context)
- << "Transformations between source and target execution environments "
- "failed (spvc-ir-pass).";
- return status;
- } else {
- cross_compiler = new (std::nothrow) spirv_cross::CompilerMSL(ir);
- }
- } else {
- cross_compiler =
- new (std::nothrow) spirv_cross::CompilerMSL(source, source_len);
- }
-
- if (!cross_compiler) {
- shaderc_spvc::ErrorLog(context)
- << "Unable to initialize SPIRV-Cross MSL compiler.";
- return shaderc_spvc_status_compilation_error;
- }
- context->cross_compiler.reset(cross_compiler);
-
- cross_compiler->set_common_options(options->glsl);
- cross_compiler->set_msl_options(options->msl);
- for (auto i : options->msl_discrete_descriptor_sets)
- cross_compiler->add_discrete_descriptor_set(i);
-
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status generate_vulkan_compiler(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options) {
- spirv_cross::CompilerReflection* cross_compiler;
-
- // spvc IR generation is under development, for now run spirv-cross
- // compiler, unless explicitly requested.
- // TODO (sarahM0): change the default to spvc IR generation when it's done
- if (context->use_spvc_parser) {
- spirv_cross::ParsedIR ir;
- shaderc_spvc_status status =
- generate_spvcir(context, &ir, source, source_len, options);
- if (status != shaderc_spvc_status_success) {
- shaderc_spvc::ErrorLog(context)
- << "Transformations between source and target execution environments "
- "failed (spvc-ir-pass).";
- return status;
- } else {
- cross_compiler = new (std::nothrow) spirv_cross::CompilerReflection(ir);
- }
- } else {
- cross_compiler =
- new (std::nothrow) spirv_cross::CompilerReflection(source, source_len);
- }
-
- if (!cross_compiler) {
- shaderc_spvc::ErrorLog(context)
- << "Unable to initialize SPIRV-Cross reflection compiler.";
- return shaderc_spvc_status_compilation_error;
- }
- context->cross_compiler.reset(cross_compiler);
-
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status generate_spvcir(const shaderc_spvc_context_t context,
- spirv_cross::ParsedIR* ir,
- const uint32_t* source, size_t source_len,
- shaderc_spvc_compile_options_t options) {
- if (context->use_spvc_parser) {
- std::vector<uint32_t> binary_output;
- spvtools::Optimizer opt(options->source_env);
- opt.SetMessageConsumer(std::bind(
- consume_spirv_tools_message, context, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
- ir->spirv = std::vector<uint32_t>(source, source + source_len);
-
- opt.RegisterPass(
- spvtools::Optimizer::PassToken(std::unique_ptr<spvtools::opt::Pass>(
- reinterpret_cast<spvtools::opt::Pass*>(
- new spvtools::opt::SpvcIrPass(ir)))));
-
- if (!opt.Run(source, source_len, &binary_output)) {
- return shaderc_spvc_status_transformation_error;
- }
- }
- return shaderc_spvc_status_success;
-}
-
-shaderc_spvc_status shaderc_spvc_decoration_to_spirv_cross_decoration(
- const shaderc_spvc_decoration decoration,
- spv::Decoration* spirv_cross_decoration_ptr) {
- if (!spirv_cross_decoration_ptr) return shaderc_spvc_status_internal_error;
-
- shaderc_spvc_status status = shaderc_spvc_status_success;
-
- switch (decoration) {
- case shaderc_spvc_decoration_specid:
- *spirv_cross_decoration_ptr = spv::DecorationSpecId;
- break;
- case shaderc_spvc_decoration_block:
- *spirv_cross_decoration_ptr = spv::DecorationBlock;
- break;
- case shaderc_spvc_decoration_rowmajor:
- *spirv_cross_decoration_ptr = spv::DecorationRowMajor;
- break;
- case shaderc_spvc_decoration_colmajor:
- *spirv_cross_decoration_ptr = spv::DecorationColMajor;
- break;
- case shaderc_spvc_decoration_arraystride:
- *spirv_cross_decoration_ptr = spv::DecorationArrayStride;
- break;
- case shaderc_spvc_decoration_matrixstride:
- *spirv_cross_decoration_ptr = spv::DecorationMatrixStride;
- break;
- case shaderc_spvc_decoration_builtin:
- *spirv_cross_decoration_ptr = spv::DecorationBuiltIn;
- break;
- case shaderc_spvc_decoration_noperspective:
- *spirv_cross_decoration_ptr = spv::DecorationNoPerspective;
- break;
- case shaderc_spvc_decoration_flat:
- *spirv_cross_decoration_ptr = spv::DecorationFlat;
- break;
- case shaderc_spvc_decoration_centroid:
- *spirv_cross_decoration_ptr = spv::DecorationCentroid;
- break;
- case shaderc_spvc_decoration_restrict:
- *spirv_cross_decoration_ptr = spv::DecorationRestrict;
- break;
- case shaderc_spvc_decoration_aliased:
- *spirv_cross_decoration_ptr = spv::DecorationAliased;
- break;
- case shaderc_spvc_decoration_nonwritable:
- *spirv_cross_decoration_ptr = spv::DecorationNonWritable;
- break;
- case shaderc_spvc_decoration_nonreadable:
- *spirv_cross_decoration_ptr = spv::DecorationNonReadable;
- break;
- case shaderc_spvc_decoration_uniform:
- *spirv_cross_decoration_ptr = spv::DecorationUniform;
- break;
- case shaderc_spvc_decoration_location:
- *spirv_cross_decoration_ptr = spv::DecorationLocation;
- break;
- case shaderc_spvc_decoration_component:
- *spirv_cross_decoration_ptr = spv::DecorationComponent;
- break;
- case shaderc_spvc_decoration_index:
- *spirv_cross_decoration_ptr = spv::DecorationIndex;
- break;
- case shaderc_spvc_decoration_binding:
- *spirv_cross_decoration_ptr = spv::DecorationBinding;
- break;
- case shaderc_spvc_decoration_descriptorset:
- *spirv_cross_decoration_ptr = spv::DecorationDescriptorSet;
- break;
- case shaderc_spvc_decoration_offset:
- *spirv_cross_decoration_ptr = spv::DecorationOffset;
- break;
- case shaderc_spvc_decoration_nocontraction:
- *spirv_cross_decoration_ptr = spv::DecorationNoContraction;
- break;
- default:
- *spirv_cross_decoration_ptr = spv::DecorationMax;
- status = shaderc_spvc_status_internal_error;
- break;
- }
- return status;
-}
-
-} // namespace spvc_private
diff --git a/libshaderc_spvc/src/spvc_private.h b/libshaderc_spvc/src/spvc_private.h
deleted file mode 100644
index 65f1e21..0000000
--- a/libshaderc_spvc/src/spvc_private.h
+++ /dev/null
@@ -1,158 +0,0 @@
-// Copyright 2019 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef LIBSHADERC_SPVC_SRC_SPVC_PRIVATE_H_
-#define LIBSHADERC_SPVC_SRC_SPVC_PRIVATE_H_
-
-#include <cstdint>
-#include <spirv_glsl.hpp>
-#include <spirv_hlsl.hpp>
-#include <spirv_msl.hpp>
-#include <spirv_reflect.hpp>
-#include <string>
-#include <vector>
-
-#include "spirv-tools/libspirv.hpp"
-#include "spvc/spvc.h"
-
-// GLSL version produced when none specified nor detected from source.
-#define DEFAULT_GLSL_VERSION 450
-
-typedef enum {
- SPVC_TARGET_LANG_UNKNOWN,
- SPVC_TARGET_LANG_GLSL,
- SPVC_TARGET_LANG_HLSL,
- SPVC_TARGET_LANG_MSL,
- SPVC_TARGET_LANG_VULKAN,
-} spvc_target_lang;
-
-struct shaderc_spvc_context {
- std::unique_ptr<spirv_cross::Compiler> cross_compiler;
- std::vector<std::string> messages;
- std::string messages_string;
- spvc_target_lang target_lang = SPVC_TARGET_LANG_UNKNOWN;
- std::vector<uint32_t> intermediate_shader;
- bool use_spvc_parser = false;
-};
-
-struct shaderc_spvc_compile_options {
- bool validate = true;
- bool optimize = true;
- bool remove_unused_variables = false;
- bool robust_buffer_access_pass = false;
- bool flatten_ubo = false;
- bool force_es = false;
- bool forced_es_setting = false;
- std::string entry_point;
- spv_target_env source_env = SPV_ENV_VULKAN_1_0;
- spv_target_env target_env = SPV_ENV_VULKAN_1_0;
- std::vector<uint32_t> msl_discrete_descriptor_sets;
- spirv_cross::CompilerGLSL::Options glsl;
- spirv_cross::CompilerHLSL::Options hlsl;
- spirv_cross::CompilerMSL::Options msl;
-};
-
-// Described in spvc.h.
-struct shaderc_spvc_compilation_result {
- std::string string_output;
- std::vector<uint32_t> binary_output;
-};
-
-namespace spvc_private {
-
-// Convert from shaderc values to spirv-tools values.
-spv_target_env get_spv_target_env(shaderc_target_env env,
- shaderc_env_version version);
-
-// Handler for spirv-tools error/warning messages that records them in the
-// results structure.
-void consume_spirv_tools_message(shaderc_spvc_context* context,
- spv_message_level_t level, const char* src,
- const spv_position_t& pos,
- const char* message);
-
-// Test whether or not the given SPIR-V binary is valid for the specific
-// environment. Invoke spirv-val to perform this operation.
-shaderc_spvc_status validate_spirv(shaderc_spvc_context* context,
- spv_target_env env, const uint32_t* source,
- size_t source_len);
-
-// Convert SPIR-V from one environment to another, if there is a known
-// conversion. If the origin and destination environments are the same, then
-// the binary is just copied to the output buffer. Invokes spirv-opt to perform
-// the actual translation.
-shaderc_spvc_status translate_spirv(shaderc_spvc_context* context,
- spv_target_env source_env,
- spv_target_env target_env,
- const uint32_t* source, size_t source_len,
- shaderc_spvc_compile_options_t options,
- std::vector<uint32_t>* target);
-
-// Execute the validation and translate steps. Specifically validates the input,
-// transforms it, then validates the transformed input. All of these steps are
-// only done if needed.
-shaderc_spvc_status validate_and_translate_spirv(
- shaderc_spvc_context* context, const uint32_t* source, size_t source_len,
- shaderc_spvc_compile_options_t options, std::vector<uint32_t>* target);
-
-// Given a configured compiler run it to generate a shader. Does all of the
-// required trapping to handle if the compile fails.
-shaderc_spvc_status generate_shader(spirv_cross::Compiler* compiler,
- shaderc_spvc_compilation_result_t result);
-
-// Given a Vulkan SPIR-V shader and set of options, create a compiler for
-// generating a GLSL shader and performing reflection.
-shaderc_spvc_status generate_glsl_compiler(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options);
-
-// Given a Vulkan SPIR-V shader and set of options, create a compiler for
-// generating a HLSL shader and performing reflection.
-shaderc_spvc_status generate_hlsl_compiler(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options);
-
-// Given a Vulkan SPIR-V shader and set of options, create a compiler for
-// generating a MSL shader and performing reflection.
-shaderc_spvc_status generate_msl_compiler(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options);
-
-// Given a Vulkan SPIR-V shader and set of options, create a compiler for
-// generating performing reflection.
-shaderc_spvc_status generate_vulkan_compiler(
- const shaderc_spvc_context_t context, const uint32_t* source,
- size_t source_len, shaderc_spvc_compile_options_t options);
-
-// Given a pointer to an SPIRV-Cross IR (with initialized spirv field), Invokes
-// spirv-opt to generate a SPIRV-Cross IR (ie. populate empty fields of the
-// given spirv_cross::ParsedIR* ir).
-shaderc_spvc_status generate_spvcir(const shaderc_spvc_context_t context,
- spirv_cross::ParsedIR* ir,
- const uint32_t* source, size_t source_len,
- shaderc_spvc_compile_options_t options);
-
-// Converts a shaderc spvc decoration value to the equivalent spirv-cross
-// decoration value and sends the result out through |spirv_cross_decoration|.
-// If the conversion fails, returns an error result.
-// Only WebGPU decorations are supported. More cases can be added if necessary.
-// PS. Added because spirv_cross forks Vulkan spirv headers instead of having
-// it as a dependency.
-shaderc_spvc_status shaderc_spvc_decoration_to_spirv_cross_decoration(
- const shaderc_spvc_decoration decoration,
- spv::Decoration* spirv_cross_decoration);
-
-} // namespace spvc_private
-
-#endif // LIBSHADERC_SPVC_SRC_SPVC_PRIVATE_H_
diff --git a/libshaderc_spvc/src/spvc_smoke_test_util.c b/libshaderc_spvc/src/spvc_smoke_test_util.c
deleted file mode 100644
index d5ae27f..0000000
--- a/libshaderc_spvc/src/spvc_smoke_test_util.c
+++ /dev/null
@@ -1,118 +0,0 @@
-// Copyright 2019 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "shaderc/shaderc.h"
-#include "spvc/spvc.h"
-
-typedef shaderc_spvc_status (*InitCmd)(const shaderc_spvc_context_t,
- const uint32_t*, size_t,
- shaderc_spvc_compile_options_t);
-
-shaderc_compilation_result_t assemble_shader(const char* shader) {
- shaderc_compiler_t shaderc;
- shaderc = shaderc_compiler_initialize();
- shaderc_compile_options_t opt = shaderc_compile_options_initialize();
- shaderc_compilation_result_t res =
- shaderc_assemble_into_spv(shaderc, shader, strlen(shader), opt);
- shaderc_compile_options_release(opt);
- shaderc_compiler_release(shaderc);
- return res;
-}
-
-int test_exec(shaderc_spvc_context_t context,
- shaderc_spvc_compile_options_t options,
- shaderc_compilation_result_t assembled_shader, InitCmd init_cmd,
- const char* target_lang) {
- shaderc_spvc_compilation_result_t result = shaderc_spvc_result_create();
- assert(result);
- shaderc_spvc_status status = init_cmd(
- context, (const uint32_t*)shaderc_result_get_bytes(assembled_shader),
- shaderc_result_get_length(assembled_shader) / sizeof(uint32_t), options);
- int ret_val;
- if (status == shaderc_spvc_status_success) {
- shaderc_spvc_status compile_status =
- shaderc_spvc_compile_shader(context, result);
- if (compile_status == shaderc_spvc_status_success) {
- const char* result_str;
- shaderc_spvc_result_get_string_output(result, &result_str);
- printf("success! %lu characters of %s\n",
- (unsigned long)(strlen(result_str)),
- target_lang);
- ret_val = 1;
- } else {
- printf("failed to produce %s\n", target_lang);
- ret_val = 0;
- }
- } else {
- printf("failed to initialize %s\n", target_lang);
- ret_val = 0;
- }
-
- shaderc_spvc_result_destroy(result);
- return ret_val;
-}
-
-int run_glsl(shaderc_spvc_context_t context,
- shaderc_spvc_compile_options_t options,
- shaderc_compilation_result_t assembled_shader) {
- return test_exec(context, options, assembled_shader,
- shaderc_spvc_initialize_for_glsl, "glsl");
-}
-
-int run_hlsl(shaderc_spvc_context_t context,
- shaderc_spvc_compile_options_t options,
- shaderc_compilation_result_t assembled_shader) {
- return test_exec(context, options, assembled_shader,
- shaderc_spvc_initialize_for_hlsl, "hlsl");
-}
-
-int run_msl(shaderc_spvc_context_t context,
- shaderc_spvc_compile_options_t options,
- shaderc_compilation_result_t assembled_shader) {
- return test_exec(context, options, assembled_shader,
- shaderc_spvc_initialize_for_msl, "msl");
-}
-
-int run_smoke_test(const char* shader, int transform_from_webgpu) {
- shaderc_compilation_result_t assembled_shader = assemble_shader(shader);
- if (assembled_shader == NULL) {
- printf("failed to assemble input!\n");
- return -1;
- }
-
- int ret_code = 0;
- shaderc_spvc_context_t context = shaderc_spvc_context_create();
- shaderc_spvc_compile_options_t options;
- if (transform_from_webgpu) {
- options = shaderc_spvc_compile_options_create(
- shaderc_spvc_spv_env_webgpu_0, shaderc_spvc_spv_env_vulkan_1_1);
- } else {
- options = shaderc_spvc_compile_options_create(
- shaderc_spvc_spv_env_vulkan_1_0, shaderc_spvc_spv_env_vulkan_1_0);
- }
-
- if (!run_glsl(context, options, assembled_shader)) ret_code = -1;
- if (!run_hlsl(context, options, assembled_shader)) ret_code = -1;
- if (!run_msl(context, options, assembled_shader)) ret_code = -1;
-
- shaderc_spvc_compile_options_destroy(options);
- shaderc_spvc_context_destroy(context);
- shaderc_result_release(assembled_shader);
-
- return ret_code;
-}
diff --git a/libshaderc_spvc/src/spvc_smoke_test_util.h b/libshaderc_spvc/src/spvc_smoke_test_util.h
deleted file mode 100644
index 430a37e..0000000
--- a/libshaderc_spvc/src/spvc_smoke_test_util.h
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2019 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// Runs the smoke test on the given shader with or without transforming the
-// input from WebGPU specific SPIR-V.
-int run_smoke_test(const char* shader, int transform_from_webgpu);
diff --git a/libshaderc_spvc/src/spvc_test.cc b/libshaderc_spvc/src/spvc_test.cc
deleted file mode 100644
index 3409668..0000000
--- a/libshaderc_spvc/src/spvc_test.cc
+++ /dev/null
@@ -1,162 +0,0 @@
-// Copyright 2018 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "spvc/spvc.h"
-
-#include <gtest/gtest.h>
-
-#include <thread>
-
-#include "common_shaders_for_test.h"
-#include "spvc_private.h"
-
-namespace {
-
-class CompileTest : public testing::Test {
- public:
- void SetUp() override {
- context_ = shaderc_spvc_context_create();
- options_ = shaderc_spvc_compile_options_create(
- shaderc_spvc_spv_env_vulkan_1_1, shaderc_spvc_spv_env_vulkan_1_1);
- result_ = shaderc_spvc_result_create();
- }
-
- void TearDown() override {
- shaderc_spvc_context_destroy(context_);
- shaderc_spvc_compile_options_destroy(options_);
- shaderc_spvc_result_destroy(result_);
- }
-
- shaderc_spvc_context_t context_;
- shaderc_spvc_compile_options_t options_;
- shaderc_spvc_compilation_result_t result_;
-};
-
-TEST(Init, MultipleCalls) {
- shaderc_spvc_context_t context1, context2, context3;
- EXPECT_NE(nullptr, context1 = shaderc_spvc_context_create());
- EXPECT_NE(nullptr, context2 = shaderc_spvc_context_create());
- EXPECT_NE(nullptr, context3 = shaderc_spvc_context_create());
- shaderc_spvc_context_destroy(context1);
- shaderc_spvc_context_destroy(context2);
- shaderc_spvc_context_destroy(context3);
-}
-
-#ifndef SHADERC_DISABLE_THREADED_TESTS
-TEST(Init, MultipleThreadsCalling) {
- shaderc_spvc_context_t context1, context2, context3;
- std::thread t1([&context1]() { context1 = shaderc_spvc_context_create(); });
- std::thread t2([&context2]() { context2 = shaderc_spvc_context_create(); });
- std::thread t3([&context3]() { context3 = shaderc_spvc_context_create(); });
- t1.join();
- t2.join();
- t3.join();
- EXPECT_NE(nullptr, context1);
- EXPECT_NE(nullptr, context2);
- EXPECT_NE(nullptr, context3);
- shaderc_spvc_context_destroy(context1);
- shaderc_spvc_context_destroy(context2);
- shaderc_spvc_context_destroy(context3);
-}
-#endif
-
-TEST_F(CompileTest, ValidShaderIntoGlslPasses) {
- {
- shaderc_spvc_status status = shaderc_spvc_initialize_for_glsl(
- context_, kSmokeShaderBinary,
- sizeof(kSmokeShaderBinary) / sizeof(uint32_t), options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- EXPECT_NE(context_->cross_compiler.get(), nullptr);
- }
- {
- shaderc_spvc_status status = shaderc_spvc_compile_shader(context_, result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
-}
-
-TEST_F(CompileTest, InvalidShaderIntoGlslPasses) {
- shaderc_spvc_status status = shaderc_spvc_initialize_for_glsl(
- context_, kInvalidShaderBinary,
- sizeof(kInvalidShaderBinary) / sizeof(uint32_t), options_);
- EXPECT_NE(shaderc_spvc_status_success, status);
- EXPECT_EQ(context_->cross_compiler.get(), nullptr);
-}
-
-TEST_F(CompileTest, ValidShaderIntoHlslPasses) {
- {
- shaderc_spvc_status status = shaderc_spvc_initialize_for_hlsl(
- context_, kSmokeShaderBinary,
- sizeof(kSmokeShaderBinary) / sizeof(uint32_t), options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- EXPECT_NE(context_->cross_compiler.get(), nullptr);
- }
- {
- shaderc_spvc_status status = shaderc_spvc_compile_shader(context_, result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
-}
-
-TEST_F(CompileTest, InvalidShaderIntoHlslPasses) {
- shaderc_spvc_status status = shaderc_spvc_initialize_for_hlsl(
- context_, kInvalidShaderBinary,
- sizeof(kInvalidShaderBinary) / sizeof(uint32_t), options_);
- EXPECT_NE(shaderc_spvc_status_success, status);
- EXPECT_EQ(context_->cross_compiler.get(), nullptr);
-}
-
-TEST_F(CompileTest, ValidShaderIntoMslPasses) {
- {
- shaderc_spvc_status status = shaderc_spvc_initialize_for_msl(
- context_, kSmokeShaderBinary,
- sizeof(kSmokeShaderBinary) / sizeof(uint32_t), options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- EXPECT_NE(context_->cross_compiler.get(), nullptr);
- }
- {
- shaderc_spvc_status status = shaderc_spvc_compile_shader(context_, result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
-}
-
-TEST_F(CompileTest, InvalidShaderIntoMslPasses) {
- shaderc_spvc_status status = shaderc_spvc_initialize_for_msl(
- context_, kInvalidShaderBinary,
- sizeof(kInvalidShaderBinary) / sizeof(uint32_t), options_);
- EXPECT_NE(shaderc_spvc_status_success, status);
- EXPECT_EQ(context_->cross_compiler.get(), nullptr);
-}
-
-TEST_F(CompileTest, ValidShaderIntoVulkanPasses) {
- {
- shaderc_spvc_status status = shaderc_spvc_initialize_for_vulkan(
- context_, kSmokeShaderBinary,
- sizeof(kSmokeShaderBinary) / sizeof(uint32_t), options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- EXPECT_NE(context_->cross_compiler.get(), nullptr);
- }
- {
- shaderc_spvc_status status = shaderc_spvc_compile_shader(context_, result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
-}
-
-TEST_F(CompileTest, InvalidShaderIntoVulkanPasses) {
- shaderc_spvc_status status = shaderc_spvc_initialize_for_vulkan(
- context_, kInvalidShaderBinary,
- sizeof(kInvalidShaderBinary) / sizeof(uint32_t), options_);
- EXPECT_NE(shaderc_spvc_status_success, status);
- EXPECT_EQ(context_->cross_compiler.get(), nullptr);
-}
-
-} // namespace
diff --git a/libshaderc_spvc/src/spvc_webgpu_c_smoke_test.c b/libshaderc_spvc/src/spvc_webgpu_c_smoke_test.c
deleted file mode 100644
index d4360a7..0000000
--- a/libshaderc_spvc/src/spvc_webgpu_c_smoke_test.c
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2019 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "common_shaders_for_test.h"
-#include "spvc_smoke_test_util.h"
-
-// This test is meant to be for the C API, so using a plain old C file, thus
-// gtest cannot be used, so running as a simple smoke test.
-int main() { return run_smoke_test(kWebGPUShader, 1); }
diff --git a/libshaderc_spvc/src/spvc_webgpu_cpp_test.cc b/libshaderc_spvc/src/spvc_webgpu_cpp_test.cc
deleted file mode 100644
index 753493b..0000000
--- a/libshaderc_spvc/src/spvc_webgpu_cpp_test.cc
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright 2019 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <gtest/gtest.h>
-
-#include "common_shaders_for_test.h"
-#include "spvc/spvc.hpp"
-
-using shaderc_spvc::CompilationResult;
-using shaderc_spvc::CompileOptions;
-using shaderc_spvc::Context;
-
-namespace {
-
-class CompileTest : public testing::Test {
- public:
- CompileTest()
- : options_(shaderc_spvc_spv_env_webgpu_0,
- shaderc_spvc_spv_env_vulkan_1_1) {}
-
- Context context_;
- CompileOptions options_;
- CompilationResult result_;
-};
-
-TEST_F(CompileTest, Glsl) {
- {
- shaderc_spvc_status status = context_.InitializeForGlsl(
- kWebGPUShaderBinary, sizeof(kWebGPUShaderBinary) / sizeof(uint32_t),
- options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
- {
- shaderc_spvc_status status = context_.CompileShader(&result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- std::string string_output;
- result_.GetStringOutput(&string_output);
- EXPECT_NE(0, string_output.size());
- std::vector<uint32_t> binary_output;
- result_.GetBinaryOutput(&binary_output);
- EXPECT_EQ(0, binary_output.size());
- }
-}
-
-TEST_F(CompileTest, Hlsl) {
- {
- shaderc_spvc_status status = context_.InitializeForHlsl(
- kWebGPUShaderBinary, sizeof(kWebGPUShaderBinary) / sizeof(uint32_t),
- options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
- {
- shaderc_spvc_status status = context_.CompileShader(&result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- std::string string_output;
- result_.GetStringOutput(&string_output);
- EXPECT_NE(0, string_output.size());
- std::vector<uint32_t> binary_output;
- result_.GetBinaryOutput(&binary_output);
- EXPECT_EQ(0, binary_output.size());
- }
-}
-
-TEST_F(CompileTest, Msl) {
- {
- shaderc_spvc_status status = context_.InitializeForMsl(
- kWebGPUShaderBinary, sizeof(kWebGPUShaderBinary) / sizeof(uint32_t),
- options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
- {
- shaderc_spvc_status status = context_.CompileShader(&result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- std::string string_output;
- result_.GetStringOutput(&string_output);
- EXPECT_NE(0, string_output.size());
- std::vector<uint32_t> binary_output;
- result_.GetBinaryOutput(&binary_output);
- EXPECT_EQ(0, binary_output.size());
- }
-}
-
-TEST_F(CompileTest, Vulkan) {
- {
- shaderc_spvc_status status = context_.InitializeForVulkan(
- kWebGPUShaderBinary, sizeof(kWebGPUShaderBinary) / sizeof(uint32_t),
- options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
- {
- shaderc_spvc_status status = context_.CompileShader(&result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- std::string string_output;
- result_.GetStringOutput(&string_output);
- EXPECT_EQ(0, string_output.size());
- std::vector<uint32_t> binary_output;
- result_.GetBinaryOutput(&binary_output);
- EXPECT_NE(0, binary_output.size());
- }
-}
-
-} // anonymous namespace
diff --git a/libshaderc_spvc/src/spvc_webgpu_test.cc b/libshaderc_spvc/src/spvc_webgpu_test.cc
deleted file mode 100644
index cb023ce..0000000
--- a/libshaderc_spvc/src/spvc_webgpu_test.cc
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright 2019 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <gtest/gtest.h>
-
-#include <thread>
-
-#include "common_shaders_for_test.h"
-#include "spvc/spvc.h"
-#include "spvc_private.h"
-
-namespace {
-
-class CompileTest : public testing::Test {
- public:
- void SetUp() override {
- context_ = shaderc_spvc_context_create();
- options_ = shaderc_spvc_compile_options_create(
- shaderc_spvc_spv_env_webgpu_0, shaderc_spvc_spv_env_vulkan_1_1);
- result_ = shaderc_spvc_result_create();
- }
-
- void TearDown() override {
- shaderc_spvc_context_destroy(context_);
- shaderc_spvc_compile_options_destroy(options_);
- shaderc_spvc_result_destroy(result_);
- }
-
- shaderc_spvc_context_t context_;
- shaderc_spvc_compile_options_t options_;
- shaderc_spvc_compilation_result_t result_;
-};
-
-TEST_F(CompileTest, ValidShaderIntoGlslPasses) {
- {
- shaderc_spvc_status status = shaderc_spvc_initialize_for_glsl(
- context_, kWebGPUShaderBinary,
- sizeof(kWebGPUShaderBinary) / sizeof(uint32_t), options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- EXPECT_NE(context_->cross_compiler.get(), nullptr);
- }
- {
- shaderc_spvc_status status =
- shaderc_spvc_compile_shader(context_, result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
-}
-
-TEST_F(CompileTest, ValidShaderIntoHlslPasses) {
- {
- shaderc_spvc_status status = shaderc_spvc_initialize_for_hlsl(
- context_, kWebGPUShaderBinary,
- sizeof(kWebGPUShaderBinary) / sizeof(uint32_t), options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- EXPECT_NE(context_->cross_compiler.get(), nullptr);
- }
- {
- shaderc_spvc_status status =
- shaderc_spvc_compile_shader(context_, result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
-}
-
-TEST_F(CompileTest, ValidShaderIntoMslPasses) {
- {
- shaderc_spvc_status status = shaderc_spvc_initialize_for_msl(
- context_, kWebGPUShaderBinary,
- sizeof(kWebGPUShaderBinary) / sizeof(uint32_t), options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- EXPECT_NE(context_->cross_compiler.get(), nullptr);
- }
- {
- shaderc_spvc_status status =
- shaderc_spvc_compile_shader(context_, result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
-}
-
-TEST_F(CompileTest, ValidShaderIntoVulkanPasses) {
- {
- shaderc_spvc_status status = shaderc_spvc_initialize_for_vulkan(
- context_, kWebGPUShaderBinary,
- sizeof(kWebGPUShaderBinary) / sizeof(uint32_t), options_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- EXPECT_NE(context_->cross_compiler.get(), nullptr);
- }
- {
- shaderc_spvc_status status =
- shaderc_spvc_compile_shader(context_, result_);
- EXPECT_EQ(shaderc_spvc_status_success, status);
- }
-}
-
-} // anonymous namespace
diff --git a/libshaderc_spvc/src/spvcir_pass.cc b/libshaderc_spvc/src/spvcir_pass.cc
deleted file mode 100644
index ee6a2c0..0000000
--- a/libshaderc_spvc/src/spvcir_pass.cc
+++ /dev/null
@@ -1,1270 +0,0 @@
-// Copyright 2019 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "spvcir_pass.h"
-
-#include "source/opt/ir_context.h"
-
-namespace spvtools {
-namespace opt {
-
-static bool decoration_is_string(spv::Decoration decoration) {
- switch (decoration) {
- case spv::DecorationHlslSemanticGOOGLE:
- return true;
-
- default:
- return false;
- }
-}
-
-void SpvcIrPass::make_constant_null(uint32_t id, uint32_t type) {
- // TODO(sarahM0): Add more tests
- auto &constant_type = get<spirv_cross::SPIRType>(type);
-
- if (constant_type.pointer) {
- auto &constant = set<spirv_cross::SPIRConstant>(id, type);
- constant.make_null(constant_type);
- } else if (!constant_type.array.empty()) {
- if (!CheckConditionAndSetErrorMessage(
- constant_type.parent_type,
- "constant type parent shouldn't be empty"))
- return;
- uint32_t parent_id = ir_->increase_bound_by(1);
- make_constant_null(parent_id, constant_type.parent_type);
-
- if (!CheckConditionAndSetErrorMessage(
- constant_type.array_size_literal.back(),
- "Array size of OpConstantNull must be a literal."))
- return;
-
- spirv_cross::SmallVector<uint32_t> elements(constant_type.array.back());
- for (uint32_t i = 0; i < constant_type.array.back(); i++)
- elements[i] = parent_id;
- set<spirv_cross::SPIRConstant>(id, type, elements.data(),
- uint32_t(elements.size()), false);
- } else if (!constant_type.member_types.empty()) {
- uint32_t member_ids =
- ir_->increase_bound_by(uint32_t(constant_type.member_types.size()));
- spirv_cross::SmallVector<uint32_t> elements(
- constant_type.member_types.size());
- for (uint32_t i = 0; i < constant_type.member_types.size(); i++) {
- make_constant_null(member_ids + i, constant_type.member_types[i]);
- elements[i] = member_ids + i;
- }
- set<spirv_cross::SPIRConstant>(id, type, elements.data(),
- uint32_t(elements.size()), false);
- } else {
- auto &constant = set<spirv_cross::SPIRConstant>(id, type);
- constant.make_null(constant_type);
- }
-}
-
-bool SpvcIrPass::types_are_logically_equivalent(
- const spirv_cross::SPIRType &a, const spirv_cross::SPIRType &b) const {
- if (a.basetype != b.basetype) return false;
- if (a.width != b.width) return false;
- if (a.vecsize != b.vecsize) return false;
- if (a.columns != b.columns) return false;
- if (a.array.size() != b.array.size()) return false;
-
- size_t array_count = a.array.size();
- if (array_count && memcmp(a.array.data(), b.array.data(),
- array_count * sizeof(uint32_t)) != 0)
- return false;
-
- if (a.basetype == spirv_cross::SPIRType::Image ||
- a.basetype == spirv_cross::SPIRType::SampledImage) {
- if (memcmp(&a.image, &b.image, sizeof(spirv_cross::SPIRType::Image)) != 0)
- return false;
- }
-
- if (a.member_types.size() != b.member_types.size()) return false;
-
- size_t member_types = a.member_types.size();
- for (size_t i = 0; i < member_types; i++) {
- if (!types_are_logically_equivalent(
- get<spirv_cross::SPIRType>(a.member_types[i]),
- get<spirv_cross::SPIRType>(b.member_types[i])))
- return false;
- }
-
- return true;
-}
-
-// Returns the string representation of the data starting at the index of the
-// given instruction, assuming data is null terminated.
-inline std::string GetWordsAsString(uint32_t index, Instruction *inst) {
- return reinterpret_cast<const char *>(inst->GetInOperand(index).words.data());
-}
-
-SpvcIrPass::SpvcIrPass(spirv_cross::ParsedIR *ir) {
- ir_ = ir;
- current_function_ = nullptr;
- current_block_ = nullptr;
- status_ = Status::SuccessWithoutChange;
-}
-
-bool SpvcIrPass::CheckConditionAndSetErrorMessage(bool condition,
- std::string message) {
- if (!condition) {
- status_ = Status::Failure;
- if (consumer()) {
- consumer()(SPV_MSG_ERROR, 0, {0, 0, 0}, message.c_str());
- } else {
- assert(condition && message.c_str());
- }
- }
- return condition;
-}
-
-Pass::Status SpvcIrPass::Process() {
- auto s = ir_->spirv.data();
- if (!CheckConditionAndSetErrorMessage(ir_->spirv.size() > 3,
- "SpvcIrPass: spirv data is too small"))
- return Status::Failure;
-
- uint32_t bound = s[3];
- ir_->set_id_bounds(bound);
- get_module()->ForEachInst(
- [this](Instruction *inst) {
- if (status_ != Status::SuccessWithoutChange) return;
- GenerateSpirvCrossIR(inst);
- },
- true);
-
- if (!CheckConditionAndSetErrorMessage(
- !current_block_,
- "SpvcIrPass: Error at the end of parsing, block was not terminated."))
- return status_;
-
- if (!CheckConditionAndSetErrorMessage(
- !current_function_,
- "SpvcIrPass: Error at the end of parsing, function was not "
- "terminated."))
- return status_;
-
- return status_;
-}
-
-void SpvcIrPass::GenerateSpirvCrossIR(Instruction *inst) {
- switch (inst->opcode()) {
- case SpvOpSourceContinued:
- case SpvOpSourceExtension:
- case SpvOpNop:
- case SpvOpModuleProcessed:
- break;
-
- // opcode: 1
- case SpvOpUndef: {
- uint32_t result_type = inst->type_id();
- uint32_t id = inst->result_id();
- set<spirv_cross::SPIRUndef>(id, result_type);
-
- if (current_block_) {
- spirv_cross::Instruction instr = {};
- instr.op = inst->opcode();
- instr.count = inst->NumOperandWords() + 1;
- instr.offset = offset_ + 1;
- instr.length = instr.count - 1;
-
- current_block_->ops.push_back(instr);
- }
- break;
- }
-
- case SpvOpSource: {
- auto lang =
- static_cast<spv::SourceLanguage>(inst->GetSingleWordInOperand(0u));
- switch (lang) {
- case spv::SourceLanguageESSL:
- ir_->source.es = true;
- ir_->source.version = inst->GetSingleWordInOperand(1u);
- ir_->source.known = true;
- ir_->source.hlsl = false;
- break;
-
- case spv::SourceLanguageGLSL:
- ir_->source.es = false;
- ir_->source.version = inst->GetSingleWordInOperand(1u);
- ir_->source.known = true;
- ir_->source.hlsl = false;
- break;
-
- case spv::SourceLanguageHLSL:
- // For purposes of cross-compiling, this is GLSL 450.
- ir_->source.es = false;
- ir_->source.version = 450;
- ir_->source.known = true;
- ir_->source.hlsl = true;
- break;
-
- default:
- ir_->source.known = false;
- break;
- }
- break;
- }
-
- case SpvOpCapability: {
- auto cap = inst->GetSingleWordInOperand(0u);
-
- if (!CheckConditionAndSetErrorMessage(
- cap != spv::CapabilityKernel,
- "SpvcIrPass: Error while parsing OpCapability, "
- "kernel capability not supported."))
- return;
- ir_->declared_capabilities.push_back(static_cast<spv::Capability>(cap));
- break;
- }
-
- case SpvOpExtension: {
- const std::string extension_name = GetWordsAsString(0u, inst);
- ir_->declared_extensions.push_back(extension_name);
- break;
- }
-
- // opcode: 5
- case SpvOpName: {
- uint32_t id = inst->GetSingleWordInOperand(0u);
- ir_->set_name(id, GetWordsAsString(1u, inst));
- break;
- }
-
- // opcode:6
- case SpvOpMemberName: {
- uint32_t id = inst->GetSingleWordInOperand(0u);
- uint32_t member = inst->GetSingleWordInOperand(1u);
- ir_->set_member_name(id, member, GetWordsAsString(2u, inst));
- break;
- }
-
- // opcode: 7
- case SpvOpString: {
- set<spirv_cross::SPIRString>(inst->result_id(),
- GetWordsAsString(0u, inst));
- break;
- }
-
- // opcode:11
- case SpvOpExtInstImport: {
- uint32_t id = inst->result_id();
- std::string ext(
- reinterpret_cast<const char *>(inst->GetInOperand(0u).words.data()));
- if (ext == "GLSL.std.450")
- set<spirv_cross::SPIRExtension>(id, spirv_cross::SPIRExtension::GLSL);
- else if (ext == "DebugInfo")
- set<spirv_cross::SPIRExtension>(
- id, spirv_cross::SPIRExtension::SPV_debug_info);
- else if (ext == "SPV_AMD_shader_ballot")
- set<spirv_cross::SPIRExtension>(
- id, spirv_cross::SPIRExtension::SPV_AMD_shader_ballot);
- else if (ext == "SPV_AMD_shader_explicit_vertex_parameter")
- set<spirv_cross::SPIRExtension>(
- id, spirv_cross::SPIRExtension::
- SPV_AMD_shader_explicit_vertex_parameter);
- else if (ext == "SPV_AMD_shader_trinary_minmax")
- set<spirv_cross::SPIRExtension>(
- id, spirv_cross::SPIRExtension::SPV_AMD_shader_trinary_minmax);
- else if (ext == "SPV_AMD_gcn_shader")
- set<spirv_cross::SPIRExtension>(
- id, spirv_cross::SPIRExtension::SPV_AMD_gcn_shader);
- else {
- // spirv-cross comment:
- // Other SPIR-V extensions which have ExtInstrs are currently not
- // supported.
- // TODO(sarahM0): figure out which ones are not supported and try to
- // add them.
- if (!CheckConditionAndSetErrorMessage(
- false,
- "SpvcIrPass: Error while parsing "
- "OpExtInstImport, SPIRV extension "
- "not supported: " +
- ext))
- return;
- }
- break;
- }
-
- // opcode: 12
- // TODO(sarahM0): Figure out how to test this.
- case SpvOpExtInst: {
- // spirv_cross comment:
- // The SPIR-V debug information extended instructions might come at
- // global scope.
- spirv_cross::Instruction instruction = {};
- instruction.op = inst->opcode();
- instruction.count = inst->NumOperandWords() + 1;
- instruction.offset = offset_ + 1;
- instruction.length = instruction.count - 1;
- if (current_block_) current_block_->ops.push_back(instruction);
- break;
- }
-
- // opcode: 14
- case SpvOpMemoryModel: {
- ir_->addressing_model =
- static_cast<spv::AddressingModel>(inst->GetSingleWordInOperand(0u));
- ir_->memory_model =
- static_cast<spv::MemoryModel>(inst->GetSingleWordInOperand(1u));
- break;
- }
-
- // opcode:15
- case SpvOpEntryPoint: {
- auto function_id = inst->GetSingleWordInOperand(1u);
- auto execution_mode =
- static_cast<spv::ExecutionModel>(inst->GetSingleWordInOperand(0u));
-
- const char *entry_name =
- reinterpret_cast<const char *>(inst->GetInOperand(2u).words.data());
-
- auto itr = ir_->entry_points.insert(std::make_pair(
- function_id, spirv_cross::SPIREntryPoint(function_id, execution_mode,
- entry_name)));
- auto &e = itr.first->second;
- ir_->set_name(function_id, e.name);
-
- for (uint32_t i = 3; i < inst->NumInOperands(); ++i) {
- e.interface_variables.push_back(inst->GetSingleWordInOperand(i));
- }
-
- if (!ir_->default_entry_point) ir_->default_entry_point = function_id;
- break;
- }
-
- // opcode: 16
- case SpvOpExecutionMode: {
- auto &execution = ir_->entry_points[inst->GetSingleWordInOperand(0u)];
- auto mode =
- static_cast<SpvExecutionMode>(inst->GetSingleWordInOperand(1u));
- execution.flags.set(mode);
-
- switch (mode) {
- case SpvExecutionModeInvocations: {
- execution.invocations = inst->GetSingleWordInOperand(2u);
- break;
- }
-
- case SpvExecutionModeLocalSize: {
- execution.workgroup_size.x = inst->GetSingleWordInOperand(2u);
- execution.workgroup_size.y = inst->GetSingleWordInOperand(3u);
- execution.workgroup_size.z = inst->GetSingleWordInOperand(4u);
- break;
- }
-
- case SpvExecutionModeOutputVertices: {
- execution.output_vertices = inst->GetSingleWordInOperand(2u);
- break;
- }
-
- default: {
- break;
- // Other executions modes are set as part of "Bitset flags" member
- // of struct SPIREntryPoint in the compiler
- }
- }
- break;
- }
-
- // opcode: 71
- case SpvOpDecorate:
- // opcode: 332
- case SpvOpDecorateId: {
- // spirv-cross comment:
- // OpDecorateId technically supports an array of arguments, but our
- // only supported decorations are single uint, so merge decorate and
- // decorate-id here.
- // TODO(sarahM0): investigate if this limitation is acceptable.
- uint32_t id = inst->GetSingleWordInOperand(0u);
-
- auto decoration =
- static_cast<spv::Decoration>(inst->GetSingleWordInOperand(1u));
- if (inst->NumInOperands() > 2) {
- // instruction offset + length = offset_ + 1 +
- // inst->NumOpreandWords()
- if (!CheckConditionAndSetErrorMessage(
- offset_ + 1 + inst->NumOperandWords() < ir_->spirv.size(),
- "SpvcIrPass: Error while parsing OpDecorate/OpDecorateId, "
- "reading out of spirv.data() bound"))
- return;
- // The extra operand of the decoration (Literal, Literal, …) are at
- // instruction offset + 2 (skipping <id>Target, Decoration)
- ir_->meta[id].decoration_word_offset[decoration] =
- uint32_t((&ir_->spirv[offset_ + 1] + 2) - ir_->spirv.data());
- ir_->set_decoration(id, decoration, inst->GetSingleWordInOperand(2u));
- } else {
- ir_->set_decoration(id, decoration);
- }
-
- break;
- }
-
- // opcode: 72
- case SpvOpMemberDecorate: {
- uint32_t id = inst->GetSingleWordInOperand(0u);
- uint32_t member = inst->GetSingleWordInOperand(1u);
- auto decoration =
- static_cast<spv::Decoration>(inst->GetSingleWordInOperand(2u));
- if (inst->NumInOperands() >= 4)
- ir_->set_member_decoration(id, member, decoration,
- inst->GetSingleWordInOperand(3u));
- else
- ir_->set_member_decoration(id, member, decoration);
- break;
- }
-
- // opcode: 73
- case SpvOpDecorationGroup: {
- // spirv-cross comment:
- // Noop, this simply means an ID should be a collector of decorations.
- // The meta array is already a flat array of decorations which will
- // contain the relevant decorations.
- break;
- }
-
- // opcode: 74
- case SpvOpGroupDecorate: {
- uint32_t group_id = inst->GetSingleWordInOperand(0u);
- auto &decorations = ir_->meta[group_id].decoration;
- auto &flags = decorations.decoration_flags;
-
- // Copies decorations from one ID to another. Only copy decorations which
- // are set in the group, i.e., we cannot just copy the meta structure
- // directly.
- for (uint32_t i = 1; i < inst->NumInOperands(); i++) {
- uint32_t target = inst->GetSingleWordInOperand(i);
- flags.for_each_bit([&](uint32_t bit) {
- auto decoration = static_cast<spv::Decoration>(bit);
-
- if (decoration_is_string(decoration)) {
- ir_->set_decoration_string(
- target, decoration,
- ir_->get_decoration_string(group_id, decoration));
- } else {
- ir_->meta[target].decoration_word_offset[decoration] =
- ir_->meta[group_id].decoration_word_offset[decoration];
- ir_->set_decoration(target, decoration,
- ir_->get_decoration(group_id, decoration));
- }
- });
- }
- break;
- }
-
- // opcode: 75
- case SpvOpGroupMemberDecorate: {
- uint32_t group_id = inst->GetSingleWordInOperand(0u);
- auto &flags = ir_->meta[group_id].decoration.decoration_flags;
-
- // Copies decorations from one ID to another. Only copy decorations which
- // are set in the group, i.e., we cannot just copy the meta structure
- // directly.
- for (uint32_t i = 1; i + 1 < inst->NumInOperands(); i += 2) {
- uint32_t target = inst->GetSingleWordInOperand(i + 0u);
- uint32_t index = inst->GetSingleWordInOperand(i + 1u);
- flags.for_each_bit([&](uint32_t bit) {
- auto decoration = static_cast<spv::Decoration>(bit);
-
- if (decoration_is_string(decoration))
- ir_->set_member_decoration_string(
- target, index, decoration,
- ir_->get_decoration_string(group_id, decoration));
- else
- ir_->set_member_decoration(
- target, index, decoration,
- ir_->get_decoration(group_id, decoration));
- });
- }
- break;
- }
-
- // opcode: 5632
- case SpvOpDecorateStringGOOGLE: {
- uint32_t id = inst->GetSingleWordInOperand(0u);
- auto decoration =
- static_cast<spv::Decoration>(inst->GetSingleWordInOperand(1u));
- ir_->set_decoration_string(id, decoration, GetWordsAsString(2u, inst));
- break;
- }
-
- // opcode: 5633
- case SpvOpMemberDecorateStringGOOGLE: {
- uint32_t id = inst->GetSingleWordInOperand(0u);
- uint32_t member = inst->GetSingleWordInOperand(1u);
- auto decoration =
- static_cast<spv::Decoration>(inst->GetSingleWordInOperand(2u));
- ir_->set_member_decoration_string(id, member, decoration,
- GetWordsAsString(3u, inst));
- break;
- }
-
- // Basic type cases
- // opcode: 19
- case SpvOpTypeVoid: {
- auto id = inst->result_id();
- auto &type = set<spirv_cross::SPIRType>(id);
- type.basetype = spirv_cross::SPIRType::Void;
- break;
- }
-
- // opcode: 20
- case SpvOpTypeBool: {
- uint32_t id = inst->result_id();
- auto &type = set<spirv_cross::SPIRType>(id);
- type.basetype = spirv_cross::SPIRType::Boolean;
- type.width = 1;
- break;
- }
-
- // opcode: 21
- case SpvOpTypeInt: {
- uint32_t id = inst->result_id();
- uint32_t width = inst->GetSingleWordInOperand(0u);
- bool signedness = inst->GetSingleWordInOperand(1u) != 0;
- auto &type = set<spirv_cross::SPIRType>(id);
- type.basetype = signedness ? spirv_cross::to_signed_basetype(width)
- : spirv_cross::to_unsigned_basetype(width);
- type.width = width;
- break;
- }
-
- // opcode: 22
- case SpvOpTypeFloat: {
- uint32_t id = inst->result_id();
- auto &type = set<spirv_cross::SPIRType>(id);
- uint32_t width = inst->GetSingleWordInOperand(0u);
- if (width == 64)
- type.basetype = spirv_cross::SPIRType::Double;
- else if (width == 32)
- type.basetype = spirv_cross::SPIRType::Float;
- else if (width == 16)
- type.basetype = spirv_cross::SPIRType::Half;
- else
- CheckConditionAndSetErrorMessage(
- false, "Unrecognized bit-width of floating point type.");
-
- type.width = width;
- break;
- }
-
- // opcode: 23
- // spirv-cross comment:
- // Build composite types by "inheriting".
- // NOTE: The self member is also copied! For pointers and array modifiers
- // this is a good thing since we can refer to decorations on pointee
- // classes which is needed for UBO/SSBO, I/O blocks in geometry/tess etc.
- case SpvOpTypeVector: {
- uint32_t id = inst->result_id();
- // TODO(sarahM0): ask if Column Count, in operand one, can be
- // double-word.
- uint32_t vecsize = inst->GetSingleWordInOperand(1u);
-
- auto &base = get<spirv_cross::SPIRType>(inst->GetSingleWordInOperand(0u));
- auto &vecbase = set<spirv_cross::SPIRType>(id);
-
- vecbase = base;
- vecbase.vecsize = vecsize;
- vecbase.self = id;
- vecbase.parent_type = inst->GetSingleWordInOperand(0u);
- break;
- }
-
- // opcode: 24
- case SpvOpTypeMatrix: {
- uint32_t id = inst->result_id();
- uint32_t colcount = inst->GetSingleWordInOperand(1u);
-
- auto &base = get<spirv_cross::SPIRType>(inst->GetSingleWordInOperand(0u));
- auto &matrixbase = set<spirv_cross::SPIRType>(id);
-
- matrixbase = base;
- matrixbase.columns = colcount;
- matrixbase.self = id;
- matrixbase.parent_type = inst->GetSingleWordInOperand(0u);
- break;
- }
-
- // opcode: 25
- case SpvOpTypeImage: {
- uint32_t id = inst->result_id();
- auto &type = set<spirv_cross::SPIRType>(id);
- type.basetype = spirv_cross::SPIRType::Image;
- type.image.type = inst->GetSingleWordInOperand(0u);
- type.image.dim = static_cast<spv::Dim>(inst->GetSingleWordInOperand(1u));
- type.image.depth = inst->GetSingleWordInOperand(2u) == 1;
- type.image.arrayed = inst->GetSingleWordInOperand(3u) != 0;
- type.image.ms = inst->GetSingleWordInOperand(4u) != 0;
- type.image.sampled = inst->GetSingleWordInOperand(5u);
- type.image.format =
- static_cast<spv::ImageFormat>(inst->GetSingleWordInOperand(6u));
- type.image.access = (inst->NumInOperands() > 7)
- ? static_cast<spv::AccessQualifier>(
- inst->GetSingleWordInOperand(7u))
- : spv::AccessQualifierMax;
- break;
- }
-
- // opcode: 26
- case SpvOpTypeSampler: {
- uint32_t id = inst->result_id();
- auto &type = set<spirv_cross::SPIRType>(id);
- type.basetype = spirv_cross::SPIRType::Sampler;
- break;
- }
-
- // opcode: 27
- case SpvOpTypeSampledImage: {
- uint32_t id = inst->result_id();
- uint32_t imagetype = inst->GetSingleWordInOperand(0u);
- auto &type = set<spirv_cross::SPIRType>(id);
- type = get<spirv_cross::SPIRType>(imagetype);
- type.basetype = spirv_cross::SPIRType::SampledImage;
- type.self = id;
- break;
- }
-
- // opcode: 28
- case SpvOpTypeArray: {
- uint32_t id = inst->result_id();
- auto &arraybase = set<spirv_cross::SPIRType>(id);
-
- uint32_t tid = inst->GetSingleWordInOperand(0u);
- auto &base = get<spirv_cross::SPIRType>(tid);
-
- arraybase = base;
- arraybase.parent_type = tid;
-
- uint32_t cid = inst->GetSingleWordInOperand(1u);
- ir_->mark_used_as_array_length(cid);
- auto *c = maybe_get<spirv_cross::SPIRConstant>(cid);
- bool literal = c && !c->specialization;
-
- arraybase.array_size_literal.push_back(literal);
- arraybase.array.push_back(literal ? c->scalar() : cid);
- // spirv-cross comment:
- // Do NOT set arraybase.self!
- break;
- }
-
- // opcode: 29
- case SpvOpTypeRuntimeArray: {
- auto id = inst->result_id();
- auto tid = inst->GetSingleWordInOperand(0u);
- auto &base = get<spirv_cross::SPIRType>(tid);
- auto &arraybase = set<spirv_cross::SPIRType>(id);
- arraybase = base;
- arraybase.array.push_back(0);
- arraybase.array_size_literal.push_back(true);
- arraybase.parent_type = tid;
- break;
- }
-
- // opcode: 32
- case SpvOpTypePointer: {
- uint32_t id = inst->result_id();
-
- auto &base = get<spirv_cross::SPIRType>(inst->GetSingleWordInOperand(1u));
- auto &ptrbase = set<spirv_cross::SPIRType>(id);
-
- ptrbase = base;
- ptrbase.pointer = true;
- ptrbase.pointer_depth++;
- ptrbase.storage =
- static_cast<spv::StorageClass>(inst->GetSingleWordInOperand(0u));
-
- if (ptrbase.storage == spv::StorageClassAtomicCounter)
- ptrbase.basetype = spirv_cross::SPIRType::AtomicCounter;
-
- ptrbase.parent_type = inst->GetSingleWordInOperand(1u);
-
- // spirv-cross comment:
- // Do NOT set ptrbase.self!
- break;
- }
-
- // opcode: 33
- case SpvOpTypeFunction: {
- auto id = inst->result_id();
- auto return_type = inst->GetSingleWordInOperand(0u);
-
- // Reading Parameter 0 Type, Parameter 1 Type, ...
- // Starting i at 1 to skip over the function return type parameter.
- auto &func = set<spirv_cross::SPIRFunctionPrototype>(id, return_type);
- for (uint32_t i = 1; i < inst->NumInOperands(); ++i) {
- func.parameter_types.push_back(inst->GetSingleWordInOperand(i));
- }
-
- break;
- }
-
- // opcode: 39
- case SpvOpTypeForwardPointer: {
- uint32_t id = inst->GetSingleWordInOperand(0u);
- auto &ptrbase = set<spirv_cross::SPIRType>(id);
- ptrbase.pointer = true;
- ptrbase.pointer_depth++;
- ptrbase.storage =
- static_cast<spv::StorageClass>(inst->GetSingleWordInOperand(1u));
- // TODO(sarahM0): add test for with AtomicCounter storage class
- if (ptrbase.storage == spv::StorageClassAtomicCounter)
- ptrbase.basetype = spirv_cross::SPIRType::AtomicCounter;
-
- break;
- }
-
- // opcode: 5341
- case SpvOpTypeAccelerationStructureKHR: {
- uint32_t id = inst->result_id();
- auto &type = set<spirv_cross::SPIRType>(id);
- type.basetype = spirv_cross::SPIRType::AccelerationStructure;
- break;
- }
-
- // Variable declaration
- // opcode: 59
- // spirv-cross comment:
- // All variables are essentially pointers with a storage qualifier.
- case SpvOpVariable: {
- uint32_t type = inst->type_id();
- uint32_t id = inst->result_id();
- auto storage =
- static_cast<spv::StorageClass>(inst->GetSingleWordInOperand(0u));
- uint32_t initializer =
- inst->NumInOperands() == 2 ? inst->GetSingleWordInOperand(1u) : 0;
-
- if (storage == spv::StorageClassFunction) {
- if (!CheckConditionAndSetErrorMessage(
- current_function_,
- "SpvcIrPass: Error while parsing OpVariable, "
- "no function currently in scope"))
- return;
- current_function_->add_local_variable(id);
- }
-
- set<spirv_cross::SPIRVariable>(id, type, storage, initializer);
-
- // spirv-cross comment:
- // hlsl based shaders don't have those decorations. force them and
- // then reset when reading/writing images
- auto &ttype = get<spirv_cross::SPIRType>(type);
- if (ttype.basetype == spirv_cross::SPIRType::BaseType::Image) {
- ir_->set_decoration(id, spv::DecorationNonWritable);
- ir_->set_decoration(id, spv::DecorationNonReadable);
- }
-
- break;
- }
-
- // opcode: 30
- case SpvOpTypeStruct: {
- uint32_t id = inst->result_id();
- auto &type = set<spirv_cross::SPIRType>(id);
- type.basetype = spirv_cross::SPIRType::Struct;
- for (uint32_t i = 0; i < inst->NumInOperands(); i++) {
- type.member_types.push_back(inst->GetSingleWordInOperand(i));
- }
-
- // TODO(sarahM0): ask about aliasing? figure out what is happening in
- // this loop.
- bool consider_aliasing = !ir_->get_name(type.self).empty();
- if (consider_aliasing) {
- for (auto &other : global_struct_cache_) {
- if (ir_->get_name(type.self) == ir_->get_name(other) &&
- types_are_logically_equivalent(
- type, get<spirv_cross::SPIRType>(other))) {
- type.type_alias = other;
- break;
- }
- }
-
- if (type.type_alias == spirv_cross::TypeID(0))
- global_struct_cache_.push_back(id);
- }
- break;
- }
-
- // Constant Cases
- // opcode: 50
- case SpvOpSpecConstant:
- // opcode: 43
- case SpvOpConstant: {
- uint32_t id = inst->result_id();
- auto &type = get<spirv_cross::SPIRType>(inst->type_id());
-
- // TODO(sarahM0): floating-point numbers of IEEE 754 are of length 16
- // bits, 32 bits, 64 bits, and any multiple of 32 bits up to 128 bits
- // Ask whether we need to support longer than 64 bits
- if (type.width > 32) {
- uint64_t combined_words = inst->GetInOperand(0u).words[1];
- combined_words = combined_words << 32;
- combined_words |= inst->GetInOperand(0u).words[0];
- set<spirv_cross::SPIRConstant>(id, inst->type_id(), combined_words,
- inst->opcode() == SpvOpSpecConstant);
- } else {
- set<spirv_cross::SPIRConstant>(id, inst->type_id(),
- inst->GetSingleWordInOperand(0u),
- inst->opcode() == SpvOpSpecConstant);
- }
- break;
- }
-
- // opcode: 49
- case SpvOpSpecConstantFalse:
- // opcode: 42
- case SpvOpConstantFalse: {
- uint32_t id = inst->result_id();
- set<spirv_cross::SPIRConstant>(id, inst->type_id(), 0u,
- inst->opcode() == SpvOpSpecConstantFalse);
- break;
- }
-
- // opcode: 48
- case SpvOpSpecConstantTrue:
- // opcode: 41
- case SpvOpConstantTrue: {
- uint32_t id = inst->result_id();
- set<spirv_cross::SPIRConstant>(id, inst->type_id(), 1u,
- inst->opcode() == SpvOpSpecConstantTrue);
- break;
- }
-
- // opcode: 46
- case SpvOpConstantNull: {
- uint32_t id = inst->result_id();
- uint32_t type = inst->type_id();
- make_constant_null(id, type);
- break;
- }
-
- // opcode: 51
- case SpvOpSpecConstantComposite:
- // opcode: 44
- case SpvOpConstantComposite: {
- uint32_t id = inst->result_id();
- uint32_t type = inst->type_id();
-
- auto &ctype = get<spirv_cross::SPIRType>(type);
-
- // spirv-cross comment:
- // We can have constants which are structs and arrays.
- // In this case, our SPIRConstant will be a list of other
- // SPIRConstant ids which we can refer to.
- if (ctype.basetype == spirv_cross::SPIRType::Struct ||
- !ctype.array.empty()) {
- set<spirv_cross::SPIRConstant>(
- id, type, (&ir_->spirv[offset_ + 1u] + 2u), inst->NumInOperands(),
- inst->opcode() == SpvOpSpecConstantComposite);
- } else {
- if (!CheckConditionAndSetErrorMessage(
- inst->NumInOperands() < 5,
- "OpConstantComposite only supports 1, 2, 3 and 4 elements."))
- return;
-
- spirv_cross::SPIRConstant remapped_constant_ops[4];
- const spirv_cross::SPIRConstant *c[4];
- for (uint32_t i = 0; i < inst->NumInOperands(); i++) {
- // spirv-cross comment:
- // Specialization constants operations can also be part of this.
- // We do not know their value, so any attempt to query
- // SPIRConstant later will fail. We can only propagate the ID of the
- // expression and use to_expression on it.
- auto *constant_op = maybe_get<spirv_cross::SPIRConstantOp>(
- inst->GetSingleWordInOperand(i));
- auto *undef_op = maybe_get<spirv_cross::SPIRUndef>(
- inst->GetSingleWordInOperand(i));
- if (constant_op) {
- if (!CheckConditionAndSetErrorMessage(
- inst->opcode() != SpvOpConstantComposite,
- "Specialization constant operation used in "
- "OpConstantComposite."))
- return;
-
- remapped_constant_ops[i].make_null(
- get<spirv_cross::SPIRType>(constant_op->basetype));
- remapped_constant_ops[i].self = constant_op->self;
- remapped_constant_ops[i].constant_type = constant_op->basetype;
- remapped_constant_ops[i].specialization = true;
- c[i] = &remapped_constant_ops[i];
- } else if (undef_op) {
- // spirv-cross comment:
- // Undefined, just pick 0.
- remapped_constant_ops[i].make_null(
- get<spirv_cross::SPIRType>(undef_op->basetype));
- remapped_constant_ops[i].constant_type = undef_op->basetype;
- c[i] = &remapped_constant_ops[i];
- } else {
- c[i] = &get<spirv_cross::SPIRConstant>(
- inst->GetSingleWordInOperand(i));
- }
- }
- set<spirv_cross::SPIRConstant>(
- id, type, c, inst->NumInOperands(),
- inst->opcode() == SpvOpSpecConstantComposite);
- }
- break;
- }
-
- case SpvOpSpecConstantOp: {
- uint32_t result_type = inst->type_id();
- uint32_t id = inst->result_id();
- auto spec_op = static_cast<spv::Op>(inst->GetSingleWordInOperand(0u));
-
- set<spirv_cross::SPIRConstantOp>(id, result_type, spec_op,
- (&ir_->spirv[offset_ + 1u] + 3u),
- inst->NumInOperands() - 1);
- break;
- }
-
- // Control Flow cases
-
- // opcode: 245
- // spirv-cross comment:
- // OpPhi is a fairly magical opcode.
- // It selects temporary variables based on which parent block we *came
- // from*. In high-level languages we can "de-SSA" by creating a function
- // local, and flush out temporaries to this function-local variable to
- // emulate SSA Phi.
- case SpvOpPhi: {
- if (!CheckConditionAndSetErrorMessage(
- current_function_,
- "SpvcIrPass: Trying to end a non-existing block."))
- return;
-
- if (!CheckConditionAndSetErrorMessage(
- current_block_, "SpvcIrPass: No block currently in scope"))
- return;
-
- uint32_t result_type = inst->type_id();
- uint32_t id = inst->result_id();
-
- // spirv-cross comment:
- // Instead of a temporary, create a new function-wide temporary with
- // this ID instead.
- auto &var = set<spirv_cross::SPIRVariable>(id, result_type,
- spv::StorageClassFunction);
- var.phi_variable = true;
-
- current_function_->add_local_variable(id);
-
- for (uint32_t i = 0; i + 1 < inst->NumInOperands(); i += 2)
- current_block_->phi_variables.push_back(
- {inst->GetSingleWordInOperand(i),
- inst->GetSingleWordInOperand(i + 1), id});
- break;
- }
-
- // opcode: 246
- case SpvOpLoopMerge: {
- if (!CheckConditionAndSetErrorMessage(
- current_block_,
- "SpvcIrPass: Trying to end a non-existing block."))
- return;
-
- current_block_->merge_block = inst->GetSingleWordInOperand(0u);
- current_block_->continue_block = inst->GetSingleWordInOperand(1u);
- current_block_->merge = spirv_cross::SPIRBlock::MergeLoop;
-
- ir_->block_meta[current_block_->self] |=
- spirv_cross::ParsedIR::BLOCK_META_LOOP_HEADER_BIT;
- ir_->block_meta[current_block_->merge_block] |=
- spirv_cross::ParsedIR::BLOCK_META_LOOP_MERGE_BIT;
-
- ir_->continue_block_to_loop_header[current_block_->continue_block] =
- spirv_cross::BlockID(current_block_->self);
- // spirv-cross comment:
- // Don't add loop headers to continue blocks,
- // which would make it impossible branch into the loop header since
- // they are treated as continues.
- if (current_block_->continue_block !=
- spirv_cross::BlockID(current_block_->self))
- ir_->block_meta[current_block_->continue_block] |=
- spirv_cross::ParsedIR::BLOCK_META_CONTINUE_BIT;
-
- if (inst->NumInOperands() > 3) {
- if (inst->GetSingleWordInOperand(2u) & spv::LoopControlUnrollMask)
- current_block_->hint = spirv_cross::SPIRBlock::HintUnroll;
- else if (inst->GetSingleWordInOperand(2u) &
- spv::LoopControlDontUnrollMask)
- current_block_->hint = spirv_cross::SPIRBlock::HintDontUnroll;
- }
- break;
- }
-
- // opcode 247
- case SpvOpSelectionMerge: {
- if (!CheckConditionAndSetErrorMessage(
- current_block_,
- "SpvcIrPass: Trying to end a non-existing block."))
- return;
- current_block_->next_block = inst->GetSingleWordInOperand(0u);
- current_block_->merge = spirv_cross::SPIRBlock::MergeSelection;
- ir_->block_meta[current_block_->next_block] |=
- spirv_cross::ParsedIR::BLOCK_META_SELECTION_MERGE_BIT;
-
- if (inst->NumInOperands() - 1 >= 2) {
- if (inst->GetSingleWordInOperand(1u) & spv::SelectionControlFlattenMask)
- current_block_->hint = spirv_cross::SPIRBlock::HintFlatten;
- else if (inst->GetSingleWordInOperand(1u) &
- spv::SelectionControlDontFlattenMask)
- current_block_->hint = spirv_cross::SPIRBlock::HintDontFlatten;
- }
- break;
- }
-
- // opcode: 248
- case SpvOpLabel: {
- // OpLabel always starts a block.
- if (!CheckConditionAndSetErrorMessage(
- current_function_,
- "SpvcIrPass: Error while parsing OpLable, blocks "
- "cannot exist outside functions!"))
- return;
-
- uint32_t id = inst->result_id();
-
- current_function_->blocks.push_back(id);
-
- if (!current_function_->entry_block) {
- current_function_->entry_block = id;
- }
- if (!CheckConditionAndSetErrorMessage(
- !current_block_,
- "SpvcIrPass: Error while parsing OpLable, cannot "
- "start a block before ending the current block."))
- return;
-
- current_block_ = &set<spirv_cross::SPIRBlock>(id);
- break;
- }
-
- // opcode: 249
- case SpvOpBranch: {
- if (!CheckConditionAndSetErrorMessage(
- current_block_,
- "SpvcIrPass: Trying to end a non-existing block."))
- return;
-
- uint32_t target = inst->GetSingleWordInOperand(0u);
- current_block_->terminator = spirv_cross::SPIRBlock::Direct;
- current_block_->next_block = target;
- current_block_ = nullptr;
- break;
- }
-
- // opcode: 250
- case SpvOpBranchConditional: {
- if (!CheckConditionAndSetErrorMessage(
- current_block_,
- "SpvcIrPass: Trying to end a non-existing block."))
- return;
-
- current_block_->condition = inst->GetSingleWordInOperand(0u);
- current_block_->true_block = inst->GetSingleWordInOperand(1u);
- current_block_->false_block = inst->GetSingleWordInOperand(2u);
-
- current_block_->terminator = spirv_cross::SPIRBlock::Select;
- current_block_ = nullptr;
- break;
- }
-
- // opcode: 251
- case SpvOpSwitch: {
- if (!CheckConditionAndSetErrorMessage(
- current_block_,
- "SpvcIrPass: Trying to end a non-existing block."))
- return;
- current_block_->terminator = spirv_cross::SPIRBlock::MultiSelect;
-
- current_block_->condition = inst->GetSingleWordInOperand(0u);
- current_block_->default_block = inst->GetSingleWordInOperand(1u);
-
- for (uint32_t i = 2; i + 1 < inst->NumInOperands(); i += 2)
- current_block_->cases.push_back({inst->GetSingleWordInOperand(i),
- inst->GetSingleWordInOperand(i + 1)});
- // spirv-cross comment:
- // If we jump to next block, make it break instead since we're inside a
- // switch case block at that point.
- ir_->block_meta[current_block_->next_block] |=
- spirv_cross::ParsedIR::BLOCK_META_MULTISELECT_MERGE_BIT;
-
- current_block_ = nullptr;
- break;
- }
-
- // opcode: 252
- case SpvOpKill: {
- if (!CheckConditionAndSetErrorMessage(
- current_block_,
- "SpvcIrPass: Trying to end a non-existing block."))
- return;
- current_block_->terminator = spirv_cross::SPIRBlock::Kill;
- current_block_ = nullptr;
- break;
- }
-
- // opcode: 253
- case SpvOpReturn: {
- if (!CheckConditionAndSetErrorMessage(
- current_block_,
- "SpvcIrPass: Error while parsing OpReturn, "
- "trying to end a non-existing block."))
- return;
- current_block_->terminator = spirv_cross::SPIRBlock::Return;
- current_block_ = nullptr;
- break;
- }
-
- // opcode: 254
- case SpvOpReturnValue: {
- if (!CheckConditionAndSetErrorMessage(
- current_block_,
- "SpvcIrPass: Trying to end a non-existing block."))
- return;
- current_block_->terminator = spirv_cross::SPIRBlock::Return;
- current_block_->return_value = inst->GetSingleWordInOperand(0u);
- current_block_ = nullptr;
- break;
- }
-
- // opcode: 255
- case SpvOpUnreachable: {
- if (!CheckConditionAndSetErrorMessage(
- current_block_,
- "SpvcIrPass: Trying to end a non-existing block. Opcode: " +
- std::to_string(inst->opcode())))
- return;
- current_block_->terminator = spirv_cross::SPIRBlock::Unreachable;
- current_block_ = nullptr;
- break;
- }
-
- // Function cases:
- // opcode: 54
- case SpvOpFunction: {
- auto result = inst->type_id();
- auto id = inst->result_id();
- auto type = inst->GetSingleWordInOperand(1u);
-
- if (!CheckConditionAndSetErrorMessage(
- !current_function_,
- "SpvcIrPass: Must end a function "
- "before starting a new one. Opcode: " +
- std::to_string(inst->opcode())))
- return;
-
- current_function_ = &set<spirv_cross::SPIRFunction>(id, result, type);
- break;
- }
-
- // opcode: 55
- case SpvOpFunctionParameter: {
- auto type = inst->type_id();
- auto id = inst->result_id();
-
- if (!CheckConditionAndSetErrorMessage(
- current_function_,
- "SpvcIrPass: OpFunctionParameter must be in a function!"))
- return;
- current_function_->add_parameter(type, id);
- set<spirv_cross::SPIRVariable>(id, type, spv::StorageClassFunction);
- break;
- }
-
- // opcode: 56
- case SpvOpFunctionEnd: {
- // Very specific error message, but seems to come up quite often.
- if (!CheckConditionAndSetErrorMessage(
- !current_block_,
- "SpvcIrPass: Error while parsing OpFunctionEnd, cannot end a "
- "function before ending the current block.\n"
- "Likely cause: If this SPIR-V was created from glslang HLSL, "
- "make sure the entry point is valid."))
- return;
- current_function_ = nullptr;
- break;
- }
-
- // opcode: 8
- case SpvOpLine: {
- // OpLine might come at global scope, but we don't care about those since
- // they will not be declared in any meaningful correct order. Ignore all
- // OpLine directives which live outside a function.
- if (current_block_) {
- spirv_cross::Instruction instr = {};
- instr.op = inst->opcode();
- instr.count = inst->NumOperandWords() + 1;
- instr.offset = offset_ + 1;
- instr.length = instr.count - 1;
- current_block_->ops.push_back(instr);
- }
- // Line directives may arrive before first OpLabel.
- // Treat this as the line of the function declaration,
- // so warnings for arguments can propagate properly.
- if (current_function_) {
- // Store the first one we find and emit it before creating the function
- // prototype.
- if (current_function_->entry_line.file_id == 0) {
- current_function_->entry_line.file_id =
- inst->GetSingleWordInOperand(0u);
- current_function_->entry_line.line_literal =
- inst->GetSingleWordInOperand(1u);
- }
- }
- break;
- }
-
- // opcode: 317
- case SpvOpNoLine: {
- // spirv_cross comment: OpNoLine might come at global scope.
- if (current_block_) {
- spirv_cross::Instruction instr = {};
- instr.op = inst->opcode();
- instr.count = inst->NumOperandWords() + 1;
- instr.offset = offset_ + 1;
- instr.length = instr.count - 1;
- current_block_->ops.push_back(instr);
- }
- break;
- }
-
- default: {
- if (!CheckConditionAndSetErrorMessage(
- current_block_,
- "SpvcIrPass: Currently no block to insert opcode."))
- return;
- spirv_cross::Instruction instr = {};
- instr.op = inst->opcode();
- instr.count = inst->NumOperandWords() + 1;
- instr.offset = offset_ + 1;
- instr.length = instr.count - 1;
-
- if (!CheckConditionAndSetErrorMessage(
- instr.count != 0,
- "SpvcIrPass: SPIR-V instructions cannot consume "
- "0 words. Invalid SPIR-V file."))
- return;
- if (!CheckConditionAndSetErrorMessage(
- offset_ <= ir_->spirv.size(),
- "SpvcIrPass: SPIR-V instruction goes out of bounds."))
- return;
- current_block_->ops.push_back(instr);
- break;
- }
- }
- offset_ += inst->NumOperandWords() + 1;
-}
-
-} // namespace opt
-} // namespace spvtools
diff --git a/libshaderc_spvc/src/spvcir_pass.h b/libshaderc_spvc/src/spvcir_pass.h
deleted file mode 100644
index b3c3a2b..0000000
--- a/libshaderc_spvc/src/spvcir_pass.h
+++ /dev/null
@@ -1,120 +0,0 @@
-// Copyright 2019 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef LIBSHADERC_SPVC_SRC_SPVCIR_PASS_H_
-#define LIBSHADERC_SPVC_SRC_SPVCIR_PASS_H_
-
-#include <spirv_glsl.hpp>
-#include <spirv_hlsl.hpp>
-#include <spirv_msl.hpp>
-
-#include "source/opt/pass.h" // Accessing a private spirv-tools header.
-#include "spirv-tools/libspirv.hpp"
-#include "spvc/spvc.h"
-
-namespace spvtools {
-namespace opt {
-// this WIP pass generates spvc IR and does not throw exceptions
-class SpvcIrPass : public Pass {
- public:
- SpvcIrPass(spirv_cross::ParsedIR *ir);
- const char *name() const override { return "spvc-if-pass"; }
- Status Process() override;
-
- IRContext::Analysis GetPreservedAnalyses() override {
- return IRContext::kAnalysisNone;
- }
-
- // Given an spirv Instruction adds its SPIRV-Corss IR equivalent to ir_
- void GenerateSpirvCrossIR(Instruction *inst);
-
- private:
- spirv_cross::ParsedIR *ir_;
- spirv_cross::SPIRFunction *current_function_ = nullptr;
- spirv_cross::SPIRBlock *current_block_ = nullptr;
- Pass::Status status_;
- // A data structure to store type aliases.
- // spirv-cross comment: This must be an ordered data structure so we always
- // pick the same type aliases.
- spirv_cross::SmallVector<uint32_t> global_struct_cache_;
- // used to save our offset into the input spirv string
- uint32_t offset_ = 5;
-
- // copied from spirv-cross (class Parser)
- // Adds an instruction to the SPIRV-Cross IR, for the given result Id and with
- // given type and arguments.
- // Returns the constructed instruction.
- // TODO(sarahM0): explore whether it's better to replace with explicit set,
- // se1, set2, ...
- template <typename T, typename... P>
- T &set(uint32_t id, P &&... args) {
- ir_->add_typed_id(static_cast<spirv_cross::Types>(T::type), id);
- auto &var =
- spirv_cross::variant_set<T>(ir_->ids[id], std::forward<P>(args)...);
- var.self = id;
- return var;
- }
-
- // copied from spirv-cross (class Parser)
- // For a given result Id returns the previously constructed instruction.
- template <typename T>
- T &get(uint32_t id) {
- return spirv_cross::variant_get<T>(ir_->ids[id]);
- }
- template <typename T>
- const T &get(uint32_t id) const {
- return spirv_cross::variant_get<T>(ir_->ids[id]);
- }
-
- // copied from spirv-cross (class Parser)
- // For a given result Id returns the instruction if it was previously
- // constructed and had the same result Type otherwise returns nullptr.
- template <typename T>
- T *maybe_get(uint32_t id) {
- if (id >= ir_->ids.size())
- return nullptr;
- else if (ir_->ids[id].get_type() ==
- static_cast<spirv_cross::Types>(T::type))
- return &get<T>(id);
- else
- return nullptr;
- }
-
- template <typename T>
- const T *maybe_get(uint32_t id) const {
- if (id >= ir_->ids.size())
- return nullptr;
- else if (ir_->ids[id].get_type() ==
- static_cast<spirv_cross::Types>(T::type))
- return &get<T>(id);
- else
- return nullptr;
- }
-
- // Check boolean condition. If false record the error message, and set pass
- // status to failure to stop processing.
- bool CheckConditionAndSetErrorMessage(bool condition, std::string message);
-
- // Returns true only if to the given spirv-cross types are equivalent
- bool types_are_logically_equivalent(const spirv_cross::SPIRType &a,
- const spirv_cross::SPIRType &b) const;
-
- // Given an id and its type, sets all of its entries and sub-entries to null
- void make_constant_null(uint32_t id, uint32_t type);
-};
-
-} // namespace opt
-} // namespace spvtools
-
-#endif // LIBSHADERC_SPVC_SRC_SPVCIR_PASS_H_
diff --git a/libshaderc_spvc/src/spvcir_test.cc b/libshaderc_spvc/src/spvcir_test.cc
deleted file mode 100644
index 75e7c50..0000000
--- a/libshaderc_spvc/src/spvcir_test.cc
+++ /dev/null
@@ -1,1572 +0,0 @@
-// Copyright 2019 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <algorithm>
-#include <cstdarg>
-#include <iostream>
-#include <sstream>
-#include <string>
-#include <unordered_set>
-#include <vector>
-
-#include "gmock/gmock.h"
-#include "spvcir_pass.h"
-#include "test/opt/assembly_builder.h"
-#include "test/opt/pass_fixture.h"
-#include "test/opt/pass_utils.h"
-
-namespace spvtools {
-namespace opt {
-namespace {
-
-using ::testing::HasSubstr;
-using ::testing::MatchesRegex;
-
-// For a given result Id returns the previously constructed instruction.
-template <typename T>
-T& get(uint32_t id, spirv_cross::ParsedIR* ir) {
- return spirv_cross::variant_get<T>(ir->ids[id]);
-}
-
-// For a given result Id returns the instruction if it was previously
-// constructed and had the same result Type otherwise returns nullptr.
-template <typename T>
-T* maybe_get(uint32_t id, spirv_cross::ParsedIR* ir) {
- if (id >= ir->ids.size())
- return nullptr;
- else if (ir->ids[id].get_type() == static_cast<spirv_cross::Types>(T::type))
- return &get<T>(id, ir);
- else
- return nullptr;
-}
-
-std::string SelectiveJoin(const std::vector<const char*>& strings,
- const std::function<bool(const char*)>& skip_dictator,
- char delimiter = '\n') {
- std::ostringstream oss;
- for (const auto* str : strings) {
- if (!skip_dictator(str)) oss << str << delimiter;
- }
- return oss.str();
-}
-
-std::string JoinAllInsts(const std::vector<const char*>& insts) {
- return SelectiveJoin(insts, [](const char*) { return false; });
-}
-
-bool createSpvcIr(spirv_cross::ParsedIR* ir, std::string text) {
- std::vector<uint32_t> binary;
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- if (!context) return false;
- context->module()->ToBinary(&binary, false);
- ir->spirv =
- std::vector<uint32_t>(binary.data(), binary.data() + binary.size());
- return true;
-}
-
-class SpvcIrParsingTest : public PassTest<::testing::Test> {
- protected:
- void SetUp() override {
- input_ = R"(
- OpCapability Shader
- %5 = OpExtInstImport "GLSL.std.450"
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- OpMemoryModel Logical VulkanKHR
- OpEntryPoint Vertex %1 "shader"
- %2 = OpTypeVoid
- %3 = OpTypeFunction %2
- %1 = OpFunction %2 None %3
- %4 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
-
- before_ = {
- // clang-format off
- "OpCapability Shader",
- "OpCapability VulkanMemoryModelKHR",
- "OpExtension \"SPV_KHR_vulkan_memory_model\"",
- "OpMemoryModel Logical VulkanKHR",
- "OpEntryPoint Vertex %1 \"shader\"",
- // clang-format on
- };
-
- after_ = {
- // clang-format off
- "%2 = OpTypeVoid",
- "%3 = OpTypeFunction %2",
- "%1 = OpFunction %2 None %3",
- "%4 = OpLabel",
- "OpReturn",
- "OpFunctionEnd"
- // clang-format on
- };
-
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- std::vector<uint32_t> binary;
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, input_,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- assert(context && "context");
- context->module()->ToBinary(&binary, false);
- ir_.spirv =
- std::vector<uint32_t>(binary.data(), binary.data() + binary.size());
- }
- std::string input_;
- spirv_cross::ParsedIR ir_;
- std::vector<const char*> before_;
- std::vector<const char*> after_;
-};
-
-TEST_F(SpvcIrParsingTest, OpExtInstImportInsruction) {
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- input_, true, false, &ir_);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_ext = maybe_get<spirv_cross::SPIRExtension>(5, &ir_);
- ASSERT_NE(spir_ext, nullptr);
- EXPECT_EQ(spir_ext->ext, spirv_cross::SPIRExtension::GLSL);
-}
-
-TEST_F(SpvcIrParsingTest, OpCapabilityInstruction) {
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- input_, true, false, &ir_);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- ASSERT_EQ(ir_.declared_capabilities.size(), 2);
- EXPECT_EQ(ir_.declared_capabilities[0], spv::Capability::CapabilityShader);
- EXPECT_EQ(ir_.declared_capabilities[1],
- spv::Capability::CapabilityVulkanMemoryModelKHR);
-}
-
-TEST_F(SpvcIrParsingTest, OpExtensionInstruction) {
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- input_, true, false, &ir_);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- ASSERT_EQ(ir_.declared_extensions.size(), 1);
- EXPECT_EQ(ir_.declared_extensions[0], "SPV_KHR_vulkan_memory_model");
-}
-
-TEST_F(SpvcIrParsingTest, OpMemoryModelInstruction) {
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- input_, true, false, &ir_);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- EXPECT_EQ(ir_.addressing_model, spv::AddressingModel::AddressingModelLogical);
- EXPECT_EQ(ir_.memory_model, spv::MemoryModel::MemoryModelVulkanKHR);
-}
-
-TEST_F(SpvcIrParsingTest, OpEntryPointInstruction) {
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- input_, true, false, &ir_);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- ASSERT_EQ(ir_.entry_points.size(), 1);
- const auto functionId = 1;
- const auto entry = *ir_.entry_points.begin();
- EXPECT_EQ(entry.first, static_cast<spirv_cross::FunctionID>(functionId));
- EXPECT_EQ(entry.second.orig_name, "shader");
- EXPECT_EQ(entry.second.model, spv::ExecutionModelVertex);
- EXPECT_EQ(entry.second.self,
- static_cast<spirv_cross::FunctionID>(functionId));
- EXPECT_EQ(ir_.meta[functionId].decoration.alias, "shader");
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpUndefInstruction) {
- const std::vector<const char*> middle = {"%10 = OpTypeFloat 32",
- "%11 = OpUndef %10"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_undef = maybe_get<spirv_cross::SPIRUndef>(11, &ir);
- ASSERT_NE(spir_undef, nullptr);
- EXPECT_EQ(spir_undef->basetype, static_cast<spirv_cross::TypeID>(10));
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpMemberDecorateInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- "OpMemberDecorate %15 0 Offset 8",
- "OpMemberDecorate %15 0 NonWritable",
- "%float = OpTypeFloat 32",
- "%v4float = OpTypeVector %float 4",
- "%_runtimearr_v4float = OpTypeRuntimeArray %v4float",
- "%15 = OpTypeStruct %_runtimearr_v4float",
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto offset =
- ir.get_member_decoration(15, 0, spv::Decoration::DecorationOffset);
- auto writable =
- ir.get_member_decoration(15, 0, spv::Decoration::DecorationNonWritable);
- EXPECT_EQ(offset, 8);
- EXPECT_EQ(writable, 1);
-}
-
-TEST_F(SpvcIrParsingTest, OpMemberNameInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- "OpMemberName %16 0 \"u\"",
- "OpMemberName %16 1 \"i\"",
- "%int = OpTypeInt 32 1",
- "%ivec4 = OpTypeVector %int 4",
- "%uint = OpTypeInt 32 0",
- "%uvec4 = OpTypeVector %uint 4",
- "%16 = OpTypeStruct %uvec4 %ivec4",
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto i = ir.get_member_name(16, 0);
- auto u = ir.get_member_name(16, 1);
- EXPECT_EQ(i, "u");
- EXPECT_EQ(u, "i");
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpExecutionModeInstruction) {
- const std::vector<const char*> middle = {
- "OpExecutionMode %1 LocalSize 4 3 5",
- "OpExecutionMode %1 OutputVertices 1",
- "OpExecutionMode %1 Invocations 1"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- ASSERT_EQ(ir.entry_points.size(), 1);
- const auto& execution = ir.entry_points[1];
- EXPECT_EQ(execution.workgroup_size.x, 4);
- EXPECT_EQ(execution.workgroup_size.y, 3);
- EXPECT_EQ(execution.workgroup_size.z, 5);
- EXPECT_EQ(execution.output_vertices, 1);
- EXPECT_EQ(execution.invocations, 1);
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeVoidInstruction) {
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- input_, true, false, &ir_);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto func_type = maybe_get<spirv_cross::SPIRType>(2, &ir_);
- ASSERT_NE(func_type, nullptr);
- EXPECT_EQ(func_type->basetype, spirv_cross::SPIRType::Void);
-}
-
-TEST_F(SpvcIrParsingTest, OpStringInstruction) {
- const std::vector<const char*> middle = {"%10 = OpString \"main\""};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_str = maybe_get<spirv_cross::SPIRString>(10, &ir);
- ASSERT_NE(spir_str, nullptr);
- EXPECT_EQ(spir_str->str, "main");
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeBoolInstruction) {
- const std::vector<const char*> middle = {"%25 = OpTypeBool",
- "%27 = OpTypeFunction %25"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto bool_type = maybe_get<spirv_cross::SPIRType>(25, &ir);
- ASSERT_NE(bool_type, nullptr);
- EXPECT_EQ(bool_type->basetype, spirv_cross::SPIRType::Boolean);
- EXPECT_EQ(bool_type->width, 1);
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeFloatInstruction16) {
- const std::vector<const char*> middle = {"%25 = OpTypeFloat 16",
- "%27 = OpTypeFunction %25"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto bool_type = maybe_get<spirv_cross::SPIRType>(25, &ir);
- ASSERT_NE(bool_type, nullptr);
- EXPECT_EQ(bool_type->basetype, spirv_cross::SPIRType::Half);
- EXPECT_EQ(bool_type->width, 16);
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeFloatInstruction32) {
- const std::vector<const char*> middle = {"%25 = OpTypeFloat 32",
- "%27 = OpTypeFunction %25"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto bool_type = maybe_get<spirv_cross::SPIRType>(25, &ir);
- ASSERT_NE(bool_type, nullptr);
- EXPECT_EQ(bool_type->basetype, spirv_cross::SPIRType::Float);
- EXPECT_EQ(bool_type->width, 32);
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeFloatInstruction64) {
- const std::vector<const char*> middle = {"%25 = OpTypeFloat 64",
- "%27 = OpTypeFunction %25"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto bool_type = maybe_get<spirv_cross::SPIRType>(25, &ir);
- ASSERT_NE(bool_type, nullptr);
- EXPECT_EQ(bool_type->basetype, spirv_cross::SPIRType::Double);
- EXPECT_EQ(bool_type->width, 64);
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeVectorInstruction) {
- const std::vector<const char*> middle = {"%6 = OpTypeFloat 32",
- "%7 = OpTypeVector %6 4"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto vector_type = maybe_get<spirv_cross::SPIRType>(7, &ir);
- ASSERT_NE(vector_type, nullptr);
- EXPECT_EQ(vector_type->basetype, spirv_cross::SPIRType::Float);
- EXPECT_EQ(vector_type->vecsize, 4);
- EXPECT_EQ(vector_type->self, static_cast<spirv_cross::TypeID>(7));
- EXPECT_EQ(vector_type->parent_type, static_cast<spirv_cross::TypeID>(6));
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeMatrixInstruction) {
- const std::vector<const char*> middle = {"%6 = OpTypeFloat 32",
- "%8 = OpTypeVector %6 4",
- "%7 = OpTypeMatrix %8 4"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto matrix_type = maybe_get<spirv_cross::SPIRType>(7, &ir);
- ASSERT_NE(matrix_type, nullptr);
- EXPECT_EQ(matrix_type->columns, 4);
- EXPECT_EQ(matrix_type->self, static_cast<spirv_cross::TypeID>(7));
- EXPECT_EQ(matrix_type->parent_type, static_cast<spirv_cross::TypeID>(8));
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeImageInstruction) {
- const std::vector<const char*> cap = {"OpCapability SampledBuffer"};
- const std::vector<const char*> middle = {
- // clang-format off
- "%5 = OpTypeInt 32 0",
- "%6 = OpTypeImage %5 Buffer 0 0 0 2 R32ui"
- // clang format on
- };
- std::string spirv = JoinAllInsts(Concat(cap,(Concat(Concat(before_, middle), after_))));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto image_type = maybe_get<spirv_cross::SPIRType>(6, &ir);
- ASSERT_NE(image_type, nullptr);
- EXPECT_EQ(image_type->image.type, static_cast<spirv_cross::TypeID>(5));
- EXPECT_EQ(image_type->image.dim, spv::Dim::DimBuffer);
- EXPECT_EQ(image_type->image.depth, 0);
- EXPECT_EQ(image_type->image.arrayed, 0);
- EXPECT_EQ(image_type->image.ms, 0);
- EXPECT_EQ(image_type->image.sampled, 2);
- EXPECT_EQ(image_type->image.format, spv::ImageFormat::ImageFormatR32ui);
-
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeSampledImageInstruction) {
- const std::vector<const char*> cap = {"OpCapability SampledBuffer"};
- const std::vector<const char*> middle = {
- // clang-format off
- "%5 = OpTypeInt 32 0",
- "%6 = OpTypeImage %5 Buffer 0 0 0 2 R32ui",
- "%18 = OpTypeSampledImage %6",
- // clang-format on
- };
- std::string spirv =
- JoinAllInsts(Concat(cap, (Concat(Concat(before_, middle), after_))));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto sampledImage_type = maybe_get<spirv_cross::SPIRType>(18, &ir);
- ASSERT_NE(sampledImage_type, nullptr);
- EXPECT_EQ(sampledImage_type->basetype, spirv_cross::SPIRType::SampledImage);
- EXPECT_EQ(sampledImage_type->self, static_cast<spirv_cross::TypeID>(18));
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeSamplerInstruction) {
- const std::vector<const char*> cap = {"OpCapability SampledBuffer"};
- const std::vector<const char*> middle = {
- // clang-format off
- "%12 = OpTypeSampler",
- // clang-format on
- };
- std::string spirv =
- JoinAllInsts(Concat(cap, (Concat(Concat(before_, middle), after_))));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto sampledImage_type = maybe_get<spirv_cross::SPIRType>(12, &ir);
- ASSERT_NE(sampledImage_type, nullptr);
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeArrayInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- "%13 = OpTypeInt 32 0",
- "%14 = OpConstant %13 70",
- " %7 = OpTypeVector %13 4",
- "%15 = OpTypeArray %7 %14"
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto array_type = maybe_get<spirv_cross::SPIRType>(15, &ir);
- ASSERT_NE(array_type, nullptr);
- EXPECT_EQ(array_type->parent_type, static_cast<spirv_cross::TypeID>(7));
- ASSERT_EQ(array_type->array_size_literal.size(), 1);
- EXPECT_TRUE(array_type->array_size_literal[0]);
- EXPECT_EQ(array_type->array[0], 70);
-
- auto constant_type = maybe_get<spirv_cross::SPIRConstant>(14, &ir);
- EXPECT_TRUE(constant_type->is_used_as_array_length);
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeArrayInstructionSpec) {
- const std::vector<const char*> middle = {
- // clang-format off
- "%12 = OpTypeInt 32 0",
- "%13 = OpTypeFloat 32",
- "%14 = OpSpecConstant %12 3",
- " %7 = OpTypeVector %13 4",
- "%15 = OpTypeArray %7 %14"
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto array_type = maybe_get<spirv_cross::SPIRType>(15, &ir);
- ASSERT_NE(array_type, nullptr);
- EXPECT_EQ(array_type->parent_type, static_cast<spirv_cross::TypeID>(7));
- ASSERT_EQ(array_type->array_size_literal.size(), 1);
- EXPECT_FALSE(array_type->array_size_literal[0]);
- EXPECT_EQ(array_type->array[0], 14);
-
- auto constant_type = maybe_get<spirv_cross::SPIRConstant>(14, &ir);
- EXPECT_TRUE(constant_type->is_used_as_array_length);
-}
-TEST_F(SpvcIrParsingTest, OpTypeRuntimeArrayInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- "%15 = OpTypeFloat 32",
- "%17 = OpTypeRuntimeArray %15",
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto run_type = maybe_get<spirv_cross::SPIRType>(17, &ir);
- ASSERT_NE(run_type, nullptr);
- ASSERT_EQ(run_type->array.size(), 1);
- EXPECT_EQ(run_type->array[0], 0);
- ASSERT_EQ(run_type->array_size_literal.size(), 1);
- EXPECT_TRUE(run_type->array_size_literal[0]);
- EXPECT_EQ(run_type->parent_type, static_cast<spirv_cross::TypeID>(15));
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeFunctionInstruction) {
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- input_, true, false, &ir_);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto func = maybe_get<spirv_cross::SPIRFunctionPrototype>(3, &ir_);
- ASSERT_NE(func, nullptr);
- EXPECT_EQ(func->return_type, static_cast<spirv_cross::TypeID>(2));
- EXPECT_TRUE(func->parameter_types.empty());
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeAccelerationStructureNVInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- "%10 = OpTypeAccelerationStructureKHR"
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_var = maybe_get<spirv_cross::SPIRType>(10, &ir);
- ASSERT_NE(spir_var, nullptr);
- EXPECT_EQ(spir_var->basetype, spirv_cross::SPIRType::AccelerationStructure);
-}
-
-
-TEST_F(SpvcIrParsingTest, SpvOpSFunctionParameterInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- "%8 = OpTypeFunction %9 %9 %9",
- "%9 = OpTypeFloat 32",
- "%add_v = OpFunction %9 None %8",
- "%10 = OpFunctionParameter %9",
- "%11 = OpFunctionParameter %9",
- "%12 = OpLabel",
- "%15 = OpFAdd %float %v %w",
- "OpReturn",
- "OpFunctionEnd"
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_var = maybe_get<spirv_cross::SPIRVariable>(10, &ir);
- ASSERT_NE(spir_var, nullptr);
- EXPECT_EQ(spir_var->basetype, static_cast<spirv_cross::TypeID>(9));
- EXPECT_EQ(spir_var->storage, spv::StorageClass::StorageClassFunction);
- EXPECT_EQ(spir_var->initializer, static_cast<spirv_cross::TypeID>(0));
- EXPECT_EQ(spir_var->basevariable, static_cast<spirv_cross::TypeID>(0));
-}
-
-TEST_F(SpvcIrParsingTest, OpFunctionInstruction) {
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- input_, true, false, &ir_);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto func = maybe_get<spirv_cross::SPIRFunction>(1, &ir_);
- ASSERT_NE(func, nullptr);
- EXPECT_EQ(func->type, spirv_cross::TypeFunction);
- EXPECT_EQ(func->return_type, static_cast<spirv_cross::TypeID>(2));
- EXPECT_EQ(func->function_type, static_cast<spirv_cross::TypeID>(3));
- EXPECT_TRUE(func->arguments.empty());
-}
-
-TEST_F(SpvcIrParsingTest, OpLabelInstruction) {
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- input_, true, false, &ir_);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto func = maybe_get<spirv_cross::SPIRFunction>(1, &ir_);
- ASSERT_NE(func, nullptr);
- auto block = maybe_get<spirv_cross::SPIRBlock>(4, &ir_);
- ASSERT_NE(block, nullptr);
- EXPECT_EQ(func->blocks.size(), static_cast<size_t>(1));
- EXPECT_EQ(func->blocks.data()[0], static_cast<spirv_cross::TypeID>(4));
- EXPECT_EQ(func->entry_block, static_cast<spirv_cross::TypeID>(4));
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpSourceInstruction) {
- const std::vector<const char*> middle = {"OpSource HLSL 500"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- EXPECT_FALSE(ir.source.es);
- EXPECT_EQ(ir.source.version, 450);
- EXPECT_TRUE(ir.source.known);
- EXPECT_TRUE(ir.source.hlsl);
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpTypeIntInstruction) {
- const std::vector<const char*> middle = {"%16 = OpTypeInt 32 1"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto int_type = maybe_get<spirv_cross::SPIRType>(16, &ir);
- ASSERT_NE(int_type, nullptr);
- EXPECT_EQ(int_type->width, 32);
- EXPECT_EQ(int_type->basetype, spirv_cross::SPIRType::Int);
- EXPECT_EQ(int_type->vecsize, 1);
- EXPECT_EQ(int_type->columns, 1);
- EXPECT_EQ(int_type->array.size(), 0);
- EXPECT_EQ(int_type->type_alias, static_cast<spirv_cross::TypeID>(0));
- EXPECT_EQ(int_type->parent_type, static_cast<spirv_cross::TypeID>(0));
- EXPECT_TRUE(int_type->member_name_cache.empty());
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpTypeIntInstructionUnsigned) {
- const std::vector<const char*> middle = {"%16 = OpTypeInt 32 0"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto int_type = maybe_get<spirv_cross::SPIRType>(16, &ir);
- ASSERT_NE(int_type, nullptr);
- EXPECT_EQ(int_type->width, 32);
- EXPECT_EQ(int_type->basetype, spirv_cross::SPIRType::UInt);
- EXPECT_EQ(int_type->vecsize, 1);
- EXPECT_EQ(int_type->columns, 1);
- EXPECT_EQ(int_type->array.size(), 0);
- EXPECT_EQ(int_type->type_alias, static_cast<spirv_cross::TypeID>(0));
- EXPECT_EQ(int_type->parent_type, static_cast<spirv_cross::TypeID>(0));
- EXPECT_TRUE(int_type->member_name_cache.empty());
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpConstantInstruction) {
- const std::vector<const char*> middle = {" %8 = OpTypeInt 32 1",
- "%13 = OpConstant %8 100"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_constant = maybe_get<spirv_cross::SPIRConstant>(13, &ir);
- ASSERT_NE(spir_constant, nullptr);
- EXPECT_EQ(spir_constant->constant_type, static_cast<spirv_cross::TypeID>(8));
- ASSERT_EQ(spir_constant->m.columns, 1);
- ASSERT_EQ(spir_constant->vector_size(), 1);
- EXPECT_EQ(spir_constant->scalar(0, 0), 100);
- EXPECT_FALSE(spir_constant->specialization);
- EXPECT_FALSE(spir_constant->is_used_as_array_length);
- EXPECT_FALSE(spir_constant->is_used_as_lut);
- EXPECT_EQ(spir_constant->subconstants.size(), 0);
- EXPECT_EQ(spir_constant->specialization_constant_macro_name, "");
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpConstantInstruction64) {
- const std::vector<const char*> middle = {" %8 = OpTypeInt 64 1",
- "%13 = OpConstant %8 0xF1F2F3F4"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_constant = maybe_get<spirv_cross::SPIRConstant>(13, &ir);
- ASSERT_NE(spir_constant, nullptr);
- EXPECT_EQ(spir_constant->constant_type, static_cast<spirv_cross::TypeID>(8));
- ASSERT_EQ(spir_constant->m.columns, 1);
- ASSERT_EQ(spir_constant->vector_size(), 1);
- EXPECT_EQ(spir_constant->scalar_u64(0, 0), 0xF1F2F3F4);
- EXPECT_FALSE(spir_constant->specialization);
- EXPECT_FALSE(spir_constant->is_used_as_array_length);
- EXPECT_FALSE(spir_constant->is_used_as_lut);
- EXPECT_EQ(spir_constant->subconstants.size(), 0);
- EXPECT_EQ(spir_constant->specialization_constant_macro_name, "");
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpSpecConstantInstruction) {
- const std::vector<const char*> middle = {"%13 = OpTypeFloat 32",
- "%14 = OpSpecConstant %13 3.14159"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_constant = maybe_get<spirv_cross::SPIRConstant>(14, &ir);
- ASSERT_NE(spir_constant, nullptr);
- EXPECT_EQ(spir_constant->constant_type, static_cast<spirv_cross::TypeID>(13));
- ASSERT_EQ(spir_constant->m.columns, 1);
- ASSERT_EQ(spir_constant->vector_size(), 1);
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(0, 0), 3.14159);
- EXPECT_TRUE(spir_constant->specialization);
- EXPECT_FALSE(spir_constant->is_used_as_array_length);
- EXPECT_FALSE(spir_constant->is_used_as_lut);
- EXPECT_EQ(spir_constant->subconstants.size(), 0);
- EXPECT_EQ(spir_constant->specialization_constant_macro_name, "");
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpConstantFalseInstruction) {
- const std::vector<const char*> middle = {" %8 = OpTypeBool",
- "%13 = OpConstantFalse %8"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_constant = maybe_get<spirv_cross::SPIRConstant>(13, &ir);
- ASSERT_NE(spir_constant, nullptr);
- EXPECT_EQ(spir_constant->constant_type, static_cast<spirv_cross::TypeID>(8));
- ASSERT_EQ(spir_constant->m.columns, 1);
- ASSERT_EQ(spir_constant->vector_size(), 1);
- EXPECT_EQ(spir_constant->scalar(0, 0), 0);
- EXPECT_FALSE(spir_constant->specialization);
- EXPECT_FALSE(spir_constant->is_used_as_array_length);
- EXPECT_FALSE(spir_constant->is_used_as_lut);
- EXPECT_EQ(spir_constant->subconstants.size(), 0);
- EXPECT_EQ(spir_constant->specialization_constant_macro_name, "");
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpSpecConstantFalseInstruction) {
- const std::vector<const char*> middle = {" %8 = OpTypeBool",
- "%13 = OpSpecConstantFalse %8"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_constant = maybe_get<spirv_cross::SPIRConstant>(13, &ir);
- ASSERT_NE(spir_constant, nullptr);
- EXPECT_EQ(spir_constant->constant_type, static_cast<spirv_cross::TypeID>(8));
- ASSERT_EQ(spir_constant->m.columns, 1);
- ASSERT_EQ(spir_constant->vector_size(), 1);
- EXPECT_EQ(spir_constant->scalar(0, 0), 0);
- EXPECT_TRUE(spir_constant->specialization);
- EXPECT_FALSE(spir_constant->is_used_as_array_length);
- EXPECT_FALSE(spir_constant->is_used_as_lut);
- EXPECT_EQ(spir_constant->subconstants.size(), 0);
- EXPECT_EQ(spir_constant->specialization_constant_macro_name, "");
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpConstantTrueInstruction) {
- const std::vector<const char*> middle = {" %8 = OpTypeBool",
- "%13 = OpConstantTrue %8"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_constant = maybe_get<spirv_cross::SPIRConstant>(13, &ir);
- ASSERT_NE(spir_constant, nullptr);
- EXPECT_EQ(spir_constant->constant_type, static_cast<spirv_cross::TypeID>(8));
- ASSERT_EQ(spir_constant->m.columns, 1);
- ASSERT_EQ(spir_constant->vector_size(), 1);
- EXPECT_EQ(spir_constant->scalar(0, 0), 1);
- EXPECT_FALSE(spir_constant->constant_is_null());
- EXPECT_FALSE(spir_constant->specialization);
- EXPECT_FALSE(spir_constant->is_used_as_array_length);
- EXPECT_FALSE(spir_constant->is_used_as_lut);
- EXPECT_EQ(spir_constant->subconstants.size(), 0);
- EXPECT_EQ(spir_constant->specialization_constant_macro_name, "");
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpSpecConstantTrueInstruction) {
- const std::vector<const char*> middle = {" %8 = OpTypeBool",
- "%13 = OpSpecConstantTrue %8"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_constant = maybe_get<spirv_cross::SPIRConstant>(13, &ir);
- ASSERT_NE(spir_constant, nullptr);
- EXPECT_EQ(spir_constant->constant_type, static_cast<spirv_cross::TypeID>(8));
- ASSERT_EQ(spir_constant->m.columns, 1);
- ASSERT_EQ(spir_constant->vector_size(), 1);
- EXPECT_EQ(spir_constant->scalar(0, 0), 1);
- EXPECT_FALSE(spir_constant->constant_is_null());
- EXPECT_TRUE(spir_constant->specialization);
- EXPECT_FALSE(spir_constant->is_used_as_array_length);
- EXPECT_FALSE(spir_constant->is_used_as_lut);
- EXPECT_EQ(spir_constant->subconstants.size(), 0);
- EXPECT_EQ(spir_constant->specialization_constant_macro_name, "");
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpConstantNullInstruction) {
- const std::vector<const char*> middle = {" %8 = OpTypeFloat 32",
- "%13 = OpConstantNull %8"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_constant = maybe_get<spirv_cross::SPIRConstant>(13, &ir);
- ASSERT_NE(spir_constant, nullptr);
- EXPECT_EQ(spir_constant->constant_type, static_cast<spirv_cross::TypeID>(8));
- ASSERT_EQ(spir_constant->m.columns, 1);
- ASSERT_EQ(spir_constant->vector_size(), 1);
- EXPECT_TRUE(spir_constant->constant_is_null());
- EXPECT_FALSE(spir_constant->specialization);
- EXPECT_FALSE(spir_constant->is_used_as_array_length);
- EXPECT_FALSE(spir_constant->is_used_as_lut);
- EXPECT_EQ(spir_constant->subconstants.size(), 0);
- EXPECT_EQ(spir_constant->specialization_constant_macro_name, "");
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpConstantNullInstructionMatrix) {
- const std::vector<const char*> middle = {
- // clang-format off
- "%float = OpTypeFloat 32",
- "%v4float = OpTypeVector %float 4",
- "%7 = OpTypeMatrix %v4float 4",
- "%13 = OpConstantNull %7"
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_constant = maybe_get<spirv_cross::SPIRConstant>(13, &ir);
- ASSERT_NE(spir_constant, nullptr);
- EXPECT_EQ(spir_constant->constant_type, static_cast<spirv_cross::TypeID>(7));
- ASSERT_EQ(spir_constant->m.columns, 4);
- ASSERT_EQ(spir_constant->vector_size(), 4);
- EXPECT_TRUE(spir_constant->constant_is_null());
- EXPECT_FALSE(spir_constant->specialization);
- EXPECT_FALSE(spir_constant->is_used_as_array_length);
- EXPECT_FALSE(spir_constant->is_used_as_lut);
- EXPECT_EQ(spir_constant->subconstants.size(), 0);
- EXPECT_EQ(spir_constant->specialization_constant_macro_name, "");
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpConstantCompositeInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- "%6 = OpTypeInt 32 0",
- "%7 = OpTypeVector %6 4",
- "%10 = OpConstant %6 11",
- "%11 = OpConstant %6 22",
- "%12 = OpConstantComposite %7 %10 %10 %11 %10",
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_constant = maybe_get<spirv_cross::SPIRConstant>(12, &ir);
- ASSERT_NE(spir_constant, nullptr);
- EXPECT_EQ(spir_constant->constant_type, static_cast<spirv_cross::TypeID>(7));
- ASSERT_EQ(spir_constant->m.columns, 1);
- ASSERT_EQ(spir_constant->vector_size(), 4);
- EXPECT_EQ(spir_constant->scalar(0, 0), 11);
- EXPECT_EQ(spir_constant->scalar(0, 1), 11);
- EXPECT_EQ(spir_constant->scalar(0, 2), 22);
- EXPECT_EQ(spir_constant->scalar(0, 3), 11);
- EXPECT_FALSE(spir_constant->constant_is_null());
- EXPECT_FALSE(spir_constant->specialization);
- EXPECT_FALSE(spir_constant->is_used_as_array_length);
- EXPECT_FALSE(spir_constant->is_used_as_lut);
- EXPECT_EQ(spir_constant->subconstants.size(), 0);
- EXPECT_EQ(spir_constant->specialization_constant_macro_name, "");
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpConstantCompositeInstructionMatrix) {
- const std::vector<const char*> middle = {
- // clang-format off
- "%float = OpTypeFloat 32",
- "%float_1 = OpConstant %float 1",
- "%float_0 = OpConstant %float 0",
- "%float_0_5 = OpConstant %float 0.5",
- "%v4float = OpTypeVector %float 4",
-"%7 = OpTypeMatrix %v4float 4",
- "%39 = OpConstantComposite %v4float %float_0_5 %float_0 %float_0 %float_0",
- "%40 = OpConstantComposite %v4float %float_0 %float_0_5 %float_0 %float_0",
- "%41 = OpConstantComposite %v4float %float_0 %float_0 %float_0_5 %float_0",
- "%43 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_1",
- "%44 = OpConstantComposite %7 %39 %40 %41 %43"
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_constant = maybe_get<spirv_cross::SPIRConstant>(44, &ir);
- ASSERT_NE(spir_constant, nullptr);
- EXPECT_EQ(spir_constant->constant_type, static_cast<spirv_cross::TypeID>(7));
- ASSERT_EQ(spir_constant->m.columns, 4);
- EXPECT_FLOAT_EQ(spir_constant->vector_size(), 4);
-
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(0, 0), 0.5);
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(0, 1), 0);
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(0, 2), 0);
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(0, 3), 0);
-
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(1, 0), 0);
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(1, 1), 0.5);
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(1, 2), 0);
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(1, 3), 0);
-
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(2, 0), 0);
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(2, 1), 0);
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(2, 2), 0.5);
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(2, 3), 0);
-
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(3, 0), 0);
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(3, 1), 0);
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(3, 2), 0);
- EXPECT_FLOAT_EQ(spir_constant->scalar_f32(3, 3), 1.0);
-
- EXPECT_FALSE(spir_constant->constant_is_null());
- EXPECT_FALSE(spir_constant->specialization);
- EXPECT_FALSE(spir_constant->is_used_as_array_length);
- EXPECT_FALSE(spir_constant->is_used_as_lut);
- EXPECT_EQ(spir_constant->subconstants.size(), 0);
- EXPECT_EQ(spir_constant->specialization_constant_macro_name, "");
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpSpecConstantCompositeInstructionSpec) {
- const std::vector<const char*> middle = {
- // clang-format off
- "%6 = OpTypeInt 32 0",
- "%7 = OpTypeVector %6 4",
- "%10 = OpConstant %6 15",
- "%11 = OpConstant %6 22",
- "%12 = OpSpecConstantComposite %7 %10 %10 %11 %10",
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_constant = maybe_get<spirv_cross::SPIRConstant>(12, &ir);
- ASSERT_NE(spir_constant, nullptr);
- EXPECT_EQ(spir_constant->constant_type, static_cast<spirv_cross::TypeID>(7));
- ASSERT_EQ(spir_constant->m.columns, 1);
- ASSERT_EQ(spir_constant->vector_size(), 4);
- EXPECT_EQ(spir_constant->scalar(0, 0), 15);
- EXPECT_EQ(spir_constant->scalar(0, 1), 15);
- EXPECT_EQ(spir_constant->scalar(0, 2), 22);
- EXPECT_EQ(spir_constant->scalar(0, 3), 15);
- EXPECT_FALSE(spir_constant->constant_is_null());
- EXPECT_TRUE(spir_constant->specialization);
- EXPECT_FALSE(spir_constant->is_used_as_array_length);
- EXPECT_FALSE(spir_constant->is_used_as_lut);
- EXPECT_EQ(spir_constant->subconstants.size(), 0);
- EXPECT_EQ(spir_constant->specialization_constant_macro_name, "");
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpSpecConstantOpInstructionSpec) {
- const std::vector<const char*> middle = {
- // clang-format off
- "%12 = OpTypeInt 32 1",
- "%13 = OpSpecConstant %12 -10",
- "%14 = OpConstant %12 2",
- "%15 = OpSpecConstantOp %12 IAdd %13 %14",
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_constant = maybe_get<spirv_cross::SPIRConstantOp>(15, &ir);
- ASSERT_NE(spir_constant, nullptr);
- EXPECT_EQ(spir_constant->basetype, static_cast<spirv_cross::TypeID>(12));
- ASSERT_EQ(spir_constant->arguments.size(), 2);
- EXPECT_EQ(spir_constant->arguments.data()[0], 13);
- EXPECT_EQ(spir_constant->arguments.data()[1], 14);
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpTypePointer) {
- const std::vector<const char*> middle = {" %8 = OpTypeInt 32 1",
- "%16 = OpTypePointer Output %8"};
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_pointer = maybe_get<spirv_cross::SPIRType>(16, &ir);
- ASSERT_NE(spir_pointer, nullptr);
- EXPECT_TRUE(spir_pointer);
- EXPECT_EQ(spir_pointer->pointer_depth, 1);
- EXPECT_EQ(spir_pointer->storage, spv::StorageClass::StorageClassOutput);
- EXPECT_EQ(spir_pointer->parent_type, static_cast<spirv_cross::TypeID>(8));
- EXPECT_EQ(spir_pointer->width, 32);
- EXPECT_EQ(spir_pointer->basetype, spirv_cross::SPIRType::Int);
- EXPECT_EQ(spir_pointer->vecsize, 1);
- EXPECT_EQ(spir_pointer->columns, 1);
- EXPECT_EQ(spir_pointer->array.size(), 0);
- EXPECT_EQ(spir_pointer->type_alias, static_cast<spirv_cross::TypeID>(0));
- EXPECT_TRUE(spir_pointer->member_name_cache.empty());
-}
-
-TEST_F(SpvcIrParsingTest, SpvOpVariableInstruction) {
- const std::vector<const char*> middle = {
- " %8 = OpTypeInt 32 1",
- "%16 = OpTypePointer Output %8",
- "%17 = OpVariable %16 Output",
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, false, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_variable = maybe_get<spirv_cross::SPIRVariable>(17, &ir);
- ASSERT_NE(spir_variable, nullptr);
- EXPECT_EQ(spir_variable->basetype, static_cast<spirv_cross::TypeID>(16));
- EXPECT_EQ(spir_variable->storage, spv::StorageClass::StorageClassOutput);
- EXPECT_EQ(spir_variable->initializer, static_cast<spirv_cross::TypeID>(0));
- EXPECT_EQ(spir_variable->basevariable, static_cast<spirv_cross::TypeID>(0));
-}
-
-TEST_F(SpvcIrParsingTest, OpDecorateInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- "OpDecorate %17 Location 0",
- " %8 = OpTypeInt 32 1",
- "%16 = OpTypePointer Output %8",
- "%17 = OpVariable %16 Output",
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_decoration = ir.find_meta(17);
- ASSERT_NE(spir_decoration, nullptr);
- auto& work_offsets = spir_decoration->decoration_word_offset;
- auto itr = work_offsets.find(spv::DecorationLocation);
- EXPECT_NE(itr, end(work_offsets));
- auto& work_offset = itr->second;
- EXPECT_EQ(work_offset, 28);
-}
-
-TEST_F(SpvcIrParsingTest, OpDecorateInstruction2) {
- const std::vector<const char*> middle = {
- // clang-format off
- "OpDecorate %17 Location 0",
- "OpDecorate %18 Location 1",
- "OpDecorate %19 Location 2",
- "OpDecorate %20 Location 3",
- " %8 = OpTypeInt 32 1",
- "%16 = OpTypePointer Output %8",
- "%17 = OpVariable %16 Output",
- "%18 = OpVariable %16 Output",
- "%19 = OpVariable %16 Output",
- "%20 = OpVariable %16 Output"
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_decoration = ir.find_meta(20);
- ASSERT_NE(spir_decoration, nullptr);
- auto& work_offsets = spir_decoration->decoration_word_offset;
- auto itr = work_offsets.find(spv::DecorationLocation);
- EXPECT_NE(itr, end(work_offsets));
- auto& work_offset = itr->second;
- EXPECT_EQ(work_offset, 40);
-}
-
-TEST_F(SpvcIrParsingTest, OpGroupDecorateInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- "OpDecorate %11 Offset 3",
- "OpDecorate %11 Restrict",
- "%11 = OpDecorationGroup",
- "OpGroupDecorate %11 %_struct_1 %_struct_2 %30",
- "%float = OpTypeFloat 32",
-"%_runtimearr = OpTypeRuntimeArray %float",
- "%_struct_1 = OpTypeStruct %float %float %float %_runtimearr",
- "%_struct_2 = OpTypeStruct %float %float %float %_runtimearr",
- "%30 = OpTypeStruct %float %float %float %_runtimearr"
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- EXPECT_EQ(ir.get_decoration(30, spv::DecorationRestrict), 1);
- EXPECT_EQ(ir.get_decoration(30, spv::DecorationOffset), 3);
-}
-
-TEST_F(SpvcIrParsingTest, OpGroupMemberDecorateInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- "OpDecorate %11 Offset 3",
- "OpDecorate %11 Restrict",
- "%11 = OpDecorationGroup",
- "OpGroupMemberDecorate %11 %_struct_1 3 %_struct_2 3 %30 3",
- "%float = OpTypeFloat 32",
-"%_runtimearr = OpTypeRuntimeArray %float",
- "%_struct_1 = OpTypeStruct %float %float %float %_runtimearr",
- "%_struct_2 = OpTypeStruct %float %float %float %_runtimearr",
- "%30 = OpTypeStruct %float %float %float %_runtimearr"
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- EXPECT_EQ(ir.get_member_decoration(30, 3, spv::DecorationRestrict), 1);
- EXPECT_EQ(ir.get_member_decoration(30, 3, spv::DecorationOffset), 3);
-}
-
-TEST_F(SpvcIrParsingTest, OpMemberDecorateStringInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- "OpCapability Shader",
- "OpCapability VulkanMemoryModelKHR",
- "OpExtension \"SPV_KHR_vulkan_memory_model\"",
- "OpExtension \"SPV_GOOGLE_hlsl_functionality1\"",
- "OpMemoryModel Logical VulkanKHR",
- "OpEntryPoint Vertex %1 \"shader\"",
- "OpMemberDecorateStringGOOGLE %30 3 HlslSemanticGOOGLE \"blah\"",
- "%float = OpTypeFloat 32",
- "%_runtimearr = OpTypeRuntimeArray %float",
- "%30 = OpTypeStruct %float %float %float %_runtimearr",
- "%2 = OpTypeVoid",
- "%3 = OpTypeFunction %2",
- "%1 = OpFunction %2 None %3",
- "%4 = OpLabel",
- "OpReturn",
- "OpFunctionEnd",
- // clang-format on
- };
- std::string spirv = JoinAllInsts(middle);
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- EXPECT_EQ(
- ir.get_member_decoration_string(30, 3, spv::DecorationHlslSemanticGOOGLE),
- "blah");
-}
-
-TEST_F(SpvcIrParsingTest, OpDecorateStringInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- "OpCapability Shader",
- "OpCapability VulkanMemoryModelKHR",
- "OpExtension \"SPV_KHR_vulkan_memory_model\"",
- "OpExtension \"SPV_GOOGLE_hlsl_functionality1\"",
- "OpMemoryModel Logical VulkanKHR",
- "OpEntryPoint Vertex %1 \"shader\"",
- "OpDecorateStringGOOGLE %10 HlslSemanticGOOGLE \"blah\"",
- "%10 = OpTypeFloat 32",
- "%2 = OpTypeVoid",
- "%3 = OpTypeFunction %2",
- "%1 = OpFunction %2 None %3",
- "%4 = OpLabel",
- "OpReturn",
- "OpFunctionEnd",
- // clang-format on
- };
- std::string spirv = JoinAllInsts(middle);
- spirv_cross::ParsedIR ir;
- createSpvcIr(&ir, spirv);
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- EXPECT_EQ(ir.get_decoration_string(10, spv::DecorationHlslSemanticGOOGLE),
- "blah");
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeForwardPointerInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- "OpCapability Shader",
- "OpCapability VulkanMemoryModelKHR",
- "OpCapability PhysicalStorageBufferAddressesEXT",
- "OpExtension \"SPV_EXT_physical_storage_buffer\"",
- "OpExtension \"SPV_KHR_vulkan_memory_model\"",
- "OpMemoryModel Logical VulkanKHR",
- "OpEntryPoint Vertex %1 \"shader\"",
- "OpTypeForwardPointer %10 PhysicalStorageBuffer",
- "%int = OpTypeInt 32 1",
- "%bufStruct = OpTypeStruct %int %int",
- "%10 = OpTypePointer PhysicalStorageBuffer %bufStruct",
- "%2 = OpTypeVoid",
- "%3 = OpTypeFunction %2",
- "%1 = OpFunction %2 None %3",
- "%4 = OpLabel",
- "OpReturn",
- "OpFunctionEnd",
- // clang-format on
- };
- std::string spirv = JoinAllInsts(middle);
- spirv_cross::ParsedIR ir;
- ASSERT_EQ(createSpvcIr(&ir, spirv), true)
- << "Could not create IRContext for input:\n" + spirv + "\n";
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- const auto ptrbase = maybe_get<spirv_cross::SPIRType>(10, &ir);
- ASSERT_NE(ptrbase, nullptr);
- EXPECT_TRUE(ptrbase->pointer);
- EXPECT_EQ(ptrbase->pointer_depth, 1);
- EXPECT_EQ(ptrbase->storage,
- spv::StorageClass::StorageClassPhysicalStorageBuffer);
-}
-
-
-TEST_F(SpvcIrParsingTest, OpNameInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- "OpDecorate %17 Location 0",
- "OpName %17 \"var\""
- " %8 = OpTypeInt 32 1",
- "%16 = OpTypePointer Output %8",
- "%17 = OpVariable %16 Output",
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- ASSERT_EQ(createSpvcIr(&ir, spirv), true)
- << "Could not create IRContext for input:\n" + spirv + "\n";
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- const auto var_name = ir.get_name(17);
- EXPECT_EQ(var_name, "var");
-}
-
-TEST_F(SpvcIrParsingTest, OpTypeStructInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- " %8 = OpTypeInt 32 1",
- "%16 = OpTypePointer Output %8",
- "%22 = OpTypeStruct %8 %8 %8 %8",
- "%20 = OpTypeStruct %8 %8 %16",
- "%21 = OpTypeStruct %8 %8 %16"
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(Concat(before_, middle), after_));
- spirv_cross::ParsedIR ir;
- ASSERT_EQ(createSpvcIr(&ir, spirv), true)
- << "Could not create IRContext for input:\n" + spirv + "\n";
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_struct = maybe_get<spirv_cross::SPIRType>(20, &ir);
- ASSERT_NE(spir_struct, nullptr);
- EXPECT_EQ(spir_struct->basetype, spirv_cross::SPIRType::Struct);
- ASSERT_EQ(spir_struct->member_types.size(), 3);
- EXPECT_EQ(spir_struct->member_types.data()[0],
- static_cast<spirv_cross::TypeID>(8));
- EXPECT_EQ(spir_struct->member_types.data()[1],
- static_cast<spirv_cross::TypeID>(8));
- EXPECT_EQ(spir_struct->member_types.data()[2],
- static_cast<spirv_cross::TypeID>(16));
-}
-
-TEST_F(SpvcIrParsingTest, OpPhiInstruction) {
- const std::vector<const char*> middle = {
- // clang-format off
- "%2 = OpTypeVoid",
- "%3 = OpTypeFunction %2",
- "%10 = OpTypeBool",
- "%11 = OpConstantFalse %10",
- "%1 = OpFunction %2 None %3",
- "%5 = OpLabel",
- "OpBranch %6",
- "%6 = OpLabel",
- "OpLoopMerge %8 %9 None",
- "OpBranchConditional %11 %9 %7",
- "%7 = OpLabel",
- "%21 = OpCopyObject %10 %11",
- "OpBranchConditional %11 %9 %9",
- "%9 = OpLabel",
- "%20 = OpPhi %10 %21 %7 %11 %6",
- "OpBranchConditional %11 %6 %8",
- "%8 = OpLabel",
- "OpReturn",
- "OpFunctionEnd",
- // clang-format on
- };
- std::string spirv = JoinAllInsts(Concat(before_, middle));
- spirv_cross::ParsedIR ir;
- ASSERT_EQ(createSpvcIr(&ir, spirv), true)
- << "Could not create IRContext for input:\n" + spirv + "\n";
-
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- spirv, true, true, &ir);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto spir_var = maybe_get<spirv_cross::SPIRVariable>(20, &ir);
- ASSERT_NE(spir_var, nullptr);
- EXPECT_EQ(spir_var->basetype, static_cast<spirv_cross::TypeID>(10));
- EXPECT_EQ(spir_var->storage, spv::StorageClass::StorageClassFunction);
- EXPECT_TRUE(spir_var->phi_variable);
-}
-
-TEST_F(SpvcIrParsingTest, OpReturnInstruction) {
- auto result = SinglePassRunAndDisassemble<SpvcIrPass, spirv_cross::ParsedIR*>(
- input_, true, false, &ir_);
- ASSERT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result))
- << " SinglePassRunAndDisassemble failed on input:\n "
- << std::get<0>(result);
-
- auto block = maybe_get<spirv_cross::SPIRBlock>(4, &ir_);
- ASSERT_NE(block, nullptr);
- EXPECT_EQ(block->terminator, spirv_cross::SPIRBlock::Return);
-}
-
-} // namespace
-} // namespace opt
-} // namespace spvtools
diff --git a/license-checker.cfg b/license-checker.cfg
index d30ca8e..0e00206 100644
--- a/license-checker.cfg
+++ b/license-checker.cfg
@@ -18,12 +18,6 @@
"cmake/*.pc.in",
"libshaderc_util/testdata/dir/subdir/include_file.2",
"libshaderc_util/testdata/include_file.1",
- "spvc/README.asciidoc",
- "spvc/test/known_failures",
- "spvc/test/known_invalids",
- "spvc/test/known_spvc_failures",
- "spvc/test/unconfirmed_invalids",
- "spvc/test/**.vert",
"utils/git-sync-deps",
diff --git a/shaderc_features.gni b/shaderc_features.gni
deleted file mode 100644
index 0d2c5fd..0000000
--- a/shaderc_features.gni
+++ /dev/null
@@ -1,24 +0,0 @@
-# Copyright 2019 The Shaderc Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-declare_args() {
- # Enables using the parsing built into spvc instead spirv-cross
- shaderc_enable_spvc_parser = false
-
- # Enables logging directly out to the terminal
- shaderc_spvc_enable_direct_logging = false
-
- # Disables logging to messages in context struct
- shaderc_spvc_disable_context_logging = false
-}
diff --git a/spvc/CMakeLists.txt b/spvc/CMakeLists.txt
deleted file mode 100644
index 399b04e..0000000
--- a/spvc/CMakeLists.txt
+++ /dev/null
@@ -1,31 +0,0 @@
-# Copyright 2020 The Shaderc Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-add_executable(spvc_exe src/main.cc)
-shaderc_default_compile_options(spvc_exe)
-target_include_directories(spvc_exe PRIVATE ${shaderc_SOURCE_DIR}/libshaderc/include ${spirv-tools_SOURCE_DIR}/include)
-set_target_properties(spvc_exe PROPERTIES OUTPUT_NAME spvc)
-target_link_libraries(spvc_exe PRIVATE shaderc_spvc shaderc_util)
-add_dependencies(spvc_exe build-version)
-
-shaderc_add_asciidoc(spvc_doc_README README)
-
-if(SHADERC_ENABLE_INSTALL)
- install(TARGETS spvc_exe
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
-endif(SHADERC_ENABLE_INSTALL)
-
-if(${SHADERC_ENABLE_TESTS})
- add_subdirectory(test)
-endif()
diff --git a/spvc/README.asciidoc b/spvc/README.asciidoc
deleted file mode 100644
index eee5c3a..0000000
--- a/spvc/README.asciidoc
+++ /dev/null
@@ -1,62 +0,0 @@
-= spvc Manual
-:toc:
-:toclevels: 3
-:numbered:
-:source-highlighter: pygments
-
-== Name
-
-`spvc` - A validating SPIR-V to GLSL/HLSL/MSL compiler with Clang-compatible options.
-
-== Synopsis
-
-----
-spvc [--help]
-
-spvc [--version]
- [--validate=<target env>]
- [-o outfile]
- shader...
-----
-
-== Description
-
-`spvc` is a wrapper around SPIRV-Cross.
-A SPIR-V module must pass validation before it is given to SPIRV-Cross for translation.
-
-=== Input file languages
-
-Spvc accepts SPIR-V binary files as input.
-
-[[output-file-naming]]
-=== Output file naming
-
-If a name is specified via `-o`, the output file will be given that name.
-Otherwise the output file name is the same as the input file name except
-with a `.glsl,` `.hlsl` or `.msl` extension, as appropriate.
-
-== Command Line Options
-
-=== Overall Options
-
-==== `--help`
-
-`--help` tells the spvc compiler to display all available options and exit.
-
-==== `--version`
-
-`--version` displays version information.
-
-==== `--validate=<source env>`
-
-`--validate` validates the input with the given environment, which is one of:
-
-* vulkan1.0
-* vulkan1.1
-
-The default is `vulkan1.0`.
-
-==== `-o`
-
-`-o` lets you specify the output file's name. It cannot be used when there are
-multiple files generated. A filename of `-` represents standard output.
diff --git a/spvc/src/main.cc b/spvc/src/main.cc
deleted file mode 100644
index 86969cb..0000000
--- a/spvc/src/main.cc
+++ /dev/null
@@ -1,407 +0,0 @@
-// Copyright 2019 The Shaderc Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <fstream>
-#include <iomanip>
-#include <iostream>
-#include <sstream>
-#include <vector>
-
-#include "libshaderc_util/args.h"
-#include "libshaderc_util/string_piece.h"
-#include "shaderc/env.h"
-#include "spvc/spvc.hpp"
-#include "shaderc/status.h"
-#include "spirv-tools/libspirv.h"
-
-using shaderc_util::string_piece;
-
-namespace {
-
-// Prints the help message.
-void PrintHelp(std::ostream* out) {
- *out << R"(spvc - Compile SPIR-V into GLSL/HLSL/MSL.
-
-Usage: spvc [options] file
-
-An input file of - represents standard input.
-
-Options:
- -h Display available options.
- --help Display available options.
- -v Display compiler version information.
- -o <output file> '-' means standard output.
- --no-validate Disable validating input and intermediate source.
- Validation is by default enabled.
- --no-optimize Disable optimizing input and intermediate source.
- Optimization is by default enabled.
- --source-env=<env> Execution environment of the input source.
- <env> is vulkan1.0 (the default), vulkan1.1,
- or webgpu0
- --entry=<name> Specify entry point.
- --language=<lang> Specify output language.
- <lang> is glsl (the default), msl or hlsl.
- --glsl-version=<ver> Specify GLSL output language version, e.g. 100
- Default is 450 if not detected from input.
- --msl-version=<ver> Specify MSL output language version, e.g. 100
- Default is 10200.
- --target-env=<env> Target intermediate execution environment to
- transform the source to before cross-compiling.
- Defaults to the value set for source-env.
- <env> must be one of the legal values for source-env.
-
- If target-env and source-env are the same, then no
- transformation is performed.
- If there is no defined transformation between source
- and target the operation will fail.
- Defined transforms:
- webgpu0 -> vulkan1.1
- vulkan1.1 -> webgpu0
- --use-spvc-parser Use the built in parser for generating spirv-cross IR
- instead of spirv-cross.
-
-
- The following flags behave as in spirv-cross:
-
- --remove-unused-variables
- --vulkan-semantics
- --separate-shader-objects
- --flatten-ubo
- --flatten-multidimensional-arrays
- --es
- --no-es
- --glsl-emit-push-constant-as-ubo
- --msl-swizzle-texture-samples
- --msl-platform=ios|macos
- --msl-pad-fragment-output
- --msl-capture-output
- --msl-domain-lower-left
- --msl-argument-buffers
- --msl-discrete-descriptor-set=<number>
- --msl-additional-fixed-sample-mask=<number>
- --emit-line-directives
- --hlsl-enable-compat
- --shader-model=<model>
-)";
-}
-
-const char kBuildVersion[] = ""
- // TODO(bug 653): #include "build-version.inc"
- ;
-
-bool ReadFile(const std::string& path, std::vector<uint32_t>* out) {
- FILE* file =
- path == "-" ? freopen(nullptr, "rb", stdin) : fopen(path.c_str(), "rb");
- if (!file) {
- std::cerr << "Failed to open SPIR-V file: " << path << std::endl;
- return false;
- }
-
- fseek(file, 0, SEEK_END);
- out->resize(ftell(file) / sizeof((*out)[0]));
- rewind(file);
-
- bool status = true;
- if (fread(out->data(), sizeof((*out)[0]), out->size(), file) != out->size()) {
- std::cerr << "Failed to read SPIR-V file: " << path << std::endl;
- out->clear();
- status = false;
- }
-
- fclose(file);
- return status;
-}
-
-bool StringPieceToEnvEnum(const string_piece& str, shaderc_spvc_spv_env* env) {
- if (!env) {
- std::cerr << "spvc: error: internal error calling StringPieceToEnvEnum"
- << std::endl;
- return false;
- }
-
- if (str == "vulkan1.0") {
- *env = shaderc_spvc_spv_env_vulkan_1_0;
- } else if (str == "vulkan1.1") {
- *env = shaderc_spvc_spv_env_vulkan_1_1;
- } else if (str == "webgpu0") {
- *env = shaderc_spvc_spv_env_webgpu_0;
- } else {
- std::cerr << "spvc: error: invalid value '" << str
- << "' in --source-env= or --target-env=" << std::endl;
- return false;
- }
- return true;
-}
-
-} // anonymous namespace
-
-int main(int argc, char** argv) {
- shaderc_spvc::Context context;
- std::vector<uint32_t> input;
- std::vector<uint32_t> msl_discrete_descriptor;
- string_piece output_path;
- string_piece output_language;
- string_piece source_str = "vulkan1.0";
- string_piece target_str = "";
-
- // Scan and find any source and target env flags, since we need to know those
- // to create options.
- for (int i = 1; i < argc; ++i) {
- const string_piece arg = argv[i];
- if (arg.starts_with("--source-env=")) {
- string_piece env;
- shaderc_util::GetOptionArgument(argc, argv, &i, "--source-env=", &env);
- source_str = env;
- } else if (arg.starts_with("--target-env=")) {
- string_piece env;
- shaderc_util::GetOptionArgument(argc, argv, &i, "--target-env=", &env);
- target_str = env;
- }
- }
-
- if (target_str == "") {
- target_str = source_str;
- }
-
- shaderc_spvc_spv_env source_env;
- if (!StringPieceToEnvEnum(source_str, &source_env)) {
- return 1;
- }
-
- shaderc_spvc_spv_env target_env;
- if (!StringPieceToEnvEnum(target_str, &target_env)) {
- return 1;
- }
-
- shaderc_spvc::CompileOptions options(source_env, target_env);
- for (int i = 1; i < argc; ++i) {
- const string_piece arg = argv[i];
- if (arg == "--help" || arg == "-h") {
- ::PrintHelp(&std::cout);
- return 0;
- } else if (arg == "-v") {
- std::cout << kBuildVersion << std::endl;
- std::cout << "Target: " << spvTargetEnvDescription(SPV_ENV_UNIVERSAL_1_0)
- << std::endl;
- return 0;
- } else if (arg.starts_with("-o")) {
- if (!shaderc_util::GetOptionArgument(argc, argv, &i, "-o",
- &output_path)) {
- std::cerr
- << "spvc: error: argument to '-o' is missing (expected 1 value)"
- << std::endl;
- return 1;
- }
- } else if (arg.starts_with("--entry=")) {
- string_piece entry_point;
- shaderc_util::GetOptionArgument(argc, argv, &i, "--entry=", &entry_point);
- options.SetEntryPoint(entry_point.data());
- } else if (arg.starts_with("--glsl-version=")) {
- string_piece version_str;
- shaderc_util::GetOptionArgument(argc, argv, &i,
- "--glsl-version=", &version_str);
- uint32_t version_num;
- if (!shaderc_util::ParseUint32(version_str.str(), &version_num)) {
- std::cerr << "spvc: error: invalid value '" << version_str
- << "' in --glsl-version=" << std::endl;
- return 1;
- }
- options.SetGLSLLanguageVersion(version_num);
- } else if (arg.starts_with("--msl-version=")) {
- string_piece version_str;
- shaderc_util::GetOptionArgument(argc, argv, &i,
- "--msl-version=", &version_str);
- uint32_t version_num;
- if (!shaderc_util::ParseUint32(version_str.str(), &version_num)) {
- std::cerr << "spvc: error: invalid value '" << version_str
- << "' in --msl-version=" << std::endl;
- return 1;
- }
- options.SetMSLLanguageVersion(version_num);
- } else if (arg.starts_with("--language=")) {
- shaderc_util::GetOptionArgument(argc, argv, &i,
- "--language=", &output_language);
- if (!(output_language == "glsl" || output_language == "msl" ||
- output_language == "hlsl" || output_language == "vulkan")) {
- std::cerr << "spvc: error: invalid value '" << output_language
- << "' in --language=" << std::endl;
- return 1;
- }
- } else if (arg == "--remove-unused-variables") {
- options.SetRemoveUnusedVariables(true);
- } else if (arg == "--no-validate") {
- options.SetValidate(false);
- } else if (arg == "--no-optimize") {
- options.SetOptimize(false);
- } else if (arg == "--robust-buffer-access-pass") {
- options.SetRobustBufferAccessPass(true);
- } else if (arg == "--vulkan-semantics") {
- options.SetVulkanSemantics(true);
- } else if (arg == "--separate-shader-objects") {
- options.SetSeparateShaderObjects(true);
- } else if (arg == "--flatten-ubo") {
- options.SetFlattenUbo(true);
- } else if (arg == "--flatten-multidimensional-arrays") {
- options.SetFlattenMultidimensionalArrays(true);
- } else if (arg == "--es") {
- options.SetES(true);
- } else if (arg == "--no-es") {
- options.SetES(false);
- } else if (arg == "--hlsl-enable-compat") {
- options.SetHLSLPointSizeCompat(true);
- options.SetHLSLPointCoordCompat(true);
- } else if (arg == "--glsl-emit-push-constant-as-ubo") {
- options.SetGLSLEmitPushConstantAsUBO(true);
- } else if (arg == "--msl-swizzle-texture-samples") {
- options.SetMSLSwizzleTextureSamples(true);
- } else if (arg.starts_with("--msl-platform=")) {
- string_piece platform;
- GetOptionArgument(argc, argv, &i, "--msl-platform=", &platform);
- if (platform == "ios") {
- options.SetMSLPlatform(shaderc_spvc_msl_platform_ios);
- } else if (platform == "macos") {
- options.SetMSLPlatform(shaderc_spvc_msl_platform_macos);
- } else {
- std::cerr << "spvc: error: invalid value '" << platform
- << "' in --msl-platform=" << std::endl;
- return 1;
- }
- } else if (arg == "--msl-pad-fragment-output") {
- options.SetMSLPadFragmentOutput(true);
- } else if (arg == "--msl-capture-output") {
- options.SetMSLCapture(true);
- } else if (arg == "--msl-domain-lower-left") {
- options.SetMSLDomainLowerLeft(true);
- } else if (arg == "--msl-argument-buffers") {
- options.SetMSLArgumentBuffers(true);
- } else if (arg.starts_with("--msl-discrete-descriptor-set=")) {
- string_piece descriptor_str;
- GetOptionArgument(argc, argv, &i,
- "--msl-discrete-descriptor-set=", &descriptor_str);
- uint32_t descriptor_num;
- if (!shaderc_util::ParseUint32(descriptor_str.str(), &descriptor_num)) {
- std::cerr << "spvc: error: invalid value '" << descriptor_str
- << "' in --msl-discrete-descriptor-set=" << std::endl;
- return 1;
- }
- msl_discrete_descriptor.push_back(descriptor_num);
- } else if (arg.starts_with("--msl-additional-fixed-sample-mask=")) {
- string_piece sample_mask_str;
- GetOptionArgument(argc, argv, &i,
- "--msl-additional-fixed-sample-mask=", &sample_mask_str);
- uint32_t sample_mask_num;
- if (!shaderc_util::ParseUint32(sample_mask_str.str(), &sample_mask_num)) {
- std::cerr << "spvc: error: invalid value '" << sample_mask_str
- << "' in --msl-additional-fixed-sample-mask=" << std::endl;
- return 1;
- }
- options.SetMSLAdditionalFixedSampleMask(sample_mask_num);
- } else if (arg == "--emit-line-directives") {
- options.SetEmitLineDirectives(true);
- } else if (arg.starts_with("--shader-model=")) {
- string_piece shader_model_str;
- shaderc_util::GetOptionArgument(argc, argv, &i,
- "--shader-model=", &shader_model_str);
- uint32_t shader_model_num;
- if (!shaderc_util::ParseUint32(shader_model_str.str(),
- &shader_model_num)) {
- std::cerr << "spvc: error: invalid value '" << shader_model_str
- << "' in --shader-model=" << std::endl;
- return 1;
- }
- options.SetHLSLShaderModel(shader_model_num);
- } else if (arg.starts_with("--source-env=")) {
- // Parsed in the previous iteration
- } else if (arg.starts_with("--target-env=")) {
- // Parsed in the previous iteration
- } else if (arg == "--use-spvc-parser") {
- context.SetUseSpvcParser(true);
- } else {
- if (!ReadFile(arg.str(), &input)) {
- std::cerr << "spvc: error: could not read file" << std::endl;
- return 1;
- }
- }
- }
-
- options.SetMSLDiscreteDescriptorSets(msl_discrete_descriptor);
-
- shaderc_spvc::CompilationResult result;
- shaderc_spvc_status status;
-
- if (output_language == "glsl") {
- status = context.InitializeForGlsl((const uint32_t*)input.data(),
- input.size(), options);
- } else if (output_language == "msl") {
- status = context.InitializeForMsl((const uint32_t*)input.data(),
- input.size(), options);
- } else if (output_language == "hlsl") {
- status = context.InitializeForHlsl((const uint32_t*)input.data(),
- input.size(), options);
- } else if (output_language == "vulkan") {
- status = context.InitializeForVulkan((const uint32_t*)input.data(),
- input.size(), options);
- } else {
- std::cerr << "Attempted to output to unknown language: " << output_language
- << std::endl;
- return 1;
- }
-
- if (status == shaderc_spvc_status_success)
- status = context.CompileShader(&result);
-
- switch (status) {
- case shaderc_spvc_status_validation_error: {
- std::cerr << "validation failed:\n" << context.GetMessages() << std::endl;
- return 1;
- }
-
- case shaderc_spvc_status_success: {
- const char* path = output_path.data();
- if (output_language != "vulkan") {
- std::string string_output;
- result.GetStringOutput(&string_output);
- if (path && strcmp(path, "-")) {
- std::basic_ofstream<char>(path) << string_output;
- } else {
- std::cout << string_output;
- }
- } else {
- if (path && strcmp(path, "-")) {
- std::vector<uint32_t> binary_output;
- result.GetBinaryOutput(&binary_output);
- std::ofstream out(path, std::ios::binary);
- out.write((char*)binary_output.data(),
- (sizeof(uint32_t) / sizeof(char)) *
- binary_output.size());
- } else {
- std::cerr << "Cowardly refusing to output binary result to screen"
- << std::endl;
- return 1;
- }
- }
- return 0;
- }
-
- case shaderc_spvc_status_compilation_error: {
- std::cerr << "compilation failed:\n"
- << context.GetMessages() << std::endl;
- return 1;
- }
-
- default:
- std::cerr << "unexpected error " << status << std::endl;
- return 1;
- }
-}
diff --git a/spvc/test/CMakeLists.txt b/spvc/test/CMakeLists.txt
deleted file mode 100644
index 0bb039c..0000000
--- a/spvc/test/CMakeLists.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-# Copyright 2020 The Shaderc Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-if(${SHADERC_ENABLE_TESTS})
- add_test(NAME spvc_spirv_cross_tests
- COMMAND ${PYTHON_EXECUTABLE}
- ${CMAKE_CURRENT_SOURCE_DIR}/run_spirv_cross_tests.py
- $<TARGET_FILE:spvc_exe>
- $<TARGET_FILE:spirv-as>
- $<TARGET_FILE:spirv-opt>
- $<TARGET_FILE:glslangValidator>
- ${SHADERC_SPIRV_CROSS_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR})
- add_test(NAME spvc_spirv_cross_spvc_parser_tests
- COMMAND ${PYTHON_EXECUTABLE}
- ${CMAKE_CURRENT_SOURCE_DIR}/run_spirv_cross_tests.py
- $<TARGET_FILE:spvc_exe>
- $<TARGET_FILE:spirv-as>
- $<TARGET_FILE:spirv-opt>
- $<TARGET_FILE:glslangValidator>
- ${SHADERC_SPIRV_CROSS_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}
- --run_spvc_parser_tests)
-endif()
diff --git a/spvc/test/known_failures b/spvc/test/known_failures
deleted file mode 100644
index c6f2b90..0000000
--- a/spvc/test/known_failures
+++ /dev/null
@@ -1,153 +0,0 @@
-shaders-hlsl-no-opt/asm/frag/phi.zero-initialize.asm.frag,False
-shaders-hlsl-no-opt/asm/temporary.zero-initialize.asm.frag,False
-shaders-hlsl-no-opt/frag/native-16bit-types.fxconly.nofxc.sm62.native-16bit.frag,False
-shaders-hlsl-no-opt/frag/variables.zero-initialize.frag,False
-shaders-hlsl/comp/access-chains.force-uav.comp,False
-shaders-hlsl/comp/access-chains.force-uav.comp,True
-shaders-hlsl/comp/image.nonwritable-uav-texture.comp,False
-shaders-hlsl/comp/image.nonwritable-uav-texture.comp,True
-shaders-hlsl/comp/num-workgroups-alone.comp,False
-shaders-hlsl/comp/num-workgroups-alone.comp,True
-shaders-hlsl/comp/num-workgroups-with-builtins.comp,False
-shaders-hlsl/comp/num-workgroups-with-builtins.comp,True
-shaders-hlsl/frag/image-query-uav.nonwritable-uav-texture.frag,False
-shaders-hlsl/frag/readonly-coherent-ssbo.force-uav.frag,False
-shaders-hlsl/frag/readonly-coherent-ssbo.force-uav.frag,True
-shaders-hlsl/frag/separate-combined-fake-overload.sm30.frag,False
-shaders-hlsl/frag/separate-combined-fake-overload.sm30.frag,True
-shaders-msl-no-opt/asm/comp/copy-logical-2.spv14.asm.comp,False
-shaders-msl-no-opt/asm/comp/copy-logical.spv14.asm.comp,False
-shaders-msl-no-opt/asm/comp/device-array-load-temporary.force-native-array.asm.comp,False
-shaders-msl-no-opt/asm/comp/device-constant-array-load-store.force-native-array.asm.comp,False
-shaders-msl-no-opt/asm/frag/phi.zero-initialize.asm.frag,False
-shaders-msl-no-opt/asm/temporary.zero-initialize.asm.frag,False
-shaders-msl-no-opt/asm/tesc/tess-fixed-input-array-builtin-array.invalid.multi-patch.asm.tesc,False
-shaders-msl-no-opt/comp/basic.dynamic-buffer.msl2.invalid.comp,False
-shaders-msl-no-opt/comp/int64.invalid.msl22.comp,False
-shaders-msl-no-opt/frag/force-active-resources.msl2.argument..force-active.discrete.frag,False
-shaders-msl-no-opt/frag/subpass-input-attachment-index-fallback.msl20.ios.framebuffer-fetch.frag,False
-shaders-msl-no-opt/frag/subpass-input-function-argument.framebuffer-fetch.ios.frag,False
-shaders-msl-no-opt/frag/variables.zero-initialize.frag,False
-shaders-msl-no-opt/vert/pass-array-by-value.force-native-array.vert,False
-shaders-msl/asm/comp/multiple-entry.asm.comp,False
-shaders-msl/asm/comp/multiple-entry.asm.comp,True
-shaders-msl/asm/frag/disable-renamed-output.frag-output.asm.frag,False
-shaders-msl/asm/frag/disable-renamed-output.frag-output.asm.frag,True
-shaders-msl/asm/frag/min-lod.msl22.asm.frag,False
-shaders-msl/asm/frag/min-lod.msl22.asm.frag,True
-shaders-msl/asm/tesc/tess-level-overrun.multi-patch.asm.tesc,False
-shaders-msl/asm/tesc/tess-level-overrun.multi-patch.asm.tesc,True
-shaders-msl/asm/vert/clip-distance-plain-variable.no-user-varying.asm.vert,False
-shaders-msl/asm/vert/clip-distance-plain-variable.no-user-varying.asm.vert,True
-shaders-msl/comp/basic.dispatchbase.comp,False
-shaders-msl/comp/basic.dispatchbase.comp,True
-shaders-msl/comp/basic.dispatchbase.msl11.comp,False
-shaders-msl/comp/basic.dispatchbase.msl11.comp,True
-shaders-msl/comp/basic.inline-block.msl2.comp,False
-shaders-msl/comp/basic.inline-block.msl2.comp,True
-shaders-msl/comp/composite-array-initialization.force-native-array.comp,False
-shaders-msl/comp/composite-array-initialization.force-native-array.comp,True
-shaders-msl/comp/copy-array-of-arrays.force-native-array.comp,False
-shaders-msl/desktop-only/tesc/basic.desktop.sso.multi-patch.tesc,False
-shaders-msl/desktop-only/tesc/basic.desktop.sso.multi-patch.tesc,True
-shaders-msl/desktop-only/tesc/struct-copy.desktop.sso.multi-patch.tesc,False
-shaders-msl/desktop-only/tesc/struct-copy.desktop.sso.multi-patch.tesc,True
-shaders-msl/desktop-only/vert/clip-cull-distance..no-user-varying.desktop.vert,False
-shaders-msl/desktop-only/vert/clip-cull-distance..no-user-varying.desktop.vert,True
-shaders-msl/desktop-only/vert/shader-draw-parameters.desktop.for-tess.vert,False
-shaders-msl/desktop-only/vert/shader-draw-parameters.desktop.for-tess.vert,True
-shaders-msl/frag/barycentric-nv-nopersp.msl22.frag,False
-shaders-msl/frag/barycentric-nv-nopersp.msl22.frag,True
-shaders-msl/frag/barycentric-nv.msl22.frag,False
-shaders-msl/frag/barycentric-nv.msl22.frag,True
-shaders-msl/frag/buffer-read-write.texture-buffer-native.msl21.frag,False
-shaders-msl/frag/buffer-read-write.texture-buffer-native.msl21.frag,True
-shaders-msl/frag/disable-frag-output.frag-output.frag,False
-shaders-msl/frag/disable-frag-output.frag-output.frag,True
-shaders-msl/frag/huge-argument-buffer.device-argument-buffer.argument.msl2.frag,False
-shaders-msl/frag/huge-argument-buffer.device-argument-buffer.argument.msl2.frag,True
-shaders-msl/frag/image-query-lod.msl22.frag,False
-shaders-msl/frag/image-query-lod.msl22.frag,True
-shaders-msl/frag/sample-mask-in-and-out.fixed-sample-mask.frag,False
-shaders-msl/frag/sample-mask-in-and-out.fixed-sample-mask.frag,True
-shaders-msl/frag/sample-mask-not-used.fixed-sample-mask.frag,False
-shaders-msl/frag/sample-mask-not-used.fixed-sample-mask.frag,True
-shaders-msl/frag/sample-mask.fixed-sample-mask.frag,False
-shaders-msl/frag/sample-mask.fixed-sample-mask.frag,True
-shaders-msl/frag/shader-arithmetic-8bit.frag,True
-shaders-msl/frag/subgroup-builtins.msl22.frag,False
-shaders-msl/frag/subgroup-builtins.msl22.frag,True
-shaders-msl/frag/texture-cube-array.ios.emulate-cube-array.frag,False
-shaders-msl/frag/texture-cube-array.ios.emulate-cube-array.frag,True
-shaders-msl/frag/vecsize-mismatch.shader-inputs.frag,False
-shaders-msl/frag/vecsize-mismatch.shader-inputs.frag,True
-shaders-msl/tesc/basic.multi-patch.tesc,False
-shaders-msl/tesc/basic.multi-patch.tesc,True
-shaders-msl/tesc/load-control-point-array-of-matrix.multi-patch.tesc,False
-shaders-msl/tesc/load-control-point-array-of-matrix.multi-patch.tesc,True
-shaders-msl/tesc/load-control-point-array-of-struct.multi-patch.tesc,False
-shaders-msl/tesc/load-control-point-array-of-struct.multi-patch.tesc,True
-shaders-msl/tesc/load-control-point-array.multi-patch.tesc,False
-shaders-msl/tesc/load-control-point-array.multi-patch.tesc,True
-shaders-msl/tesc/matrix-output.multi-patch.tesc,False
-shaders-msl/tesc/matrix-output.multi-patch.tesc,True
-shaders-msl/tesc/struct-output.multi-patch.tesc,False
-shaders-msl/tesc/struct-output.multi-patch.tesc,True
-shaders-msl/tesc/water_tess.multi-patch.tesc,False
-shaders-msl/tesc/water_tess.multi-patch.tesc,True
-shaders-msl/vert/basic.for-tess.vert,False
-shaders-msl/vert/basic.for-tess.vert,True
-shaders-msl/vert/clip-distance-block.no-user-varying.vert,False
-shaders-msl/vert/clip-distance-block.no-user-varying.vert,True
-shaders-msl/vert/float-math.invariant-float-math.vert,False
-shaders-msl/vert/float-math.invariant-float-math.vert,True
-shaders-msl/vert/leaf-function.for-tess.vert,False
-shaders-msl/vert/leaf-function.for-tess.vert,True
-shaders-msl/vert/no_stage_out.for-tess.vert,False
-shaders-msl/vert/no_stage_out.for-tess.vert,True
-shaders-msl/vert/return-array.force-native-array.vert,False
-shaders-msl/vert/signedness-mismatch.shader-inputs.vert,False
-shaders-msl/vert/signedness-mismatch.shader-inputs.vert,True
-shaders-msl/vert/texture_buffer.texture-buffer-native.msl21.vert,False
-shaders-msl/vert/texture_buffer.texture-buffer-native.msl21.vert,True
-shaders-no-opt/asm/comp/copy-logical.spv14.asm.comp,False
-shaders-no-opt/asm/frag/phi.zero-initialize.asm.frag,False
-shaders-no-opt/asm/temporary.zero-initialize.asm.frag,False
-shaders-no-opt/frag/variables.zero-initialize.frag,False
-shaders-no-opt/vert/io-blocks.force-flattened-io.vert,False
-shaders-reflection/asm/aliased-entry-point-names.asm.multi,False
-shaders-reflection/asm/comp/pointer-to-array-of-physical-pointer.asm.comp,False
-shaders-reflection/asm/op-source-glsl-ssbo-1.asm.comp,False
-shaders-reflection/asm/op-source-glsl-ssbo-2.asm.comp,False
-shaders-reflection/asm/op-source-hlsl-uav-1.asm.comp,False
-shaders-reflection/asm/op-source-hlsl-uav-2.asm.comp,False
-shaders-reflection/asm/op-source-none-ssbo-1.asm.comp,False
-shaders-reflection/asm/op-source-none-ssbo-2.asm.comp,False
-shaders-reflection/asm/op-source-none-uav-1.asm.comp,False
-shaders-reflection/asm/op-source-none-uav-2.asm.comp,False
-shaders-reflection/comp/array-of-physical-pointer.comp,False
-shaders-reflection/comp/physical-pointer.comp,False
-shaders-reflection/comp/struct-layout.comp,False
-shaders-reflection/comp/struct-packing.comp,False
-shaders-reflection/comp/workgroup-size-spec-constant.comp,False
-shaders-reflection/frag/combined-texture-sampler-shadow.vk.frag,False
-shaders-reflection/frag/combined-texture-sampler.vk.frag,False
-shaders-reflection/frag/image-load-store-uint-coord.asm.frag,False
-shaders-reflection/frag/input-attachment-ms.vk.frag,False
-shaders-reflection/frag/input-attachment.vk.frag,False
-shaders-reflection/frag/push-constant.vk.frag,False
-shaders-reflection/frag/separate-sampler-texture-array.vk.frag,False
-shaders-reflection/frag/spec-constant.vk.frag,False
-shaders-reflection/rgen/acceleration_structure.vk.rgen,False
-shaders-reflection/vert/array-size-reflection.vert,False
-shaders-reflection/vert/read-from-row-major-array.vert,False
-shaders-reflection/vert/stride-reflection.vert,False
-shaders-reflection/vert/texture_buffer.vert,False
-shaders-ue4/asm/frag/subpass-input.ios.framebuffer-fetch.asm.frag,False
-shaders-ue4/asm/frag/subpass-input.ios.framebuffer-fetch.asm.frag,True
-shaders-ue4/asm/frag/texture-atomics.asm.graphics-robust-access.frag,True
-shaders/asm/frag/image-fetch-no-sampler.no-samplerless.asm.vk.frag,False
-shaders/asm/frag/image-fetch-no-sampler.no-samplerless.asm.vk.frag,True
-shaders/asm/frag/image-query-no-sampler.no-samplerless.vk.asm.frag,False
-shaders/desktop-only/frag/image-size.no-qualifier-deduction.frag,False
-shaders/desktop-only/frag/image-size.no-qualifier-deduction.frag,True
diff --git a/spvc/test/known_invalids b/spvc/test/known_invalids
deleted file mode 100644
index c3a3a12..0000000
--- a/spvc/test/known_invalids
+++ /dev/null
@@ -1,5 +0,0 @@
-shaders-msl-no-opt/asm/comp/composite-construct-buffer-struct.asm.comp,False
-shaders-msl-no-opt/asm/comp/device-array-load-temporary.asm.comp,False
-shaders-msl-no-opt/asm/comp/device-constant-array-load-store.asm.comp,False
-shaders-no-opt/asm/frag/for-loop-dedicated-merge-block-inverted.asm.invalid.frag,False
-shaders-no-opt/asm/frag/for-loop-dedicated-merge-block-non-inverted.asm.invalid.frag,False \ No newline at end of file
diff --git a/spvc/test/known_spvc_failures b/spvc/test/known_spvc_failures
deleted file mode 100644
index d3276b3..0000000
--- a/spvc/test/known_spvc_failures
+++ /dev/null
@@ -1,200 +0,0 @@
-shaders-hlsl-no-opt/asm/frag/phi.zero-initialize.asm.frag,False
-shaders-hlsl-no-opt/asm/frag/struct-packing-last-element-array-matrix-rule.invalid.asm.frag,False
-shaders-hlsl-no-opt/asm/frag/switch-block-case-fallthrough.asm.invalid.frag,False
-shaders-hlsl-no-opt/asm/temporary.zero-initialize.asm.frag,False
-shaders-hlsl-no-opt/frag/constant-buffer-array.invalid.sm51.frag,False
-shaders-hlsl-no-opt/frag/fp16.invalid.desktop.frag,False
-shaders-hlsl-no-opt/frag/native-16bit-types.fxconly.nofxc.sm62.native-16bit.frag,False
-shaders-hlsl-no-opt/frag/variables.zero-initialize.frag,False
-shaders-hlsl/asm/comp/control-flow-hints.asm.comp,False
-shaders-hlsl/asm/comp/control-flow-hints.asm.comp,True
-shaders-hlsl/comp/access-chains.force-uav.comp,False
-shaders-hlsl/comp/access-chains.force-uav.comp,True
-shaders-hlsl/comp/image.nonwritable-uav-texture.comp,False
-shaders-hlsl/comp/image.nonwritable-uav-texture.comp,True
-shaders-hlsl/comp/num-workgroups-alone.comp,False
-shaders-hlsl/comp/num-workgroups-alone.comp,True
-shaders-hlsl/comp/num-workgroups-with-builtins.comp,False
-shaders-hlsl/comp/num-workgroups-with-builtins.comp,True
-shaders-hlsl/frag/image-query-uav.nonwritable-uav-texture.frag,False
-shaders-hlsl/frag/readonly-coherent-ssbo.force-uav.frag,False
-shaders-hlsl/frag/readonly-coherent-ssbo.force-uav.frag,True
-shaders-hlsl/frag/separate-combined-fake-overload.sm30.frag,False
-shaders-hlsl/frag/separate-combined-fake-overload.sm30.frag,True
-shaders-msl-no-opt/asm/comp/composite-construct-buffer-struct.asm.comp,False
-shaders-msl-no-opt/asm/comp/copy-logical-2.spv14.asm.comp,False
-shaders-msl-no-opt/asm/comp/copy-logical.spv14.asm.comp,False
-shaders-msl-no-opt/asm/comp/device-array-load-temporary.asm.comp,False
-shaders-msl-no-opt/asm/comp/device-array-load-temporary.force-native-array.asm.comp,False
-shaders-msl-no-opt/asm/comp/device-constant-array-load-store.asm.comp,False
-shaders-msl-no-opt/asm/comp/device-constant-array-load-store.force-native-array.asm.comp,False
-shaders-msl-no-opt/asm/frag/phi.zero-initialize.asm.frag,False
-shaders-msl-no-opt/asm/frag/switch-block-case-fallthrough.asm.invalid.frag,False
-shaders-msl-no-opt/asm/packing/load-packed-no-forwarding-3.asm.comp,False
-shaders-msl-no-opt/asm/packing/load-packed-no-forwarding-5.asm.comp,False
-shaders-msl-no-opt/asm/packing/load-packed-no-forwarding.asm.comp,False
-shaders-msl-no-opt/asm/packing/packed-vector-extract-insert.asm.comp,False
-shaders-msl-no-opt/asm/packing/scalar-array-float2.asm.frag,False
-shaders-msl-no-opt/asm/packing/scalar-array-float3-one-element.asm.frag,False
-shaders-msl-no-opt/asm/packing/scalar-array-float3.asm.frag,False
-shaders-msl-no-opt/asm/packing/scalar-float2x2-col-major.invalid.asm.frag,False
-shaders-msl-no-opt/asm/packing/scalar-float2x3-col-major.invalid.asm.frag,False
-shaders-msl-no-opt/asm/packing/scalar-float3x2-col-major.invalid.asm.frag,False
-shaders-msl-no-opt/asm/packing/scalar-float3x3-col-major.invalid.asm.frag,False
-shaders-msl-no-opt/asm/temporary.zero-initialize.asm.frag,False
-shaders-msl-no-opt/asm/tesc/tess-fixed-input-array-builtin-array.invalid.multi-patch.asm.tesc,False
-shaders-msl-no-opt/comp/basic.dynamic-buffer.msl2.invalid.comp,False
-shaders-msl-no-opt/comp/int64.invalid.msl22.comp,False
-shaders-msl-no-opt/frag/16bit-constants.invalid.frag,False
-shaders-msl-no-opt/frag/force-active-resources.msl2.argument..force-active.discrete.frag,False
-shaders-msl-no-opt/frag/fp16.desktop.invalid.frag,False
-shaders-msl-no-opt/frag/min-max-clamp.invalid.asm.frag,False
-shaders-msl-no-opt/frag/shadow-compare-global-alias.invalid.frag,False
-shaders-msl-no-opt/frag/subpass-input-attachment-index-fallback.msl20.ios.framebuffer-fetch.frag,False
-shaders-msl-no-opt/frag/subpass-input-function-argument.framebuffer-fetch.ios.frag,False
-shaders-msl-no-opt/frag/variables.zero-initialize.frag,False
-shaders-msl-no-opt/packing/array-of-vec3.comp,False
-shaders-msl-no-opt/packing/load-store-col-rows.comp,False
-shaders-msl-no-opt/packing/matrix-2x3-scalar.comp,False
-shaders-msl-no-opt/packing/matrix-3x2-scalar.comp,False
-shaders-msl-no-opt/packing/matrix-3x3-scalar.comp,False
-shaders-msl-no-opt/packing/matrix-multiply-unpacked-col-major-2.comp,False
-shaders-msl-no-opt/packing/matrix-multiply-unpacked-row-major-2.comp,False
-shaders-msl-no-opt/packing/struct-packing-array-of-scalar.comp,False
-shaders-msl-no-opt/packing/struct-packing-recursive.comp,False
-shaders-msl-no-opt/packing/struct-packing.comp,False
-shaders-msl-no-opt/vert/pass-array-by-value.force-native-array.vert,False
-shaders-msl/asm/comp/multiple-entry.asm.comp,False
-shaders-msl/asm/comp/multiple-entry.asm.comp,True
-shaders-msl/asm/frag/disable-renamed-output.frag-output.asm.frag,False
-shaders-msl/asm/frag/disable-renamed-output.frag-output.asm.frag,True
-shaders-msl/asm/frag/min-lod.msl22.asm.frag,False
-shaders-msl/asm/frag/min-lod.msl22.asm.frag,True
-shaders-msl/asm/tesc/tess-level-overrun.multi-patch.asm.tesc,False
-shaders-msl/asm/tesc/tess-level-overrun.multi-patch.asm.tesc,True
-shaders-msl/asm/vert/clip-distance-plain-variable.no-user-varying.asm.vert,False
-shaders-msl/asm/vert/clip-distance-plain-variable.no-user-varying.asm.vert,True
-shaders-msl/comp/basic.dispatchbase.comp,False
-shaders-msl/comp/basic.dispatchbase.comp,True
-shaders-msl/comp/basic.dispatchbase.msl11.comp,False
-shaders-msl/comp/basic.dispatchbase.msl11.comp,True
-shaders-msl/comp/basic.inline-block.msl2.comp,False
-shaders-msl/comp/basic.inline-block.msl2.comp,True
-shaders-msl/comp/composite-array-initialization.force-native-array.comp,False
-shaders-msl/comp/composite-array-initialization.force-native-array.comp,True
-shaders-msl/comp/copy-array-of-arrays.force-native-array.comp,False
-shaders-msl/desktop-only/tesc/basic.desktop.sso.multi-patch.tesc,False
-shaders-msl/desktop-only/tesc/basic.desktop.sso.multi-patch.tesc,True
-shaders-msl/desktop-only/tesc/struct-copy.desktop.sso.multi-patch.tesc,False
-shaders-msl/desktop-only/tesc/struct-copy.desktop.sso.multi-patch.tesc,True
-shaders-msl/desktop-only/vert/clip-cull-distance..no-user-varying.desktop.vert,False
-shaders-msl/desktop-only/vert/clip-cull-distance..no-user-varying.desktop.vert,True
-shaders-msl/desktop-only/vert/shader-draw-parameters.desktop.for-tess.vert,False
-shaders-msl/desktop-only/vert/shader-draw-parameters.desktop.for-tess.vert,True
-shaders-msl/frag/barycentric-nv-nopersp.msl22.frag,False
-shaders-msl/frag/barycentric-nv-nopersp.msl22.frag,True
-shaders-msl/frag/barycentric-nv.msl22.frag,False
-shaders-msl/frag/barycentric-nv.msl22.frag,True
-shaders-msl/frag/buffer-read-write.texture-buffer-native.msl21.frag,False
-shaders-msl/frag/buffer-read-write.texture-buffer-native.msl21.frag,True
-shaders-msl/frag/disable-frag-output.frag-output.frag,False
-shaders-msl/frag/disable-frag-output.frag-output.frag,True
-shaders-msl/frag/huge-argument-buffer.device-argument-buffer.argument.msl2.frag,False
-shaders-msl/frag/huge-argument-buffer.device-argument-buffer.argument.msl2.frag,True
-shaders-msl/frag/image-query-lod.msl22.frag,False
-shaders-msl/frag/image-query-lod.msl22.frag,True
-shaders-msl/frag/sample-mask-in-and-out.fixed-sample-mask.frag,False
-shaders-msl/frag/sample-mask-in-and-out.fixed-sample-mask.frag,True
-shaders-msl/frag/sample-mask-not-used.fixed-sample-mask.frag,False
-shaders-msl/frag/sample-mask-not-used.fixed-sample-mask.frag,True
-shaders-msl/frag/sample-mask.fixed-sample-mask.frag,False
-shaders-msl/frag/sample-mask.fixed-sample-mask.frag,True
-shaders-msl/frag/shader-arithmetic-8bit.frag,True
-shaders-msl/frag/subgroup-builtins.msl22.frag,False
-shaders-msl/frag/subgroup-builtins.msl22.frag,True
-shaders-msl/frag/texture-cube-array.ios.emulate-cube-array.frag,False
-shaders-msl/frag/texture-cube-array.ios.emulate-cube-array.frag,True
-shaders-msl/frag/vecsize-mismatch.shader-inputs.frag,False
-shaders-msl/frag/vecsize-mismatch.shader-inputs.frag,True
-shaders-msl/tesc/basic.multi-patch.tesc,False
-shaders-msl/tesc/basic.multi-patch.tesc,True
-shaders-msl/tesc/load-control-point-array-of-matrix.multi-patch.tesc,False
-shaders-msl/tesc/load-control-point-array-of-matrix.multi-patch.tesc,True
-shaders-msl/tesc/load-control-point-array-of-struct.multi-patch.tesc,False
-shaders-msl/tesc/load-control-point-array-of-struct.multi-patch.tesc,True
-shaders-msl/tesc/load-control-point-array.multi-patch.tesc,False
-shaders-msl/tesc/load-control-point-array.multi-patch.tesc,True
-shaders-msl/tesc/matrix-output.multi-patch.tesc,False
-shaders-msl/tesc/matrix-output.multi-patch.tesc,True
-shaders-msl/tesc/struct-output.multi-patch.tesc,False
-shaders-msl/tesc/struct-output.multi-patch.tesc,True
-shaders-msl/tesc/water_tess.multi-patch.tesc,False
-shaders-msl/tesc/water_tess.multi-patch.tesc,True
-shaders-msl/vert/basic.for-tess.vert,False
-shaders-msl/vert/basic.for-tess.vert,True
-shaders-msl/vert/clip-distance-block.no-user-varying.vert,False
-shaders-msl/vert/clip-distance-block.no-user-varying.vert,True
-shaders-msl/vert/float-math.invariant-float-math.vert,False
-shaders-msl/vert/float-math.invariant-float-math.vert,True
-shaders-msl/vert/leaf-function.for-tess.vert,False
-shaders-msl/vert/leaf-function.for-tess.vert,True
-shaders-msl/vert/no_stage_out.for-tess.vert,False
-shaders-msl/vert/no_stage_out.for-tess.vert,True
-shaders-msl/vert/return-array.force-native-array.vert,False
-shaders-msl/vert/signedness-mismatch.shader-inputs.vert,False
-shaders-msl/vert/signedness-mismatch.shader-inputs.vert,True
-shaders-msl/vert/texture_buffer.texture-buffer-native.msl21.vert,False
-shaders-msl/vert/texture_buffer.texture-buffer-native.msl21.vert,True
-shaders-no-opt/asm/comp/copy-logical.spv14.asm.comp,False
-shaders-no-opt/asm/comp/extended-debug-extinst.invalid.asm.comp,False
-shaders-no-opt/asm/comp/phi-temporary-copy-loop-variable.asm.invalid.comp,False
-shaders-no-opt/asm/frag/do-while-continue-phi.asm.invalid.frag,False
-shaders-no-opt/asm/frag/for-loop-dedicated-merge-block-inverted.asm.invalid.frag,False
-shaders-no-opt/asm/frag/for-loop-dedicated-merge-block-non-inverted.asm.invalid.frag,False
-shaders-no-opt/asm/frag/loop-merge-to-continue.asm.invalid.frag,False
-shaders-no-opt/asm/frag/phi.zero-initialize.asm.frag,False
-shaders-no-opt/asm/frag/selection-merge-to-continue.asm.invalid.frag,False
-shaders-no-opt/asm/frag/switch-block-case-fallthrough.asm.invalid.frag,False
-shaders-no-opt/asm/frag/switch-merge-to-continue.asm.invalid.frag,False
-shaders-no-opt/asm/temporary.zero-initialize.asm.frag,False
-shaders-no-opt/frag/16bit-constants.invalid.frag,False
-shaders-no-opt/frag/fp16.invalid.desktop.frag,False
-shaders-no-opt/frag/multi-dimensional.desktop.invalid.flatten_dim.frag,False
-shaders-no-opt/frag/variables.zero-initialize.frag,False
-shaders-no-opt/vert/io-blocks.force-flattened-io.vert,False
-shaders-reflection/asm/aliased-entry-point-names.asm.multi,False
-shaders-reflection/asm/comp/pointer-to-array-of-physical-pointer.asm.comp,False
-shaders-reflection/asm/op-source-glsl-ssbo-1.asm.comp,False
-shaders-reflection/asm/op-source-glsl-ssbo-2.asm.comp,False
-shaders-reflection/asm/op-source-hlsl-uav-1.asm.comp,False
-shaders-reflection/asm/op-source-hlsl-uav-2.asm.comp,False
-shaders-reflection/asm/op-source-none-ssbo-1.asm.comp,False
-shaders-reflection/asm/op-source-none-ssbo-2.asm.comp,False
-shaders-reflection/asm/op-source-none-uav-1.asm.comp,False
-shaders-reflection/asm/op-source-none-uav-2.asm.comp,False
-shaders-reflection/comp/array-of-physical-pointer.comp,False
-shaders-reflection/comp/physical-pointer.comp,False
-shaders-reflection/comp/struct-layout.comp,False
-shaders-reflection/comp/struct-packing.comp,False
-shaders-reflection/comp/workgroup-size-spec-constant.comp,False
-shaders-reflection/frag/combined-texture-sampler-shadow.vk.frag,False
-shaders-reflection/frag/combined-texture-sampler.vk.frag,False
-shaders-reflection/frag/image-load-store-uint-coord.asm.frag,False
-shaders-reflection/frag/input-attachment-ms.vk.frag,False
-shaders-reflection/frag/input-attachment.vk.frag,False
-shaders-reflection/frag/push-constant.vk.frag,False
-shaders-reflection/frag/separate-sampler-texture-array.vk.frag,False
-shaders-reflection/frag/spec-constant.vk.frag,False
-shaders-reflection/rgen/acceleration_structure.vk.rgen,False
-shaders-reflection/vert/array-size-reflection.vert,False
-shaders-reflection/vert/read-from-row-major-array.vert,False
-shaders-reflection/vert/stride-reflection.vert,False
-shaders-reflection/vert/texture_buffer.vert,False
-shaders-ue4/asm/frag/subpass-input.ios.framebuffer-fetch.asm.frag,False
-shaders-ue4/asm/frag/subpass-input.ios.framebuffer-fetch.asm.frag,True
-shaders-ue4/asm/frag/texture-atomics.asm.graphics-robust-access.frag,True
-shaders/asm/frag/image-fetch-no-sampler.no-samplerless.asm.vk.frag,False
-shaders/asm/frag/image-fetch-no-sampler.no-samplerless.asm.vk.frag,True
-shaders/asm/frag/image-query-no-sampler.no-samplerless.vk.asm.frag,False
-shaders/desktop-only/frag/image-size.no-qualifier-deduction.frag,False
-shaders/desktop-only/frag/image-size.no-qualifier-deduction.frag,True
diff --git a/spvc/test/reference/shaders-hlsl-no-opt/asm/vert/spvc_OpSource.asm.vert b/spvc/test/reference/shaders-hlsl-no-opt/asm/vert/spvc_OpSource.asm.vert
deleted file mode 100644
index 103ff46..0000000
--- a/spvc/test/reference/shaders-hlsl-no-opt/asm/vert/spvc_OpSource.asm.vert
+++ /dev/null
@@ -1,8 +0,0 @@
-void vert_main()
-{
-}
-
-void main()
-{
- vert_main();
-}
diff --git a/spvc/test/reference/shaders-hlsl-no-opt/asm/vert/spvc_trivial_shader.asm.vert b/spvc/test/reference/shaders-hlsl-no-opt/asm/vert/spvc_trivial_shader.asm.vert
deleted file mode 100644
index 103ff46..0000000
--- a/spvc/test/reference/shaders-hlsl-no-opt/asm/vert/spvc_trivial_shader.asm.vert
+++ /dev/null
@@ -1,8 +0,0 @@
-void vert_main()
-{
-}
-
-void main()
-{
- vert_main();
-}
diff --git a/spvc/test/run_spirv_cross_tests.py b/spvc/test/run_spirv_cross_tests.py
deleted file mode 100644
index dc7afcd..0000000
--- a/spvc/test/run_spirv_cross_tests.py
+++ /dev/null
@@ -1,683 +0,0 @@
-# Copyright 2019 The Shaderc Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-"""Run the spirv-cross tests on spvc."""
-
-from multiprocessing import Pool
-import argparse
-import filecmp
-import itertools
-import os
-import re
-import subprocess
-import sys
-import tempfile
-
-
-class TestEnv:
- """Container for cross-test environmental data and operations."""
-
- def __init__(self, script_args):
- """Takes in the output of ArgumentParser.parse_args()"""
- self.dry_run = script_args.dry_run
- self.verbose = script_args.verbose
- self.give_up = script_args.give_up
- self.cross_dir = script_args.cross_dir
- self.spvc = script_args.spvc
- self.spirv_as = script_args.spirv_as
- self.spirv_opt = script_args.spirv_opt
- self.glslang = script_args.glslang
- self.spvc_test_dir = script_args.spvc_test_dir
- self.run_spvc_with_validation = True
- self.use_spvc_parser = script_args.run_spvc_parser_tests
-
- def log_unexpected(self, test_list, test_result):
- """Log list of test cases with unexpected outcome."""
- if not len(test_list):
- log_string = 'Encountered 0 unexpected ' + test_result
- else:
- log_string = 'Encountered ' + format(
- len(test_list)) + ' unexpected ' + test_result + '(s):\n'
- test_list = ['\t{}'.format(test) for test in test_list]
- log_string += '\n'.join(test_list)
- print(log_string)
-
- def log_missing_failures(self, failures):
- """Log list of known failing test cases that were not run."""
- if not len(failures):
- log_string = 'Encountered 0 missing failures'
- else:
- log_string = 'Encountered {} missing failures(s):\n'.format(
- len(failures))
- failures = ['\t{}'.format(failure) for failure in failures]
- log_string += '\n'.join(failures)
- print(log_string)
-
- def log_missing_invalids(self, invalids):
- """Log list of known invalid test cases that were not run."""
- if not len(invalids):
- log_string = 'Encountered 0 missing invalids'
- else:
- log_string = 'Encountered {} missing invalid(s):\n'.format(
- len(invalids))
- invalids = ['\t{}'.format(invalid) for invalid in invalids]
- log_string += '\n'.join(invalids)
- print(log_string)
-
- def log_failure(self, shader, optimize):
- """Log a test case failure."""
- if self.verbose:
- log_string = 'FAILED {}, optimize = {}'.format(shader, optimize)
- print(log_string)
-
- def log_command(self, cmd):
- """Log calling a command."""
- if self.verbose:
- # make sure it's all strings
- cmd = [str(x) for x in cmd]
- # first item is the command path, keep only last component
- cmd[0] = os.path.basename(cmd[0])
- # if last item is a path in SPIRV-Cross dir, trim that dir
- if cmd[-1].startswith(self.cross_dir):
- cmd[-1] = cmd[-1][len(self.cross_dir) + 1:]
- log_string = ' '.join(cmd) + '\n'
- print(log_string)
-
- def check_output(self, cmd):
- """Quietly run a command.
-
- Returns status of |cmd|, output of |cmd|.
- """
- self.log_command(cmd)
- if self.dry_run:
- return True, None
-
- try:
- out = subprocess.check_output(cmd)
- return True, out
- except subprocess.SubprocessError as e:
- return False, e.output
-
- def run_spirv_as(self, inp, out, flags):
- """Run spirv-as.
-
- Returns status of spirv-as, output of spirv-as.
- """
- return self.check_output([self.spirv_as] + flags + ['-o', out, inp])
-
- def run_spirv_opt(self, inp, out, flags):
- """Run spirv-opt.
-
- Returns status of spirv-out, output of spirv-out.
- """
- return self.check_output([self.spirv_opt] + flags + ['--skip-validation', '-O', '-o', out, inp])
-
- def run_glslang_compile(self, inp, out, flags):
- """Run glslangValidator as a compiler.
-
- Returns status of glslangValidator, output of glslangValidator.
- """
- return self.check_output([self.glslang] + flags + ['-o', out, inp])
-
- def run_spvc(self, inp, out, flags):
- """Run spvc.
-
- Returns status of spvc, output of spvc. Exits entirely if spvc
- fails and give_up flag is set.
- """
- if not self.run_spvc_with_validation:
- flags.append('--no-validate')
-
- if self.use_spvc_parser:
- flags.append('--use-spvc-parser')
-
- status, output = self.check_output(
- [self.spvc] + flags + ['-o', out, '--source-env=vulkan1.1', '--target-env=vulkan1.1', inp])
- if not status and self.give_up:
- print('Bailing due to failure in run_spvc with give_up set')
- sys.exit()
- return status, output
-
- def check_reference(self, result, shader, optimize):
- """Compare result file to reference file and count matches.
-
- Returns the result of the comparison and the reference file
- being used. Exits entirely if spvc fails and give_up flag is
- set.
- """
- if optimize:
- reference = os.path.join('reference', 'opt', shader)
- else:
- reference = os.path.join('reference', shader)
- self.log_command(['reference', reference, optimize])
- reference_dir = ''
- if 'spvc' in shader:
- reference_dir = self.spvc_test_dir
- else:
- reference_dir = self.cross_dir
- if self.dry_run or filecmp.cmp(
- result, os.path.join(reference_dir, reference), False):
- return True, reference
- elif self.give_up:
- print('Bailing due to failure in check_reference with give_up set')
- sys.exit()
-
- return False, reference
-
- def compile_input_shader(self, shader, filename, optimize):
- """Prepare Vulkan binary for input to spvc.
-
- The test input is either:
- - Vulkan text, assembled with spirv-as
- - GLSL, converted with glslang
- Optionally pass through spirv-opt.
- Returns the status of the operation, and the temp file that the shader
- was compiled to.
- """
- _, tmpfile = tempfile.mkstemp()
- if 'spvc' in filename:
- shader_path = os.path.join(self.spvc_test_dir, shader)
- else:
- shader_path = os.path.join(self.cross_dir, shader)
- if '.asm.' in filename:
- flags = ['--target-env', 'vulkan1.1']
- if '.preserve.' in filename:
- flags.append('--preserve-numeric-ids')
- result, _ = self.run_spirv_as(shader_path, tmpfile, flags)
- else:
- result, _ = self.run_glslang_compile(shader_path, tmpfile, [
- '--amb', '--target-env', 'vulkan1.1', '-V'])
- if optimize:
- if '.graphics-robust-access.' in shader:
- result, _ = self.run_spirv_opt(tmpfile, tmpfile, ['--graphics-robust-access'])
- else:
- result, _ = self.run_spirv_opt(tmpfile, tmpfile, [])
- return result, tmpfile
-
-
-def remove_files(*filenames):
- """Remove files and be quiet if they don't exist or can't be removed."""
- for i in filenames:
- try:
- os.remove(i)
- except:
- pass
-
-
-def test_glsl(test_env, shader, filename, optimize):
- """Test spvc producing GLSL the same way SPIRV-Cross is tested.
-
- There are three steps: compile input, convert to GLSL, check result.
- Returns a list of successful tests and a list of failed tests.
- """
- successes = []
- failures = []
-
- # Files with .nocompat. in their name are known to not work.
- if '.nocompat.' in filename:
- return [], []
-
- status, input_shader = test_env.compile_input_shader(
- shader, filename, optimize and ('.noopt.' not in filename) and ('.invalid.' not in filename))
- if not status:
- remove_files(input_shader)
- failures.append((shader, optimize))
- test_env.log_failure(shader, optimize)
- return successes, failures
-
- # Run spvc to convert Vulkan to GLSL. Up to two tests are performed:
- # - Regular test on most files
- # - Vulkan-specific test on Vulkan test input
- flags = ['--entry=main', '--language=glsl']
- if '.noeliminate' not in filename:
- flags.append('--remove-unused-variables')
- if '.legacy.' in filename:
- flags.extend(['--glsl-version=100', '--es'])
- if '.flatten.' in filename:
- flags.append('--flatten-ubo')
- if '.flatten_dim.' in filename:
- flags.append('--flatten-multidimensional-arrays')
- if '.push-ubo.' in filename:
- flags.append('--glsl-emit-push-constant-as-ubo')
- if '.sso.' in filename:
- flags.append('--separate-shader-objects')
- if '.line' in filename:
- flags.append('--emit-line-directives')
- output = input_shader + filename
- if '.vk.' in filename:
- status, _ = test_env.run_spvc(
- input_shader, output, flags + ['--vulkan-semantics'])
- else:
- status, _ = test_env.run_spvc(input_shader, output, flags)
- if not status:
- output = None
-
- if output:
- reference_shader = shader
- if '.vk.' in filename:
- reference_shader = shader + '.vk'
- result, _ = test_env.check_reference(
- output, reference_shader, optimize)
- if result:
- successes.append((shader, optimize))
- else:
- failures.append((shader, optimize))
- test_env.log_failure(shader, optimize)
- else:
- failures.append((shader, optimize))
- test_env.log_failure(shader, optimize)
-
- remove_files(input_shader, output)
- return successes, failures
-
-
-def lookup(table, filename):
- """Search first column of 'table' to return item from second column.
-
- The last item will be returned if nothing earlier matches.
- """
- for needle, haystack in zip(table[0::2], table[1::2]):
- if '.' + needle + '.' in filename:
- break
- return haystack
-
-
-shader_models = (
- 'sm60', '60',
- 'sm51', '51',
- 'sm30', '30',
- '', '50',
-)
-msl_standards = (
- 'msl2', '20000',
- 'msl21', '20100',
- 'msl11', '10100',
- '', '10200',
-)
-msl_standards_ios = (
- 'msl2', '-std=ios-metal2.0',
- 'msl21', '-std=ios-metal2.1',
- 'msl11', '-std=ios-metal1.1',
- 'msl10', '-std=ios-metal1.0',
- '', '-std=ios-metal1.2',
-)
-msl_standards_macos = (
- 'msl2', '-std=macos-metal2.0',
- 'msl21', '-std=macos-metal2.1',
- 'msl11', '-std=macos-metal1.1',
- '', '-std=macos-metal1.2',
-)
-
-
-def test_msl(test_env, shader, filename, optimize):
- """Test spvc producing MSL the same way SPIRV-Cross is tested.
-
- There are three steps: compile input, convert to HLSL, check result.
- Returns a list of successful tests and a list of failed tests.
- """
- successes = []
- failures = []
-
- # Files with .nocompat. in their name are known to not work.
- if '.nocompat.' in filename:
- return [], []
-
- status, input_shader = test_env.compile_input_shader(
- shader, filename, optimize and ('.noopt.' not in filename))
- if not status:
- remove_files(input_shader)
- failures.append((shader, optimize))
- test_env.log_failure(shader, optimize)
- return successes, failures
-
- # Run spvc to convert Vulkan to MSL.
- flags = ['--entry=main', '--language=msl',
- '--msl-version=' + lookup(msl_standards, filename)]
- if '.swizzle.' in filename:
- flags.append('--msl-swizzle-texture-samples')
- if '.ios.' in filename:
- flags.append('--msl-platform=ios')
- if '.pad-fragment.' in filename:
- flags.append('--msl-pad-fragment-output')
- if '.capture.' in filename:
- flags.append('--msl-capture-output')
- if '.domain.' in filename:
- flags.append('--msl-domain-lower-left')
- if '.argument.' in shader:
- flags.append('--msl-argument-buffers')
- if '.discrete.' in shader:
- flags.append('--msl-discrete-descriptor-set=2')
- flags.append('--msl-discrete-descriptor-set=3')
- if '.line' in filename:
- flags.append('--emit-line-directives')
-
- output = input_shader + filename
- status, _ = test_env.run_spvc(input_shader, output, flags)
- if not status:
- remove_files(input_shader)
- failures.append((shader, optimize))
- test_env.log_failure(shader, optimize)
- return successes, failures
-
- # Check result.
- if output:
- result, reference = test_env.check_reference(output, shader, optimize)
- if result:
- successes.append((shader, optimize))
- else:
- failures.append((shader, optimize))
- test_env.log_failure(shader, optimize)
- else:
- failures.append((shader, optimize))
- test_env.log_failure(shader, optimize)
-
- remove_files(input_shader, output)
- return successes, failures
-
-
-def test_hlsl(test_env, shader, filename, optimize):
- """Test spvc producing HLSL the same way SPIRV-Cross is tested.
-
- There are three steps: compile input, convert to HLSL, check result.
- Returns a list of successful tests and a list of failed tests.
- """
- successes = []
- failures = []
-
- # Files with .nocompat. in their name are known to not work.
- if '.nocompat.' in filename:
- return [], []
-
- status, input_shader = test_env.compile_input_shader(
- shader, filename, optimize and ('.noopt.' not in filename))
- if not status:
- remove_files(input_shader)
- failures.append((shader, optimize))
- test_env.log_failure(shader, optimize)
- return successes, failures
-
- flags = ['--entry=main', '--language=hlsl']
- if '.line' in filename:
- flags.append('--emit-line-directives')
- # Run spvc to convert Vulkan to HLSL.
- output = input_shader + filename
- status, _ = test_env.run_spvc(input_shader, output, flags + ['--hlsl-enable-compat', '--shader-model=' + lookup(shader_models, filename)])
- if not status:
- remove_files(input_shader)
- failures.append((shader, optimize))
- test_env.log_failure(shader, optimize)
- return successes, failures
-
- if output:
- # TODO(bug 649): Log dxc run here
- result, _ = test_env.check_reference(output, shader, optimize)
- if result:
- successes.append((shader, optimize))
- else:
- failures.append((shader, optimize))
- test_env.log_failure(shader, optimize)
- else:
- failures.append((shader, optimize))
- test_env.log_failure(shader, optimize)
-
- remove_files(input_shader, output)
- return successes, failures
-
-
-def test_reflection(test_env, shader, filename, optimize):
- """Currently a no-op test. Needs to be implemented.
-
- Returns a tuple indicating the passed in test has failed.
- """
- test_env.log_failure(shader, optimize)
- return [], [(shader, optimize)], []
- # TODO(bug 650): Implement this test
-
-
-# TODO(bug 651): Allow our own tests, not just spirv-cross tests.
-test_case_dirs = (
- # directory function optimize
- ('shaders', test_glsl, False),
- ('shaders', test_glsl, True),
- ('shaders-no-opt', test_glsl, False),
- ('shaders-msl', test_msl, False),
- ('shaders-msl', test_msl, True),
- ('shaders-msl-no-opt', test_msl, False),
- ('shaders-hlsl', test_hlsl, False),
- ('shaders-hlsl', test_hlsl, True),
- ('shaders-hlsl-no-opt', test_hlsl, False),
- ('shaders-ue4', test_msl, False),
- ('shaders-ue4', test_msl, True),
- ('shaders-reflection', test_reflection, False),
-)
-
-
-def work_function(work_args):
- """Unpacks the test case args and invokes the appropriate in test
- function."""
- (test_function, test_env, shader, filename, optimize) = work_args
- return test_function(test_env, shader, filename, optimize)
-
-
-def read_expectation_file(filename):
- """Reads in an expectation file.
-
- Input file is expected to be formatted as '<file>,<optimized>' per
- line. Returns an array of tuples of the parsed test cases.
- """
- with open(filename, 'r') as f:
- expectations = f.read().splitlines()
- if len(expectations):
- return set(map(lambda x: (x.split(',')[0], x.split(',')[1] == 'True'), expectations))
- else:
- return []
-
-
-def main():
- parser = argparse.ArgumentParser()
- parser.add_argument('-v', '--verbose', dest='verbose',
- action='store_true', help='Enable additional diagnostic logging')
- parser.add_argument('-n', '--dry-run', dest='dry_run',
- action='store_true', help='Do not execute commands')
- parser.add_argument('-g', '--give-up', dest='give_up',
- action='store_true', help='Quit after first failure')
- parser.add_argument('-f', '--test-filter', dest='test_filter', action='store',
- metavar='<test filter regex>', help='Only run tests that contain given regex string')
- parser.add_argument('-j', '--jobs', dest='jobs', type=int, default=0, action='store',
- metavar='<number of processes to use>', help='Use as many processes as specified, 0 indicates let the script decide.')
- parser.add_argument('--update_known_failures', dest='update_known_failures',
- action='store_true', help='Write out the failures to spvc/test/known_failures')
- parser.add_argument('--update_unconfirmed_invalids', dest='update_unconfirmed_invalids',
- action='store_true', help='Write out the non-known_invalids to spvc/test/unconfirmed_invalids')
- parser.add_argument('--run_spvc_parser_tests', dest='run_spvc_parser_tests',
- action='store_true', help='Run tests stored in spvir-cross and spvc directory using spvc parser')
- parser.add_argument('spvc', metavar='<spvc executable>')
- parser.add_argument('spirv_as', metavar='<spirv-as executable>')
- parser.add_argument('spirv_opt', metavar='<spirv-opt executable>')
- parser.add_argument('glslang', metavar='<glslangValidator executable>')
- parser.add_argument('cross_dir', metavar='<SPIRV-cross directory>')
- parser.add_argument('spvc_test_dir', metavar='<spvc test directory>')
- script_args = parser.parse_args()
-
- test_env = TestEnv(script_args)
-
- test_regex = None
- if script_args.test_filter:
- print('Filtering tests using \'{}\''.format(script_args.test_filter))
- print('Will not check for missing failures')
- test_regex = re.compile(script_args.test_filter)
-
- # Adding tests:
- # Walk SPIRV-Cross test directory and add files to tests list
- # if --run_spvc_parser_tests, also walk spvc test directory and add them to tests list
- tests = []
- for test_case_dir, test_function, optimize in test_case_dirs:
- walk_dir = os.path.join(script_args.cross_dir, test_case_dir)
- for dirpath, dirnames, filenames in os.walk(walk_dir):
- dirnames.sort()
- reldir = os.path.relpath(dirpath, script_args.cross_dir)
- for filename in sorted(filenames):
- shader = os.path.join(reldir, filename)
- if not test_regex or re.search(test_regex, shader):
- tests.append((test_function, test_env,
- shader, filename, optimize))
- if script_args.run_spvc_parser_tests:
- walk_dir = os.path.join(script_args.spvc_test_dir, test_case_dir)
- for dirpath, dirnames, filenames in os.walk(walk_dir):
- dirnames.sort()
- reldir = os.path.relpath(dirpath, script_args.spvc_test_dir)
- for filename in sorted(filenames):
- shader = os.path.join(reldir, filename)
- if not test_regex or re.search(test_regex, shader):
- tests.append((test_function, test_env,
- shader, filename, optimize))
-
- if not script_args.jobs:
- pool = Pool()
- else:
- pool = Pool(script_args.jobs)
-
- # run all test without --no-validate flag
- test_env.run_spvc_with_validation = True
- results = pool.map(work_function, tests)
- # This can occur if -f is passed in with a pattern that doesn't match to
- # anything, or only matches to tests that are skipped.
- if not results:
- print('Did not receive any results from workers...')
- return False
- successes, failures = zip(*results)
-
- # run all tests with --no-validate flag
- test_env.run_spvc_with_validation = False
- results = pool.map(work_function, tests)
- # This can occur if -f is passed in with a pattern that doesn't match to
- # anything, or only matches to tests that are skipped.
- # This branch should be unreachable since the early check would have been activated
- if not results:
- print(
- 'Did not receive any results from workers (happened while --no-validate run)...')
- return False
- successes_without_validation, _ = zip(*results)
-
- # Flattening lists of lists, and convert path markers if needed
- successes = list(itertools.chain.from_iterable(successes))
- successes = list(
- map(lambda x: (x[0].replace(os.path.sep, '/'), x[1]), successes))
-
- failures = list(itertools.chain.from_iterable(failures))
- failures = list(
- map(lambda x: (x[0].replace(os.path.sep, '/'), x[1]), failures))
-
- successes_without_validation = list(
- itertools.chain.from_iterable(successes_without_validation))
- successes_without_validation = list(
- map(lambda x: (x[0].replace(os.path.sep, '/'), x[1]), successes_without_validation))
-
- # Splitting the failures into 'true' failures and cases that just don't pass
- # validation. spirv-cross is more permissive then the spec, so there exists
- # test cases that spirv-cross will process, but won't pass strict
- # validation.
- failures.sort()
- invalids = []
- for failure in failures:
- if failure in successes_without_validation:
- invalids.append(failure)
- failures = list(filter(lambda x: x not in invalids, failures))
-
- print('{} test cases'.format(len(successes) + len(failures) + len(invalids)))
- print('{} passed and'.format(len(successes)))
- print('{} passed with --no-validation flag'.format(len(successes_without_validation)))
-
- if script_args.run_spvc_parser_tests:
- fail_file = os.path.join(os.path.dirname(
- os.path.realpath(__file__)), 'known_spvc_failures')
- print('Parser = spvc, Tests Directory = spirv-cross/ + spvc/, Failures File = known_spvc_failures')
- else:
- fail_file = os.path.join(os.path.dirname(
- os.path.realpath(__file__)), 'known_failures')
- print('Parser = spirv-cross, Tests Directory = spirv-cross/, Failures File = known_failures')
-
- if script_args.update_known_failures:
- print('Updating {}'.format(fail_file))
- with open(fail_file, 'w+') as f:
- for failure in failures:
- f. write('{},{}\n'.format(failure[0], failure[1]))
- known_failures = read_expectation_file(fail_file)
-
- known_invalid_file = os.path.join(os.path.dirname(
- os.path.realpath(__file__)), 'known_invalids')
- known_invalids = read_expectation_file(known_invalid_file)
-
- unconfirmed_invalid_file = os.path.join(os.path.dirname(
- os.path.realpath(__file__)), 'unconfirmed_invalids')
- if script_args.update_unconfirmed_invalids:
- print('Updating {}'.format(unconfirmed_invalid_file))
- with open(unconfirmed_invalid_file, 'w+') as f:
- for invalid in invalids:
- if invalid not in known_invalids:
- f. write('{},{}\n'.format(invalid[0], invalid[1]))
- unconfirmed_invalids = read_expectation_file(unconfirmed_invalid_file)
-
- unexpected_successes = []
- unexpected_failures = []
- unexpected_invalids = []
- unexpected_valids = []
-
- for success in successes:
- if success in known_failures:
- unexpected_successes.append(success)
- if success in known_invalids or success in unconfirmed_invalids:
- unexpected_valids.append(success)
-
- for failure in failures:
- if failure not in known_failures:
- unexpected_failures.append(failure)
-
- for invalid in invalids:
- if invalid not in known_invalids and invalid not in unconfirmed_invalids:
- unexpected_invalids.append(invalid)
-
- test_env.log_unexpected(unexpected_successes, 'success')
- test_env.log_unexpected(unexpected_failures, 'failure')
- test_env.log_unexpected(unexpected_invalids, 'invalid')
- test_env.log_unexpected(unexpected_valids, 'valid')
-
- # Checking that there are no previously failed or invalid tests that just
- # were not ran.
- all_ran_cases = []
- all_ran_cases += successes
- all_ran_cases += failures
- all_ran_cases += invalids
-
- missing_failures = []
- if not script_args.test_filter:
- for failure in known_failures:
- if failure not in all_ran_cases:
- missing_failures.append(failure)
- test_env.log_missing_failures(missing_failures)
-
- missing_invalids = []
- if not script_args.test_filter:
- for invalid in known_invalids:
- if invalid not in all_ran_cases:
- missing_invalids.append(invalid)
- for invalid in unconfirmed_invalids:
- if invalid not in all_ran_cases:
- missing_invalids.append(invalid)
- test_env.log_missing_invalids(missing_invalids)
-
- return len(unexpected_successes) + len(unexpected_failures) + len(unexpected_invalids) + len(unexpected_valids) + len(missing_failures) + len(missing_invalids)
-
-
-if __name__ == '__main__':
- sys.exit(main())
diff --git a/spvc/test/run_spirv_cross_tests_wrapper.sh b/spvc/test/run_spirv_cross_tests_wrapper.sh
deleted file mode 100755
index 9ddc404..0000000
--- a/spvc/test/run_spirv_cross_tests_wrapper.sh
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/env bash
-
-# Copyright 2019 The Shaderc Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Wrapper for run_spirv_cross_tests.py that takes in the build directory and
-# spirv-cross locations, and assumes they are laid out in a standard way,
-# instead of requiring your to specify all of the paths. Assumes that is it a
-# sibling to the python file in the directory structure.
-#
-# To invoke:
-# run_spirv_cross_tests_wrapper.sh <build_dir> <cross_dir>
-#
-# <build_dir> is the directory the repo was built in, paths to binaries are
-# expected to conform to a default layout.
-# NOTE: If you need to specify per-binary paths, you will need to
-# invoke the .py directly.
-# <cross_dir> is the directory the external spirv-cross repo was checked out
-# to.
-
-if [ "$#" -lt 2 ]; then
- echo "At least 2 arguments are required, $# provided"
- exit 1
-fi
-
-script_path=$(dirname "$0")
-build_path="$1"
-
-spvc_path="$1/spvc/spvc"
-glslang_path="$1/third_party/glslang/StandAlone/glslangValidator"
-spirv_tools_path="$1/third_party/spirv-tools/tools"
-spirv_as_path="$spirv_tools_path/spirv-as"
-spirv_opt_path="$spirv_tools_path/spirv-opt"
-cross_path="$2"
-spvc_test_dir="$script_path"
-
-shift 2
-
-python3 $script_path/run_spirv_cross_tests.py "$spvc_path" "$spirv_as_path" "$spirv_opt_path" "$glslang_path" "$cross_path" "$spvc_test_dir" $@
diff --git a/spvc/test/shaders-hlsl-no-opt/asm/vert/spvc_OpSource.asm.vert b/spvc/test/shaders-hlsl-no-opt/asm/vert/spvc_OpSource.asm.vert
deleted file mode 100644
index 8288bd0..0000000
--- a/spvc/test/shaders-hlsl-no-opt/asm/vert/spvc_OpSource.asm.vert
+++ /dev/null
@@ -1,12 +0,0 @@
- OpCapability Shader
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- OpMemoryModel Logical VulkanKHR
- OpEntryPoint Vertex %func "shader"
- OpSource HLSL 500
-%void = OpTypeVoid
-%main = OpTypeFunction %void
-%func = OpFunction %void None %main
-%label = OpLabel
- OpReturn
- OpFunctionEnd
diff --git a/spvc/test/shaders-hlsl-no-opt/asm/vert/spvc_trivial_shader.asm.vert b/spvc/test/shaders-hlsl-no-opt/asm/vert/spvc_trivial_shader.asm.vert
deleted file mode 100644
index c88ff7f..0000000
--- a/spvc/test/shaders-hlsl-no-opt/asm/vert/spvc_trivial_shader.asm.vert
+++ /dev/null
@@ -1,11 +0,0 @@
- OpCapability Shader
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- OpMemoryModel Logical VulkanKHR
- OpEntryPoint Vertex %func "shader"
-%void = OpTypeVoid
-%main = OpTypeFunction %void
-%func = OpFunction %void None %main
-%label = OpLabel
- OpReturn
- OpFunctionEnd
diff --git a/spvc/test/unconfirmed_invalids b/spvc/test/unconfirmed_invalids
deleted file mode 100644
index b50ffde..0000000
--- a/spvc/test/unconfirmed_invalids
+++ /dev/null
@@ -1,39 +0,0 @@
-shaders-hlsl-no-opt/asm/frag/struct-packing-last-element-array-matrix-rule.invalid.asm.frag,False
-shaders-hlsl-no-opt/asm/frag/switch-block-case-fallthrough.asm.invalid.frag,False
-shaders-hlsl-no-opt/frag/constant-buffer-array.invalid.sm51.frag,False
-shaders-hlsl-no-opt/frag/fp16.invalid.desktop.frag,False
-shaders-msl-no-opt/asm/frag/switch-block-case-fallthrough.asm.invalid.frag,False
-shaders-msl-no-opt/asm/packing/load-packed-no-forwarding-3.asm.comp,False
-shaders-msl-no-opt/asm/packing/load-packed-no-forwarding-5.asm.comp,False
-shaders-msl-no-opt/asm/packing/load-packed-no-forwarding.asm.comp,False
-shaders-msl-no-opt/asm/packing/packed-vector-extract-insert.asm.comp,False
-shaders-msl-no-opt/asm/packing/scalar-array-float2.asm.frag,False
-shaders-msl-no-opt/asm/packing/scalar-array-float3-one-element.asm.frag,False
-shaders-msl-no-opt/asm/packing/scalar-array-float3.asm.frag,False
-shaders-msl-no-opt/asm/packing/scalar-float2x2-col-major.invalid.asm.frag,False
-shaders-msl-no-opt/asm/packing/scalar-float2x3-col-major.invalid.asm.frag,False
-shaders-msl-no-opt/asm/packing/scalar-float3x2-col-major.invalid.asm.frag,False
-shaders-msl-no-opt/asm/packing/scalar-float3x3-col-major.invalid.asm.frag,False
-shaders-msl-no-opt/frag/16bit-constants.invalid.frag,False
-shaders-msl-no-opt/frag/fp16.desktop.invalid.frag,False
-shaders-msl-no-opt/frag/min-max-clamp.invalid.asm.frag,False
-shaders-msl-no-opt/frag/shadow-compare-global-alias.invalid.frag,False
-shaders-msl-no-opt/packing/array-of-vec3.comp,False
-shaders-msl-no-opt/packing/load-store-col-rows.comp,False
-shaders-msl-no-opt/packing/matrix-2x3-scalar.comp,False
-shaders-msl-no-opt/packing/matrix-3x2-scalar.comp,False
-shaders-msl-no-opt/packing/matrix-3x3-scalar.comp,False
-shaders-msl-no-opt/packing/matrix-multiply-unpacked-col-major-2.comp,False
-shaders-msl-no-opt/packing/matrix-multiply-unpacked-row-major-2.comp,False
-shaders-msl-no-opt/packing/struct-packing-array-of-scalar.comp,False
-shaders-msl-no-opt/packing/struct-packing-recursive.comp,False
-shaders-msl-no-opt/packing/struct-packing.comp,False
-shaders-no-opt/asm/comp/phi-temporary-copy-loop-variable.asm.invalid.comp,False
-shaders-no-opt/asm/frag/do-while-continue-phi.asm.invalid.frag,False
-shaders-no-opt/asm/frag/loop-merge-to-continue.asm.invalid.frag,False
-shaders-no-opt/asm/frag/selection-merge-to-continue.asm.invalid.frag,False
-shaders-no-opt/asm/frag/switch-block-case-fallthrough.asm.invalid.frag,False
-shaders-no-opt/asm/frag/switch-merge-to-continue.asm.invalid.frag,False
-shaders-no-opt/frag/16bit-constants.invalid.frag,False
-shaders-no-opt/frag/fp16.invalid.desktop.frag,False
-shaders-no-opt/frag/multi-dimensional.desktop.invalid.flatten_dim.frag,False
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index b2293b3..7bd9617 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -9,8 +9,6 @@ set(SHADERC_SPIRV_TOOLS_DIR "${SHADERC_THIRD_PARTY_ROOT_DIR}/spirv-tools" CACHE
"Location of spirv-tools source")
set(SHADERC_SPIRV_HEADERS_DIR "${SHADERC_THIRD_PARTY_ROOT_DIR}/spirv-headers" CACHE STRING
"Location of spirv-headers source")
-set(SHADERC_SPIRV_CROSS_DIR "${SHADERC_THIRD_PARTY_ROOT_DIR}/spirv-cross" CACHE STRING
- "Location of SPIRV-Cross source")
set(SHADERC_GLSLANG_DIR "${SHADERC_THIRD_PARTY_ROOT_DIR}/glslang" CACHE STRING
"Location of glslang source")
set(SHADERC_EFFCEE_DIR "${SHADERC_THIRD_PARTY_ROOT_DIR}/effcee" CACHE STRING
@@ -81,27 +79,6 @@ if (NOT TARGET glslang)
endif()
endif()
-if (SHADERC_ENABLE_SPVC)
- if (NOT TARGET spirv-cross-core)
- if (IS_DIRECTORY ${SHADERC_SPIRV_CROSS_DIR})
- # Add -fPIC to SPIRV-Cross build, if supported
- if (COMPILER_SUPPORTS_PIC)
- set(CXX_BACK ${CMAKE_CXX_FLAGS})
- set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-fPIC")
- # cmake inserts a semicolon, change it to a space.
- string(REGEX REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
- add_subdirectory(${SHADERC_SPIRV_CROSS_DIR} spirv-cross)
- set(CMAKE_CXX_FLAGS ${CXX_BACK})
- else()
- add_subdirectory(${SHADERC_SPIRV_CROSS_DIR} spirv-cross)
- endif()
- endif()
- if (NOT TARGET spirv-cross-core)
- message(FATAL_ERROR "SPIRV-Cross was not found - required for compilation")
- endif()
- endif()
-endif (SHADERC_ENABLE_SPVC)
-
if (SHADERC_ENABLE_WGSL_OUTPUT)
# Use Google Tint for WGSL output.
if (NOT TARGET libtint)
diff --git a/utils/roll-deps b/utils/roll-deps
index fa05c62..4962fd6 100755
--- a/utils/roll-deps
+++ b/utils/roll-deps
@@ -26,8 +26,6 @@ googletest_dir="third_party/googletest/"
googletest_trunk="origin/master"
re2_dir="third_party/re2/"
re2_trunk="origin/master"
-spirv_cross_dir="third_party/spirv-cross/"
-spirv_cross_trunk="origin/master"
spirv_headers_dir="third_party/spirv-headers/"
spirv_headers_trunk="origin/master"
spirv_tools_dir="third_party/spirv-tools/"
@@ -49,7 +47,6 @@ roll-dep --ignore-dirty-tree --roll-to="${effcee_trunk}" "${effcee_dir}"
roll-dep --ignore-dirty-tree --roll-to="${glslang_trunk}" "${glslang_dir}"
roll-dep --ignore-dirty-tree --roll-to="${googletest_trunk}" "${googletest_dir}"
roll-dep --ignore-dirty-tree --roll-to="${re2_trunk}" "${re2_dir}"
-roll-dep --ignore-dirty-tree --roll-to="${spirv_cross_trunk}" "${spirv_cross_dir}"
roll-dep --ignore-dirty-tree --roll-to="${spirv_headers_trunk}" "${spirv_headers_dir}"
roll-dep --ignore-dirty-tree --roll-to="${spirv_tools_trunk}" "${spirv_tools_dir}"