Remove HLSL override generation
This CL removes the override emission from the HLSL backend. The override should be removed by the substitute_override transform before making it to the backend. Bug: tint:1155 Change-Id: I6fecf47a5f5616a81281b179853e0f00ba31011f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/101663 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
1524d9e1bf
commit
f6a9404978
|
@ -2846,7 +2846,12 @@ bool GeneratorImpl::EmitGlobalVariable(const ast::Variable* global) {
|
|||
}
|
||||
}
|
||||
},
|
||||
[&](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
|
||||
},
|
||||
|
@ -4092,36 +4097,6 @@ bool GeneratorImpl::EmitLet(const ast::Let* let) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitOverride(const ast::Override* override) {
|
||||
auto* sem = builder_.Sem().Get(override);
|
||||
auto* type = sem->Type();
|
||||
|
||||
auto override_id = sem->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 << "static const ";
|
||||
if (!EmitTypeAndName(out, type, sem->StorageClass(), sem->Access(),
|
||||
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,
|
||||
|
|
|
@ -449,10 +449,6 @@ class GeneratorImpl : public TextGenerator {
|
|||
/// @param let the variable to generate
|
||||
/// @returns true if the variable was emitted
|
||||
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 call to a helper vector assignment function for the input assignment
|
||||
/// statement and vector type. This is used to work around FXC issues where
|
||||
/// assignments to vectors with dynamic indices cause compilation failures.
|
||||
|
|
|
@ -712,40 +712,6 @@ void main() {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_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::Empty,
|
||||
utils::Vector{
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
WorkgroupSize("width", "height", "depth"),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#ifndef WGSL_SPEC_CONSTANT_7
|
||||
#define WGSL_SPEC_CONSTANT_7 2
|
||||
#endif
|
||||
static const int width = WGSL_SPEC_CONSTANT_7;
|
||||
#ifndef WGSL_SPEC_CONSTANT_8
|
||||
#define WGSL_SPEC_CONSTANT_8 3
|
||||
#endif
|
||||
static const int height = WGSL_SPEC_CONSTANT_8;
|
||||
#ifndef WGSL_SPEC_CONSTANT_9
|
||||
#define WGSL_SPEC_CONSTANT_9 4
|
||||
#endif
|
||||
static const int depth = WGSL_SPEC_CONSTANT_9;
|
||||
|
||||
[numthreads(WGSL_SPEC_CONSTANT_7, WGSL_SPEC_CONSTANT_8, WGSL_SPEC_CONSTANT_9)]
|
||||
void main() {
|
||||
return;
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {
|
||||
Func("my_func",
|
||||
utils::Vector{
|
||||
|
|
|
@ -242,50 +242,5 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_arr_vec2_bool) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_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
|
||||
static const float pos = WGSL_SPEC_CONSTANT_23;
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_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
|
||||
static const float pos = WGSL_SPEC_CONSTANT_23;
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_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
|
||||
static const float a = WGSL_SPEC_CONSTANT_0;
|
||||
#ifndef WGSL_SPEC_CONSTANT_1
|
||||
#define WGSL_SPEC_CONSTANT_1 2.0f
|
||||
#endif
|
||||
static const float b = WGSL_SPEC_CONSTANT_1;
|
||||
)");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::writer::hlsl
|
||||
|
|
Loading…
Reference in New Issue