diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index 132f542239..3f989992d6 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -1884,7 +1884,12 @@ bool GeneratorImpl::EmitGlobalVariable(const ast::Variable* global) { } }, [&](const ast::Let* let) { return EmitProgramConstVariable(let); }, - [&](const ast::Override* override) { return EmitOverride(override); }, + [&](const ast::Override*) { + // Override is removed with SubstituteOverride + TINT_ICE(Writer, diagnostics_) + << "Override should have been removed by the substitute_override transform."; + return false; + }, [&](const ast::Const*) { return true; // Constants are embedded at their use }, @@ -2985,38 +2990,6 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { return true; } -bool GeneratorImpl::EmitOverride(const ast::Override* override) { - auto* sem = builder_.Sem().Get(override); - auto* type = sem->Type(); - - auto* global = sem->As(); - auto override_id = global->OverrideId(); - - line() << "#ifndef " << kSpecConstantPrefix << override_id.value; - - if (override->constructor != nullptr) { - auto out = line(); - out << "#define " << kSpecConstantPrefix << override_id.value << " "; - if (!EmitExpression(out, override->constructor)) { - return false; - } - } else { - line() << "#error spec constant required for constant id " << override_id.value; - } - line() << "#endif"; - { - auto out = line(); - out << "const "; - if (!EmitTypeAndName(out, type, ast::StorageClass::kNone, ast::Access::kUndefined, - builder_.Symbols().NameFor(override->symbol))) { - return false; - } - out << " = " << kSpecConstantPrefix << override_id.value << ";"; - } - - return true; -} - template bool GeneratorImpl::CallBuiltinHelper(std::ostream& out, const ast::CallExpression* call, diff --git a/src/tint/writer/glsl/generator_impl.h b/src/tint/writer/glsl/generator_impl.h index e70bdc244f..cab688136b 100644 --- a/src/tint/writer/glsl/generator_impl.h +++ b/src/tint/writer/glsl/generator_impl.h @@ -457,10 +457,6 @@ class GeneratorImpl : public TextGenerator { /// @param let the 'let' to emit /// @returns true if the variable was emitted bool EmitProgramConstVariable(const ast::Variable* 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); /// Handles generating a builtin method name /// @param builtin the semantic info for the builtin /// @returns the name or "" if not valid diff --git a/src/tint/writer/glsl/generator_impl_function_test.cc b/src/tint/writer/glsl/generator_impl_function_test.cc index fd74e2d815..473c30cee3 100644 --- a/src/tint/writer/glsl/generator_impl_function_test.cc +++ b/src/tint/writer/glsl/generator_impl_function_test.cc @@ -783,41 +783,6 @@ void main() { )"); } -TEST_F(GlslGeneratorImplTest_Function, - Emit_Attribute_EntryPoint_Compute_WithWorkgroup_OverridableConst) { - Override("width", ty.i32(), Construct(ty.i32(), 2_i), Id(7_u)); - Override("height", ty.i32(), Construct(ty.i32(), 3_i), Id(8_u)); - Override("depth", ty.i32(), Construct(ty.i32(), 4_i), Id(9_u)); - Func("main", utils::Empty, ty.void_(), {}, - utils::Vector{ - Stage(ast::PipelineStage::kCompute), - WorkgroupSize("width", "height", "depth"), - }); - - GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.error(); - EXPECT_EQ(gen.result(), R"(#version 310 es - -#ifndef WGSL_SPEC_CONSTANT_7 -#define WGSL_SPEC_CONSTANT_7 2 -#endif -const int width = WGSL_SPEC_CONSTANT_7; -#ifndef WGSL_SPEC_CONSTANT_8 -#define WGSL_SPEC_CONSTANT_8 3 -#endif -const int height = WGSL_SPEC_CONSTANT_8; -#ifndef WGSL_SPEC_CONSTANT_9 -#define WGSL_SPEC_CONSTANT_9 4 -#endif -const int depth = WGSL_SPEC_CONSTANT_9; -layout(local_size_x = WGSL_SPEC_CONSTANT_7, local_size_y = WGSL_SPEC_CONSTANT_8, local_size_z = WGSL_SPEC_CONSTANT_9) in; -void main() { - return; -} -)"); -} - TEST_F(GlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) { Func("my_func", utils::Vector{Param("a", ty.array())}, ty.void_(), utils::Vector{ diff --git a/src/tint/writer/glsl/generator_impl_module_constant_test.cc b/src/tint/writer/glsl/generator_impl_module_constant_test.cc index 26dbf2e15b..b9da4d5a5d 100644 --- a/src/tint/writer/glsl/generator_impl_module_constant_test.cc +++ b/src/tint/writer/glsl/generator_impl_module_constant_test.cc @@ -345,50 +345,5 @@ void f() { )"); } -TEST_F(GlslGeneratorImplTest_ModuleConstant, 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(), R"(#ifndef WGSL_SPEC_CONSTANT_23 -#define WGSL_SPEC_CONSTANT_23 3.0f -#endif -const float pos = WGSL_SPEC_CONSTANT_23; -)"); -} - -TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_Override_NoConstructor) { - auto* var = Override("pos", ty.f32(), Id(23_a)); - - GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.EmitOverride(var)) << gen.error(); - EXPECT_EQ(gen.result(), R"(#ifndef WGSL_SPEC_CONSTANT_23 -#error spec constant required for constant id 23 -#endif -const float pos = WGSL_SPEC_CONSTANT_23; -)"); -} - -TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_Override_NoId) { - auto* a = Override("a", ty.f32(), Expr(3_f), Id(0_a)); - auto* b = Override("b", ty.f32(), Expr(2_f)); - - GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.EmitOverride(a)) << gen.error(); - ASSERT_TRUE(gen.EmitOverride(b)) << gen.error(); - EXPECT_EQ(gen.result(), R"(#ifndef WGSL_SPEC_CONSTANT_0 -#define WGSL_SPEC_CONSTANT_0 3.0f -#endif -const float a = WGSL_SPEC_CONSTANT_0; -#ifndef WGSL_SPEC_CONSTANT_1 -#define WGSL_SPEC_CONSTANT_1 2.0f -#endif -const float b = WGSL_SPEC_CONSTANT_1; -)"); -} - } // namespace } // namespace tint::writer::glsl