diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp index cf8a3ccf04..0941922823 100644 --- a/src/dawn_native/ShaderModule.cpp +++ b/src/dawn_native/ShaderModule.cpp @@ -26,13 +26,6 @@ #include "dawn_native/RenderPipeline.h" #include "dawn_native/TintUtils.h" -#include -#include - -// 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 -// is at 3 while spirv-headers is at 4. -#undef SPV_REVISION #include #include @@ -400,50 +393,6 @@ namespace dawn_native { } } - MaybeError ValidateSpirv(const uint32_t* code, uint32_t codeSize) { - spvtools::SpirvTools spirvTools(SPV_ENV_VULKAN_1_1); - - std::ostringstream errorStream; - errorStream << "SPIRV Validation failure:" << std::endl; - - spirvTools.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; - } - }); - - if (!spirvTools.Validate(code, codeSize)) { - std::string disassembly; - if (spirvTools.Disassemble(std::vector(code, code + codeSize), - &disassembly, - SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES | - SPV_BINARY_TO_TEXT_OPTION_INDENT)) { - errorStream << "disassembly:" << std::endl << disassembly; - } - - return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); - } - - return {}; - } - ResultOrError ParseWGSL(const tint::Source::File* file, OwnedCompilationMessages* outMessages) { std::ostringstream errorStream; @@ -482,21 +431,6 @@ namespace dawn_native { return std::move(program); } - ResultOrError> ModuleToSPIRV(const tint::Program* program) { - std::ostringstream errorStream; - errorStream << "Tint SPIR-V writer failure:" << std::endl; - - tint::writer::spirv::Options options; - options.emit_vertex_point_size = true; - auto result = tint::writer::spirv::Generate(program, options); - if (!result.success) { - errorStream << "Generator: " << result.error << std::endl; - return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); - } - - return std::move(result.spirv); - } - std::vector GetBindGroupMinBufferSizes( const EntryPointMetadata::BindingGroupInfoMap& shaderBindings, const BindGroupLayoutBase* layout) { @@ -653,13 +587,6 @@ namespace dawn_native { } case BindingInfoType::Sampler: - // Allow mismatched samplers when using SPIRV-Cross since we can't reflect - // data that's precise enough. - // TODO(dawn:571): Remove once we use Tint unconditionnally for reflection. - if (!device->IsToggleEnabled(Toggle::UseTintGenerator)) { - break; - } - if ((layoutInfo.sampler.type == wgpu::SamplerBindingType::Comparison) != shaderInfo.sampler.isComparison) { return DAWN_VALIDATION_ERROR( @@ -993,7 +920,7 @@ namespace dawn_native { default; bool ShaderModuleParseResult::HasParsedShader() const { - return tintProgram != nullptr || spirv.size() > 0; + return tintProgram != nullptr; } // TintSource is a PIMPL container for a tint::Source::File, which needs to be kept alive for as @@ -1059,16 +986,9 @@ namespace dawn_native { } std::vector spirv(spirvDesc->code, spirvDesc->code + spirvDesc->codeSize); - if (device->IsToggleEnabled(Toggle::UseTintGenerator)) { - tint::Program program; - DAWN_TRY_ASSIGN(program, ParseSPIRV(spirv, outMessages)); - parseResult->tintProgram = std::make_unique(std::move(program)); - } else { - if (device->IsValidationEnabled()) { - DAWN_TRY(ValidateSpirv(spirv.data(), spirv.size())); - } - parseResult->spirv = std::move(spirv); - } + tint::Program program; + DAWN_TRY_ASSIGN(program, ParseSPIRV(spirv, outMessages)); + parseResult->tintProgram = std::make_unique(std::move(program)); } else if (wgslDesc) { auto tintSource = std::make_unique("", wgslDesc->source); @@ -1080,17 +1000,8 @@ namespace dawn_native { tint::Program program; DAWN_TRY_ASSIGN(program, ParseWGSL(&tintSource->file, outMessages)); - - if (device->IsToggleEnabled(Toggle::UseTintGenerator)) { - parseResult->tintProgram = std::make_unique(std::move(program)); - parseResult->tintSource = std::move(tintSource); - } else { - std::vector spirv; - DAWN_TRY_ASSIGN(spirv, ModuleToSPIRV(&program)); - DAWN_TRY(ValidateSpirv(spirv.data(), spirv.size())); - - parseResult->spirv = std::move(spirv); - } + parseResult->tintProgram = std::make_unique(std::move(program)); + parseResult->tintSource = std::move(tintSource); } return {}; @@ -1269,13 +1180,8 @@ namespace dawn_native { a->mWgsl == b->mWgsl; } - const std::vector& ShaderModuleBase::GetSpirv() const { - ASSERT(!GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)); - return mSpirv; - } - const tint::Program* ShaderModuleBase::GetTintProgram() const { - ASSERT(GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)); + ASSERT(mTintProgram); return mTintProgram.get(); } @@ -1325,60 +1231,9 @@ namespace dawn_native { return mCompilationMessages.get(); } - ResultOrError> ShaderModuleBase::GeneratePullingSpirv( - const std::vector& spirv, - const VertexState& vertexState, - const std::string& entryPoint, - BindGroupIndex pullingBufferBindingSet) const { - tint::Program program; - DAWN_TRY_ASSIGN(program, ParseSPIRV(spirv, nullptr)); - - return GeneratePullingSpirv(&program, vertexState, entryPoint, pullingBufferBindingSet); - } - - ResultOrError> ShaderModuleBase::GeneratePullingSpirv( - const tint::Program* programIn, - const VertexState& vertexState, - const std::string& entryPoint, - BindGroupIndex pullingBufferBindingSet) const { - std::ostringstream errorStream; - errorStream << "Tint vertex pulling failure:" << std::endl; - - tint::transform::Manager transformManager; - transformManager.Add(); - if (GetDevice()->IsRobustnessEnabled()) { - transformManager.Add(); - } - - tint::transform::DataMap transformInputs; - - AddVertexPullingTransformConfig(vertexState, entryPoint, pullingBufferBindingSet, - &transformInputs); - - // A nullptr is passed in for the CompilationMessages here since this method is called - // during RenderPipeline creation, by which point the shader module's CompilationInfo - // may have already been queried. - tint::Program program; - DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, programIn, transformInputs, - nullptr, nullptr)); - - tint::writer::spirv::Options options; - options.emit_vertex_point_size = true; - auto result = tint::writer::spirv::Generate(&program, options); - if (!result.success) { - errorStream << "Generator: " << result.error << std::endl; - return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); - } - - std::vector spirv = std::move(result.spirv); - DAWN_TRY(ValidateSpirv(spirv.data(), spirv.size())); - return std::move(spirv); - } - MaybeError ShaderModuleBase::InitializeBase(ShaderModuleParseResult* parseResult) { mTintProgram = std::move(parseResult->tintProgram); mTintSource = std::move(parseResult->tintSource); - mSpirv = std::move(parseResult->spirv); DAWN_TRY_ASSIGN(mEntryPoints, ReflectShaderUsingTint(GetDevice(), mTintProgram.get())); return {}; diff --git a/src/dawn_native/ShaderModule.h b/src/dawn_native/ShaderModule.h index 83c0a8d732..6240cecd08 100644 --- a/src/dawn_native/ShaderModule.h +++ b/src/dawn_native/ShaderModule.h @@ -45,10 +45,6 @@ namespace tint { } // namespace tint -namespace spirv_cross { - class Compiler; -} - namespace dawn_native { struct EntryPointMetadata; @@ -95,7 +91,6 @@ namespace dawn_native { std::unique_ptr tintProgram; std::unique_ptr tintSource; - std::vector spirv; }; MaybeError ValidateShaderModuleDescriptor(DeviceBase* device, @@ -220,7 +215,6 @@ namespace dawn_native { bool operator()(const ShaderModuleBase* a, const ShaderModuleBase* b) const; }; - const std::vector& GetSpirv() const; const tint::Program* GetTintProgram() const; void APIGetCompilationInfo(wgpu::CompilationInfoCallback callback, void* userdata); @@ -230,18 +224,6 @@ namespace dawn_native { OwnedCompilationMessages* GetCompilationMessages() const; - ResultOrError> GeneratePullingSpirv( - const std::vector& spirv, - const VertexState& vertexState, - const std::string& entryPoint, - BindGroupIndex pullingBufferBindingSet) const; - - ResultOrError> GeneratePullingSpirv( - const tint::Program* program, - const VertexState& vertexState, - const std::string& entryPoint, - BindGroupIndex pullingBufferBindingSet) const; - protected: MaybeError InitializeBase(ShaderModuleParseResult* parseResult); @@ -254,10 +236,7 @@ namespace dawn_native { std::vector mOriginalSpirv; std::string mWgsl; - // Data computed from what is in the descriptor. mSpirv is set iff !UseTintGenerator while - // mTintProgram is set iff UseTintGenerator. EntryPointMetadataTable mEntryPoints; - std::vector mSpirv; std::unique_ptr mTintProgram; std::unique_ptr mTintSource; // Keep the tint::Source::File alive diff --git a/src/dawn_native/opengl/ShaderModuleGL.cpp b/src/dawn_native/opengl/ShaderModuleGL.cpp index 24a9adbcb3..5d9b9578fb 100644 --- a/src/dawn_native/opengl/ShaderModuleGL.cpp +++ b/src/dawn_native/opengl/ShaderModuleGL.cpp @@ -29,6 +29,7 @@ // is at 3 while spirv-headers is at 4. #undef SPV_REVISION #include +#include #include diff --git a/src/dawn_native/vulkan/ShaderModuleVk.cpp b/src/dawn_native/vulkan/ShaderModuleVk.cpp index 5fb97b531f..51429516cb 100644 --- a/src/dawn_native/vulkan/ShaderModuleVk.cpp +++ b/src/dawn_native/vulkan/ShaderModuleVk.cpp @@ -22,6 +22,7 @@ #include "dawn_native/vulkan/VulkanError.h" #include +#include namespace dawn_native { namespace vulkan {