[hlsl-writer] Emit zero matrix values.

This CL extends the zero emission to support matrices.

Bug: tint:7
Change-Id: I7e39a68c83edb096fc4b365c66539e8a8b7cb1db
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27443
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
Reviewed-by: David Neto <dneto@google.com>
diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc
index 1ffda9d..4ed643d 100644
--- a/src/writer/hlsl/generator_impl.cc
+++ b/src/writer/hlsl/generator_impl.cc
@@ -1430,6 +1430,16 @@
     out << "0u";
   } else if (type->IsVector()) {
     return EmitZeroValue(out, type->AsVector()->type());
+  } else if (type->IsMatrix()) {
+    auto* mat = type->AsMatrix();
+    for (uint32_t i = 0; i < (mat->rows() * mat->columns()); i++) {
+      if (i != 0) {
+        out << ", ";
+      }
+      if (!EmitZeroValue(out, mat->type())) {
+        return false;
+      }
+    }
   } else {
     error_ = "Invalid type for zero emission: " + type->type_name();
     return false;
diff --git a/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc b/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc
index 1a85ec9..bef692f 100644
--- a/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc
+++ b/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc
@@ -19,6 +19,7 @@
 #include "src/ast/module.h"
 #include "src/ast/type/array_type.h"
 #include "src/ast/type/f32_type.h"
+#include "src/ast/type/matrix_type.h"
 #include "src/ast/type/vector_type.h"
 #include "src/ast/variable.h"
 #include "src/ast/variable_decl_statement.h"
@@ -130,6 +131,27 @@
 )");
 }
 
+TEST_F(HlslGeneratorImplTest_VariableDecl,
+       Emit_VariableDeclStatement_Initializer_ZeroMat) {
+  ast::type::F32Type f32;
+  ast::type::MatrixType mat(&f32, 3, 2);
+
+  ast::ExpressionList values;
+  auto zero_mat =
+      std::make_unique<ast::TypeConstructorExpression>(&mat, std::move(values));
+
+  auto var =
+      std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &mat);
+  var->set_constructor(std::move(zero_mat));
+
+  ast::VariableDeclStatement stmt(std::move(var));
+  ASSERT_TRUE(gen().EmitStatement(out(), &stmt)) << gen().error();
+  EXPECT_EQ(
+      result(),
+      R"(matrix<float, 3, 2> a = matrix<float, 3, 2>(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
+)");
+}
+
 }  // namespace
 }  // namespace hlsl
 }  // namespace writer