From 7fe018c06578ff04d0e4ec2a0ada2c34a82ef6b0 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Tue, 9 Mar 2021 13:58:07 +0000 Subject: [PATCH] ShaderModule: Use transform::Renamer For sanitizing symbols. Replaces use of Inspector::GetRemappedNameForEntryPoint() Change-Id: I1e20f719e0e80c04c5c4e4ae52bdb47f8d0572f6 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/43884 Reviewed-by: Ryan Harrison Reviewed-by: Corentin Wallez Commit-Queue: Corentin Wallez --- src/dawn_native/d3d12/ShaderModuleD3D12.cpp | 19 ++++++++++------ src/dawn_native/metal/ShaderModuleMTL.mm | 24 ++++++++++++++++----- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp index 07be2ff9bc..d9ce9a6391 100644 --- a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp +++ b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp @@ -207,19 +207,20 @@ namespace dawn_native { namespace d3d12 { tint::transform::Manager transformManager; transformManager.append(std::make_unique()); - if (stage == SingleShaderStage::Vertex) { transformManager.append(std::make_unique( layout->GetFirstIndexOffsetShaderRegister(), layout->GetFirstIndexOffsetRegisterSpace())); } + transformManager.append(std::make_unique()); + transformManager.append(std::make_unique()); tint::transform::Transform::Output output = transformManager.Run(mTintProgram.get()); tint::Program& program = output.program; if (!program.IsValid()) { - auto err = tint::diag::Formatter{}.format(program.Diagnostics()); - errorStream << "Tint program transform error: " << err << std::endl; + errorStream << "Tint program transform error: " << program.Diagnostics().str() + << std::endl; return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); } @@ -234,9 +235,15 @@ namespace dawn_native { namespace d3d12 { } } - ASSERT(remappedEntryPointName != nullptr); - tint::inspector::Inspector inspector(&program); - *remappedEntryPointName = inspector.GetRemappedNameForEntryPoint(entryPointName); + if (auto* data = output.data.Get()) { + auto it = data->remappings.find(entryPointName); + if (it == data->remappings.end()) { + return DAWN_VALIDATION_ERROR("Could not find remapped name for entry point."); + } + *remappedEntryPointName = it->second; + } else { + return DAWN_VALIDATION_ERROR("Transform output missing renamer data."); + } tint::writer::hlsl::Generator generator(&program); // TODO: Switch to GenerateEntryPoint once HLSL writer supports it. diff --git a/src/dawn_native/metal/ShaderModuleMTL.mm b/src/dawn_native/metal/ShaderModuleMTL.mm index 11241e9cd1..1f9df97781 100644 --- a/src/dawn_native/metal/ShaderModuleMTL.mm +++ b/src/dawn_native/metal/ShaderModuleMTL.mm @@ -87,13 +87,27 @@ namespace dawn_native { namespace metal { } } transformManager.append(std::make_unique()); + transformManager.append(std::make_unique()); + transformManager.append(std::make_unique()); - tint::Program program; - DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, mTintProgram.get())); + tint::transform::Transform::Output output = transformManager.Run(mTintProgram.get()); - ASSERT(remappedEntryPointName != nullptr); - tint::inspector::Inspector inspector(&program); - *remappedEntryPointName = inspector.GetRemappedNameForEntryPoint(entryPointName); + tint::Program& program = output.program; + if (!program.IsValid()) { + errorStream << "Tint program transform error: " << program.Diagnostics().str() + << std::endl; + return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); + } + + if (auto* data = output.data.Get()) { + auto it = data->remappings.find(entryPointName); + if (it == data->remappings.end()) { + return DAWN_VALIDATION_ERROR("Could not find remapped name for entry point."); + } + *remappedEntryPointName = it->second; + } else { + return DAWN_VALIDATION_ERROR("Transform output missing renamer data."); + } tint::writer::msl::Generator generator(&program); if (!generator.Generate()) {