writer/msl: Fix zero-valued matrix constructors

Fixed: tint:813
Change-Id: Ia22f4264de89da76ab0a10cf52f267fcb1e2dbd4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51440
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
James Price 2021-05-19 11:15:58 +00:00 committed by Commit Bot service account
parent cbe816f93d
commit 94867592cd
4 changed files with 19 additions and 3 deletions

View File

@ -935,7 +935,14 @@ bool GeneratorImpl::EmitZeroValue(typ::Type type) {
} else if (auto* vec = type->As<sem::Vector>()) {
return EmitZeroValue(vec->type());
} else if (auto* mat = type->As<sem::Matrix>()) {
return EmitZeroValue(mat->type());
if (!EmitType(mat, "")) {
return false;
}
out_ << "(";
if (!EmitZeroValue(mat->type())) {
return false;
}
out_ << ")";
} else if (auto* arr = type->As<sem::Array>()) {
out_ << "{";
if (!EmitZeroValue(arr->ElemType())) {

View File

@ -131,6 +131,15 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) {
"float2x3(float3(1.0f, 2.0f, 3.0f), float3(3.0f, 4.0f, 5.0f))"));
}
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat_Empty) {
WrapInFunction(mat4x4<f32>());
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("float4x4(0.0f)"));
}
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) {
WrapInFunction(
Construct(ty.array(ty.vec3<f32>(), 3), vec3<f32>(1.0f, 2.0f, 3.0f),

View File

@ -107,7 +107,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) {
gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
EXPECT_EQ(gen.result(), " float3x2 a = 0.0f;\n");
EXPECT_EQ(gen.result(), " float3x2 a = float3x2(0.0f);\n");
}
// TODO(crbug.com/tint/726): module-scope private and workgroup variables not

View File

@ -2,7 +2,7 @@
using namespace metal;
kernel void tint_symbol() {
float3x3 m = 0.0f;
float3x3 m = float3x3(0.0f);
float3 const v = m[1];
float const f = v[1];
return;