From 1a4d90667b47b5eb0867465757aae0d7b1ce8ced Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Thu, 23 Apr 2020 20:35:32 +0000 Subject: [PATCH] [spirv-writer] Add start of single swizzle test case This CL adds a DISABLED test for the single swizzle case. Bug: tint:5 Change-Id: I75df147adba4e2e2b7eb6bfd0e0ede951502a73d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20300 Reviewed-by: David Neto --- .../spirv/builder_accessor_expression_test.cc | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/writer/spirv/builder_accessor_expression_test.cc b/src/writer/spirv/builder_accessor_expression_test.cc index 9aa4a0efc3..28c1fde2d4 100644 --- a/src/writer/spirv/builder_accessor_expression_test.cc +++ b/src/writer/spirv/builder_accessor_expression_test.cc @@ -235,11 +235,44 @@ TEST_F(BuilderTest, MemberAccessor_Nested) { } TEST_F(BuilderTest, DISABLED_MemberAccessor_Swizzle_Single) { - // vec.x + ast::type::F32Type f32; + ast::type::VectorType vec3(&f32, 3); + + ast::Variable var("ident", ast::StorageClass::kFunction, &vec3); + + ast::MemberAccessorExpression expr( + std::make_unique("ident"), + std::make_unique("y")); + + Context ctx; + ast::Module mod; + TypeDeterminer td(&ctx, &mod); + td.RegisterVariableForTesting(&var); + ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); + + Builder b(&mod); + b.push_function(Function{}); + ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error(); + + EXPECT_EQ(b.GenerateAccessorExpression(&expr), 6u); + + EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 +%2 = OpTypeVector %3 3 +%1 = OpTypePointer Function %2 +%5 = OpTypeInt 32 0 +%6 = OpConstant %5 1 +%7 = OpTypePointer Function %3 +)"); + EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), + R"(%1 = OpVariable %1 Function +)"); + EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), + R"(%7 = OpAccessChain %7 %1 %6 +)"); } TEST_F(BuilderTest, DISABLED_MemberAccessor_Swizzle_Multiple) { - // vec.xy + // vec.yx } TEST_F(BuilderTest, DISABLED_Accessor_Mixed) {