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 <rharrison@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Ben Clayton 2021-03-09 13:58:07 +00:00 committed by Commit Bot service account
parent 7c3b5740db
commit 7fe018c065
2 changed files with 32 additions and 11 deletions

View File

@ -207,19 +207,20 @@ namespace dawn_native { namespace d3d12 {
tint::transform::Manager transformManager; tint::transform::Manager transformManager;
transformManager.append(std::make_unique<tint::transform::BoundArrayAccessors>()); transformManager.append(std::make_unique<tint::transform::BoundArrayAccessors>());
if (stage == SingleShaderStage::Vertex) { if (stage == SingleShaderStage::Vertex) {
transformManager.append(std::make_unique<tint::transform::FirstIndexOffset>( transformManager.append(std::make_unique<tint::transform::FirstIndexOffset>(
layout->GetFirstIndexOffsetShaderRegister(), layout->GetFirstIndexOffsetShaderRegister(),
layout->GetFirstIndexOffsetRegisterSpace())); layout->GetFirstIndexOffsetRegisterSpace()));
} }
transformManager.append(std::make_unique<tint::transform::Renamer>());
transformManager.append(std::make_unique<tint::transform::Hlsl>());
tint::transform::Transform::Output output = transformManager.Run(mTintProgram.get()); tint::transform::Transform::Output output = transformManager.Run(mTintProgram.get());
tint::Program& program = output.program; tint::Program& program = output.program;
if (!program.IsValid()) { if (!program.IsValid()) {
auto err = tint::diag::Formatter{}.format(program.Diagnostics()); errorStream << "Tint program transform error: " << program.Diagnostics().str()
errorStream << "Tint program transform error: " << err << std::endl; << std::endl;
return DAWN_VALIDATION_ERROR(errorStream.str().c_str()); return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
} }
@ -234,9 +235,15 @@ namespace dawn_native { namespace d3d12 {
} }
} }
ASSERT(remappedEntryPointName != nullptr); if (auto* data = output.data.Get<tint::transform::Renamer::Data>()) {
tint::inspector::Inspector inspector(&program); auto it = data->remappings.find(entryPointName);
*remappedEntryPointName = inspector.GetRemappedNameForEntryPoint(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); tint::writer::hlsl::Generator generator(&program);
// TODO: Switch to GenerateEntryPoint once HLSL writer supports it. // TODO: Switch to GenerateEntryPoint once HLSL writer supports it.

View File

@ -87,13 +87,27 @@ namespace dawn_native { namespace metal {
} }
} }
transformManager.append(std::make_unique<tint::transform::BoundArrayAccessors>()); transformManager.append(std::make_unique<tint::transform::BoundArrayAccessors>());
transformManager.append(std::make_unique<tint::transform::Renamer>());
transformManager.append(std::make_unique<tint::transform::Msl>());
tint::Program program; tint::transform::Transform::Output output = transformManager.Run(mTintProgram.get());
DAWN_TRY_ASSIGN(program, RunTransforms(&transformManager, mTintProgram.get()));
ASSERT(remappedEntryPointName != nullptr); tint::Program& program = output.program;
tint::inspector::Inspector inspector(&program); if (!program.IsValid()) {
*remappedEntryPointName = inspector.GetRemappedNameForEntryPoint(entryPointName); errorStream << "Tint program transform error: " << program.Diagnostics().str()
<< std::endl;
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
}
if (auto* data = output.data.Get<tint::transform::Renamer::Data>()) {
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); tint::writer::msl::Generator generator(&program);
if (!generator.Generate()) { if (!generator.Generate()) {