More spirv-cross related removal
Bug: dawn:1036
Change-Id: Ia60c71558bd2c47a6b7148d86b8dcedfaa79ba89
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/61585
Reviewed-by: Stephen White <senorblanco@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp
index cf8a3cc..0941922 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 <spirv-tools/libspirv.hpp>
-#include <spirv-tools/optimizer.hpp>
-
-// 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 <tint/tint.h>
#include <sstream>
@@ -400,50 +393,6 @@
}
}
- 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<uint32_t>(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<tint::Program> ParseWGSL(const tint::Source::File* file,
OwnedCompilationMessages* outMessages) {
std::ostringstream errorStream;
@@ -482,21 +431,6 @@
return std::move(program);
}
- ResultOrError<std::vector<uint32_t>> 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<uint64_t> GetBindGroupMinBufferSizes(
const EntryPointMetadata::BindingGroupInfoMap& shaderBindings,
const BindGroupLayoutBase* layout) {
@@ -653,13 +587,6 @@
}
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 @@
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 @@
}
std::vector<uint32_t> 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<tint::Program>(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<tint::Program>(std::move(program));
} else if (wgslDesc) {
auto tintSource = std::make_unique<TintSource>("", wgslDesc->source);
@@ -1080,17 +1000,8 @@
tint::Program program;
DAWN_TRY_ASSIGN(program, ParseWGSL(&tintSource->file, outMessages));
-
- if (device->IsToggleEnabled(Toggle::UseTintGenerator)) {
- parseResult->tintProgram = std::make_unique<tint::Program>(std::move(program));
- parseResult->tintSource = std::move(tintSource);
- } else {
- std::vector<uint32_t> spirv;
- DAWN_TRY_ASSIGN(spirv, ModuleToSPIRV(&program));
- DAWN_TRY(ValidateSpirv(spirv.data(), spirv.size()));
-
- parseResult->spirv = std::move(spirv);
- }
+ parseResult->tintProgram = std::make_unique<tint::Program>(std::move(program));
+ parseResult->tintSource = std::move(tintSource);
}
return {};
@@ -1269,13 +1180,8 @@
a->mWgsl == b->mWgsl;
}
- const std::vector<uint32_t>& 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 @@
return mCompilationMessages.get();
}
- ResultOrError<std::vector<uint32_t>> ShaderModuleBase::GeneratePullingSpirv(
- const std::vector<uint32_t>& 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<std::vector<uint32_t>> 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<tint::transform::VertexPulling>();
- if (GetDevice()->IsRobustnessEnabled()) {
- transformManager.Add<tint::transform::BoundArrayAccessors>();
- }
-
- 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<uint32_t> 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 83c0a8d..6240cec 100644
--- a/src/dawn_native/ShaderModule.h
+++ b/src/dawn_native/ShaderModule.h
@@ -45,10 +45,6 @@
} // namespace tint
-namespace spirv_cross {
- class Compiler;
-}
-
namespace dawn_native {
struct EntryPointMetadata;
@@ -95,7 +91,6 @@
std::unique_ptr<tint::Program> tintProgram;
std::unique_ptr<TintSource> tintSource;
- std::vector<uint32_t> spirv;
};
MaybeError ValidateShaderModuleDescriptor(DeviceBase* device,
@@ -220,7 +215,6 @@
bool operator()(const ShaderModuleBase* a, const ShaderModuleBase* b) const;
};
- const std::vector<uint32_t>& GetSpirv() const;
const tint::Program* GetTintProgram() const;
void APIGetCompilationInfo(wgpu::CompilationInfoCallback callback, void* userdata);
@@ -230,18 +224,6 @@
OwnedCompilationMessages* GetCompilationMessages() const;
- ResultOrError<std::vector<uint32_t>> GeneratePullingSpirv(
- const std::vector<uint32_t>& spirv,
- const VertexState& vertexState,
- const std::string& entryPoint,
- BindGroupIndex pullingBufferBindingSet) const;
-
- ResultOrError<std::vector<uint32_t>> GeneratePullingSpirv(
- const tint::Program* program,
- const VertexState& vertexState,
- const std::string& entryPoint,
- BindGroupIndex pullingBufferBindingSet) const;
-
protected:
MaybeError InitializeBase(ShaderModuleParseResult* parseResult);
@@ -254,10 +236,7 @@
std::vector<uint32_t> 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<uint32_t> mSpirv;
std::unique_ptr<tint::Program> mTintProgram;
std::unique_ptr<TintSource> mTintSource; // Keep the tint::Source::File alive
diff --git a/src/dawn_native/opengl/ShaderModuleGL.cpp b/src/dawn_native/opengl/ShaderModuleGL.cpp
index 24a9adb..5d9b957 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 <tint/tint.h>
+#include <spirv-tools/libspirv.hpp>
#include <sstream>
diff --git a/src/dawn_native/vulkan/ShaderModuleVk.cpp b/src/dawn_native/vulkan/ShaderModuleVk.cpp
index 5fb97b5..5142951 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 <tint/tint.h>
+#include <spirv-tools/libspirv.hpp>
namespace dawn_native { namespace vulkan {