diff --git a/scripts/dawn_features.gni b/scripts/dawn_features.gni index ac9531c47c..f3be9a9416 100644 --- a/scripts/dawn_features.gni +++ b/scripts/dawn_features.gni @@ -104,5 +104,9 @@ declare_args() { dawn_supports_glfw_for_windowing = (is_win && !dawn_is_winuwp) || (is_linux && !is_chromeos) || is_mac -# Much of the backend code is shared, so define a convenience var. +# Much of the GL backend code is shared, so define a convenience var. dawn_enable_opengl = dawn_enable_opengles || dawn_enable_desktop_gl + +# The GL backends are the last to use SPIRV-Cross, so only compile it in +# if they are enabled. +dawn_use_spirv_cross = dawn_enable_opengl diff --git a/src/common/BUILD.gn b/src/common/BUILD.gn index afaa18f2d5..ebb7018dc1 100644 --- a/src/common/BUILD.gn +++ b/src/common/BUILD.gn @@ -85,6 +85,10 @@ config("dawn_internal") { defines += [ "DAWN_USE_X11" ] } + if (dawn_use_spirv_cross) { + defines += [ "DAWN_USE_SPIRV_CROSS" ] + } + if (dawn_enable_error_injection) { defines += [ "DAWN_ENABLE_ERROR_INJECTION" ] } diff --git a/src/dawn_native/BUILD.gn b/src/dawn_native/BUILD.gn index f73bfe2425..27731a5f84 100644 --- a/src/dawn_native/BUILD.gn +++ b/src/dawn_native/BUILD.gn @@ -145,11 +145,13 @@ source_set("dawn_native_sources") { ":dawn_native_headers", ":dawn_native_utils_gen", "${dawn_root}/src/common", - "${dawn_root}/third_party/gn/spirv_cross:spirv_cross", "${dawn_spirv_tools_dir}:spvtools_opt", "${dawn_spirv_tools_dir}:spvtools_val", "${dawn_tint_dir}/src:libtint", ] + if (dawn_use_spirv_cross) { + deps += [ "${dawn_root}/third_party/gn/spirv_cross:spirv_cross" ] + } defines = [] libs = [] data_deps = [] @@ -282,8 +284,6 @@ source_set("dawn_native_sources") { "Sampler.h", "ShaderModule.cpp", "ShaderModule.h", - "SpirvUtils.cpp", - "SpirvUtils.h", "StagingBuffer.cpp", "StagingBuffer.h", "Subresource.cpp", @@ -313,6 +313,13 @@ source_set("dawn_native_sources") { ] } + if (dawn_use_spirv_cross) { + sources += [ + "SpirvUtils.cpp", + "SpirvUtils.h", + ] + } + # Only win32 app needs to link with user32.lib # In UWP, all availiable APIs are defined in WindowsApp.lib if (is_win && !dawn_is_winuwp) { diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp index 9db81ed822..87af445dbb 100644 --- a/src/dawn_native/ShaderModule.cpp +++ b/src/dawn_native/ShaderModule.cpp @@ -24,12 +24,16 @@ #include "dawn_native/Pipeline.h" #include "dawn_native/PipelineLayout.h" #include "dawn_native/RenderPipeline.h" -#include "dawn_native/SpirvUtils.h" +#if defined(DAWN_USE_SPIRV_CROSS) +# include "dawn_native/SpirvUtils.h" +#endif #include "dawn_native/TintUtils.h" #include #include -#include +#if defined(DAWN_USE_SPIRV_CROSS) +# include +#endif // Tint include must be after spirv_cross.hpp, because spirv-cross has its own // version of spirv_headers. We also need to undef SPV_REVISION because SPIRV-Cross @@ -529,44 +533,6 @@ namespace dawn_native { return requiredBufferSizes; } - ResultOrError> RunRobustBufferAccessPass( - const std::vector& spirv) { - spvtools::Optimizer opt(SPV_ENV_VULKAN_1_1); - - std::ostringstream errorStream; - errorStream << "SPIRV Optimizer failure:" << std::endl; - opt.SetMessageConsumer([&errorStream](spv_message_level_t level, const char*, - const spv_position_t& position, - const char* message) { - switch (level) { - case SPV_MSG_FATAL: - case SPV_MSG_INTERNAL_ERROR: - case SPV_MSG_ERROR: - errorStream << "error: line " << position.index << ": " << message - << std::endl; - break; - case SPV_MSG_WARNING: - errorStream << "warning: line " << position.index << ": " << message - << std::endl; - break; - case SPV_MSG_INFO: - errorStream << "info: line " << position.index << ": " << message - << std::endl; - break; - default: - break; - } - }); - opt.RegisterPass(spvtools::CreateGraphicsRobustAccessPass()); - - std::vector result; - if (!opt.Run(spirv.data(), spirv.size(), &result, spvtools::ValidatorOptions(), - false)) { - return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); - } - return std::move(result); - } - MaybeError ValidateCompatibilityWithBindGroupLayout(DeviceBase* device, BindGroupIndex group, const EntryPointMetadata& entryPoint, @@ -713,6 +679,7 @@ namespace dawn_native { return {}; } +#if defined(DAWN_USE_SPIRV_CROSS) ResultOrError> ExtractSpirvInfo( const DeviceBase* device, const spirv_cross::Compiler& compiler, @@ -956,6 +923,7 @@ namespace dawn_native { return {std::move(metadata)}; } +#endif ResultOrError ReflectShaderUsingTint( DeviceBase*, @@ -1656,21 +1624,11 @@ namespace dawn_native { mTintSource = std::move(parseResult->tintSource); mSpirv = std::move(parseResult->spirv); - if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) { - DAWN_TRY_ASSIGN(mEntryPoints, ReflectShaderUsingTint(GetDevice(), mTintProgram.get())); - } else { - // If not using Tint to generate backend code, run the robust buffer access pass now - // since all backends will use this SPIR-V. If Tint is used, the robustness pass should - // be run per-backend. - if (GetDevice()->IsRobustnessEnabled()) { - DAWN_TRY_ASSIGN(mSpirv, RunRobustBufferAccessPass(mSpirv)); - } - DAWN_TRY_ASSIGN(mEntryPoints, ReflectShaderUsingSPIRVCross(GetDevice(), mSpirv)); - } - + DAWN_TRY_ASSIGN(mEntryPoints, ReflectShaderUsingTint(GetDevice(), mTintProgram.get())); return {}; } +#if defined(DAWN_USE_SPIRV_CROSS) ResultOrError ShaderModuleBase::ReflectShaderUsingSPIRVCross( DeviceBase* device, const std::vector& spirv) { @@ -1688,6 +1646,7 @@ namespace dawn_native { } return std::move(result); } +#endif size_t PipelineLayoutEntryPointPairHashFunc::operator()( const PipelineLayoutEntryPointPair& pair) const { diff --git a/src/dawn_native/ShaderModule.h b/src/dawn_native/ShaderModule.h index c8ad650949..7d92c42b75 100644 --- a/src/dawn_native/ShaderModule.h +++ b/src/dawn_native/ShaderModule.h @@ -240,9 +240,11 @@ namespace dawn_native { protected: MaybeError InitializeBase(ShaderModuleParseResult* parseResult); +#if defined(DAWN_USE_SPIRV_CROSS) static ResultOrError ReflectShaderUsingSPIRVCross( DeviceBase* device, const std::vector& spirv); +#endif private: ShaderModuleBase(DeviceBase* device, ObjectBase::ErrorTag tag); diff --git a/src/dawn_native/SpirvUtils.h b/src/dawn_native/SpirvUtils.h index ff356df837..3719794658 100644 --- a/src/dawn_native/SpirvUtils.h +++ b/src/dawn_native/SpirvUtils.h @@ -18,6 +18,10 @@ #ifndef DAWNNATIVE_SPIRV_UTILS_H_ #define DAWNNATIVE_SPIRV_UTILS_H_ +#if !defined(DAWN_USE_SPIRV_CROSS) +# error "SpirvCross.h should not be included if dawn_use_spirv_cross is false" +#endif + #include "dawn_native/Format.h" #include "dawn_native/PerStage.h" #include "dawn_native/VertexFormat.h" diff --git a/src/dawn_native/null/DeviceNull.cpp b/src/dawn_native/null/DeviceNull.cpp index 06945e40c7..6baad31e6a 100644 --- a/src/dawn_native/null/DeviceNull.cpp +++ b/src/dawn_native/null/DeviceNull.cpp @@ -20,8 +20,6 @@ #include "dawn_native/Instance.h" #include "dawn_native/Surface.h" -#include - namespace dawn_native { namespace null { // Implementation of pre-Device objects: the null adapter, null backend connection and Connect()