From a33bc2c6f2a657e4f91f27534da640aa063c4892 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Tue, 27 Sep 2022 20:44:06 +0000 Subject: [PATCH] Add some GLSL zero initialization tests. This CL adds tests for GLSL zero initialization of an array, array of arrays and array of structs. Bug: chromium:1367602 Change-Id: I4246512f9238dcccc02c9c181b7a211958491dad Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/103880 Commit-Queue: Ben Clayton Reviewed-by: Ben Clayton Auto-Submit: Dan Sinclair --- ...rator_impl_variable_decl_statement_test.cc | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/tint/writer/glsl/generator_impl_variable_decl_statement_test.cc b/src/tint/writer/glsl/generator_impl_variable_decl_statement_test.cc index 6cac4631f3..27c5e867cd 100644 --- a/src/tint/writer/glsl/generator_impl_variable_decl_statement_test.cc +++ b/src/tint/writer/glsl/generator_impl_variable_decl_statement_test.cc @@ -367,6 +367,75 @@ void f() { )"); } +TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_arr_f32_zero) { + auto* C = Const("C", Construct(ty.array())); + Func("f", utils::Empty, ty.void_(), + utils::Vector{ + Decl(C), + Decl(Let("l", Expr(C))), + }); + + GeneratorImpl& gen = Build(); + + ASSERT_TRUE(gen.Generate()) << gen.error(); + + EXPECT_EQ(gen.result(), R"(#version 310 es + +void f() { + float l[2] = float[2](0.0f, 0.0f); +} + +)"); +} + +TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_arr_arr_f32_zero) { + auto* C = Const("C", Construct(ty.array(ty.array(), 3_i))); + Func("f", utils::Empty, ty.void_(), + utils::Vector{ + Decl(C), + Decl(Let("l", Expr(C))), + }); + + GeneratorImpl& gen = Build(); + + ASSERT_TRUE(gen.Generate()) << gen.error(); + + EXPECT_EQ(gen.result(), R"(#version 310 es + +void f() { + float l[3][2] = float[3][2](float[2](0.0f, 0.0f), float[2](0.0f, 0.0f), float[2](0.0f, 0.0f)); +} + +)"); +} + +TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_arr_struct_zero) { + Structure("S", utils::Vector{Member("a", ty.i32()), Member("b", ty.f32())}); + auto* C = Const("C", Construct(ty.array(ty.type_name("S"), 2_i))); + Func("f", utils::Empty, ty.void_(), + utils::Vector{ + Decl(C), + Decl(Let("l", Expr(C))), + }); + + GeneratorImpl& gen = Build(); + + ASSERT_TRUE(gen.Generate()) << gen.error(); + + EXPECT_EQ(gen.result(), R"(#version 310 es + +struct S { + int a; + float b; +}; + +void f() { + S l[2] = S[2](S(0, 0.0f), S(0, 0.0f)); +} + +)"); +} + TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_arr_vec2_bool) { auto* C = Const("C", Construct(ty.array(ty.vec2(), 3_u), // vec2(true, false), //