Remove MSL override generation

This CL removes the override emission from the MSL backend. The
override should be removed by the substitute_override transform
before making it to the backend.

Bug: tint:1155
Change-Id: I9d3852a7e20b258a2f0af200bff6268037eaa0b5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/101662
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair 2022-09-09 16:14:10 +00:00 committed by Dawn LUCI CQ
parent e214a130dd
commit 5432767a04
3 changed files with 5 additions and 45 deletions

View File

@ -271,9 +271,11 @@ bool GeneratorImpl::Generate() {
[&](const ast::Const*) { [&](const ast::Const*) {
return true; // Constants are embedded at their use return true; // Constants are embedded at their use
}, },
[&](const ast::Override* override) { [&](const ast::Override*) {
TINT_DEFER(line()); // Override is removed with SubstituteOverride
return EmitOverride(override); TINT_ICE(Writer, diagnostics_)
<< "Override should have been removed by the substitute_override transform.";
return false;
}, },
[&](const ast::Function* func) { [&](const ast::Function* func) {
TINT_DEFER(line()); TINT_DEFER(line());
@ -3038,22 +3040,6 @@ bool GeneratorImpl::EmitLet(const ast::Let* let) {
return true; return true;
} }
bool GeneratorImpl::EmitOverride(const ast::Override* override) {
auto* global = program_->Sem().Get<sem::GlobalVariable>(override);
auto* type = global->Type();
auto out = line();
out << "constant ";
if (!EmitType(out, type, program_->Symbols().NameFor(override->symbol))) {
return false;
}
out << " " << program_->Symbols().NameFor(override->symbol);
out << " [[function_constant(" << global->OverrideId().value << ")]];";
return true;
}
GeneratorImpl::SizeAndAlign GeneratorImpl::MslPackedTypeSizeAndAlign(const sem::Type* ty) { GeneratorImpl::SizeAndAlign GeneratorImpl::MslPackedTypeSizeAndAlign(const sem::Type* ty) {
return Switch( return Switch(
ty, ty,

View File

@ -356,10 +356,6 @@ class GeneratorImpl : public TextGenerator {
/// @param let the variable to generate /// @param let the variable to generate
/// @returns true if the variable was emitted /// @returns true if the variable was emitted
bool EmitLet(const ast::Let* let); bool EmitLet(const ast::Let* let);
/// Handles generating a module-scope 'override' declaration
/// @param override the 'override' to emit
/// @returns true if the variable was emitted
bool EmitOverride(const ast::Override* override);
/// Emits the zero value for the given type /// Emits the zero value for the given type
/// @param out the output of the expression stream /// @param out the output of the expression stream
/// @param type the type to emit the value for /// @param type the type to emit the value for

View File

@ -328,27 +328,5 @@ void f() {
)"); )");
} }
TEST_F(MslGeneratorImplTest, Emit_Override) {
auto* var = Override("pos", ty.f32(), Expr(3_f), Id(23_a));
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitOverride(var)) << gen.error();
EXPECT_EQ(gen.result(), "constant float pos [[function_constant(23)]];\n");
}
TEST_F(MslGeneratorImplTest, Emit_Override_NoId) {
auto* var_a = Override("a", ty.f32(), Id(0_a));
auto* var_b = Override("b", ty.f32());
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitOverride(var_a)) << gen.error();
ASSERT_TRUE(gen.EmitOverride(var_b)) << gen.error();
EXPECT_EQ(gen.result(), R"(constant float a [[function_constant(0)]];
constant float b [[function_constant(1)]];
)");
}
} // namespace } // namespace
} // namespace tint::writer::msl } // namespace tint::writer::msl