diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-07-16 11:45:35 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-07-17 08:59:23 +0000 |
commit | 552906b0f222c5d5dd11b9fd73829d510980461a (patch) | |
tree | 3a11e6ed0538a81dd83b20cf3a4783e297f26d91 /chromium/third_party/shaderc | |
parent | 1b05827804eaf047779b597718c03e7d38344261 (diff) | |
download | qtwebengine-chromium-552906b0f222c5d5dd11b9fd73829d510980461a.tar.gz |
BASELINE: Update Chromium to 83.0.4103.122
Change-Id: Ie3a82f5bb0076eec2a7c6a6162326b4301ee291e
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/third_party/shaderc')
46 files changed, 2131 insertions, 467 deletions
diff --git a/chromium/third_party/shaderc/src/BUILD.gn b/chromium/third_party/shaderc/src/BUILD.gn index acab160d1fc..d9bd6028f0e 100644 --- a/chromium/third_party/shaderc/src/BUILD.gn +++ b/chromium/third_party/shaderc/src/BUILD.gn @@ -20,6 +20,8 @@ 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 @@ -176,6 +178,10 @@ config("shaderc_spvc_public") { } component("libshaderc_spvc") { + public_deps = [ ":libshaderc_spvc_sources" ] +} + +source_set("libshaderc_spvc_sources") { public_configs = [ ":shaderc_spvc_public", ] @@ -185,6 +191,14 @@ component("libshaderc_spvc") { "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", @@ -192,6 +206,8 @@ component("libshaderc_spvc") { "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", diff --git a/chromium/third_party/shaderc/src/CHANGES b/chromium/third_party/shaderc/src/CHANGES index c26ed30cb7d..9fcb17a2ce6 100644 --- a/chromium/third_party/shaderc/src/CHANGES +++ b/chromium/third_party/shaderc/src/CHANGES @@ -1,12 +1,19 @@ Revision history for Shaderc -v2019.1-dev 2019-06-04 +v2020.0-dev 2020-01-22 + - Start v2020.0-dev + +v2019.1 2020-01-22 - glslc, libshaderc: - Add -fnan-clamp: Generate code for max and min builtins so that, given a NaN operand, will return the other operand. Similarly, the clamp builtin favours non-NaN operands, as if clamp was implemented as the composition of max and min. - Add -finvert-y + - Using SetBeforeHlslLegalization for more relaxed validation rules + - Added support for SPIR-V 1.5 + - Add --emit-line-directive option + - Added support for Vulkan 1.2 - spvc: - Add many options: --flatten-multidimensional-arrays @@ -22,11 +29,44 @@ v2019.1-dev 2019-06-04 --msl-discrete-descriptor-set=<number> --hlsl-enable-compat - Reintroduce shaderc_spvc_compile_options_set_shader_model - - Infrastructure + - Added option to inject robust buffer access code + - Added support for emitting ToVulkan shaders + - Added spirv-opt based IR generation as alternative to built in spirv_cross IR gen + - Added API for specifying source and target execution environments + - Added option & reflection API methods neede by Dawn + - Substantial internal refactoring and code cleanup + - Large number of breaking changes to the API + - Replaced shaderc_spvc_compile_options_set_shader_model with + shaderc_spvc_compile_options_set_hlsl_shader_model + - Compiler initialization and shader generation moved into seperate calls + - Seperated return codes from shaderc ones + - Many small API changes + - Improvements to testing + - Refactoring and clean up of run_spirv_cross_tests.py + - Seperation of expectations into known failures, known invalids, and cases + that need investigation + - Tweaks and fixes to substantially increase passing cases + - Added support for running tests using spvc IR generation + - Infrastructure - Update DEPS with cross-verified commits from associated repos. - Add utils/roll-deps + - Infrastructure: + - Removed Appveyor artifacts link + - Improvements and clean up of DEPS rolling scripts + - Enabled warnings about implicit fallthrough + - Enabled improper semicolon warnings + - Restricted -fPIC to platforms that support it + - Converted remaining scripts to use Python 3 + - Replaced nosetest with unittest + - Removed assumptions aabout location of spirv-tools, effcee, and RE2 + - Migrated BUILD.gn spirv_cross dependency to local repo - Fixes: - Fix duplicate install paths when using VisualStudio + - Fixed BUILD.gn for Chromium, Dawn & Fuchsia + - Explicitly enabled HLSL support in glslang + - Added installing necessary headers in Android.mk + - Removed unsupported Unicode characters + - Fixed detection of spirv-headers directory #666: Update Docker file to use Python3 v2019.0 2019-06-04 diff --git a/chromium/third_party/shaderc/src/CMakeLists.txt b/chromium/third_party/shaderc/src/CMakeLists.txt index 5845cb42602..93a808a20b6 100644 --- a/chromium/third_party/shaderc/src/CMakeLists.txt +++ b/chromium/third_party/shaderc/src/CMakeLists.txt @@ -26,9 +26,19 @@ else() message(STATUS "Configuring Shaderc to avoid building tests.") endif() -set (CMAKE_CXX_STANDARD 11) +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_NV_EXTENSIONS "Enables support of Nvidia-specific extensions" ON) +option(SHADERC_ENABLE_WERROR_COMPILE "Enable passing -Werror to compiler, if available" ON) + +set (CMAKE_CXX_STANDARD 11) include(GNUInstallDirs) include(cmake/setup_build.cmake) @@ -56,10 +66,6 @@ if (COMPILER_SUPPORTS_EXTRA_SEMI_WARNING) add_compile_options("-Wextra-semi") endif() -if(SHADERC_ENABLE_NV_EXTENSIONS) - add_definitions(-DNV_EXTENSIONS) -endif(SHADERC_ENABLE_NV_EXTENSIONS) - find_host_package(PythonInterp 3 REQUIRED) add_custom_target(check-copyright ALL diff --git a/chromium/third_party/shaderc/src/DEPS b/chromium/third_party/shaderc/src/DEPS index 971ad005a08..1f9329f5f31 100644 --- a/chromium/third_party/shaderc/src/DEPS +++ b/chromium/third_party/shaderc/src/DEPS @@ -5,12 +5,12 @@ vars = { 'khronos_git': 'https://github.com/KhronosGroup', 'effcee_revision' : '98980e2b785403b5f43c23ed5a81e1a22e7297e8', - 'glslang_revision': '0de87ee9a5bf5d094a3faa1a71fd9080e80b6be0', - 'googletest_revision': 'ae8d1fc81b1469905b3d0fa6f8a077f58fc4b250', - 're2_revision': 'bb8e777557ddbdeabdedea4f23613c5021ffd7b1', - 'spirv_headers_revision': '204cd131c42b90d129073719f2766293ce35c081', - 'spirv_tools_revision': 'e82a428605f6ce0a07337b36f8ba3935c9f165ac', - 'spirv_cross_revision': '15b860eb1c9510e20831743e9996bf9d7883c7fc', + 'glslang_revision': 'e157435c1e777aa1052f446dafed162b4a722e03', + 'googletest_revision': '67cc66080d64e3fa5124fe57ed0cf15e2cecfdeb', + 're2_revision': '209eda1b607909cf3c9ad084264039546155aeaa', + 'spirv_headers_revision': 'f8bf11a0253a32375c32cad92c841237b96696c0', + 'spirv_tools_revision': 'fd773eb50d628c1981338addc093df879757c2cf', + 'spirv_cross_revision': '9b3c5e12be12c55533f3bd3ab9cc617ec0f393d8', } deps = { diff --git a/chromium/third_party/shaderc/src/README.md b/chromium/third_party/shaderc/src/README.md index 69f3c7aaedf..051b93a1be7 100644 --- a/chromium/third_party/shaderc/src/README.md +++ b/chromium/third_party/shaderc/src/README.md @@ -266,6 +266,7 @@ older versions of Shaderc and its dependencies. * **Python:** [pyshaderc][pyshaderc] * **Rust:** [shaderc-rs][shaderc-rs] +* **Go:** [gshaderc][gshaderc] [khr-glslang]: https://github.com/KhronosGroup/glslang [spirv-tools]: https://github.com/KhronosGroup/SPIRV-Tools @@ -274,3 +275,4 @@ older versions of Shaderc and its dependencies. [shaderc-rs]: https://github.com/google/shaderc-rs [appveyor]: https://ci.appveyor.com/project/dneto0/shaderc [dawn]: https://dawn.googlesource.com/dawn +[gshaderc]: https://github.com/celer/gshaderc diff --git a/chromium/third_party/shaderc/src/cmake/utils.cmake b/chromium/third_party/shaderc/src/cmake/utils.cmake index 6281574f2bf..049d48a480b 100644 --- a/chromium/third_party/shaderc/src/cmake/utils.cmake +++ b/chromium/third_party/shaderc/src/cmake/utils.cmake @@ -9,7 +9,11 @@ endfunction(shaderc_use_gmock) function(shaderc_default_c_compile_options TARGET) if (NOT "${MSVC}") - target_compile_options(${TARGET} PRIVATE -Wall -Werror -fvisibility=hidden) + if (SHADERC_ENABLE_WERROR_COMPILE) + target_compile_options(${TARGET} PRIVATE -Wall -Werror -fvisibility=hidden) + else() + target_compile_options(${TARGET} PRIVATE -Wall -fvisibility=hidden) + endif() if (NOT "${MINGW}") target_compile_options(${TARGET} PRIVATE -fPIC) endif() diff --git a/chromium/third_party/shaderc/src/downloads.md b/chromium/third_party/shaderc/src/downloads.md index 2671e26d74c..72a04464d1f 100644 --- a/chromium/third_party/shaderc/src/downloads.md +++ b/chromium/third_party/shaderc/src/downloads.md @@ -1,6 +1,9 @@ # Downloads Download the latest builds. +**Note: These binaries are just the artifacts of the builders and have not + undergone any QA, thus they should be considered unsupported.** + ## Release | Windows | Linux | MacOS | | --- | --- | --- | diff --git a/chromium/third_party/shaderc/src/glslc/README.asciidoc b/chromium/third_party/shaderc/src/glslc/README.asciidoc index 23ce6cc583e..bfcdbb4067b 100644 --- a/chromium/third_party/shaderc/src/glslc/README.asciidoc +++ b/chromium/third_party/shaderc/src/glslc/README.asciidoc @@ -107,11 +107,11 @@ Otherwise, ** If the input file has a <<shader-stage-selection,shader stage selection extension>>, the output file will be named as by appending the file extension for the compilation stage to the input file's name. E.g., `glslc -c foo.vert` - will generate `foo.vert.spv`, and `glslc -s bar.frag` will generate + will generate `foo.vert.spv`, and `glslc -S bar.frag` will generate `bar.frag.spvasm`. ** Otherwise, the output file will be named as by replacing the input file's file extension, if any, with the file extension for the compilation stage. - E.g., `glslc -c foo` will generate `foo.spv`, and `glslc -s bar.glsl` will + E.g., `glslc -c foo` will generate `foo.spv`, and `glslc -S bar.glsl` will generate `bar.spvasm`. * If no compilation stage is selected, the output file will be named `a.spv`. @@ -136,8 +136,8 @@ multiple files generated. A filename of `-` represents standard output. === Language and Mode Selection Options -[[option-finverty]] -==== `-finverty` +[[option-finvert-y]] +==== `-finvert-y` Inverts position.Y output in a vertex shader. @@ -231,12 +231,14 @@ the following: * `vulkan`: create SPIR-V under Vulkan 1.0 semantics. * `vulkan1.0`: create SPIR-V under Vulkan 1.0 semantics. * `vulkan1.1`: create SPIR-V under Vulkan 1.1 semantics. +* `vulkan1.2`: create SPIR-V under Vulkan 1.2 semantics. * `opengl`: create SPIR-V under OpenGL 4.5 semantics. * `opengl4.5`: create SPIR-V under OpenGL 4.5 semantics. * `opengl_compat`: create SPIR-V under OpenGL semantics, including compatibility profile functions. -Generated code uses SPIR-V 1.0, except that code compiled for Vulkan 1.1 uses SPIR-V 1.3. +Generated code uses SPIR-V 1.0, except for code compiled for Vulkan 1.1, which uses +SPIR-V 1.3, and code compiled for Vulkan 1.5, which uses SPIR-V 1.5. If this option is not specified, a default of `vulkan1.0` is used. @@ -244,8 +246,9 @@ If this option is not specified, a default of `vulkan1.0` is used. `--target-spv=<value>` lets you specify the SPIR-V version to be used by the generated module. The default is to use the highest version of SPIR-V required to be supported -by the target environment. For example, the default is SPIR-V 1.0 for Vulkan 1.0, and -and SPIR-V 1.3 for Vulkan 1.1. +by the target environment. The defaults for specific Vulkan target environments are +as follows: SPIR-V 1.0 for Vulkan 1.0, SPIR-V 1.3 for Vulkan 1.1, and SPIR-V 1.5 for +Vulkan 1.2. The ``<value>`` can be one of the following: @@ -254,6 +257,7 @@ The ``<value>`` can be one of the following: * `spv1.2` * `spv1.3` * `spv1.4` +* `spv1.5` ==== `-x` diff --git a/chromium/third_party/shaderc/src/glslc/src/main.cc b/chromium/third_party/shaderc/src/glslc/src/main.cc index dfba88629e4..bed325bb5b2 100644 --- a/chromium/third_party/shaderc/src/glslc/src/main.cc +++ b/chromium/third_party/shaderc/src/glslc/src/main.cc @@ -145,7 +145,7 @@ Options: -std=<value> Version and profile for GLSL input files. Possible values are concatenations of version and profile, e.g. 310es, 450core, etc. Ignored for HLSL files. - -S Only run preprocess and compilation steps. + -S Emit SPIR-V assembly instead of binary. --show-limits Display available limit names and their default values. --target-env=<environment> Set the target client environment, and the semantics @@ -153,6 +153,7 @@ Options: the client version. Values are: vulkan1.0 # The default vulkan1.1 + vulkan1.2 vulkan # Same as vulkan1.0 opengl4.5 opengl # Same as opengl4.5 @@ -161,7 +162,8 @@ Options: module. The default is the highest version of SPIR-V required to be supported for the target environment. For example, default for vulkan1.0 is spv1.0, and - the default for vulkan1.1 is spv1.3. + the default for vulkan1.1 is spv1.3, + the default for vulkan1.2 is spv1.5. Values are: spv1.0, spv1.1, spv1.2, spv1.3, spv1.4, spv1.5 --version Display compiler version information. @@ -425,6 +427,9 @@ int main(int argc, char** argv) { } else if (target_env_str == "vulkan1.1") { target_env = shaderc_target_env_vulkan; version = shaderc_env_version_vulkan_1_1; + } else if (target_env_str == "vulkan1.2") { + target_env = shaderc_target_env_vulkan; + version = shaderc_env_version_vulkan_1_2; } else if (target_env_str == "opengl") { target_env = shaderc_target_env_opengl; } else if (target_env_str == "opengl4.5") { diff --git a/chromium/third_party/shaderc/src/glslc/src/shader_stage.cc b/chromium/third_party/shaderc/src/glslc/src/shader_stage.cc index 3e4716d37eb..23f15b1cd6c 100644 --- a/chromium/third_party/shaderc/src/glslc/src/shader_stage.cc +++ b/chromium/third_party/shaderc/src/glslc/src/shader_stage.cc @@ -44,7 +44,6 @@ shaderc_shader_kind MapStageNameToForcedKind(const string_piece& stage_name) { {"geom", shaderc_glsl_geometry_shader}, {"compute", shaderc_glsl_compute_shader}, {"comp", shaderc_glsl_compute_shader}, -#ifdef NV_EXTENSIONS {"rgen", shaderc_glsl_raygen_shader }, {"rahit", shaderc_glsl_anyhit_shader }, {"rchit", shaderc_glsl_closesthit_shader }, @@ -53,7 +52,6 @@ shaderc_shader_kind MapStageNameToForcedKind(const string_piece& stage_name) { {"rcall", shaderc_glsl_callable_shader }, {"task", shaderc_glsl_task_shader }, {"mesh", shaderc_glsl_mesh_shader }, -#endif }; for (const auto& entry : string_to_kind) { if (stage_name == entry.id) return entry.stage; @@ -79,7 +77,6 @@ shaderc_shader_kind DeduceDefaultShaderKindFromFileName( {"geom", shaderc_glsl_default_geometry_shader}, {"comp", shaderc_glsl_default_compute_shader}, {"spvasm", shaderc_spirv_assembly}, -#ifdef NV_EXTENSIONS {"rgen", shaderc_glsl_default_raygen_shader }, {"rahit", shaderc_glsl_default_anyhit_shader }, {"rchit", shaderc_glsl_default_closesthit_shader }, @@ -88,7 +85,6 @@ shaderc_shader_kind DeduceDefaultShaderKindFromFileName( {"rcall", shaderc_glsl_default_callable_shader }, {"task", shaderc_glsl_default_task_shader }, {"mesh", shaderc_glsl_default_mesh_shader }, -#endif }; const string_piece extension = glslc::GetFileExtension(file_name); diff --git a/chromium/third_party/shaderc/src/glslc/src/stage_test.cc b/chromium/third_party/shaderc/src/glslc/src/stage_test.cc index 80eef92ac88..31776734a97 100644 --- a/chromium/third_party/shaderc/src/glslc/src/stage_test.cc +++ b/chromium/third_party/shaderc/src/glslc/src/stage_test.cc @@ -49,7 +49,6 @@ TEST(DeduceDefaultShaderKindFromFileName, ValidStage) { EXPECT_EQ(shaderc_glsl_default_compute_shader, glslc::DeduceDefaultShaderKindFromFileName("a.comp")); -#ifdef NV_EXTENSIONS EXPECT_EQ(shaderc_glsl_default_raygen_shader, glslc::DeduceDefaultShaderKindFromFileName("a.rgen")); @@ -73,7 +72,6 @@ TEST(DeduceDefaultShaderKindFromFileName, ValidStage) { EXPECT_EQ(shaderc_glsl_default_mesh_shader, glslc::DeduceDefaultShaderKindFromFileName("a.mesh")); -#endif } TEST(DeduceDefaultShaderKindFromFileName, InvalidStage) { diff --git a/chromium/third_party/shaderc/src/libshaderc/Android.mk b/chromium/third_party/shaderc/src/libshaderc/Android.mk index 4d8cdd711e0..64618afc61f 100644 --- a/chromium/third_party/shaderc/src/libshaderc/Android.mk +++ b/chromium/third_party/shaderc/src/libshaderc/Android.mk @@ -5,9 +5,11 @@ LOCAL_CPP_EXTENSION := .cc .cpp .cxx LOCAL_MODULE:=shaderc LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)/include LOCAL_SRC_FILES:=src/shaderc.cc -LOCAL_C_INCLUDES:=$(LOCAL_PATH)/include +# The Shaderc third_party/Android.mk deduces SPVHEADERS_LOCAL_PATH, +# or delegates that responsibility to SPIRV-Tools' Android.mk. +LOCAL_C_INCLUDES:=$(LOCAL_PATH)/include $(SPVHEADERS_LOCAL_PATH)/include LOCAL_STATIC_LIBRARIES:=shaderc_util SPIRV-Tools-opt -LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -DNV_EXTENSIONS -DENABLE_HLSL=1 +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/chromium/third_party/shaderc/src/libshaderc/CMakeLists.txt b/chromium/third_party/shaderc/src/libshaderc/CMakeLists.txt index 0ffa06f2a56..f4a80d86330 100644 --- a/chromium/third_party/shaderc/src/libshaderc/CMakeLists.txt +++ b/chromium/third_party/shaderc/src/libshaderc/CMakeLists.txt @@ -12,11 +12,17 @@ set(SHADERC_SOURCES add_library(shaderc STATIC ${SHADERC_SOURCES}) shaderc_default_compile_options(shaderc) -target_include_directories(shaderc PUBLIC include PRIVATE ${glslang_SOURCE_DIR}) +target_include_directories(shaderc + PUBLIC include + PRIVATE ${glslang_SOURCE_DIR} + ${SPIRV-Headers_SOURCE_DIR}/include) add_library(shaderc_shared SHARED ${SHADERC_SOURCES}) shaderc_default_compile_options(shaderc_shared) -target_include_directories(shaderc_shared PUBLIC include PRIVATE ${glslang_SOURCE_DIR}) +target_include_directories(shaderc_shared + PUBLIC include + PRIVATE ${glslang_SOURCE_DIR} + ${SPIRV-Headers_SOURCE_DIR}/include) target_compile_definitions(shaderc_shared PRIVATE SHADERC_IMPLEMENTATION PUBLIC SHADERC_SHAREDLIB @@ -56,6 +62,7 @@ shaderc_add_tests( LINK_LIBS shaderc INCLUDE_DIRS include ${shaderc_SOURCE_DIR}/libshaderc_util/include ${glslang_SOURCE_DIR} ${spirv-tools_SOURCE_DIR}/include + ${SPIRV-Headers_SOURCE_DIR}/include TEST_NAMES shaderc shaderc_cpp @@ -66,6 +73,7 @@ shaderc_add_tests( LINK_LIBS shaderc_shared SPIRV-Tools INCLUDE_DIRS include ${shaderc_SOURCE_DIR}/libshaderc_util/include ${glslang_SOURCE_DIR} ${spirv-tools_SOURCE_DIR}/include + ${SPIRV-Headers_SOURCE_DIR}/include TEST_NAMES shaderc shaderc_cpp @@ -95,6 +103,7 @@ shaderc_add_tests( LINK_LIBS shaderc_combined ${CMAKE_THREAD_LIBS_INIT} INCLUDE_DIRS include ${shaderc_SOURCE_DIR}/libshaderc_util/include ${glslang_SOURCE_DIR} ${spirv-tools_SOURCE_DIR}/include + ${SPIRV-Headers_SOURCE_DIR}/include TEST_NAMES shaderc shaderc_cpp) diff --git a/chromium/third_party/shaderc/src/libshaderc/include/shaderc/env.h b/chromium/third_party/shaderc/src/libshaderc/include/shaderc/env.h index 2b6dafd81f0..a0e7a021934 100644 --- a/chromium/third_party/shaderc/src/libshaderc/include/shaderc/env.h +++ b/chromium/third_party/shaderc/src/libshaderc/include/shaderc/env.h @@ -38,6 +38,7 @@ typedef enum { // See vulkan.h shaderc_env_version_vulkan_1_0 = ((1u << 22)), shaderc_env_version_vulkan_1_1 = ((1u << 22) | (1 << 12)), + shaderc_env_version_vulkan_1_2 = ((1u << 22) | (2 << 12)), // For OpenGL, use the number from #version in shaders. // TODO(dneto): Currently no difference between OpenGL 4.5 and 4.6. // See glslang/Standalone/Standalone.cpp diff --git a/chromium/third_party/shaderc/src/libshaderc/include/shaderc/shaderc.h b/chromium/third_party/shaderc/src/libshaderc/include/shaderc/shaderc.h index 2fad35ced3f..54a9f6503ef 100644 --- a/chromium/third_party/shaderc/src/libshaderc/include/shaderc/shaderc.h +++ b/chromium/third_party/shaderc/src/libshaderc/include/shaderc/shaderc.h @@ -63,7 +63,6 @@ typedef enum { shaderc_glsl_default_tess_control_shader, shaderc_glsl_default_tess_evaluation_shader, shaderc_spirv_assembly, -#ifdef NV_EXTENSIONS shaderc_raygen_shader, shaderc_anyhit_shader, shaderc_closesthit_shader, @@ -88,7 +87,6 @@ typedef enum { shaderc_glsl_mesh_shader = shaderc_mesh_shader, shaderc_glsl_default_task_shader, shaderc_glsl_default_mesh_shader, -#endif } shaderc_shader_kind; typedef enum { diff --git a/chromium/third_party/shaderc/src/libshaderc/src/common_shaders_for_test.h b/chromium/third_party/shaderc/src/libshaderc/src/common_shaders_for_test.h index d6479e3f6b1..8a2ee415225 100644 --- a/chromium/third_party/shaderc/src/libshaderc/src/common_shaders_for_test.h +++ b/chromium/third_party/shaderc/src/libshaderc/src/common_shaders_for_test.h @@ -316,7 +316,6 @@ const char kGlslShaderComputeSubgroupBarrier[] = #extension GL_KHR_shader_subgroup_basic : enable void main() { subgroupBarrier(); })"; -#ifdef NV_EXTENSIONS // A GLSL task shader using a regular barrier. const char kGlslShaderTaskBarrier[] = R"(#version 450 @@ -352,7 +351,6 @@ const char kGlslShaderMeshSubgroupBarrier[] = layout(max_primitives=32) out; layout(triangles) out; void main() { subgroupBarrier(); })"; -#endif const char kGlslMultipleFnShader[] = R"(#version 450 diff --git a/chromium/third_party/shaderc/src/libshaderc/src/shaderc.cc b/chromium/third_party/shaderc/src/libshaderc/src/shaderc.cc index fa318a11e5e..0421656c98b 100644 --- a/chromium/third_party/shaderc/src/libshaderc/src/shaderc.cc +++ b/chromium/third_party/shaderc/src/libshaderc/src/shaderc.cc @@ -12,21 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "shaderc_private.h" - #include <algorithm> #include <cassert> #include <cstdint> #include <sstream> #include <vector> -#include "SPIRV/spirv.hpp" - #include "libshaderc_util/compiler.h" #include "libshaderc_util/counting_includer.h" #include "libshaderc_util/resources.h" #include "libshaderc_util/spirv_tools_wrapper.h" #include "libshaderc_util/version_profile.h" +#include "shaderc_private.h" +#include "spirv/unified1/spirv.hpp" #if (defined(_MSC_VER) && !defined(_CPPUNWIND)) || !defined(__EXCEPTIONS) #define TRY_IF_EXCEPTIONS_ENABLED @@ -57,7 +55,6 @@ EShLanguage GetForcedStage(shaderc_shader_kind kind) { case shaderc_glsl_tess_evaluation_shader: return EShLangTessEvaluation; -#ifdef NV_EXTENSIONS case shaderc_glsl_raygen_shader: return EShLangRayGenNV; case shaderc_glsl_anyhit_shader: @@ -74,7 +71,6 @@ EShLanguage GetForcedStage(shaderc_shader_kind kind) { return EShLangTaskNV; case shaderc_glsl_mesh_shader: return EShLangMeshNV; -#endif case shaderc_glsl_infer_from_source: case shaderc_glsl_default_vertex_shader: @@ -83,7 +79,6 @@ EShLanguage GetForcedStage(shaderc_shader_kind kind) { case shaderc_glsl_default_geometry_shader: case shaderc_glsl_default_tess_control_shader: case shaderc_glsl_default_tess_evaluation_shader: -#ifdef NV_EXTENSIONS case shaderc_glsl_default_raygen_shader: case shaderc_glsl_default_anyhit_shader: case shaderc_glsl_default_closesthit_shader: @@ -92,7 +87,6 @@ EShLanguage GetForcedStage(shaderc_shader_kind kind) { case shaderc_glsl_default_callable_shader: case shaderc_glsl_default_task_shader: case shaderc_glsl_default_mesh_shader: -#endif case shaderc_spirv_assembly: return EShLangCount; } @@ -150,7 +144,6 @@ class StageDeducer { case shaderc_glsl_tess_control_shader: case shaderc_glsl_tess_evaluation_shader: case shaderc_glsl_infer_from_source: -#ifdef NV_EXTENSIONS case shaderc_glsl_raygen_shader: case shaderc_glsl_anyhit_shader: case shaderc_glsl_closesthit_shader: @@ -159,7 +152,6 @@ class StageDeducer { case shaderc_glsl_callable_shader: case shaderc_glsl_task_shader: case shaderc_glsl_mesh_shader: -#endif return EShLangCount; case shaderc_glsl_default_vertex_shader: return EShLangVertex; @@ -173,7 +165,6 @@ class StageDeducer { return EShLangTessControl; case shaderc_glsl_default_tess_evaluation_shader: return EShLangTessEvaluation; -#ifdef NV_EXTENSIONS case shaderc_glsl_default_raygen_shader: return EShLangRayGenNV; case shaderc_glsl_default_anyhit_shader: @@ -190,7 +181,6 @@ class StageDeducer { return EShLangTaskNV; case shaderc_glsl_default_mesh_shader: return EShLangMeshNV; -#endif case shaderc_spirv_assembly: return EShLangCount; } @@ -287,6 +277,8 @@ shaderc_util::Compiler::TargetEnv GetCompilerTargetEnv(shaderc_target_env env) { return shaderc_util::Compiler::TargetEnv::OpenGL; case shaderc_target_env_opengl_compat: return shaderc_util::Compiler::TargetEnv::OpenGLCompat; + case shaderc_target_env_webgpu: + return shaderc_util::Compiler::TargetEnv::WebGPU; case shaderc_target_env_vulkan: default: break; @@ -307,6 +299,10 @@ shaderc_util::Compiler::TargetEnvVersion GetCompilerTargetEnvVersion( version_number) { return Compiler::TargetEnvVersion::Vulkan_1_1; } + if (static_cast<uint32_t>(Compiler::TargetEnvVersion::Vulkan_1_2) == + version_number) { + return Compiler::TargetEnvVersion::Vulkan_1_2; + } if (static_cast<uint32_t>(Compiler::TargetEnvVersion::OpenGL_4_5) == version_number) { return Compiler::TargetEnvVersion::OpenGL_4_5; @@ -775,6 +771,7 @@ bool shaderc_parse_version_profile(const char* str, int* version, *profile = shaderc_profile_none; return true; case EBadProfile: + case EProfileCount: return false; } diff --git a/chromium/third_party/shaderc/src/libshaderc/src/shaderc_cpp_test.cc b/chromium/third_party/shaderc/src/libshaderc/src/shaderc_cpp_test.cc index 407d8f4a486..744d2ee1395 100644 --- a/chromium/third_party/shaderc/src/libshaderc/src/shaderc_cpp_test.cc +++ b/chromium/third_party/shaderc/src/libshaderc/src/shaderc_cpp_test.cc @@ -14,15 +14,15 @@ #include <gmock/gmock.h> #include <gtest/gtest.h> + #include <memory> #include <thread> #include <unordered_map> -#include "SPIRV/spirv.hpp" -#include "spirv-tools/libspirv.hpp" - #include "common_shaders_for_test.h" #include "shaderc/shaderc.hpp" +#include "spirv-tools/libspirv.hpp" +#include "spirv/unified1/spirv.hpp" namespace { diff --git a/chromium/third_party/shaderc/src/libshaderc/src/shaderc_private.h b/chromium/third_party/shaderc/src/libshaderc/src/shaderc_private.h index 30dc86366cb..87c41a28876 100644 --- a/chromium/third_party/shaderc/src/libshaderc/src/shaderc_private.h +++ b/chromium/third_party/shaderc/src/libshaderc/src/shaderc_private.h @@ -111,7 +111,6 @@ inline shaderc_util::Compiler::Stage shaderc_convert_specific_stage( return shaderc_util::Compiler::Stage::Geometry; case shaderc_compute_shader: return shaderc_util::Compiler::Stage::Compute; -#if NV_EXTENSIONS case shaderc_raygen_shader: return shaderc_util::Compiler::Stage::RayGenNV; case shaderc_intersection_shader: @@ -128,7 +127,6 @@ inline shaderc_util::Compiler::Stage shaderc_convert_specific_stage( return shaderc_util::Compiler::Stage::TaskNV; case shaderc_mesh_shader: return shaderc_util::Compiler::Stage::MeshNV; -#endif default: // We don't care about the other kinds. break; diff --git a/chromium/third_party/shaderc/src/libshaderc/src/shaderc_private_test.cc b/chromium/third_party/shaderc/src/libshaderc/src/shaderc_private_test.cc index 3b645512f8b..72a7577fcd1 100644 --- a/chromium/third_party/shaderc/src/libshaderc/src/shaderc_private_test.cc +++ b/chromium/third_party/shaderc/src/libshaderc/src/shaderc_private_test.cc @@ -30,7 +30,6 @@ TEST(ConvertSpecificStage, Exhaustive) { shaderc_convert_specific_stage(shaderc_geometry_shader)); EXPECT_EQ(shaderc_util::Compiler::Stage::Compute, shaderc_convert_specific_stage(shaderc_compute_shader)); -#ifdef NV_EXTENSIONS EXPECT_EQ(shaderc_util::Compiler::Stage::RayGenNV, shaderc_convert_specific_stage(shaderc_raygen_shader)); EXPECT_EQ(shaderc_util::Compiler::Stage::AnyHitNV, @@ -47,6 +46,5 @@ TEST(ConvertSpecificStage, Exhaustive) { shaderc_convert_specific_stage(shaderc_task_shader)); EXPECT_EQ(shaderc_util::Compiler::Stage::MeshNV, shaderc_convert_specific_stage(shaderc_mesh_shader)); -#endif } } // anonymous namespace diff --git a/chromium/third_party/shaderc/src/libshaderc/src/shaderc_test.cc b/chromium/third_party/shaderc/src/libshaderc/src/shaderc_test.cc index a54b87c0c44..14f28abdfc8 100644 --- a/chromium/third_party/shaderc/src/libshaderc/src/shaderc_test.cc +++ b/chromium/third_party/shaderc/src/libshaderc/src/shaderc_test.cc @@ -12,16 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "shaderc/shaderc.h" + #include <gmock/gmock.h> #include <gtest/gtest.h> + #include <memory> #include <thread> #include <unordered_map> -#include "SPIRV/spirv.hpp" - #include "common_shaders_for_test.h" -#include "shaderc/shaderc.h" +#include "spirv/unified1/spirv.hpp" namespace { @@ -1216,7 +1217,6 @@ TEST_F(CompileStringWithOptionsTest, shaderc_glsl_compute_shader, options_.get())); } -#ifdef NV_EXTENSIONS // task shader TEST_F(CompileStringWithOptionsTest, TargetEnvRespectedWhenCompilingVulkan1_0TaskShaderToVulkan1_0Succeeds) { @@ -1290,7 +1290,6 @@ TEST_F(CompileStringWithOptionsTest, EXPECT_TRUE(CompilesToValidSpv(compiler_, kGlslShaderMeshSubgroupBarrier, shaderc_glsl_mesh_shader, options_.get())); } -#endif TEST_F(CompileStringWithOptionsTest, DISABLED_TargetEnvIgnoredWhenPreprocessing) { diff --git a/chromium/third_party/shaderc/src/libshaderc_spvc/Android.mk b/chromium/third_party/shaderc/src/libshaderc_spvc/Android.mk index 6a2dffce199..f0579a8599e 100644 --- a/chromium/third_party/shaderc/src/libshaderc_spvc/Android.mk +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/Android.mk @@ -8,7 +8,7 @@ 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 -DNV_EXTENSIONS -DENABLE_HLSL=1 +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/chromium/third_party/shaderc/src/libshaderc_spvc/CMakeLists.txt b/chromium/third_party/shaderc/src/libshaderc_spvc/CMakeLists.txt index 964ac160243..b22f9ebfba7 100644 --- a/chromium/third_party/shaderc/src/libshaderc_spvc/CMakeLists.txt +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/CMakeLists.txt @@ -17,6 +17,7 @@ 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 @@ -29,8 +30,8 @@ target_include_directories(shaderc_spvc PUBLIC include ${shaderc_SOURCE_DIR}/libshaderc/include ${spirv-tools_SOURCE_DIR}/include - ${spirv-tools_SOURCE_DIR}/ - ${CMAKE_CURRENT_BINARY_DIR}/../third_party/spirv-tools/) + ${spirv-tools_SOURCE_DIR} + ${spirv-tools_BINARY_DIR}) target_link_libraries(shaderc_spvc PRIVATE ${SPVC_LIBS}) add_library(shaderc_spvc_shared SHARED ${SPVC_SOURCES}) @@ -40,8 +41,8 @@ target_include_directories(shaderc_spvc_shared PUBLIC include ${shaderc_SOURCE_DIR}/libshaderc/include ${spirv-tools_SOURCE_DIR}/include - ${spirv-tools_SOURCE_DIR}/ - ${CMAKE_CURRENT_BINARY_DIR}/../third_party/spirv-tools/) + ${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 @@ -72,8 +73,8 @@ shaderc_add_tests( TEST_PREFIX shaderc LINK_LIBS shaderc_spvc ${SPVC_LIBS} INCLUDE_DIRS include ${shaderc_SOURCE_DIR}/libshaderc/include ${SPIRV-Cross_SOURCE_DIR}/.. - ${SPIRV-Cross_SOURCE_DIR}/../effcee - ${SPIRV-Cross_SOURCE_DIR}/../re2 + ${effcee_SOURCE_DIR} + ${RE2_SOURCE_DIR} TEST_NAMES spvc spvc_cpp diff --git a/chromium/third_party/shaderc/src/libshaderc_spvc/include/spvc/spvc.h b/chromium/third_party/shaderc/src/libshaderc_spvc/include/spvc/spvc.h index 47873146670..d2e4db9df79 100644 --- a/chromium/third_party/shaderc/src/libshaderc_spvc/include/spvc/spvc.h +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/include/spvc/spvc.h @@ -27,31 +27,37 @@ extern "C" { #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_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, @@ -66,11 +72,188 @@ typedef enum { 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_sampled_texture = 0x00000004, + shaderc_spvc_binding_type_storage_texture = 0x00000005, + shaderc_spvc_binding_type_readonly_storage_texture = 0x00000006, + shaderc_spvc_binding_type_writeonly_storage_texture = 0x00000007, +} 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; +} 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. @@ -95,12 +278,12 @@ SHADERC_EXPORT const char* shaderc_spvc_context_get_messages( // 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 void* shaderc_spvc_context_get_compiler( - const shaderc_spvc_context_t context); +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 void shaderc_spvc_context_set_use_spvc_parser( +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 @@ -112,11 +295,10 @@ typedef struct shaderc_spvc_compile_options* shaderc_spvc_compile_options_t; // 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(void); +shaderc_spvc_compile_options_create(shaderc_spvc_spv_env source_env, + shaderc_spvc_spv_env target_env); // Returns a copy of the given options. -// If NULL is passed as the parameter the call is the same as -// shaderc_spvc_compile_options_init. SHADERC_EXPORT shaderc_spvc_compile_options_t shaderc_spvc_compile_options_clone( const shaderc_spvc_compile_options_t options); @@ -127,12 +309,30 @@ shaderc_spvc_compile_options_clone( 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 void shaderc_spvc_compile_options_set_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 void shaderc_spvc_compile_options_set_remove_unused_variables( +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: @@ -140,134 +340,140 @@ SHADERC_EXPORT void shaderc_spvc_compile_options_set_remove_unused_variables( // 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 void shaderc_spvc_compile_options_set_robust_buffer_access_pass( +SHADERC_EXPORT shaderc_spvc_status +shaderc_spvc_compile_options_set_robust_buffer_access_pass( shaderc_spvc_compile_options_t options, bool b); -SHADERC_EXPORT void shaderc_spvc_compile_options_set_emit_line_directives( +SHADERC_EXPORT shaderc_spvc_status +shaderc_spvc_compile_options_set_emit_line_directives( shaderc_spvc_compile_options_t options, bool b); -// 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 void shaderc_spvc_compile_options_set_source_env( - shaderc_spvc_compile_options_t options, shaderc_target_env env, - shaderc_env_version version); - -// 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 void shaderc_spvc_compile_options_set_target_env( - shaderc_spvc_compile_options_t options, shaderc_target_env env, - shaderc_env_version version); // If true, Vulkan GLSL features are used instead of GL-compatible features. -SHADERC_EXPORT void shaderc_spvc_compile_options_set_vulkan_semantics( +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 void shaderc_spvc_compile_options_set_separate_shader_objects( +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 void shaderc_spvc_compile_options_set_flatten_ubo( +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 void shaderc_spvc_compile_options_set_glsl_language_version( +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 void +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 void shaderc_spvc_compile_options_set_es( +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 void +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 void shaderc_spvc_compile_options_set_msl_language_version( +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 void +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 void shaderc_spvc_compile_options_set_msl_platform( +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 void shaderc_spvc_compile_options_set_msl_pad_fragment_output( +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 void shaderc_spvc_compile_options_set_msl_capture( +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 void shaderc_spvc_compile_options_set_msl_domain_lower_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 void shaderc_spvc_compile_options_set_msl_argument_buffers( +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 void +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 void +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 void +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 HLSL shader model. Default is 30. -SHADERC_EXPORT void shaderc_spvc_compile_options_set_hlsl_shader_model( +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 void shaderc_spvc_compile_options_set_hlsl_point_size_compat( +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 void shaderc_spvc_compile_options_set_hlsl_point_coord_compat( +SHADERC_EXPORT shaderc_spvc_status +shaderc_spvc_compile_options_set_hlsl_point_coord_compat( shaderc_spvc_compile_options_t options, bool 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_EXPORT void shaderc_spvc_compile_options_set_fixup_clipspace( +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 void shaderc_spvc_compile_options_set_flip_vert_y( +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 void shaderc_spvc_compile_options_set_validate( +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 void shaderc_spvc_compile_options_set_optimize( +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 @@ -310,6 +516,40 @@ 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. @@ -317,6 +557,69 @@ 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. @@ -334,18 +637,18 @@ SHADERC_EXPORT void shaderc_spvc_result_destroy( // Get validation/compilation result as a string. This is only supported // compiling to GLSL, HSL, and MSL. -SHADERC_EXPORT const char* shaderc_spvc_result_get_string_output( - const shaderc_spvc_compilation_result_t result); +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 const uint32_t* shaderc_spvc_result_get_binary_output( - const shaderc_spvc_compilation_result_t result); +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 uint32_t shaderc_spvc_result_get_binary_length( - const shaderc_spvc_compilation_result_t result); +SHADERC_EXPORT shaderc_spvc_status shaderc_spvc_result_get_binary_length( + const shaderc_spvc_compilation_result_t result, uint32_t* len); #ifdef __cplusplus } diff --git a/chromium/third_party/shaderc/src/libshaderc_spvc/include/spvc/spvc.hpp b/chromium/third_party/shaderc/src/libshaderc_spvc/include/spvc/spvc.hpp index 54562b71c3f..c417dcb44ff 100644 --- a/chromium/third_party/shaderc/src/libshaderc_spvc/include/spvc/spvc.hpp +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/include/spvc/spvc.hpp @@ -15,6 +15,7 @@ #ifndef SHADERC_SPVC_HPP_ #define SHADERC_SPVC_HPP_ +#include <functional> #include <memory> #include <string> #include <vector> @@ -22,6 +23,7 @@ #include "spvc.h" namespace shaderc_spvc { + // A CompilationResult contains the compiler output, compilation status, // and messages. // @@ -53,18 +55,36 @@ class CompilationResult { return *this; } - const std::string GetStringOutput() const { - return shaderc_spvc_result_get_string_output(result_.get()); - } - - const std::vector<uint32_t> GetBinaryOutput() const { - const uint32_t* binary_output = - shaderc_spvc_result_get_binary_output(result_.get()); - uint32_t binary_length = - shaderc_spvc_result_get_binary_length(result_.get()); - if (!binary_output || !binary_length) return {}; - - return std::vector<uint32_t>(binary_output, binary_output + binary_length); + 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 (!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: @@ -81,9 +101,14 @@ class CompilationResult { // Contains any options that can have default values for a compilation. class CompileOptions { public: - CompileOptions() - : options_(shaderc_spvc_compile_options_create(), + 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())); @@ -94,30 +119,35 @@ class CompileOptions { options_.reset(other.options_.release()); } + // DEPRECATED // Set the environment for the input SPIR-V. Default is Vulkan 1.0. - void SetSourceEnvironment(shaderc_target_env env, - shaderc_env_version version) { - shaderc_spvc_compile_options_set_source_env(options_.get(), env, version); + 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. - void SetTargetEnvironment(shaderc_target_env env, - shaderc_env_version version) { - shaderc_spvc_compile_options_set_target_env(options_.get(), env, version); + 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. - void SetEntryPoint(const std::string& entry_point) { - shaderc_spvc_compile_options_set_entry_point(options_.get(), - entry_point.c_str()); + 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. - void SetRemoveUnusedVariables(bool b) { - shaderc_spvc_compile_options_set_remove_unused_variables(options_.get(), b); + 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: @@ -125,148 +155,167 @@ class CompileOptions { // arrays, providing guarantees satisfying Vulkan's robustBufferAccess rules. // This is useful when an implementation does not support robust-buffer access // as a driver option. - void SetRobustBufferAccessPass(bool b){ - shaderc_spvc_compile_options_set_robust_buffer_access_pass(options_.get(), - b); + shaderc_spvc_status SetRobustBufferAccessPass(bool b) { + return shaderc_spvc_compile_options_set_robust_buffer_access_pass( + options_.get(), b); } - void SetEmitLineDirectives(bool b){ - shaderc_spvc_compile_options_set_emit_line_directives(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. - void SetVulkanSemantics(bool b) { - shaderc_spvc_compile_options_set_vulkan_semantics(options_.get(), b); + 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. - void SetSeparateShaderObjects(bool b) { - shaderc_spvc_compile_options_set_separate_shader_objects(options_.get(), b); + 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. - void SetFlattenUbo(bool b) { - shaderc_spvc_compile_options_set_flatten_ubo(options_.get(), b); + 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). - void SetGLSLLanguageVersion(uint32_t version) { - shaderc_spvc_compile_options_set_glsl_language_version(options_.get(), - version); + 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. - void SetFlattenMultidimensionalArrays(bool b) { - shaderc_spvc_compile_options_set_flatten_multidimensional_arrays( + 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. - void SetES(bool b) { shaderc_spvc_compile_options_set_es(options_.get(), b); } + 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. - void SetGLSLEmitPushConstantAsUBO(bool b) { - shaderc_spvc_compile_options_set_glsl_emit_push_constant_as_ubo( + 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). - void SetMSLLanguageVersion(uint32_t version) { - shaderc_spvc_compile_options_set_msl_language_version(options_.get(), - version); + 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. - void SetMSLSwizzleTextureSamples(bool b) { - shaderc_spvc_compile_options_set_msl_swizzle_texture_samples(options_.get(), - b); + 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. - void SetMSLPlatform(shaderc_spvc_msl_platform platform) { - shaderc_spvc_compile_options_set_msl_platform(options_.get(), platform); + 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. - void SetMSLPadFragmentOutput(bool b) { - shaderc_spvc_compile_options_set_msl_pad_fragment_output(options_.get(), b); + 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. - void SetMSLCapture(bool b) { - shaderc_spvc_compile_options_set_msl_capture(options_.get(), b); + 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. - void SetMSLDomainLowerLeft(bool b) { - shaderc_spvc_compile_options_set_msl_domain_lower_left(options_.get(), b); + 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. - void SetMSLArgumentBuffers(bool b) { - shaderc_spvc_compile_options_set_msl_argument_buffers(options_.get(), b); + 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. - void SetMSLDiscreteDescriptorSets(const std::vector<uint32_t> descriptors) { - shaderc_spvc_compile_options_set_msl_discrete_descriptor_sets( + 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 - void SetMSLEnablePointSizeBuiltIn(bool b) { - shaderc_spvc_compile_options_set_msl_enable_point_size_builtin( + 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 - void SetMSLBufferSizeBufferIndex(uint32_t index) { - shaderc_spvc_compile_options_set_msl_buffer_size_buffer_index( + shaderc_spvc_status SetMSLBufferSizeBufferIndex(uint32_t index) { + return shaderc_spvc_compile_options_set_msl_buffer_size_buffer_index( options_.get(), index); } // Which HLSL shader model should be used. Default is 30. - void SetHLSLShaderModel(uint32_t model) { - shaderc_spvc_compile_options_set_hlsl_shader_model(options_.get(), model); + 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. - void SetHLSLPointSizeCompat(bool b) { - shaderc_spvc_compile_options_set_hlsl_point_size_compat(options_.get(), b); + 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. - void SetHLSLPointCoordCompat(bool b) { - shaderc_spvc_compile_options_set_hlsl_point_coord_compat(options_.get(), b); + shaderc_spvc_status SetHLSLPointCoordCompat(bool b) { + return shaderc_spvc_compile_options_set_hlsl_point_coord_compat( + 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] - void SetFixupClipspace(bool b) { - shaderc_spvc_compile_options_set_fixup_clipspace(options_.get(), b); + 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. - void SetFlipVertY(bool b) { - shaderc_spvc_compile_options_set_flip_vert_y(options_.get(), b); + 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. - void SetValidate(bool b) { - shaderc_spvc_compile_options_set_validate(options_.get(), b); + 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. - void SetOptimize(bool b) { - shaderc_spvc_compile_options_set_optimize(options_.get(), b); + 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 @@ -307,12 +356,12 @@ class Context { // ownership. // This is being exposed temporarily to ease integration of spvc into Dawn, // but this is will be removed in the future without warning. - void* GetCompiler() const { - return shaderc_spvc_context_get_compiler(context_.get()); + shaderc_spvc_status GetCompiler(void** compiler) { + return shaderc_spvc_context_get_compiler(context_.get(), compiler); } - void SetUseSpvcParser(bool b) { - shaderc_spvc_context_set_use_spvc_parser(context_.get(), b); + 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. @@ -361,6 +410,159 @@ class Context { 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); + } + private: Context(const Context&) = delete; Context& operator=(const Context& other) = delete; diff --git a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc.cc b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc.cc index 7bb92fbd50d..6c7d0ffd09a 100644 --- a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc.cc +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc.cc @@ -12,8 +12,326 @@ // 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; } @@ -24,23 +342,39 @@ void shaderc_spvc_context_destroy(shaderc_spvc_context_t context) { const char* shaderc_spvc_context_get_messages( const shaderc_spvc_context_t context) { - return context->messages.c_str(); + for (const auto& message : context->messages) { + context->messages_string += message; + } + context->messages.clear(); + return context->messages_string.c_str(); } -void* shaderc_spvc_context_get_compiler(const shaderc_spvc_context_t context) { - return context->cross_compiler.get(); +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; } -void shaderc_spvc_context_set_use_spvc_parser(shaderc_spvc_context_t context, - bool b) { +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_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; } @@ -48,7 +382,7 @@ shaderc_spvc_compile_options_t shaderc_spvc_compile_options_create() { 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 shaderc_spvc_compile_options_create(); + return nullptr; } void shaderc_spvc_compile_options_destroy( @@ -56,87 +390,149 @@ void shaderc_spvc_compile_options_destroy( if (options) delete options; } -void shaderc_spvc_compile_options_set_source_env( +// 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; } -void shaderc_spvc_compile_options_set_target_env( +// 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; } -void shaderc_spvc_compile_options_set_entry_point( +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; } -void shaderc_spvc_compile_options_set_remove_unused_variables( +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; } -void shaderc_spvc_compile_options_set_robust_buffer_access_pass( +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; } -void shaderc_spvc_compile_options_set_emit_line_directives( +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; } -void shaderc_spvc_compile_options_set_vulkan_semantics( +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; } -void shaderc_spvc_compile_options_set_separate_shader_objects( +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; } -void shaderc_spvc_compile_options_set_flatten_ubo( +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; } -void shaderc_spvc_compile_options_set_glsl_language_version( +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; } -void shaderc_spvc_compile_options_set_flatten_multidimensional_arrays( +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; } -void shaderc_spvc_compile_options_set_es(shaderc_spvc_compile_options_t options, - bool b) { +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; } -void shaderc_spvc_compile_options_set_glsl_emit_push_constant_as_ubo( +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; } -void shaderc_spvc_compile_options_set_msl_language_version( +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; } -void shaderc_spvc_compile_options_set_msl_swizzle_texture_samples( +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; } -void shaderc_spvc_compile_options_set_msl_platform( +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; @@ -145,84 +541,130 @@ void shaderc_spvc_compile_options_set_msl_platform( options->msl.platform = spirv_cross::CompilerMSL::Options::macOS; break; } + return shaderc_spvc_status_success; } -void shaderc_spvc_compile_options_set_msl_pad_fragment_output( +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; } -void shaderc_spvc_compile_options_set_msl_capture( +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; } -void shaderc_spvc_compile_options_set_msl_domain_lower_left( +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; } -void shaderc_spvc_compile_options_set_msl_argument_buffers( +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; } -void shaderc_spvc_compile_options_set_msl_discrete_descriptor_sets( +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; } -void shaderc_spvc_compile_options_set_msl_enable_point_size_builtin( +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; } -void shaderc_spvc_compile_options_set_msl_buffer_size_buffer_index( +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; } -void shaderc_spvc_compile_options_set_hlsl_shader_model( +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; } -void shaderc_spvc_compile_options_set_hlsl_point_size_compat( +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; } -void shaderc_spvc_compile_options_set_hlsl_point_coord_compat( +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; } -void shaderc_spvc_compile_options_set_fixup_clipspace( +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; } -void shaderc_spvc_compile_options_set_flip_vert_y( +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; } -void shaderc_spvc_compile_options_set_validate( +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; } -void shaderc_spvc_compile_options_set_optimize( +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 (!data || size < sizeof(*options)) return 0; + if (!options || !data || size < sizeof(*options)) return 0; memcpy(static_cast<void*>(options), data, sizeof(*options)); return sizeof(*options); @@ -234,7 +676,6 @@ shaderc_spvc_status shaderc_spvc_initialize_impl( shaderc_spvc_status (*generator)(const shaderc_spvc_context_t, const uint32_t*, size_t, shaderc_spvc_compile_options_t)) { - if (!context) return shaderc_spvc_status_configuration_error; 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; @@ -249,6 +690,10 @@ shaderc_spvc_status shaderc_spvc_initialize_impl( 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); @@ -257,6 +702,10 @@ shaderc_spvc_status shaderc_spvc_initialize_for_glsl( 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); @@ -265,6 +714,10 @@ shaderc_spvc_status shaderc_spvc_initialize_for_hlsl( 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); @@ -273,6 +726,10 @@ shaderc_spvc_status shaderc_spvc_initialize_for_msl( 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); @@ -281,8 +738,12 @@ shaderc_spvc_status shaderc_spvc_initialize_for_vulkan( shaderc_spvc_status shaderc_spvc_compile_shader( const shaderc_spvc_context_t context, shaderc_spvc_compilation_result_t result) { - if (!context->cross_compiler || - context->target_lang == SPVC_TARGET_LANG_UNKNOWN) { + 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; } @@ -295,24 +756,25 @@ shaderc_spvc_status shaderc_spvc_compile_shader( shaderc_spvc_status status = spvc_private::generate_shader(context->cross_compiler.get(), result); if (status != shaderc_spvc_status_success) { - context->messages.append("Compilation failed. Partial source:\n"); + 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()); - context->messages.append(cast_compiler->get_partial_source()); + 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()); - context->messages.append(cast_compiler->get_partial_source()); + 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()); - context->messages.append(cast_compiler->get_partial_source()); + shaderc_spvc::ErrorLog(context) << cast_compiler->get_partial_source(); } else { - context->messages.append("Unexpected target language in context\n"); + shaderc_spvc::ErrorLog(context) + << "Unexpected target language in context"; } context->cross_compiler.reset(); } @@ -323,6 +785,9 @@ shaderc_spvc_status shaderc_spvc_compile_shader( 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( @@ -331,13 +796,355 @@ shaderc_spvc_status shaderc_spvc_set_decoration( context->cross_compiler->set_decoration(static_cast<spirv_cross::ID>(id), spirv_cross_decoration, argument); } else { - context->messages.append( - "Decoration Conversion failed. shaderc_spvc_decoration not " - "supported.\n "); + 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; + + 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; + 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; } @@ -346,17 +1153,30 @@ void shaderc_spvc_result_destroy(shaderc_spvc_compilation_result_t result) { if (result) delete result; } -const char* shaderc_spvc_result_get_string_output( - const shaderc_spvc_compilation_result_t result) { - return result->string_output.c_str(); +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; } -const uint32_t* shaderc_spvc_result_get_binary_output( - const shaderc_spvc_compilation_result_t result) { - return result->binary_output.data(); +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; } -uint32_t shaderc_spvc_result_get_binary_length( - const shaderc_spvc_compilation_result_t result) { - return result->binary_output.size(); +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/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_cpp_test.cc b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_cpp_test.cc index f56847ae7d1..09ad88b5c47 100644 --- a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_cpp_test.cc +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_cpp_test.cc @@ -41,8 +41,12 @@ TEST_F(CompileTest, Glsl) { { shaderc_spvc_status status = context_.CompileShader(&result_); EXPECT_EQ(shaderc_spvc_status_success, status); - EXPECT_NE(0, result_.GetStringOutput().size()); - EXPECT_EQ(0, result_.GetBinaryOutput().size()); + 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()); } } @@ -56,8 +60,12 @@ TEST_F(CompileTest, Hlsl) { { shaderc_spvc_status status = context_.CompileShader(&result_); EXPECT_EQ(shaderc_spvc_status_success, status); - EXPECT_NE(0, result_.GetStringOutput().size()); - EXPECT_EQ(0, result_.GetBinaryOutput().size()); + 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()); } } @@ -72,8 +80,12 @@ TEST_F(CompileTest, Msl) { { shaderc_spvc_status status = context_.CompileShader(&result_); EXPECT_EQ(shaderc_spvc_status_success, status); - EXPECT_NE(0, result_.GetStringOutput().size()); - EXPECT_EQ(0, result_.GetBinaryOutput().size()); + 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()); } } @@ -87,8 +99,12 @@ TEST_F(CompileTest, Vulkan) { { shaderc_spvc_status status = context_.CompileShader(&result_); EXPECT_EQ(shaderc_spvc_status_success, status); - EXPECT_EQ(0, result_.GetStringOutput().size()); - EXPECT_NE(0, result_.GetBinaryOutput().size()); + 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()); } } diff --git a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_log.cc b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_log.cc new file mode 100644 index 00000000000..b382c4ffb31 --- /dev/null +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_log.cc @@ -0,0 +1,88 @@ +// 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/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_log.h b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_log.h new file mode 100644 index 00000000000..827fbd5378d --- /dev/null +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_log.h @@ -0,0 +1,79 @@ +// 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/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_private.cc b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_private.cc index f16525e3555..69ca3e4befa 100644 --- a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_private.cc +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_private.cc @@ -15,6 +15,7 @@ #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 @@ -65,8 +66,26 @@ 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) { - context->messages.append(message); - context->messages.append("\n"); + 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, @@ -74,7 +93,7 @@ shaderc_spvc_status validate_spirv(shaderc_spvc_context* context, size_t source_len) { spvtools::SpirvTools tools(env); if (!tools.IsValid()) { - context->messages.append("Could not initialize SPIRV-Tools.\n"); + shaderc_spvc::ErrorLog(context) << "Could not initialize SPIRV-Tools."; return shaderc_spvc_status_internal_error; } @@ -83,7 +102,7 @@ shaderc_spvc_status validate_spirv(shaderc_spvc_context* context, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); if (!tools.Validate(source, source_len, spvtools::ValidatorOptions())) { - context->messages.append("Validation of shader failed.\n"); + shaderc_spvc::ErrorLog(context) << "Validation of shader failed."; return shaderc_spvc_status_validation_error; } @@ -97,7 +116,8 @@ shaderc_spvc_status translate_spirv(shaderc_spvc_context* context, shaderc_spvc_compile_options_t options, std::vector<uint32_t>* target) { if (!target) { - context->messages.append("null provided for translation destination.\n"); + shaderc_spvc::ErrorLog(context) + << "null provided for translation destination."; return shaderc_spvc_status_transformation_error; } @@ -118,9 +138,9 @@ shaderc_spvc_status translate_spirv(shaderc_spvc_context* context, target_env == SPV_ENV_WEBGPU_0) { opt.RegisterVulkanToWebGPUPasses(); } else { - context->messages.append( - "No defined transformation between source and " - "target execution environments.\n"); + shaderc_spvc::ErrorLog(context) + << "No defined transformation between source and target execution " + "environments."; return shaderc_spvc_status_transformation_error; } @@ -129,9 +149,8 @@ shaderc_spvc_status translate_spirv(shaderc_spvc_context* context, } if (!opt.Run(source, source_len, target)) { - context->messages.append( - "Transformations between source and target " - "execution environments failed.\n"); + shaderc_spvc::ErrorLog(context) << "Transformations between source and " + "target execution environments failed."; return shaderc_spvc_status_transformation_error; } @@ -145,7 +164,7 @@ shaderc_spvc_status validate_and_translate_spirv( if (options->validate) { status = validate_spirv(context, options->source_env, source, source_len); if (status != shaderc_spvc_status_success) { - context->messages.append("Validation of input source failed.\n"); + shaderc_spvc::ErrorLog(context) << "Validation of input source failed."; return status; } } @@ -159,7 +178,8 @@ shaderc_spvc_status validate_and_translate_spirv( status = validate_spirv(context, options->target_env, target->data(), target->size()); if (status != shaderc_spvc_status_success) { - context->messages.append("Validation of transformed source failed.\n"); + shaderc_spvc::ErrorLog(context) + << "Validation of transformed source failed."; return status; } } @@ -193,9 +213,9 @@ shaderc_spvc_status generate_glsl_compiler( spirv_cross::ParsedIR ir; status = generate_spvcir(context, &ir, source, source_len, options); if (status != shaderc_spvc_status_success) { - context->messages.append( - "Transformations between source and target " - "execution environments failed (spvc-ir-pass).\n"); + 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); @@ -206,8 +226,8 @@ shaderc_spvc_status generate_glsl_compiler( } if (!cross_compiler) { - context->messages.append( - "Unable to initialize SPIRV-Cross GLSL compiler.\n"); + shaderc_spvc::ErrorLog(context) + << "Unable to initialize SPIRV-Cross GLSL compiler."; return shaderc_spvc_status_compilation_error; } context->cross_compiler.reset(cross_compiler); @@ -243,12 +263,12 @@ shaderc_spvc_status generate_glsl_compiler( if (stage_count != 1) { context->cross_compiler.reset(); if (stage_count == 0) { - context->messages.append("There is no entry point with name: " + - options->entry_point); + shaderc_spvc::ErrorLog(context) + << "There is no entry point with name: " << options->entry_point; } else { - context->messages.append( - "There is more than one entry point with name: " + - options->entry_point + ". Use --stage."); + shaderc_spvc::ErrorLog(context) + << "There is more than one entry point with name: " + << options->entry_point << ". Use --stage."; } return shaderc_spvc_status_compilation_error; } @@ -317,9 +337,9 @@ shaderc_spvc_status generate_hlsl_compiler( spirv_cross::ParsedIR ir; status = generate_spvcir(context, &ir, source, source_len, options); if (status != shaderc_spvc_status_success) { - context->messages.append( - "Transformations between source and target " - "execution environments failed (spvc-ir-pass).\n"); + 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); @@ -329,8 +349,8 @@ shaderc_spvc_status generate_hlsl_compiler( new (std::nothrow) spirv_cross::CompilerHLSL(source, source_len); } if (!cross_compiler) { - context->messages.append( - "Unable to initialize SPIRV-Cross HLSL compiler.\n"); + shaderc_spvc::ErrorLog(context) + << "Unable to initialize SPIRV-Cross HLSL compiler."; return shaderc_spvc_status_compilation_error; } context->cross_compiler.reset(cross_compiler); @@ -353,9 +373,9 @@ shaderc_spvc_status generate_msl_compiler( spirv_cross::ParsedIR ir; status = generate_spvcir(context, &ir, source, source_len, options); if (status != shaderc_spvc_status_success) { - context->messages.append( - "Transformations between source and target " - "execution environments failed (spvc-ir-pass).\n"); + 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); @@ -366,8 +386,8 @@ shaderc_spvc_status generate_msl_compiler( } if (!cross_compiler) { - context->messages.append( - "Unable to initialize SPIRV-Cross MSL compiler.\n"); + shaderc_spvc::ErrorLog(context) + << "Unable to initialize SPIRV-Cross MSL compiler."; return shaderc_spvc_status_compilation_error; } context->cross_compiler.reset(cross_compiler); @@ -393,9 +413,9 @@ shaderc_spvc_status generate_vulkan_compiler( shaderc_spvc_status status = generate_spvcir(context, &ir, source, source_len, options); if (status != shaderc_spvc_status_success) { - context->messages.append( - "Transformations between source and target " - "execution environments failed (spvc-ir-pass).\n"); + 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); @@ -406,9 +426,8 @@ shaderc_spvc_status generate_vulkan_compiler( } if (!cross_compiler) { - context->messages.append( - "Unable to initialize SPIRV-Cross reflection " - "compiler.\n"); + shaderc_spvc::ErrorLog(context) + << "Unable to initialize SPIRV-Cross reflection compiler."; return shaderc_spvc_status_compilation_error; } context->cross_compiler.reset(cross_compiler); @@ -448,70 +467,70 @@ shaderc_spvc_status shaderc_spvc_decoration_to_spirv_cross_decoration( shaderc_spvc_status status = shaderc_spvc_status_success; switch (decoration) { - case SHADERC_SPVC_DECORATION_SPECID: + case shaderc_spvc_decoration_specid: *spirv_cross_decoration_ptr = spv::DecorationSpecId; break; - case SHADERC_SPVC_DECORATION_BLOCK: + case shaderc_spvc_decoration_block: *spirv_cross_decoration_ptr = spv::DecorationBlock; break; - case SHADERC_SPVC_DECORATION_ROWMAJOR: + case shaderc_spvc_decoration_rowmajor: *spirv_cross_decoration_ptr = spv::DecorationRowMajor; break; - case SHADERC_SPVC_DECORATION_COLMAJOR: + case shaderc_spvc_decoration_colmajor: *spirv_cross_decoration_ptr = spv::DecorationColMajor; break; - case SHADERC_SPVC_DECORATION_ARRAYSTRIDE: + case shaderc_spvc_decoration_arraystride: *spirv_cross_decoration_ptr = spv::DecorationArrayStride; break; - case SHADERC_SPVC_DECORATION_MATRIXSTRIDE: + case shaderc_spvc_decoration_matrixstride: *spirv_cross_decoration_ptr = spv::DecorationMatrixStride; break; - case SHADERC_SPVC_DECORATION_BUILTIN: + case shaderc_spvc_decoration_builtin: *spirv_cross_decoration_ptr = spv::DecorationBuiltIn; break; - case SHADERC_SPVC_DECORATION_NOPERSPECTIVE: + case shaderc_spvc_decoration_noperspective: *spirv_cross_decoration_ptr = spv::DecorationNoPerspective; break; - case SHADERC_SPVC_DECORATION_FLAT: + case shaderc_spvc_decoration_flat: *spirv_cross_decoration_ptr = spv::DecorationFlat; break; - case SHADERC_SPVC_DECORATION_CENTROID: + case shaderc_spvc_decoration_centroid: *spirv_cross_decoration_ptr = spv::DecorationCentroid; break; - case SHADERC_SPVC_DECORATION_RESTRICT: + case shaderc_spvc_decoration_restrict: *spirv_cross_decoration_ptr = spv::DecorationRestrict; break; - case SHADERC_SPVC_DECORATION_ALIASED: + case shaderc_spvc_decoration_aliased: *spirv_cross_decoration_ptr = spv::DecorationAliased; break; - case SHADERC_SPVC_DECORATION_NONWRITABLE: + case shaderc_spvc_decoration_nonwritable: *spirv_cross_decoration_ptr = spv::DecorationNonWritable; break; - case SHADERC_SPVC_DECORATION_NONREADABLE: + case shaderc_spvc_decoration_nonreadable: *spirv_cross_decoration_ptr = spv::DecorationNonReadable; break; - case SHADERC_SPVC_DECORATION_UNIFORM: + case shaderc_spvc_decoration_uniform: *spirv_cross_decoration_ptr = spv::DecorationUniform; break; - case SHADERC_SPVC_DECORATION_LOCATION: + case shaderc_spvc_decoration_location: *spirv_cross_decoration_ptr = spv::DecorationLocation; break; - case SHADERC_SPVC_DECORATION_COMPONENT: + case shaderc_spvc_decoration_component: *spirv_cross_decoration_ptr = spv::DecorationComponent; break; - case SHADERC_SPVC_DECORATION_INDEX: + case shaderc_spvc_decoration_index: *spirv_cross_decoration_ptr = spv::DecorationIndex; break; - case SHADERC_SPVC_DECORATION_BINDING: + case shaderc_spvc_decoration_binding: *spirv_cross_decoration_ptr = spv::DecorationBinding; break; - case SHADERC_SPVC_DECORATION_DESCRIPTORSET: + case shaderc_spvc_decoration_descriptorset: *spirv_cross_decoration_ptr = spv::DecorationDescriptorSet; break; - case SHADERC_SPVC_DECORATION_OFFSET: + case shaderc_spvc_decoration_offset: *spirv_cross_decoration_ptr = spv::DecorationOffset; break; - case SHADERC_SPVC_DECORATION_NOCONTRACTION: + case shaderc_spvc_decoration_nocontraction: *spirv_cross_decoration_ptr = spv::DecorationNoContraction; break; default: diff --git a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_private.h b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_private.h index 8816f1d17ba..65f1e214855 100644 --- a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_private.h +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_private.h @@ -12,6 +12,9 @@ // 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> @@ -36,7 +39,8 @@ typedef enum { struct shaderc_spvc_context { std::unique_ptr<spirv_cross::Compiler> cross_compiler; - std::string messages; + 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; @@ -150,3 +154,5 @@ shaderc_spvc_status shaderc_spvc_decoration_to_spirv_cross_decoration( spv::Decoration* spirv_cross_decoration); } // namespace spvc_private + +#endif // LIBSHADERC_SPVC_SRC_SPVC_PRIVATE_H_ diff --git a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_smoke_test_util.c b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_smoke_test_util.c index 5f4a7db51df..d5ae27ff837 100644 --- a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_smoke_test_util.c +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_smoke_test_util.c @@ -48,9 +48,10 @@ int test_exec(shaderc_spvc_context_t context, 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( - shaderc_spvc_result_get_string_output(result))), + (unsigned long)(strlen(result_str)), target_lang); ret_val = 1; } else { @@ -96,13 +97,13 @@ int run_smoke_test(const char* shader, int transform_from_webgpu) { int ret_code = 0; shaderc_spvc_context_t context = shaderc_spvc_context_create(); - shaderc_spvc_compile_options_t options = - shaderc_spvc_compile_options_create(); + shaderc_spvc_compile_options_t options; if (transform_from_webgpu) { - shaderc_spvc_compile_options_set_source_env( - options, shaderc_target_env_webgpu, shaderc_env_version_webgpu); - shaderc_spvc_compile_options_set_target_env( - options, shaderc_target_env_vulkan, shaderc_env_version_vulkan_1_1); + 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; diff --git a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_test.cc b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_test.cc index bc61d6960dd..7a572bd079b 100644 --- a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_test.cc +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_test.cc @@ -27,7 +27,8 @@ class CompileTest : public testing::Test { public: void SetUp() override { context_ = shaderc_spvc_context_create(); - options_ = shaderc_spvc_compile_options_create(); + options_ = shaderc_spvc_compile_options_create( + shaderc_spvc_spv_env_vulkan_1_0, shaderc_spvc_spv_env_vulkan_1_0); result_ = shaderc_spvc_result_create(); } diff --git a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_webgpu_cpp_test.cc b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_webgpu_cpp_test.cc index 30a8ac33df1..753493b2a46 100644 --- a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_webgpu_cpp_test.cc +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_webgpu_cpp_test.cc @@ -25,12 +25,9 @@ namespace { class CompileTest : public testing::Test { public: - void SetUp() override { - options_.SetSourceEnvironment(shaderc_target_env_webgpu, - shaderc_env_version_webgpu); - options_.SetTargetEnvironment(shaderc_target_env_vulkan, - shaderc_env_version_vulkan_1_1); - } + CompileTest() + : options_(shaderc_spvc_spv_env_webgpu_0, + shaderc_spvc_spv_env_vulkan_1_1) {} Context context_; CompileOptions options_; @@ -47,8 +44,12 @@ TEST_F(CompileTest, Glsl) { { shaderc_spvc_status status = context_.CompileShader(&result_); EXPECT_EQ(shaderc_spvc_status_success, status); - EXPECT_NE(0, result_.GetStringOutput().size()); - EXPECT_EQ(0, result_.GetBinaryOutput().size()); + 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()); } } @@ -62,8 +63,12 @@ TEST_F(CompileTest, Hlsl) { { shaderc_spvc_status status = context_.CompileShader(&result_); EXPECT_EQ(shaderc_spvc_status_success, status); - EXPECT_NE(0, result_.GetStringOutput().size()); - EXPECT_EQ(0, result_.GetBinaryOutput().size()); + 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()); } } @@ -77,8 +82,12 @@ TEST_F(CompileTest, Msl) { { shaderc_spvc_status status = context_.CompileShader(&result_); EXPECT_EQ(shaderc_spvc_status_success, status); - EXPECT_NE(0, result_.GetStringOutput().size()); - EXPECT_EQ(0, result_.GetBinaryOutput().size()); + 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()); } } @@ -92,8 +101,12 @@ TEST_F(CompileTest, Vulkan) { { shaderc_spvc_status status = context_.CompileShader(&result_); EXPECT_EQ(shaderc_spvc_status_success, status); - EXPECT_EQ(0, result_.GetStringOutput().size()); - EXPECT_NE(0, result_.GetBinaryOutput().size()); + 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()); } } diff --git a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_webgpu_test.cc b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_webgpu_test.cc index 9516d49cacc..cb023ce8e90 100644 --- a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_webgpu_test.cc +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvc_webgpu_test.cc @@ -26,13 +26,9 @@ class CompileTest : public testing::Test { public: void SetUp() override { context_ = shaderc_spvc_context_create(); - options_ = shaderc_spvc_compile_options_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(); - - shaderc_spvc_compile_options_set_source_env( - options_, shaderc_target_env_webgpu, shaderc_env_version_webgpu); - shaderc_spvc_compile_options_set_target_env( - options_, shaderc_target_env_vulkan, shaderc_env_version_vulkan_1_1); } void TearDown() override { diff --git a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvcir_pass.cc b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvcir_pass.cc index 0e66df5fb9d..97f8ef7675a 100644 --- a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvcir_pass.cc +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvcir_pass.cc @@ -231,7 +231,7 @@ void SpvcIrPass::GenerateSpirvCrossIR(Instruction *inst) { case SpvOpExtension: { const std::string extension_name = GetWordsAsString(0u, inst); - ir_->declared_extensions.push_back(std::move(extension_name)); + ir_->declared_extensions.push_back(extension_name); break; } @@ -1264,7 +1264,6 @@ void SpvcIrPass::GenerateSpirvCrossIR(Instruction *inst) { } } offset_ += inst->NumOperandWords() + 1; - return; } } // namespace opt diff --git a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvcir_pass.h b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvcir_pass.h index 4afeadfb802..b3c3a2b6d8e 100644 --- a/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvcir_pass.h +++ b/chromium/third_party/shaderc/src/libshaderc_spvc/src/spvcir_pass.h @@ -12,6 +12,9 @@ // 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> @@ -113,3 +116,5 @@ class SpvcIrPass : public Pass { } // namespace opt } // namespace spvtools + +#endif // LIBSHADERC_SPVC_SRC_SPVCIR_PASS_H_ diff --git a/chromium/third_party/shaderc/src/libshaderc_util/Android.mk b/chromium/third_party/shaderc/src/libshaderc_util/Android.mk index 36e6542befb..81b4c76caea 100644 --- a/chromium/third_party/shaderc/src/libshaderc_util/Android.mk +++ b/chromium/third_party/shaderc/src/libshaderc_util/Android.mk @@ -2,7 +2,7 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE:=shaderc_util -LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -DNV_EXTENSIONS -DENABLE_HLSL=1 +LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -DENABLE_HLSL=1 LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)/include LOCAL_SRC_FILES:=src/args.cc \ src/compiler.cc \ diff --git a/chromium/third_party/shaderc/src/libshaderc_util/include/libshaderc_util/compiler.h b/chromium/third_party/shaderc/src/libshaderc_util/include/libshaderc_util/compiler.h index a41457ebd4a..036fd7ead0c 100644 --- a/chromium/third_party/shaderc/src/libshaderc_util/include/libshaderc_util/compiler.h +++ b/chromium/third_party/shaderc/src/libshaderc_util/include/libshaderc_util/compiler.h @@ -109,6 +109,7 @@ class Compiler { Vulkan, // Default to Vulkan 1.0 OpenGL, // Default to OpenGL 4.5 OpenGLCompat, // Deprecated. + WebGPU, }; // Target environment versions. These numbers match those used by Glslang. @@ -117,6 +118,7 @@ class Compiler { // For Vulkan, use numbering scheme from vulkan.h Vulkan_1_0 = ((1 << 22)), // Vulkan 1.0 Vulkan_1_1 = ((1 << 22) | (1 << 12)), // Vulkan 1.1 + Vulkan_1_2 = ((1 << 22) | (2 << 12)), // Vulkan 1.2 // For OpenGL, use the numbering from #version in shaders. OpenGL_4_5 = 450, }; @@ -181,7 +183,6 @@ class Compiler { Geometry, Fragment, Compute, -#ifdef NV_EXTENSIONS RayGenNV, IntersectNV, AnyHitNV, @@ -190,7 +191,6 @@ class Compiler { CallableNV, TaskNV, MeshNV, -#endif StageEnd, }; enum { kNumStages = int(Stage::StageEnd) }; @@ -204,7 +204,6 @@ class Compiler { Stage::Geometry, Stage::Fragment, Stage::Compute, -#ifdef NV_EXTENSIONS Stage::RayGenNV, Stage::IntersectNV, Stage::AnyHitNV, @@ -213,7 +212,6 @@ class Compiler { Stage::CallableNV, Stage::TaskNV, Stage::MeshNV, -#endif }}; return values; } @@ -587,7 +585,6 @@ inline Compiler::Stage ConvertToStage(EShLanguage stage) { return Compiler::Stage::Fragment; case EShLangCompute: return Compiler::Stage::Compute; -#ifdef NV_EXTENSIONS case EShLangRayGenNV: return Compiler::Stage::RayGenNV; case EShLangIntersectNV: @@ -604,7 +601,6 @@ inline Compiler::Stage ConvertToStage(EShLanguage stage) { return Compiler::Stage::TaskNV; case EShLangMeshNV: return Compiler::Stage::MeshNV; -#endif default: break; } diff --git a/chromium/third_party/shaderc/src/libshaderc_util/include/libshaderc_util/spirv_tools_wrapper.h b/chromium/third_party/shaderc/src/libshaderc_util/include/libshaderc_util/spirv_tools_wrapper.h index 09d84627312..d1083a092d4 100644 --- a/chromium/third_party/shaderc/src/libshaderc_util/include/libshaderc_util/spirv_tools_wrapper.h +++ b/chromium/third_party/shaderc/src/libshaderc_util/include/libshaderc_util/spirv_tools_wrapper.h @@ -46,6 +46,7 @@ enum class PassId { kLegalizationPasses, kPerformancePasses, kSizePasses, + kVulkanToWebGPUPasses, // SPIRV-Tools specific passes kNullPass, diff --git a/chromium/third_party/shaderc/src/libshaderc_util/src/compiler.cc b/chromium/third_party/shaderc/src/libshaderc_util/src/compiler.cc index ec31f08ad7c..d347091c69a 100644 --- a/chromium/third_party/shaderc/src/libshaderc_util/src/compiler.cc +++ b/chromium/third_party/shaderc/src/libshaderc_util/src/compiler.cc @@ -83,6 +83,7 @@ EShMessages GetMessageRules(shaderc_util::Compiler::TargetEnv env, case Compiler::TargetEnv::OpenGL: result = static_cast<EShMessages>(result | EShMsgSpvRules); break; + case Compiler::TargetEnv::WebGPU: case Compiler::TargetEnv::Vulkan: result = static_cast<EShMessages>(result | EShMsgSpvRules | EShMsgVulkanRules); @@ -143,10 +144,18 @@ std::tuple<bool, std::vector<uint32_t>, size_t> Compiler::Compile( std::vector<uint32_t>& compilation_output_data = std::get<1>(result_tuple); size_t& compilation_output_data_size_in_bytes = std::get<2>(result_tuple); + // glslang doesn't currently support WebGPU, so we need to fake it by having + // it generate Vulkan1.1 and then use spirv-opt later to convert to WebGPU. + bool is_webgpu = target_env_ == Compiler::TargetEnv::WebGPU; + TargetEnv internal_target_env = + !is_webgpu ? target_env_ : Compiler::TargetEnv::Vulkan; + TargetEnvVersion internal_target_env_version = + !is_webgpu ? target_env_version_ : Compiler::TargetEnvVersion::Vulkan_1_1; + // Check target environment. const auto target_client_info = GetGlslangClientInfo( - error_tag, target_env_, target_env_version_, target_spirv_version_, - target_spirv_version_is_forced_); + error_tag, internal_target_env, internal_target_env_version, + target_spirv_version_, target_spirv_version_is_forced_); if (!target_client_info.error.empty()) { *error_stream << target_client_info.error; *total_warnings = 0; @@ -248,8 +257,9 @@ std::tuple<bool, std::vector<uint32_t>, size_t> Compiler::Compile( shader.setInvertY(invert_y_enabled_); shader.setNanMinMaxClamp(nan_clamp_); - const EShMessages rules = GetMessageRules( - target_env_, source_language_, hlsl_offsets_, generate_debug_info_); + const EShMessages rules = + GetMessageRules(internal_target_env, source_language_, hlsl_offsets_, + generate_debug_info_); bool success = shader.parse(&limits_, default_version_, default_profile_, force_version_profile_, kNotForwardCompatible, @@ -298,10 +308,15 @@ std::tuple<bool, std::vector<uint32_t>, size_t> Compiler::Compile( opt_passes.insert(opt_passes.end(), enabled_opt_passes_.begin(), enabled_opt_passes_.end()); + // WebGPU goes last, since it is converting the env. + if (is_webgpu) { + opt_passes.push_back(PassId::kVulkanToWebGPUPasses); + } + if (!opt_passes.empty()) { std::string opt_errors; - if (!SpirvToolsOptimize(target_env_, target_env_version_, opt_passes, - &spirv, &opt_errors)) { + if (!SpirvToolsOptimize(internal_target_env, internal_target_env_version, + opt_passes, &spirv, &opt_errors)) { *error_stream << "shaderc: internal error: compilation succeeded but " "failed to optimize: " << opt_errors << "\n"; @@ -311,6 +326,8 @@ std::tuple<bool, std::vector<uint32_t>, size_t> Compiler::Compile( if (output_type == OutputType::SpirvAssemblyText) { std::string text_or_error; + // spirv-tools does know about WebGPU, so don't need to punt to Vulkan1.1 + // here. if (!SpirvToolsDisassemble(target_env_, target_env_version_, spirv, &text_or_error)) { *error_stream << "shaderc: internal error: compilation succeeded but " @@ -408,6 +425,14 @@ void Compiler::SetSuppressWarnings() { suppress_warnings_ = true; } std::tuple<bool, std::string, std::string> Compiler::PreprocessShader( const std::string& error_tag, const string_piece& shader_source, const string_piece& shader_preamble, CountingIncluder& includer) const { + // glslang doesn't currently support WebGPU, so we need to fake it by having + // it generate Vulkan1.1 and then use spirv-opt later to convert to WebGPU. + bool is_webgpu = target_env_ == Compiler::TargetEnv::WebGPU; + TargetEnv internal_target_env = + !is_webgpu ? target_env_ : Compiler::TargetEnv::Vulkan; + TargetEnvVersion internal_target_env_version = + !is_webgpu ? target_env_version_ : Compiler::TargetEnvVersion::Vulkan_1_1; + // The stage does not matter for preprocessing. glslang::TShader shader(EShLangVertex); const char* shader_strings = shader_source.data(); @@ -417,8 +442,8 @@ std::tuple<bool, std::string, std::string> Compiler::PreprocessShader( &string_names, 1); shader.setPreamble(shader_preamble.data()); auto target_client_info = GetGlslangClientInfo( - error_tag, target_env_, target_env_version_, target_spirv_version_, - target_spirv_version_is_forced_); + error_tag, internal_target_env, internal_target_env_version, + target_spirv_version_, target_spirv_version_is_forced_); if (!target_client_info.error.empty()) { return std::make_tuple(false, "", target_client_info.error); } @@ -435,7 +460,8 @@ std::tuple<bool, std::string, std::string> Compiler::PreprocessShader( // flag. const auto rules = static_cast<EShMessages>( EShMsgOnlyPreprocessor | - GetMessageRules(target_env_, source_language_, hlsl_offsets_, false)); + GetMessageRules(internal_target_env, source_language_, hlsl_offsets_, + false)); std::string preprocessed_shader; const bool success = shader.preprocess( @@ -671,6 +697,9 @@ GlslangClientInfo GetGlslangClientInfo( } else if (env_version == Compiler::TargetEnvVersion::Vulkan_1_1) { result.client_version = glslang::EShTargetVulkan_1_1; result.target_language_version = glslang::EShTargetSpv_1_3; + } else if (env_version == Compiler::TargetEnvVersion::Vulkan_1_2) { + result.client_version = glslang::EShTargetVulkan_1_2; + result.target_language_version = glslang::EShTargetSpv_1_5; } else { errs << "error:" << error_tag << ": Invalid target client version " << static_cast<uint32_t>(env_version) << " for Vulkan environment " diff --git a/chromium/third_party/shaderc/src/libshaderc_util/src/compiler_test.cc b/chromium/third_party/shaderc/src/libshaderc_util/src/compiler_test.cc index 8c62cec3b71..3f5ff64dc83 100644 --- a/chromium/third_party/shaderc/src/libshaderc_util/src/compiler_test.cc +++ b/chromium/third_party/shaderc/src/libshaderc_util/src/compiler_test.cc @@ -165,7 +165,7 @@ void main() { o = clamp(i, vec4(0.5), vec4(1.0)); } std::string Disassemble(const std::vector<uint32_t> binary) { std::string result; shaderc_util::SpirvToolsDisassemble(Compiler::TargetEnv::Vulkan, - Compiler::TargetEnvVersion::Vulkan_1_1, + Compiler::TargetEnvVersion::Vulkan_1_2, binary, &result); return result; } diff --git a/chromium/third_party/shaderc/src/libshaderc_util/src/shader_stage.cc b/chromium/third_party/shaderc/src/libshaderc_util/src/shader_stage.cc index e0f875691fd..3122a3d2fa6 100644 --- a/chromium/third_party/shaderc/src/libshaderc_util/src/shader_stage.cc +++ b/chromium/third_party/shaderc/src/libshaderc_util/src/shader_stage.cc @@ -34,7 +34,6 @@ EShLanguage MapStageNameToLanguage(const string_piece& stage_name) { {"tesseval", EShLangTessEvaluation}, {"geometry", EShLangGeometry}, {"compute", EShLangCompute}, -#ifdef NV_EXTENSIONS {"raygen", EShLangRayGenNV}, {"intersect", EShLangIntersectNV}, {"anyhit", EShLangAnyHitNV}, @@ -43,7 +42,6 @@ EShLanguage MapStageNameToLanguage(const string_piece& stage_name) { {"callable", EShLangCallableNV}, {"task", EShLangTaskNV}, {"mesh", EShLangMeshNV}, -#endif }; for (const auto& entry : string_to_stage) { diff --git a/chromium/third_party/shaderc/src/libshaderc_util/src/spirv_tools_wrapper.cc b/chromium/third_party/shaderc/src/libshaderc_util/src/spirv_tools_wrapper.cc index 3aa384b82c6..372f9a295e7 100644 --- a/chromium/third_party/shaderc/src/libshaderc_util/src/spirv_tools_wrapper.cc +++ b/chromium/third_party/shaderc/src/libshaderc_util/src/spirv_tools_wrapper.cc @@ -35,6 +35,8 @@ spv_target_env GetSpirvToolsTargetEnv(Compiler::TargetEnv env, return SPV_ENV_VULKAN_1_0; case Compiler::TargetEnvVersion::Vulkan_1_1: return SPV_ENV_VULKAN_1_1; + case Compiler::TargetEnvVersion::Vulkan_1_2: + return SPV_ENV_VULKAN_1_2; default: break; } @@ -43,6 +45,8 @@ spv_target_env GetSpirvToolsTargetEnv(Compiler::TargetEnv env, return SPV_ENV_OPENGL_4_5; case Compiler::TargetEnv::OpenGLCompat: // Deprecated return SPV_ENV_OPENGL_4_5; + case Compiler::TargetEnv::WebGPU: + return SPV_ENV_WEBGPU_0; } assert(false && "unexpected target environment or version"); return SPV_ENV_VULKAN_1_0; @@ -141,6 +145,9 @@ bool SpirvToolsOptimize(Compiler::TargetEnv env, case PassId::kSizePasses: optimizer.RegisterSizePasses(); break; + case PassId::kVulkanToWebGPUPasses: + optimizer.RegisterVulkanToWebGPUPasses(); + break; case PassId::kNullPass: // We actually don't need to do anything for null pass. break; diff --git a/chromium/third_party/shaderc/src/shaderc_features.gni b/chromium/third_party/shaderc/src/shaderc_features.gni index 332ca15a477..0d2c5fd2d43 100644 --- a/chromium/third_party/shaderc/src/shaderc_features.gni +++ b/chromium/third_party/shaderc/src/shaderc_features.gni @@ -15,4 +15,10 @@ 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/chromium/third_party/shaderc/src/spvc/src/main.cc b/chromium/third_party/shaderc/src/spvc/src/main.cc index 48333f83310..8a31af6d344 100644 --- a/chromium/third_party/shaderc/src/spvc/src/main.cc +++ b/chromium/third_party/shaderc/src/spvc/src/main.cc @@ -120,18 +120,68 @@ bool ReadFile(const std::string& path, std::vector<uint32_t>* out) { return true; } +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; - shaderc_spvc::CompileOptions options; std::vector<uint32_t> input; std::vector<uint32_t> msl_discrete_descriptor; string_piece output_path; string_piece output_language; - string_piece source_env = "vulkan1.0"; - string_piece target_env = ""; + 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") { @@ -258,41 +308,9 @@ int main(int argc, char** argv) { } options.SetHLSLShaderModel(shader_model_num); } else if (arg.starts_with("--source-env=")) { - string_piece env; - shaderc_util::GetOptionArgument(argc, argv, &i, "--source-env=", &env); - source_env = env; - if (env == "vulkan1.0") { - options.SetSourceEnvironment(shaderc_target_env_vulkan, - shaderc_env_version_vulkan_1_0); - } else if (env == "vulkan1.1") { - options.SetSourceEnvironment(shaderc_target_env_vulkan, - shaderc_env_version_vulkan_1_1); - } else if (env == "webgpu0") { - options.SetSourceEnvironment(shaderc_target_env_webgpu, - shaderc_env_version_webgpu); - } else { - std::cerr << "spvc: error: invalid value '" << env - << "' in --source-env=" << std::endl; - return 1; - } + // Parsed in the previous iteration } else if (arg.starts_with("--target-env=")) { - string_piece env; - shaderc_util::GetOptionArgument(argc, argv, &i, "--target-env=", &env); - target_env = env; - if (env == "vulkan1.0") { - options.SetTargetEnvironment(shaderc_target_env_vulkan, - shaderc_env_version_vulkan_1_0); - } else if (env == "vulkan1.1") { - options.SetTargetEnvironment(shaderc_target_env_vulkan, - shaderc_env_version_vulkan_1_1); - } else if (env == "webgpu0") { - options.SetTargetEnvironment(shaderc_target_env_webgpu, - shaderc_env_version_webgpu); - } else { - std::cerr << "spvc: error: invalid value '" << env - << "' in --target-env=" << std::endl; - return 1; - } + // Parsed in the previous iteration } else if (arg == "--use-spvc-parser") { context.SetUseSpvcParser(true); } else { @@ -303,24 +321,6 @@ int main(int argc, char** argv) { } } - if (target_env == "") { - if (source_env == "vulkan1.0") { - options.SetTargetEnvironment(shaderc_target_env_vulkan, - shaderc_env_version_vulkan_1_0); - } else if (source_env == "vulkan1.1") { - options.SetTargetEnvironment(shaderc_target_env_vulkan, - shaderc_env_version_vulkan_1_1); - } else if (source_env == "webgpu0") { - options.SetTargetEnvironment(shaderc_target_env_webgpu, - shaderc_env_version_webgpu); - } else { - // This should be caught above when parsing --source-target= - std::cerr << "spvc: error: invalid value '" << source_env - << "' in --source-env=" << std::endl; - return 1; - } - } - options.SetMSLDiscreteDescriptorSets(msl_discrete_descriptor); shaderc_spvc::CompilationResult result; @@ -356,17 +356,21 @@ int main(int argc, char** argv) { 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) << result.GetStringOutput(); + std::basic_ofstream<char>(path) << string_output; } else { - std::cout << result.GetStringOutput(); + 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*)result.GetBinaryOutput().data(), + out.write((char*)binary_output.data(), (sizeof(uint32_t) / sizeof(char)) * - result.GetBinaryOutput().size()); + binary_output.size()); } else { std::cerr << "Cowardly refusing to output binary result to screen" << std::endl; |