Migrate from tint::ast::Module to tint::Program

Depends on: https://dawn-review.googlesource.com/c/tint/+/38556

Bug: tint:390
Change-Id: I12104d80370ddc1a3277770ca051cbd0992b758e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/38522
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2021-01-26 12:24:48 +00:00 committed by Commit Bot service account
parent b3177d418e
commit e0feccacaf
9 changed files with 102 additions and 100 deletions

View File

@ -179,7 +179,7 @@ namespace dawn_native {
} }
#ifdef DAWN_ENABLE_WGSL #ifdef DAWN_ENABLE_WGSL
ResultOrError<tint::ast::Module> ParseWGSL(const tint::Source::File* file) { ResultOrError<tint::Program> ParseWGSL(const tint::Source::File* file) {
std::ostringstream errorStream; std::ostringstream errorStream;
errorStream << "Tint WGSL reader failure:" << std::endl; errorStream << "Tint WGSL reader failure:" << std::endl;
@ -192,22 +192,23 @@ namespace dawn_native {
return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
} }
tint::ast::Module module = parser.module(); tint::Program program = parser.program();
if (!module.IsValid()) { if (!program.IsValid()) {
errorStream << "Invalid module generated..." << std::endl; errorStream << "Invalid program generated..." << std::endl;
return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
} }
tint::TypeDeterminer typeDeterminer(&module); tint::diag::List diagnostics = tint::TypeDeterminer::Run(&program);
if (!typeDeterminer.Determine()) { if (diagnostics.contains_errors()) {
errorStream << "Type Determination: " << typeDeterminer.error(); std::string err = tint::diag::Formatter{}.format(diagnostics);
errorStream << "Type Determination: " << err;
return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
} }
return std::move(module); return std::move(program);
} }
ResultOrError<tint::ast::Module> ParseSPIRV(const std::vector<uint32_t>& spirv) { ResultOrError<tint::Program> ParseSPIRV(const std::vector<uint32_t>& spirv) {
std::ostringstream errorStream; std::ostringstream errorStream;
errorStream << "Tint SPIRV reader failure:" << std::endl; errorStream << "Tint SPIRV reader failure:" << std::endl;
@ -217,27 +218,28 @@ namespace dawn_native {
return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
} }
tint::ast::Module module = parser.module(); tint::Program program = parser.program();
if (!module.IsValid()) { if (!program.IsValid()) {
errorStream << "Invalid module generated..." << std::endl; errorStream << "Invalid program generated..." << std::endl;
return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
} }
tint::TypeDeterminer typeDeterminer(&module); tint::diag::List diagnostics = tint::TypeDeterminer::Run(&program);
if (!typeDeterminer.Determine()) { if (diagnostics.contains_errors()) {
errorStream << "Type Determination: " << typeDeterminer.error(); std::string err = tint::diag::Formatter{}.format(diagnostics);
errorStream << "Type Determination: " << err;
return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
} }
return std::move(module); return std::move(program);
} }
MaybeError ValidateModule(tint::ast::Module* module) { MaybeError ValidateModule(tint::Program* program) {
std::ostringstream errorStream; std::ostringstream errorStream;
errorStream << "Tint module validation" << std::endl; errorStream << "Tint program validation" << std::endl;
tint::Validator validator; tint::Validator validator;
if (!validator.Validate(module)) { if (!validator.Validate(program)) {
auto err = tint::diag::Formatter{}.format(validator.diagnostics()); auto err = tint::diag::Formatter{}.format(validator.diagnostics());
errorStream << "Validation: " << err << std::endl; errorStream << "Validation: " << err << std::endl;
return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
@ -246,11 +248,11 @@ namespace dawn_native {
return {}; return {};
} }
ResultOrError<std::vector<uint32_t>> ModuleToSPIRV(tint::ast::Module module) { ResultOrError<std::vector<uint32_t>> ModuleToSPIRV(tint::Program program) {
std::ostringstream errorStream; std::ostringstream errorStream;
errorStream << "Tint SPIR-V writer failure:" << std::endl; errorStream << "Tint SPIR-V writer failure:" << std::endl;
tint::writer::spirv::Generator generator(std::move(module)); tint::writer::spirv::Generator generator(&program);
if (!generator.Generate()) { if (!generator.Generate()) {
errorStream << "Generator: " << generator.error() << std::endl; errorStream << "Generator: " << generator.error() << std::endl;
return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
@ -691,14 +693,14 @@ namespace dawn_native {
// PopulateMetadataUsingSPIRVCross will be removed. // PopulateMetadataUsingSPIRVCross will be removed.
ResultOrError<EntryPointMetadataTable> ReflectShaderUsingTint( ResultOrError<EntryPointMetadataTable> ReflectShaderUsingTint(
DeviceBase*, DeviceBase*,
const tint::ast::Module& module) { const tint::Program& program) {
ASSERT(module.IsValid()); ASSERT(program.IsValid());
EntryPointMetadataTable result; EntryPointMetadataTable result;
std::ostringstream errorStream; std::ostringstream errorStream;
errorStream << "Tint Reflection failure:" << std::endl; errorStream << "Tint Reflection failure:" << std::endl;
tint::inspector::Inspector inspector(module); tint::inspector::Inspector inspector(&program);
auto entryPoints = inspector.GetEntryPoints(); auto entryPoints = inspector.GetEntryPoints();
if (inspector.has_error()) { if (inspector.has_error()) {
errorStream << "Inspector: " << inspector.error() << std::endl; errorStream << "Inspector: " << inspector.error() << std::endl;
@ -857,12 +859,12 @@ namespace dawn_native {
std::vector<uint32_t> spirv(spirvDesc->code, spirvDesc->code + spirvDesc->codeSize); std::vector<uint32_t> spirv(spirvDesc->code, spirvDesc->code + spirvDesc->codeSize);
if (device->IsToggleEnabled(Toggle::UseTintGenerator)) { if (device->IsToggleEnabled(Toggle::UseTintGenerator)) {
#ifdef DAWN_ENABLE_WGSL #ifdef DAWN_ENABLE_WGSL
tint::ast::Module module; tint::Program program;
DAWN_TRY_ASSIGN(module, ParseSPIRV(spirv)); DAWN_TRY_ASSIGN(program, ParseSPIRV(spirv));
if (device->IsValidationEnabled()) { if (device->IsValidationEnabled()) {
DAWN_TRY(ValidateModule(&module)); DAWN_TRY(ValidateModule(&program));
} }
parseResult.tintModule = std::make_unique<tint::ast::Module>(std::move(module)); parseResult.tintProgram = std::make_unique<tint::Program>(std::move(program));
#else #else
return DAWN_VALIDATION_ERROR("Using Tint is not enabled in this build."); return DAWN_VALIDATION_ERROR("Using Tint is not enabled in this build.");
#endif // DAWN_ENABLE_WGSL #endif // DAWN_ENABLE_WGSL
@ -883,37 +885,37 @@ namespace dawn_native {
tint::Source::File file("", wgslDesc->source); tint::Source::File file("", wgslDesc->source);
if (device->IsToggleEnabled(Toggle::UseTintGenerator)) { if (device->IsToggleEnabled(Toggle::UseTintGenerator)) {
tint::ast::Module module; tint::Program program;
DAWN_TRY_ASSIGN(module, ParseWGSL(&file)); DAWN_TRY_ASSIGN(program, ParseWGSL(&file));
if (device->IsValidationEnabled()) { if (device->IsValidationEnabled()) {
DAWN_TRY(ValidateModule(&module)); DAWN_TRY(ValidateModule(&program));
} }
parseResult.tintModule = std::make_unique<tint::ast::Module>(std::move(module)); parseResult.tintProgram = std::make_unique<tint::Program>(std::move(program));
} else { } else {
tint::ast::Module module; tint::Program program;
DAWN_TRY_ASSIGN(module, ParseWGSL(&file)); DAWN_TRY_ASSIGN(program, ParseWGSL(&file));
{ {
tint::transform::Manager transformManager; tint::transform::Manager transformManager;
transformManager.append( transformManager.append(
std::make_unique<tint::transform::EmitVertexPointSize>()); std::make_unique<tint::transform::EmitVertexPointSize>());
DAWN_TRY_ASSIGN(module, RunTransforms(&transformManager, &module)); DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, &program));
} }
if (device->IsValidationEnabled()) { if (device->IsValidationEnabled()) {
DAWN_TRY(ValidateModule(&module)); DAWN_TRY(ValidateModule(&program));
} }
// Keep the Tint module around. The Metal backend will use it for vertex // Keep the Tint program around. The Metal backend will use it for vertex
// pulling since we can't go WGSL->point size transform->spirv->Tint. // pulling since we can't go WGSL->point size transform->spirv->Tint.
// Tint's spirv reader doesn't understand point size. crbug.com/tint/412. // Tint's spirv reader doesn't understand point size. crbug.com/tint/412.
auto tintModule = std::make_unique<tint::ast::Module>(module.Clone()); auto tintProgram = std::make_unique<tint::Program>(program.Clone());
std::vector<uint32_t> spirv; std::vector<uint32_t> spirv;
DAWN_TRY_ASSIGN(spirv, ModuleToSPIRV(std::move(module))); DAWN_TRY_ASSIGN(spirv, ModuleToSPIRV(std::move(program)));
DAWN_TRY(ValidateSpirv(spirv.data(), spirv.size())); DAWN_TRY(ValidateSpirv(spirv.data(), spirv.size()));
parseResult.tintModule = std::move(tintModule); parseResult.tintProgram = std::move(tintProgram);
parseResult.spirv = std::move(spirv); parseResult.spirv = std::move(spirv);
} }
break; break;
@ -940,19 +942,19 @@ namespace dawn_native {
} }
#ifdef DAWN_ENABLE_WGSL #ifdef DAWN_ENABLE_WGSL
ResultOrError<tint::ast::Module> RunTransforms(tint::transform::Manager* manager, ResultOrError<tint::Program> RunTransforms(tint::transform::Manager* manager,
tint::ast::Module* module) { tint::Program* program) {
tint::transform::Transform::Output output = manager->Run(module); tint::transform::Transform::Output output = manager->Run(program);
if (output.diagnostics.contains_errors()) { if (output.diagnostics.contains_errors()) {
std::string err = std::string err =
"Tint transform failure: " + tint::diag::Formatter{}.format(output.diagnostics); "Tint transform failure: " + tint::diag::Formatter{}.format(output.diagnostics);
return DAWN_VALIDATION_ERROR(err.c_str()); return DAWN_VALIDATION_ERROR(err.c_str());
} }
if (!output.module.IsValid()) { if (!output.program.IsValid()) {
return DAWN_VALIDATION_ERROR("Tint transform did not produce valid module."); return DAWN_VALIDATION_ERROR("Tint transform did not produce valid program.");
} }
return std::move(output.module); return std::move(output.program);
} }
std::unique_ptr<tint::transform::VertexPulling> MakeVertexPullingTransform( std::unique_ptr<tint::transform::VertexPulling> MakeVertexPullingTransform(
@ -1080,14 +1082,14 @@ namespace dawn_native {
const VertexStateDescriptor& vertexState, const VertexStateDescriptor& vertexState,
const std::string& entryPoint, const std::string& entryPoint,
BindGroupIndex pullingBufferBindingSet) const { BindGroupIndex pullingBufferBindingSet) const {
tint::ast::Module module; tint::Program program;
DAWN_TRY_ASSIGN(module, ParseSPIRV(spirv)); DAWN_TRY_ASSIGN(program, ParseSPIRV(spirv));
return GeneratePullingSpirv(&module, vertexState, entryPoint, pullingBufferBindingSet); return GeneratePullingSpirv(&program, vertexState, entryPoint, pullingBufferBindingSet);
} }
ResultOrError<std::vector<uint32_t>> ShaderModuleBase::GeneratePullingSpirv( ResultOrError<std::vector<uint32_t>> ShaderModuleBase::GeneratePullingSpirv(
tint::ast::Module* moduleIn, tint::Program* programIn,
const VertexStateDescriptor& vertexState, const VertexStateDescriptor& vertexState,
const std::string& entryPoint, const std::string& entryPoint,
BindGroupIndex pullingBufferBindingSet) const { BindGroupIndex pullingBufferBindingSet) const {
@ -1104,10 +1106,10 @@ namespace dawn_native {
// transformManager.append(std::make_unique<tint::transform::BoundArrayAccessors>()); // transformManager.append(std::make_unique<tint::transform::BoundArrayAccessors>());
} }
tint::ast::Module module; tint::Program program;
DAWN_TRY_ASSIGN(module, RunTransforms(&transformManager, moduleIn)); DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, programIn));
tint::writer::spirv::Generator generator(std::move(module)); tint::writer::spirv::Generator generator(&program);
if (!generator.Generate()) { if (!generator.Generate()) {
errorStream << "Generator: " << generator.error() << std::endl; errorStream << "Generator: " << generator.error() << std::endl;
return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
@ -1124,7 +1126,7 @@ namespace dawn_native {
MaybeError ShaderModuleBase::InitializeBase(ShaderModuleParseResult* parseResult) { MaybeError ShaderModuleBase::InitializeBase(ShaderModuleParseResult* parseResult) {
#ifdef DAWN_ENABLE_WGSL #ifdef DAWN_ENABLE_WGSL
tint::ast::Module* module = parseResult->tintModule.get(); tint::Program* program = parseResult->tintProgram.get();
#endif #endif
mSpirv = std::move(parseResult->spirv); mSpirv = std::move(parseResult->spirv);
@ -1142,13 +1144,15 @@ namespace dawn_native {
std::vector<uint32_t> localSpirv; std::vector<uint32_t> localSpirv;
if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) { if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) {
#ifdef DAWN_ENABLE_WGSL #ifdef DAWN_ENABLE_WGSL
ASSERT(module != nullptr); ASSERT(program != nullptr);
tint::ast::Module clonedModule = module->Clone(); tint::Program clonedProgram = program->Clone();
tint::TypeDeterminer typeDeterminer(&clonedModule);
if (!typeDeterminer.Determine()) { tint::diag::List diagnostics = tint::TypeDeterminer::Run(&clonedProgram);
return DAWN_VALIDATION_ERROR(typeDeterminer.error().c_str()); if (diagnostics.contains_errors()) {
std::string err = tint::diag::Formatter{}.format(diagnostics);
return DAWN_VALIDATION_ERROR(err.c_str());
} }
DAWN_TRY_ASSIGN(localSpirv, ModuleToSPIRV(std::move(clonedModule))); DAWN_TRY_ASSIGN(localSpirv, ModuleToSPIRV(std::move(clonedProgram)));
DAWN_TRY(ValidateSpirv(localSpirv.data(), localSpirv.size())); DAWN_TRY(ValidateSpirv(localSpirv.data(), localSpirv.size()));
spirvPtr = &localSpirv; spirvPtr = &localSpirv;
#else #else
@ -1158,18 +1162,18 @@ namespace dawn_native {
if (GetDevice()->IsToggleEnabled(Toggle::UseTintInspector)) { if (GetDevice()->IsToggleEnabled(Toggle::UseTintInspector)) {
#ifdef DAWN_ENABLE_WGSL #ifdef DAWN_ENABLE_WGSL
tint::ast::Module localModule; tint::Program localProgram;
tint::ast::Module* modulePtr = module; tint::Program* programPtr = program;
if (!GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) { if (!GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) {
// We have mSpirv, but no Tint module // We have mSpirv, but no Tint program
DAWN_TRY_ASSIGN(localModule, ParseSPIRV(mSpirv)); DAWN_TRY_ASSIGN(localProgram, ParseSPIRV(mSpirv));
DAWN_TRY(ValidateModule(&localModule)); DAWN_TRY(ValidateModule(&localProgram));
modulePtr = &localModule; programPtr = &localProgram;
} }
EntryPointMetadataTable table; EntryPointMetadataTable table;
DAWN_TRY_ASSIGN(table, ReflectShaderUsingTint(GetDevice(), *modulePtr)); DAWN_TRY_ASSIGN(table, ReflectShaderUsingTint(GetDevice(), *programPtr));
DAWN_TRY(PopulateMetadataUsingSPIRVCross(GetDevice(), *spirvPtr, &table)); DAWN_TRY(PopulateMetadataUsingSPIRVCross(GetDevice(), *spirvPtr, &table));
mEntryPoints = std::move(table); mEntryPoints = std::move(table);
#else #else

View File

@ -33,9 +33,7 @@
namespace tint { namespace tint {
namespace ast { class Program;
class Module;
} // namespace ast
namespace transform { namespace transform {
class Manager; class Manager;
@ -63,7 +61,7 @@ namespace dawn_native {
ShaderModuleParseResult& operator=(ShaderModuleParseResult&& rhs); ShaderModuleParseResult& operator=(ShaderModuleParseResult&& rhs);
#ifdef DAWN_ENABLE_WGSL #ifdef DAWN_ENABLE_WGSL
std::unique_ptr<tint::ast::Module> tintModule; std::unique_ptr<tint::Program> tintProgram;
#endif #endif
std::vector<uint32_t> spirv; std::vector<uint32_t> spirv;
}; };
@ -78,8 +76,8 @@ namespace dawn_native {
RequiredBufferSizes ComputeRequiredBufferSizesForLayout(const EntryPointMetadata& entryPoint, RequiredBufferSizes ComputeRequiredBufferSizesForLayout(const EntryPointMetadata& entryPoint,
const PipelineLayoutBase* layout); const PipelineLayoutBase* layout);
#ifdef DAWN_ENABLE_WGSL #ifdef DAWN_ENABLE_WGSL
ResultOrError<tint::ast::Module> RunTransforms(tint::transform::Manager* manager, ResultOrError<tint::Program> RunTransforms(tint::transform::Manager* manager,
tint::ast::Module* module); tint::Program* program);
std::unique_ptr<tint::transform::VertexPulling> MakeVertexPullingTransform( std::unique_ptr<tint::transform::VertexPulling> MakeVertexPullingTransform(
const VertexStateDescriptor& vertexState, const VertexStateDescriptor& vertexState,
@ -88,7 +86,7 @@ namespace dawn_native {
#endif #endif
// Contains all the reflection data for a valid (ShaderModule, entryPoint, stage). They are // Contains all the reflection data for a valid (ShaderModule, entryPoint, stage). They are
// stored in the ShaderModuleBase and destroyed only when the shader module is destroyed so // stored in the ShaderModuleBase and destroyed only when the shader program is destroyed so
// pointers to EntryPointMetadata are safe to store as long as you also keep a Ref to the // pointers to EntryPointMetadata are safe to store as long as you also keep a Ref to the
// ShaderModuleBase. // ShaderModuleBase.
struct EntryPointMetadata { struct EntryPointMetadata {
@ -132,7 +130,7 @@ namespace dawn_native {
static ShaderModuleBase* MakeError(DeviceBase* device); static ShaderModuleBase* MakeError(DeviceBase* device);
// Return true iff the module has an entrypoint called `entryPoint`. // Return true iff the program has an entrypoint called `entryPoint`.
bool HasEntryPoint(const std::string& entryPoint) const; bool HasEntryPoint(const std::string& entryPoint) const;
// Returns the metadata for the given `entryPoint`. HasEntryPoint with the same argument // Returns the metadata for the given `entryPoint`. HasEntryPoint with the same argument
@ -156,7 +154,7 @@ namespace dawn_native {
BindGroupIndex pullingBufferBindingSet) const; BindGroupIndex pullingBufferBindingSet) const;
ResultOrError<std::vector<uint32_t>> GeneratePullingSpirv( ResultOrError<std::vector<uint32_t>> GeneratePullingSpirv(
tint::ast::Module* module, tint::Program* program,
const VertexStateDescriptor& vertexState, const VertexStateDescriptor& vertexState,
const std::string& entryPoint, const std::string& entryPoint,
BindGroupIndex pullingBufferBindingSet) const; BindGroupIndex pullingBufferBindingSet) const;

View File

@ -188,7 +188,7 @@ namespace dawn_native { namespace d3d12 {
MaybeError ShaderModule::Initialize(ShaderModuleParseResult* parseResult) { MaybeError ShaderModule::Initialize(ShaderModuleParseResult* parseResult) {
DAWN_TRY(InitializeBase(parseResult)); DAWN_TRY(InitializeBase(parseResult));
#ifdef DAWN_ENABLE_WGSL #ifdef DAWN_ENABLE_WGSL
mTintModule = std::move(parseResult->tintModule); mTintProgram = std::move(parseResult->tintProgram);
#endif #endif
return {}; return {};
} }
@ -217,8 +217,8 @@ namespace dawn_native { namespace d3d12 {
transformManager.append(std::move(transformer)); transformManager.append(std::move(transformer));
} }
tint::ast::Module module; tint::Program program;
DAWN_TRY_ASSIGN(module, RunTransforms(&transformManager, mTintModule.get())); DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, mTintProgram.get()));
if (firstOffsetTransform != nullptr) { if (firstOffsetTransform != nullptr) {
// Functions are only available after transform has been performed // Functions are only available after transform has been performed
@ -235,10 +235,10 @@ namespace dawn_native { namespace d3d12 {
} }
ASSERT(remappedEntryPointName != nullptr); ASSERT(remappedEntryPointName != nullptr);
tint::inspector::Inspector inspector(module); tint::inspector::Inspector inspector(&program);
*remappedEntryPointName = inspector.GetRemappedNameForEntryPoint(entryPointName); *remappedEntryPointName = inspector.GetRemappedNameForEntryPoint(entryPointName);
tint::writer::hlsl::Generator generator(std::move(module)); tint::writer::hlsl::Generator generator(&program);
// TODO: Switch to GenerateEntryPoint once HLSL writer supports it. // TODO: Switch to GenerateEntryPoint once HLSL writer supports it.
if (!generator.Generate()) { if (!generator.Generate()) {
errorStream << "Generator: " << generator.error() << std::endl; errorStream << "Generator: " << generator.error() << std::endl;

View File

@ -78,7 +78,7 @@ namespace dawn_native { namespace d3d12 {
uint64_t GetD3DCompilerVersion() const; uint64_t GetD3DCompilerVersion() const;
#ifdef DAWN_ENABLE_WGSL #ifdef DAWN_ENABLE_WGSL
std::unique_ptr<tint::ast::Module> mTintModule; std::unique_ptr<tint::Program> mTintProgram;
#endif #endif
}; };

View File

@ -71,7 +71,7 @@ namespace dawn_native { namespace metal {
MaybeError Initialize(ShaderModuleParseResult* parseResult); MaybeError Initialize(ShaderModuleParseResult* parseResult);
#ifdef DAWN_ENABLE_WGSL #ifdef DAWN_ENABLE_WGSL
std::unique_ptr<tint::ast::Module> mTintModule; std::unique_ptr<tint::Program> mTintProgram;
#endif #endif
}; };

View File

@ -50,7 +50,7 @@ namespace dawn_native { namespace metal {
MaybeError ShaderModule::Initialize(ShaderModuleParseResult* parseResult) { MaybeError ShaderModule::Initialize(ShaderModuleParseResult* parseResult) {
DAWN_TRY(InitializeBase(parseResult)); DAWN_TRY(InitializeBase(parseResult));
#ifdef DAWN_ENABLE_WGSL #ifdef DAWN_ENABLE_WGSL
mTintModule = std::move(parseResult->tintModule); mTintProgram = std::move(parseResult->tintProgram);
#endif #endif
return {}; return {};
} }
@ -88,14 +88,14 @@ namespace dawn_native { namespace metal {
} }
transformManager.append(std::make_unique<tint::transform::BoundArrayAccessors>()); transformManager.append(std::make_unique<tint::transform::BoundArrayAccessors>());
tint::ast::Module module; tint::Program program;
DAWN_TRY_ASSIGN(module, RunTransforms(&transformManager, mTintModule.get())); DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, mTintProgram.get()));
ASSERT(remappedEntryPointName != nullptr); ASSERT(remappedEntryPointName != nullptr);
tint::inspector::Inspector inspector(module); tint::inspector::Inspector inspector(&program);
*remappedEntryPointName = inspector.GetRemappedNameForEntryPoint(entryPointName); *remappedEntryPointName = inspector.GetRemappedNameForEntryPoint(entryPointName);
tint::writer::msl::Generator generator(std::move(module)); tint::writer::msl::Generator generator(&program);
if (!generator.Generate()) { if (!generator.Generate()) {
errorStream << "Generator: " << generator.error() << std::endl; errorStream << "Generator: " << generator.error() << std::endl;
return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
@ -123,9 +123,9 @@ namespace dawn_native { namespace metal {
std::vector<uint32_t> pullingSpirv; std::vector<uint32_t> pullingSpirv;
if (GetDevice()->IsToggleEnabled(Toggle::MetalEnableVertexPulling) && if (GetDevice()->IsToggleEnabled(Toggle::MetalEnableVertexPulling) &&
stage == SingleShaderStage::Vertex) { stage == SingleShaderStage::Vertex) {
if (mTintModule) { if (mTintProgram) {
DAWN_TRY_ASSIGN(pullingSpirv, DAWN_TRY_ASSIGN(pullingSpirv,
GeneratePullingSpirv(mTintModule.get(), GeneratePullingSpirv(mTintProgram.get(),
*renderPipeline->GetVertexStateDescriptor(), *renderPipeline->GetVertexStateDescriptor(),
entryPointName, kPullingBufferBindingSet)); entryPointName, kPullingBufferBindingSet));
} else { } else {

View File

@ -82,7 +82,7 @@ namespace dawn_native { namespace opengl {
DAWN_TRY(InitializeBase(parseResult)); DAWN_TRY(InitializeBase(parseResult));
if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) { if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) {
#ifdef DAWN_ENABLE_WGSL #ifdef DAWN_ENABLE_WGSL
tint::ast::Module module = std::move(*parseResult->tintModule.release()); tint::Program program = std::move(*parseResult->tintProgram.release());
std::ostringstream errorStream; std::ostringstream errorStream;
errorStream << "Tint SPIR-V (for GLSL) writer failure:" << std::endl; errorStream << "Tint SPIR-V (for GLSL) writer failure:" << std::endl;
@ -91,9 +91,9 @@ namespace dawn_native { namespace opengl {
transformManager.append(std::make_unique<tint::transform::BoundArrayAccessors>()); transformManager.append(std::make_unique<tint::transform::BoundArrayAccessors>());
transformManager.append(std::make_unique<tint::transform::EmitVertexPointSize>()); transformManager.append(std::make_unique<tint::transform::EmitVertexPointSize>());
DAWN_TRY_ASSIGN(module, RunTransforms(&transformManager, &module)); DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, &program));
tint::writer::spirv::Generator generator(std::move(module)); tint::writer::spirv::Generator generator(&program);
if (!generator.Generate()) { if (!generator.Generate()) {
errorStream << "Generator: " << generator.error() << std::endl; errorStream << "Generator: " << generator.error() << std::endl;
return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); return DAWN_VALIDATION_ERROR(errorStream.str().c_str());

View File

@ -53,7 +53,7 @@ namespace dawn_native { namespace vulkan {
const std::vector<uint32_t>* spirvPtr; const std::vector<uint32_t>* spirvPtr;
if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) { if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) {
#ifdef DAWN_ENABLE_WGSL #ifdef DAWN_ENABLE_WGSL
tint::ast::Module module = std::move(*std::move(parseResult->tintModule).release()); tint::Program program = std::move(*std::move(parseResult->tintProgram).release());
std::ostringstream errorStream; std::ostringstream errorStream;
errorStream << "Tint SPIR-V writer failure:" << std::endl; errorStream << "Tint SPIR-V writer failure:" << std::endl;
@ -62,9 +62,9 @@ namespace dawn_native { namespace vulkan {
transformManager.append(std::make_unique<tint::transform::BoundArrayAccessors>()); transformManager.append(std::make_unique<tint::transform::BoundArrayAccessors>());
transformManager.append(std::make_unique<tint::transform::EmitVertexPointSize>()); transformManager.append(std::make_unique<tint::transform::EmitVertexPointSize>());
DAWN_TRY_ASSIGN(module, RunTransforms(&transformManager, &module)); DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, &program));
tint::writer::spirv::Generator generator(std::move(module)); tint::writer::spirv::Generator generator(&program);
if (!generator.Generate()) { if (!generator.Generate()) {
errorStream << "Generator: " << generator.error() << std::endl; errorStream << "Generator: " << generator.error() << std::endl;
return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); return DAWN_VALIDATION_ERROR(errorStream.str().c_str());

View File

@ -79,17 +79,17 @@ namespace DawnSPIRVCrossFuzzer {
return 0; return 0;
} }
tint::ast::Module module = parser.module(); tint::Program program = parser.program();
if (!module.IsValid()) { if (!program.IsValid()) {
return 0; return 0;
} }
tint::TypeDeterminer type_determiner(&module); tint::TypeDeterminer type_determiner(&program);
if (!type_determiner.Determine()) { if (!type_determiner.Determine()) {
return 0; return 0;
} }
tint::writer::spirv::Generator generator(std::move(module)); tint::writer::spirv::Generator generator(&program);
if (!generator.Generate()) { if (!generator.Generate()) {
return 0; return 0;
} }