From d5638c93c575469914328cc8f618de652082fca9 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Fri, 26 Feb 2021 18:53:36 +0000 Subject: [PATCH] BoundArrayAccessors: Add more tests Bug: tint:521 Change-Id: I0a9ea7f487b052d1ee6ffa5be079d18633acc72c Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42844 Commit-Queue: Austin Eng Auto-Submit: Ben Clayton Reviewed-by: Austin Eng --- src/transform/bound_array_accessors_test.cc | 73 +++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/transform/bound_array_accessors_test.cc b/src/transform/bound_array_accessors_test.cc index 58def8f6e8..c5bef53b9e 100644 --- a/src/transform/bound_array_accessors_test.cc +++ b/src/transform/bound_array_accessors_test.cc @@ -218,6 +218,79 @@ fn f() -> void { EXPECT_EQ(expect, str(got)); } +TEST_F(BoundArrayAccessorsTest, Vector_Swizzle_Idx_Scalar) { + auto* src = R"( +var a : vec3; + +fn f() -> void { + var b : f32 = a.xy[2]; +} +)"; + + auto* expect = R"( +var a : vec3; + +fn f() -> void { + var b : f32 = a.xy[1]; +} +)"; + + auto got = Transform(src); + + EXPECT_EQ(expect, str(got)); +} + +TEST_F(BoundArrayAccessorsTest, Vector_Swizzle_Idx_Var) { + auto* src = R"( +var a : vec3; + +var c : u32; + +fn f() -> void { + var b : f32 = a.xy[c]; +} +)"; + + auto* expect = R"( +var a : vec3; + +var c : u32; + +fn f() -> void { + var b : f32 = a.xy[min(u32(c), 1u)]; +} +)"; + + auto got = Transform(src); + + EXPECT_EQ(expect, str(got)); +} +TEST_F(BoundArrayAccessorsTest, Vector_Swizzle_Idx_Expr) { + auto* src = R"( +var a : vec3; + +var c : u32; + +fn f() -> void { + var b : f32 = a.xy[c + 2 - 3]; +} +)"; + + auto* expect = R"( +var a : vec3; + +var c : u32; + +fn f() -> void { + var b : f32 = a.xy[min(u32(((c + 2) - 3)), 1u)]; +} +)"; + + auto got = Transform(src); + + EXPECT_EQ(expect, str(got)); +} + TEST_F(BoundArrayAccessorsTest, Vector_Idx_Negative) { auto* src = R"( var a : vec3;