Remove GLSL override generation

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

Bug: tint:1155
Change-Id: Ic95413cfedaf417f54cab80aef413f745ccf3bfa
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/101664
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:55:58 +00:00 committed by Dawn LUCI CQ
parent e1854b2d72
commit 3526bc4f42
4 changed files with 6 additions and 117 deletions

View File

@ -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<sem::GlobalVariable>();
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 <typename F>
bool GeneratorImpl::CallBuiltinHelper(std::ostream& out,
const ast::CallExpression* call,

View File

@ -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

View File

@ -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<f32, 5>())}, ty.void_(),
utils::Vector{

View File

@ -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