mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-10 15:15:58 +00:00
writer/msl: Simplify type constructor generation
The special-case for zero-valued constructors is unnecessary, as an empty initializer list already correctly zero-initializes for all types. This was causing an additional {} to be emitted for empty structures, which the MSL compiler rejects. Fixed: tint:821 Change-Id: Ib48c73eadef15b517e14b248229ecfbbfeb13f81 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51822 Commit-Queue: James Price <jrprice@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Auto-Submit: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
ba1fb84855
commit
6c582778cf
@ -892,13 +892,6 @@ bool GeneratorImpl::EmitTypeConstructor(ast::TypeConstructorExpression* expr) {
|
|||||||
out_ << "(";
|
out_ << "(";
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the type constructor is empty then we need to construct with the zero
|
|
||||||
// value for all components.
|
|
||||||
if (expr->values().empty()) {
|
|
||||||
if (!EmitZeroValue(type)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto* e : expr->values()) {
|
for (auto* e : expr->values()) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
@ -910,7 +903,6 @@ bool GeneratorImpl::EmitTypeConstructor(ast::TypeConstructorExpression* expr) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (type->IsAnyOf<sem::Array, sem::Struct>()) {
|
if (type->IsAnyOf<sem::Array, sem::Struct>()) {
|
||||||
out_ << "}";
|
out_ << "}";
|
||||||
|
@ -112,7 +112,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec_Empty) {
|
|||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||||
EXPECT_THAT(gen.result(), HasSubstr("float3(0.0f)"));
|
EXPECT_THAT(gen.result(), HasSubstr("float3()"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) {
|
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) {
|
||||||
@ -137,7 +137,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat_Empty) {
|
|||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||||
EXPECT_THAT(gen.result(), HasSubstr("float4x4(0.0f)"));
|
EXPECT_THAT(gen.result(), HasSubstr("float4x4()"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) {
|
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) {
|
||||||
@ -168,6 +168,18 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Struct) {
|
|||||||
EXPECT_THAT(gen.result(), HasSubstr("{1, 2.0f, int3(3, 4, 5)}"));
|
EXPECT_THAT(gen.result(), HasSubstr("{1, 2.0f, int3(3, 4, 5)}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Struct_Empty) {
|
||||||
|
auto* str = Structure("S", {});
|
||||||
|
|
||||||
|
WrapInFunction(Construct(str));
|
||||||
|
|
||||||
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||||
|
EXPECT_THAT(gen.result(), HasSubstr("{}"));
|
||||||
|
EXPECT_THAT(gen.result(), Not(HasSubstr("{{}}")));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace msl
|
} // namespace msl
|
||||||
} // namespace writer
|
} // namespace writer
|
||||||
|
@ -214,7 +214,7 @@ struct tint_symbol_3 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
vertex tint_symbol vert_main() {
|
vertex tint_symbol vert_main() {
|
||||||
Interface const tint_symbol_1 = {0.5f, 0.25f, float4(0.0f)};
|
Interface const tint_symbol_1 = {0.5f, 0.25f, float4()};
|
||||||
return {tint_symbol_1.col1, tint_symbol_1.col2, tint_symbol_1.pos};
|
return {tint_symbol_1.col1, tint_symbol_1.col2, tint_symbol_1.pos};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
|
|||||||
gen.increment_indent();
|
gen.increment_indent();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), " float const a = float(0.0f);\n");
|
EXPECT_EQ(gen.result(), " float const a = float();\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) {
|
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) {
|
||||||
@ -150,7 +150,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) {
|
|||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
||||||
EXPECT_EQ(gen.result(), R"(float3 a = float3(0.0f);
|
EXPECT_EQ(gen.result(), R"(float3 a = float3();
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ void bar() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fragment tint_symbol_1 tint_symbol() {
|
fragment tint_symbol_1 tint_symbol() {
|
||||||
float2 a = float2(0.0f);
|
float2 a = float2();
|
||||||
bar();
|
bar();
|
||||||
return {float4(0.400000006f, 0.400000006f, 0.800000012f, 1.0f)};
|
return {float4(0.400000006f, 0.400000006f, 0.800000012f, 1.0f)};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user