| // Copyright 2022 The Tint Authors. |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #include "src/tint/transform/packed_vec3.h" |
| |
| #include <string> |
| #include <utility> |
| #include <vector> |
| |
| #include "src/tint/ast/module.h" |
| #include "src/tint/program_builder.h" |
| #include "src/tint/sem/struct.h" |
| #include "src/tint/sem/variable.h" |
| #include "src/tint/transform/test_helper.h" |
| #include "src/tint/type/array.h" |
| #include "src/tint/utils/string.h" |
| |
| namespace tint::transform { |
| namespace { |
| |
| using PackedVec3Test = TransformTest; |
| |
| TEST_F(PackedVec3Test, ShouldRun_EmptyModule) { |
| auto* src = R"()"; |
| |
| EXPECT_FALSE(ShouldRun<PackedVec3>(src)); |
| } |
| |
| TEST_F(PackedVec3Test, ShouldRun_NoHostShareableVec3s) { |
| auto* src = R"( |
| struct S { |
| v : vec3<f32>, |
| m : mat3x3<f32>, |
| a : array<vec3<f32>, 4>, |
| } |
| |
| var<private> p_s : S; |
| var<private> p_v : vec3<f32>; |
| var<private> p_m : mat3x3<f32>; |
| var<private> p_a : array<vec3<f32>, 4>; |
| |
| var<workgroup> w_s : S; |
| var<workgroup> w_v : vec3<f32>; |
| var<workgroup> w_m : mat3x3<f32>; |
| var<workgroup> w_a : array<vec3<f32>, 4>; |
| |
| fn f() { |
| var f_s : S; |
| var f_v : vec3<f32>; |
| var f_m : mat3x3<f32>; |
| var f_a : array<vec3<f32>, 4>; |
| } |
| )"; |
| |
| EXPECT_FALSE(ShouldRun<PackedVec3>(src)); |
| } |
| |
| TEST_F(PackedVec3Test, ShouldRun_Vec4Vec2) { |
| auto* src = R"( |
| struct S { |
| v4 : vec4<f32>, |
| v2 : vec2<f32>, |
| } |
| |
| @group(0) @binding(0) var<uniform> Ps : S; // Host sharable |
| @group(0) @binding(1) var<uniform> Pv4 : vec4<f32>; // Host sharable |
| @group(0) @binding(2) var<uniform> Pv2 : vec2<f32>; // Host sharable |
| )"; |
| |
| EXPECT_FALSE(ShouldRun<PackedVec3>(src)); |
| } |
| |
| TEST_F(PackedVec3Test, ShouldRun_OtherMatrices) { |
| auto* src = R"( |
| struct S { |
| m2x2 : mat2x2<f32>, |
| m2x4 : mat2x4<f32>, |
| m3x2 : mat3x2<f32>, |
| m3x4 : mat3x4<f32>, |
| m4x2 : mat4x2<f32>, |
| m4x4 : mat4x4<f32>, |
| } |
| |
| @group(0) @binding(0) var<uniform> Ps : S; // Host sharable |
| @group(0) @binding(1) var<uniform> Pm2x2 : mat2x2<f32>; // Host sharable |
| @group(0) @binding(2) var<uniform> Pm2x4 : mat2x4<f32>; // Host sharable |
| @group(0) @binding(3) var<uniform> Pm3x2 : mat3x2<f32>; // Host sharable |
| @group(0) @binding(4) var<uniform> Pm3x4 : mat3x4<f32>; // Host sharable |
| @group(0) @binding(5) var<uniform> Pm4x2 : mat4x2<f32>; // Host sharable |
| @group(0) @binding(6) var<uniform> Pm4x4 : mat4x4<f32>; // Host sharable |
| )"; |
| |
| EXPECT_FALSE(ShouldRun<PackedVec3>(src)); |
| } |
| |
| TEST_F(PackedVec3Test, ShouldRun_ArrayOfNonVec3) { |
| auto* src = R"( |
| struct S { |
| arr_v : array<vec2<f32>, 4>, |
| arr_m : array<mat3x2<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage> Ps : S; // Host sharable |
| @group(0) @binding(1) var<storage> Parr_v : array<vec2<f32>, 4>; // Host sharable |
| @group(0) @binding(2) var<storage> Parr_m : array<mat3x2<f32>, 4>; // Host sharable |
| )"; |
| |
| EXPECT_FALSE(ShouldRun<PackedVec3>(src)); |
| } |
| |
| TEST_F(PackedVec3Test, ShouldRun_HostSharable_Vec3) { |
| auto* src = R"( |
| @group(0) @binding(0) var<uniform> P : vec3<f32>; // Host sharable |
| )"; |
| |
| EXPECT_TRUE(ShouldRun<PackedVec3>(src)); |
| } |
| |
| TEST_F(PackedVec3Test, ShouldRun_HostSharable_Mat3x3) { |
| auto* src = R"( |
| @group(0) @binding(0) var<uniform> P : mat3x3<f32>; // Host sharable |
| )"; |
| |
| EXPECT_TRUE(ShouldRun<PackedVec3>(src)); |
| } |
| |
| TEST_F(PackedVec3Test, ShouldRun_HostSharable_ArrayOfVec3) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> P : array<vec3<f32>>; // Host sharable |
| )"; |
| |
| EXPECT_TRUE(ShouldRun<PackedVec3>(src)); |
| } |
| |
| TEST_F(PackedVec3Test, ShouldRun_HostSharable_ArrayOfMat3x3) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> P : array<mat3x3<f32>>; // Host sharable |
| )"; |
| |
| EXPECT_TRUE(ShouldRun<PackedVec3>(src)); |
| } |
| |
| TEST_F(PackedVec3Test, ShouldRun_HostSharableStruct_Vec3) { |
| auto* src = R"( |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<uniform> P : S; // Host sharable |
| )"; |
| |
| EXPECT_TRUE(ShouldRun<PackedVec3>(src)); |
| } |
| |
| TEST_F(PackedVec3Test, ShouldRun_HostSharableStruct_Mat3x3) { |
| auto* src = R"( |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<uniform> P : S; // Host sharable |
| )"; |
| |
| EXPECT_TRUE(ShouldRun<PackedVec3>(src)); |
| } |
| |
| TEST_F(PackedVec3Test, ShouldRun_HostSharableStruct_ArrayOfVec3) { |
| auto* src = R"( |
| struct S { |
| a : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<uniform> P : S; // Host sharable |
| )"; |
| |
| EXPECT_TRUE(ShouldRun<PackedVec3>(src)); |
| } |
| |
| TEST_F(PackedVec3Test, ShouldRun_HostSharableStruct_ArrayOfMat3x3) { |
| auto* src = R"( |
| struct S { |
| a : array<mat3x3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<uniform> P : S; // Host sharable |
| )"; |
| |
| EXPECT_TRUE(ShouldRun<PackedVec3>(src)); |
| } |
| |
| TEST_F(PackedVec3Test, Vec3_ReadVector) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> v : vec3<f32>; |
| |
| fn f() { |
| let x = v; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| @group(0) @binding(0) var<storage> v : __packed_vec3<f32>; |
| |
| fn f() { |
| let x = vec3<f32>(v); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Vec3_ReadComponent_MemberAccessChain) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> v : vec3<f32>; |
| |
| fn f() { |
| let x = v.yz.x; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| @group(0) @binding(0) var<storage> v : __packed_vec3<f32>; |
| |
| fn f() { |
| let x = vec3<f32>(v).yz.x; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Vec3_ReadComponent_IndexAccessor) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> v : vec3<f32>; |
| |
| fn f() { |
| let x = v[1]; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| @group(0) @binding(0) var<storage> v : __packed_vec3<f32>; |
| |
| fn f() { |
| let x = v[1]; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Vec3_WriteVector_ValueRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> v : vec3<f32>; |
| |
| fn f() { |
| v = vec3(1.23); |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| @group(0) @binding(0) var<storage, read_write> v : __packed_vec3<f32>; |
| |
| fn f() { |
| v = __packed_vec3<f32>(vec3(1.22999999999999998224)); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Vec3_WriteVector_RefRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> v : vec3<f32>; |
| @group(0) @binding(1) var<uniform> in : vec3<f32>; |
| |
| fn f() { |
| v = in; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| @group(0) @binding(0) var<storage, read_write> v : __packed_vec3<f32>; |
| |
| @group(0) @binding(1) var<uniform> in : __packed_vec3<f32>; |
| |
| fn f() { |
| v = in; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Vec3_WriteComponent_MemberAccessor) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> v : vec3<f32>; |
| |
| fn f() { |
| v.y = 1.23; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| @group(0) @binding(0) var<storage, read_write> v : __packed_vec3<f32>; |
| |
| fn f() { |
| v.y = 1.22999999999999998224; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Vec3_WriteComponent_IndexAccessor) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> v : vec3<f32>; |
| |
| fn f() { |
| v[1] = 1.23; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| @group(0) @binding(0) var<storage, read_write> v : __packed_vec3<f32>; |
| |
| fn f() { |
| v[1] = 1.22999999999999998224; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfVec3_ReadArray) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> arr : array<vec3<f32>, 4>; |
| |
| fn f() { |
| let x = arr; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| fn tint_unpack_vec3_in_composite(in : array<tint_packed_vec3_f32_array_element, 4u>) -> array<vec3<f32>, 4u> { |
| var result : array<vec3<f32>, 4u>; |
| for(var i : u32; (i < 4u); i = (i + 1)) { |
| result[i] = vec3<f32>(in[i].elements); |
| } |
| return result; |
| } |
| |
| @group(0) @binding(0) var<storage> arr : array<tint_packed_vec3_f32_array_element, 4u>; |
| |
| fn f() { |
| let x = tint_unpack_vec3_in_composite(arr); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfVec3_ReadVector) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> arr : array<vec3<f32>, 4>; |
| |
| fn f() { |
| let x = arr[0]; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> arr : array<tint_packed_vec3_f32_array_element, 4u>; |
| |
| fn f() { |
| let x = vec3<f32>(arr[0].elements); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfVec3_ReadComponent_MemberAccessor) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> arr : array<vec3<f32>, 4>; |
| |
| fn f() { |
| let x = arr[0].y; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> arr : array<tint_packed_vec3_f32_array_element, 4u>; |
| |
| fn f() { |
| let x = arr[0].elements.y; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfVec3_ReadComponent_IndexAccessor) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> arr : array<vec3<f32>, 4>; |
| |
| fn f() { |
| let x = arr[0][1]; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> arr : array<tint_packed_vec3_f32_array_element, 4u>; |
| |
| fn f() { |
| let x = arr[0].elements[1]; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfVec3_WriteArray_ValueRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> arr : array<vec3<f32>, 2>; |
| |
| fn f() { |
| arr = array(vec3(1.5, 2.5, 3.5), vec3(4.5, 5.5, 6.5)); |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| fn tint_pack_vec3_in_composite(in : array<vec3<f32>, 2u>) -> array<tint_packed_vec3_f32_array_element, 2u> { |
| var result : array<tint_packed_vec3_f32_array_element, 2u>; |
| for(var i : u32; (i < 2u); i = (i + 1)) { |
| result[i] = tint_packed_vec3_f32_array_element(__packed_vec3<f32>(in[i])); |
| } |
| return result; |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> arr : array<tint_packed_vec3_f32_array_element, 2u>; |
| |
| fn f() { |
| arr = tint_pack_vec3_in_composite(array(vec3(1.5, 2.5, 3.5), vec3(4.5, 5.5, 6.5))); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfVec3_WriteArray_RefRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> arr : array<vec3<f32>, 2>; |
| @group(0) @binding(1) var<uniform> in : array<vec3<f32>, 2>; |
| |
| fn f() { |
| arr = in; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> arr : array<tint_packed_vec3_f32_array_element, 2u>; |
| |
| @group(0) @binding(1) var<uniform> in : array<tint_packed_vec3_f32_array_element, 2u>; |
| |
| fn f() { |
| arr = in; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfVec3_WriteVector_ValueRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> arr : array<vec3<f32>, 4>; |
| |
| fn f() { |
| arr[0] = vec3(1.23); |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> arr : array<tint_packed_vec3_f32_array_element, 4u>; |
| |
| fn f() { |
| arr[0].elements = __packed_vec3<f32>(vec3(1.22999999999999998224)); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfVec3_WriteVector_RefRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> arr : array<vec3<f32>, 4>; |
| @group(0) @binding(1) var<uniform> in_arr : array<vec3<f32>, 4>; |
| @group(0) @binding(2) var<uniform> in_vec : vec3<f32>; |
| |
| fn f() { |
| arr[0] = in_arr[0]; |
| arr[1] = in_vec; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> arr : array<tint_packed_vec3_f32_array_element, 4u>; |
| |
| @group(0) @binding(1) var<uniform> in_arr : array<tint_packed_vec3_f32_array_element, 4u>; |
| |
| @group(0) @binding(2) var<uniform> in_vec : __packed_vec3<f32>; |
| |
| fn f() { |
| arr[0].elements = in_arr[0].elements; |
| arr[1].elements = in_vec; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfVec3_WriteComponent_MemberAccessor) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> arr : array<vec3<f32>, 4>; |
| |
| fn f() { |
| arr[0].y = 1.23; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> arr : array<tint_packed_vec3_f32_array_element, 4u>; |
| |
| fn f() { |
| arr[0].elements.y = 1.22999999999999998224; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfVec3_WriteComponent_IndexAccessor) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> arr : array<vec3<f32>, 4>; |
| |
| fn f() { |
| arr[0][1] = 1.23; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> arr : array<tint_packed_vec3_f32_array_element, 4u>; |
| |
| fn f() { |
| arr[0].elements[1] = 1.22999999999999998224; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Matrix_ReadMatrix) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> m : mat3x3<f32>; |
| |
| fn f() { |
| let x = m; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| fn tint_unpack_vec3_in_composite(in : array<tint_packed_vec3_f32_array_element, 3u>) -> mat3x3<f32> { |
| var result : mat3x3<f32>; |
| for(var i : u32; (i < 3u); i = (i + 1)) { |
| result[i] = vec3<f32>(in[i].elements); |
| } |
| return result; |
| } |
| |
| @group(0) @binding(0) var<storage> m : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| fn f() { |
| let x = tint_unpack_vec3_in_composite(m); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Matrix_ReadColumn) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> m : mat3x3<f32>; |
| |
| fn f() { |
| let x = m[1]; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> m : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| fn f() { |
| let x = vec3<f32>(m[1].elements); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Matrix_ReadComponent_MemberAccessChain) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> m : mat3x3<f32>; |
| |
| fn f() { |
| let x = m[1].yz.x; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> m : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| fn f() { |
| let x = vec3<f32>(m[1].elements).yz.x; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Matrix_ReadComponent_IndexAccessor) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> m : mat3x3<f32>; |
| |
| fn f() { |
| let x = m[2][1]; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> m : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| fn f() { |
| let x = m[2].elements[1]; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Matrix_WriteMatrix_ValueRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> m : mat3x3<f32>; |
| |
| fn f() { |
| m = mat3x3(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5); |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| fn tint_pack_vec3_in_composite(in : mat3x3<f32>) -> array<tint_packed_vec3_f32_array_element, 3u> { |
| var result : array<tint_packed_vec3_f32_array_element, 3u>; |
| for(var i : u32; (i < 3u); i = (i + 1)) { |
| result[i] = tint_packed_vec3_f32_array_element(__packed_vec3<f32>(in[i])); |
| } |
| return result; |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> m : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| fn f() { |
| m = tint_pack_vec3_in_composite(mat3x3(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5)); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Matrix_WriteMatrix_RefRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> m : mat3x3<f32>; |
| @group(0) @binding(1) var<uniform> in : mat3x3<f32>; |
| |
| fn f() { |
| m = in; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> m : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| @group(0) @binding(1) var<uniform> in : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| fn f() { |
| m = in; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Matrix_WriteColumn_ValueRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> m : mat3x3<f32>; |
| |
| fn f() { |
| m[1] = vec3(1.23); |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> m : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| fn f() { |
| m[1].elements = __packed_vec3<f32>(vec3(1.22999999999999998224)); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Matrix_WriteColumn_RefRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> m : mat3x3<f32>; |
| @group(0) @binding(1) var<uniform> in_mat : mat3x3<f32>; |
| @group(0) @binding(1) var<uniform> in_vec : vec3<f32>; |
| |
| fn f() { |
| m[0] = in_mat[0]; |
| m[1] = in_vec; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> m : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| @group(0) @binding(1) var<uniform> in_mat : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| @group(0) @binding(1) var<uniform> in_vec : __packed_vec3<f32>; |
| |
| fn f() { |
| m[0].elements = in_mat[0].elements; |
| m[1].elements = in_vec; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Matrix_WriteComponent_MemberAccessor) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> m : mat3x3<f32>; |
| |
| fn f() { |
| m[1].y = 1.23; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> m : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| fn f() { |
| m[1].elements.y = 1.22999999999999998224; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, Matrix_WriteComponent_IndexAccessor) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> m : mat3x3<f32>; |
| |
| fn f() { |
| m[1][2] = 1.23; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> m : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| fn f() { |
| m[1].elements[2] = 1.22999999999999998224; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfMatrix_ReadArray) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> arr : array<mat3x3<f32>, 4>; |
| |
| fn f() { |
| let x = arr; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| fn tint_unpack_vec3_in_composite(in : array<tint_packed_vec3_f32_array_element, 3u>) -> mat3x3<f32> { |
| var result : mat3x3<f32>; |
| for(var i : u32; (i < 3u); i = (i + 1)) { |
| result[i] = vec3<f32>(in[i].elements); |
| } |
| return result; |
| } |
| |
| fn tint_unpack_vec3_in_composite_1(in : array<array<tint_packed_vec3_f32_array_element, 3u>, 4u>) -> array<mat3x3<f32>, 4u> { |
| var result : array<mat3x3<f32>, 4u>; |
| for(var i : u32; (i < 4u); i = (i + 1)) { |
| result[i] = tint_unpack_vec3_in_composite(in[i]); |
| } |
| return result; |
| } |
| |
| @group(0) @binding(0) var<storage> arr : array<array<tint_packed_vec3_f32_array_element, 3u>, 4u>; |
| |
| fn f() { |
| let x = tint_unpack_vec3_in_composite_1(arr); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfMatrix_ReadMatrix) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> arr : array<mat3x3<f32>, 4>; |
| |
| fn f() { |
| let x = arr[0]; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| fn tint_unpack_vec3_in_composite(in : array<tint_packed_vec3_f32_array_element, 3u>) -> mat3x3<f32> { |
| var result : mat3x3<f32>; |
| for(var i : u32; (i < 3u); i = (i + 1)) { |
| result[i] = vec3<f32>(in[i].elements); |
| } |
| return result; |
| } |
| |
| @group(0) @binding(0) var<storage> arr : array<array<tint_packed_vec3_f32_array_element, 3u>, 4u>; |
| |
| fn f() { |
| let x = tint_unpack_vec3_in_composite(arr[0]); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfMatrix_ReadColumn) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> arr : array<mat3x3<f32>, 4>; |
| |
| fn f() { |
| let x = arr[0][1]; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> arr : array<array<tint_packed_vec3_f32_array_element, 3u>, 4u>; |
| |
| fn f() { |
| let x = vec3<f32>(arr[0][1].elements); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfMatrix_ReadComponent_MemberAccessor) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> arr : array<mat3x3<f32>, 4>; |
| |
| fn f() { |
| let x = arr[0][1].y; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> arr : array<array<tint_packed_vec3_f32_array_element, 3u>, 4u>; |
| |
| fn f() { |
| let x = arr[0][1].elements.y; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfMatrix_ReadComponent_IndexAccessor) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage> arr : array<mat3x3<f32>, 4>; |
| |
| fn f() { |
| let x = arr[0][1][2]; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> arr : array<array<tint_packed_vec3_f32_array_element, 3u>, 4u>; |
| |
| fn f() { |
| let x = arr[0][1].elements[2]; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfMatrix_WriteArray_ValueRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> arr : array<mat3x3<f32>, 2>; |
| |
| fn f() { |
| arr = array(mat3x3<f32>(), mat3x3(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5)); |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| fn tint_pack_vec3_in_composite(in : mat3x3<f32>) -> array<tint_packed_vec3_f32_array_element, 3u> { |
| var result : array<tint_packed_vec3_f32_array_element, 3u>; |
| for(var i : u32; (i < 3u); i = (i + 1)) { |
| result[i] = tint_packed_vec3_f32_array_element(__packed_vec3<f32>(in[i])); |
| } |
| return result; |
| } |
| |
| fn tint_pack_vec3_in_composite_1(in : array<mat3x3<f32>, 2u>) -> array<array<tint_packed_vec3_f32_array_element, 3u>, 2u> { |
| var result : array<array<tint_packed_vec3_f32_array_element, 3u>, 2u>; |
| for(var i : u32; (i < 2u); i = (i + 1)) { |
| result[i] = tint_pack_vec3_in_composite(in[i]); |
| } |
| return result; |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> arr : array<array<tint_packed_vec3_f32_array_element, 3u>, 2u>; |
| |
| fn f() { |
| arr = tint_pack_vec3_in_composite_1(array(mat3x3<f32>(), mat3x3(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5))); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfMatrix_WriteArray_RefRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> arr : array<mat3x3<f32>, 2>; |
| @group(0) @binding(1) var<uniform> in : array<mat3x3<f32>, 2>; |
| |
| fn f() { |
| arr = in; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> arr : array<array<tint_packed_vec3_f32_array_element, 3u>, 2u>; |
| |
| @group(0) @binding(1) var<uniform> in : array<array<tint_packed_vec3_f32_array_element, 3u>, 2u>; |
| |
| fn f() { |
| arr = in; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfMatrix_WriteMatrix_ValueRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> arr : array<mat3x3<f32>, 4>; |
| |
| fn f() { |
| arr[0] = mat3x3(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9); |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| fn tint_pack_vec3_in_composite(in : mat3x3<f32>) -> array<tint_packed_vec3_f32_array_element, 3u> { |
| var result : array<tint_packed_vec3_f32_array_element, 3u>; |
| for(var i : u32; (i < 3u); i = (i + 1)) { |
| result[i] = tint_packed_vec3_f32_array_element(__packed_vec3<f32>(in[i])); |
| } |
| return result; |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> arr : array<array<tint_packed_vec3_f32_array_element, 3u>, 4u>; |
| |
| fn f() { |
| arr[0] = tint_pack_vec3_in_composite(mat3x3(1.10000000000000008882, 2.20000000000000017764, 3.29999999999999982236, 4.40000000000000035527, 5.5, 6.59999999999999964473, 7.70000000000000017764, 8.80000000000000071054, 9.90000000000000035527)); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfMatrix_WriteMatrix_RefRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> arr : array<mat3x3<f32>, 4>; |
| @group(0) @binding(1) var<uniform> in_arr : array<mat3x3<f32>, 4>; |
| @group(0) @binding(2) var<uniform> in_mat : mat3x3<f32>; |
| |
| fn f() { |
| arr[0] = in_arr[0]; |
| arr[1] = in_mat; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> arr : array<array<tint_packed_vec3_f32_array_element, 3u>, 4u>; |
| |
| @group(0) @binding(1) var<uniform> in_arr : array<array<tint_packed_vec3_f32_array_element, 3u>, 4u>; |
| |
| @group(0) @binding(2) var<uniform> in_mat : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| fn f() { |
| arr[0] = in_arr[0]; |
| arr[1] = in_mat; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfMatrix_WriteVector_ValueRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> arr : array<mat3x3<f32>, 4>; |
| |
| fn f() { |
| arr[0][1] = vec3(1.23); |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> arr : array<array<tint_packed_vec3_f32_array_element, 3u>, 4u>; |
| |
| fn f() { |
| arr[0][1].elements = __packed_vec3<f32>(vec3(1.22999999999999998224)); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfMatrix_WriteVector_RefRHS) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> arr : array<mat3x3<f32>, 4>; |
| @group(0) @binding(1) var<uniform> in_arr : array<mat3x3<f32>, 4>; |
| @group(0) @binding(2) var<uniform> in_mat : mat3x3<f32>; |
| @group(0) @binding(3) var<uniform> in_vec : vec3<f32>; |
| |
| fn f() { |
| arr[0][0] = arr[0][1]; |
| arr[0][1] = in_mat[2]; |
| arr[0][2] = in_vec; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> arr : array<array<tint_packed_vec3_f32_array_element, 3u>, 4u>; |
| |
| @group(0) @binding(1) var<uniform> in_arr : array<array<tint_packed_vec3_f32_array_element, 3u>, 4u>; |
| |
| @group(0) @binding(2) var<uniform> in_mat : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| @group(0) @binding(3) var<uniform> in_vec : __packed_vec3<f32>; |
| |
| fn f() { |
| arr[0][0].elements = arr[0][1].elements; |
| arr[0][1].elements = in_mat[2].elements; |
| arr[0][2].elements = in_vec; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfMatrix_WriteComponent_MemberAccessor) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> arr : array<mat3x3<f32>, 4>; |
| |
| fn f() { |
| arr[0][1].y = 1.23; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> arr : array<array<tint_packed_vec3_f32_array_element, 3u>, 4u>; |
| |
| fn f() { |
| arr[0][1].elements.y = 1.22999999999999998224; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, ArrayOfMatrix_WriteComponent_IndexAccessor) { |
| auto* src = R"( |
| @group(0) @binding(0) var<storage, read_write> arr : array<mat3x3<f32>, 4>; |
| |
| fn f() { |
| arr[0][1][2] = 1.23; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> arr : array<array<tint_packed_vec3_f32_array_element, 3u>, 4u>; |
| |
| fn f() { |
| arr[0][1].elements[2] = 1.22999999999999998224; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Vec3_ReadStruct) { |
| auto* src = R"( |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S; |
| |
| fn f() { |
| let x = P; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| v : __packed_vec3<f32>, |
| } |
| |
| fn tint_unpack_vec3_in_composite(in : S_tint_packed_vec3) -> S { |
| var result : S; |
| result.v = vec3<f32>(in.v); |
| return result; |
| } |
| |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S_tint_packed_vec3; |
| |
| fn f() { |
| let x = tint_unpack_vec3_in_composite(P); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Vec3_ReadVector) { |
| auto* src = R"( |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S; |
| |
| fn f() { |
| let x = P.v; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| v : __packed_vec3<f32>, |
| } |
| |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S_tint_packed_vec3; |
| |
| fn f() { |
| let x = vec3<f32>(P.v); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Vec3_ReadComponent_MemberAccessChain) { |
| auto* src = R"( |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S; |
| |
| fn f() { |
| let x = P.v.yz.x; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| v : __packed_vec3<f32>, |
| } |
| |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S_tint_packed_vec3; |
| |
| fn f() { |
| let x = vec3<f32>(P.v).yz.x; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Vec3_ReadComponent_IndexAccessor) { |
| auto* src = R"( |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S; |
| |
| fn f() { |
| let x = P.v[1]; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| v : __packed_vec3<f32>, |
| } |
| |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S_tint_packed_vec3; |
| |
| fn f() { |
| let x = P.v[1]; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Vec3_WriteStruct_ValueRHS) { |
| auto* src = R"( |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| |
| fn f() { |
| P = S(vec3(1.23)); |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| v : __packed_vec3<f32>, |
| } |
| |
| fn tint_pack_vec3_in_composite(in : S) -> S_tint_packed_vec3 { |
| var result : S_tint_packed_vec3; |
| result.v = __packed_vec3<f32>(in.v); |
| return result; |
| } |
| |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| fn f() { |
| P = tint_pack_vec3_in_composite(S(vec3(1.22999999999999998224))); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Vec3_WriteStruct_RefRHS) { |
| auto* src = R"( |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| @group(0) @binding(1) var<uniform> in : S; |
| |
| fn f() { |
| P = in; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| v : __packed_vec3<f32>, |
| } |
| |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| @group(0) @binding(1) var<uniform> in : S_tint_packed_vec3; |
| |
| fn f() { |
| P = in; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Vec3_WriteVector_ValueRHS) { |
| auto* src = R"( |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| |
| fn f() { |
| P.v = vec3(1.23); |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| v : __packed_vec3<f32>, |
| } |
| |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| fn f() { |
| P.v = __packed_vec3<f32>(vec3(1.22999999999999998224)); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Vec3_WriteVector_RefRHS) { |
| auto* src = R"( |
| struct S { |
| v1 : vec3<f32>, |
| v2 : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| @group(0) @binding(1) var<uniform> in_str : S; |
| @group(0) @binding(2) var<uniform> in_vec : vec3<f32>; |
| |
| fn f() { |
| P.v1 = in_str.v1; |
| P.v2 = in_vec; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| v1 : __packed_vec3<f32>, |
| @align(16) |
| v2 : __packed_vec3<f32>, |
| } |
| |
| struct S { |
| v1 : vec3<f32>, |
| v2 : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| @group(0) @binding(1) var<uniform> in_str : S_tint_packed_vec3; |
| |
| @group(0) @binding(2) var<uniform> in_vec : __packed_vec3<f32>; |
| |
| fn f() { |
| P.v1 = in_str.v1; |
| P.v2 = in_vec; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Vec3_WriteComponent_MemberAccessor) { |
| auto* src = R"( |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| |
| fn f() { |
| P.v.y = 1.23; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| v : __packed_vec3<f32>, |
| } |
| |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| fn f() { |
| P.v.y = 1.22999999999999998224; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Vec3_WriteComponent_IndexAccessor) { |
| auto* src = R"( |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| |
| fn f() { |
| P.v[1] = 1.23; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| v : __packed_vec3<f32>, |
| } |
| |
| struct S { |
| v : vec3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| fn f() { |
| P.v[1] = 1.22999999999999998224; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_ArrayOfVec3_ReadStruct) { |
| auto* src = R"( |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S; |
| |
| fn f() { |
| let x = P; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| arr : array<tint_packed_vec3_f32_array_element, 4u>, |
| } |
| |
| fn tint_unpack_vec3_in_composite(in : array<tint_packed_vec3_f32_array_element, 4u>) -> array<vec3<f32>, 4u> { |
| var result : array<vec3<f32>, 4u>; |
| for(var i : u32; (i < 4u); i = (i + 1)) { |
| result[i] = vec3<f32>(in[i].elements); |
| } |
| return result; |
| } |
| |
| fn tint_unpack_vec3_in_composite_1(in : S_tint_packed_vec3) -> S { |
| var result : S; |
| result.arr = tint_unpack_vec3_in_composite(in.arr); |
| return result; |
| } |
| |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S_tint_packed_vec3; |
| |
| fn f() { |
| let x = tint_unpack_vec3_in_composite_1(P); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_ArrayOfVec3_ReadArray) { |
| auto* src = R"( |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S; |
| |
| fn f() { |
| let x = P.arr; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| arr : array<tint_packed_vec3_f32_array_element, 4u>, |
| } |
| |
| fn tint_unpack_vec3_in_composite(in : array<tint_packed_vec3_f32_array_element, 4u>) -> array<vec3<f32>, 4u> { |
| var result : array<vec3<f32>, 4u>; |
| for(var i : u32; (i < 4u); i = (i + 1)) { |
| result[i] = vec3<f32>(in[i].elements); |
| } |
| return result; |
| } |
| |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S_tint_packed_vec3; |
| |
| fn f() { |
| let x = tint_unpack_vec3_in_composite(P.arr); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_ArrayOfVec3_ReadVector) { |
| auto* src = R"( |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S; |
| |
| fn f() { |
| let x = P.arr[0]; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| arr : array<tint_packed_vec3_f32_array_element, 4u>, |
| } |
| |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S_tint_packed_vec3; |
| |
| fn f() { |
| let x = vec3<f32>(P.arr[0].elements); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_ArrayOfVec3_ReadComponent_MemberAccessor) { |
| auto* src = R"( |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S; |
| |
| fn f() { |
| let x = P.arr[0].y; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| arr : array<tint_packed_vec3_f32_array_element, 4u>, |
| } |
| |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S_tint_packed_vec3; |
| |
| fn f() { |
| let x = P.arr[0].elements.y; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_ArrayOfVec3_ReadComponent_IndexAccessor) { |
| auto* src = R"( |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S; |
| |
| fn f() { |
| let x = P.arr[0][1]; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| arr : array<tint_packed_vec3_f32_array_element, 4u>, |
| } |
| |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S_tint_packed_vec3; |
| |
| fn f() { |
| let x = P.arr[0].elements[1]; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_ArrayOfVec3_WriteStruct_ValueRHS) { |
| auto* src = R"( |
| struct S { |
| arr : array<vec3<f32>, 2>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| |
| fn f() { |
| P = S(array(vec3(1.5, 4.5, 7.5), vec3(9.5, 6.5, 3.5))); |
| } |
| )"; |
| |
| auto* expect = |
| R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| arr : array<tint_packed_vec3_f32_array_element, 2u>, |
| } |
| |
| fn tint_pack_vec3_in_composite(in : array<vec3<f32>, 2u>) -> array<tint_packed_vec3_f32_array_element, 2u> { |
| var result : array<tint_packed_vec3_f32_array_element, 2u>; |
| for(var i : u32; (i < 2u); i = (i + 1)) { |
| result[i] = tint_packed_vec3_f32_array_element(__packed_vec3<f32>(in[i])); |
| } |
| return result; |
| } |
| |
| fn tint_pack_vec3_in_composite_1(in : S) -> S_tint_packed_vec3 { |
| var result : S_tint_packed_vec3; |
| result.arr = tint_pack_vec3_in_composite(in.arr); |
| return result; |
| } |
| |
| struct S { |
| arr : array<vec3<f32>, 2>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| fn f() { |
| P = tint_pack_vec3_in_composite_1(S(array(vec3(1.5, 4.5, 7.5), vec3(9.5, 6.5, 3.5)))); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_ArrayOfVec3_WriteStruct_RefRHS) { |
| auto* src = R"( |
| struct S { |
| arr : array<vec3<f32>, 2>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| @group(0) @binding(1) var<uniform> in : S; |
| |
| fn f() { |
| P = in; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| arr : array<tint_packed_vec3_f32_array_element, 2u>, |
| } |
| |
| struct S { |
| arr : array<vec3<f32>, 2>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| @group(0) @binding(1) var<uniform> in : S_tint_packed_vec3; |
| |
| fn f() { |
| P = in; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_ArrayOfVec3_WriteArray_ValueRHS) { |
| auto* src = R"( |
| struct S { |
| arr : array<vec3<f32>, 2>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| |
| fn f() { |
| P.arr = array(vec3(1.5, 4.5, 7.5), vec3(9.5, 6.5, 3.5)); |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| arr : array<tint_packed_vec3_f32_array_element, 2u>, |
| } |
| |
| fn tint_pack_vec3_in_composite(in : array<vec3<f32>, 2u>) -> array<tint_packed_vec3_f32_array_element, 2u> { |
| var result : array<tint_packed_vec3_f32_array_element, 2u>; |
| for(var i : u32; (i < 2u); i = (i + 1)) { |
| result[i] = tint_packed_vec3_f32_array_element(__packed_vec3<f32>(in[i])); |
| } |
| return result; |
| } |
| |
| struct S { |
| arr : array<vec3<f32>, 2>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| fn f() { |
| P.arr = tint_pack_vec3_in_composite(array(vec3(1.5, 4.5, 7.5), vec3(9.5, 6.5, 3.5))); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_ArrayOfVec3_WriteArray_RefRHS) { |
| auto* src = R"( |
| struct S { |
| arr1 : array<vec3<f32>, 2>, |
| arr2 : array<vec3<f32>, 2>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| @group(0) @binding(1) var<uniform> in_str : S; |
| @group(0) @binding(2) var<uniform> in_arr : array<vec3<f32>, 2>; |
| |
| fn f() { |
| P.arr1 = in_str.arr1; |
| P.arr2 = in_arr; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| arr1 : array<tint_packed_vec3_f32_array_element, 2u>, |
| @align(16) |
| arr2 : array<tint_packed_vec3_f32_array_element, 2u>, |
| } |
| |
| struct S { |
| arr1 : array<vec3<f32>, 2>, |
| arr2 : array<vec3<f32>, 2>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| @group(0) @binding(1) var<uniform> in_str : S_tint_packed_vec3; |
| |
| @group(0) @binding(2) var<uniform> in_arr : array<tint_packed_vec3_f32_array_element, 2u>; |
| |
| fn f() { |
| P.arr1 = in_str.arr1; |
| P.arr2 = in_arr; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_ArrayOfVec3_WriteVector_ValueRHS) { |
| auto* src = R"( |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| |
| fn f() { |
| P.arr[0] = vec3(1.23); |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| arr : array<tint_packed_vec3_f32_array_element, 4u>, |
| } |
| |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| fn f() { |
| P.arr[0].elements = __packed_vec3<f32>(vec3(1.22999999999999998224)); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_ArrayOfVec3_WriteVector_RefRHS) { |
| auto* src = R"( |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| @group(0) @binding(1) var<uniform> in_str : S; |
| @group(0) @binding(2) var<uniform> in_arr : array<vec3<f32>, 4>; |
| @group(0) @binding(3) var<uniform> in_vec : vec3<f32>; |
| |
| fn f() { |
| P.arr[0] = in_str.arr[0]; |
| P.arr[1] = in_arr[1]; |
| P.arr[2] = in_vec; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| arr : array<tint_packed_vec3_f32_array_element, 4u>, |
| } |
| |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| @group(0) @binding(1) var<uniform> in_str : S_tint_packed_vec3; |
| |
| @group(0) @binding(2) var<uniform> in_arr : array<tint_packed_vec3_f32_array_element, 4u>; |
| |
| @group(0) @binding(3) var<uniform> in_vec : __packed_vec3<f32>; |
| |
| fn f() { |
| P.arr[0].elements = in_str.arr[0].elements; |
| P.arr[1].elements = in_arr[1].elements; |
| P.arr[2].elements = in_vec; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_ArrayOfVec3_WriteComponent_MemberAccessor) { |
| auto* src = R"( |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| |
| fn f() { |
| P.arr[0].y = 1.23; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| arr : array<tint_packed_vec3_f32_array_element, 4u>, |
| } |
| |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| fn f() { |
| P.arr[0].elements.y = 1.22999999999999998224; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_ArrayOfVec3_WriteComponent_IndexAccessor) { |
| auto* src = R"( |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| |
| fn f() { |
| P.arr[0][1] = 1.23; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| arr : array<tint_packed_vec3_f32_array_element, 4u>, |
| } |
| |
| struct S { |
| arr : array<vec3<f32>, 4>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| fn f() { |
| P.arr[0].elements[1] = 1.22999999999999998224; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Matrix_ReadStruct) { |
| auto* src = R"( |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S; |
| |
| fn f() { |
| let x = P; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| m : array<tint_packed_vec3_f32_array_element, 3u>, |
| } |
| |
| fn tint_unpack_vec3_in_composite(in : array<tint_packed_vec3_f32_array_element, 3u>) -> mat3x3<f32> { |
| var result : mat3x3<f32>; |
| for(var i : u32; (i < 3u); i = (i + 1)) { |
| result[i] = vec3<f32>(in[i].elements); |
| } |
| return result; |
| } |
| |
| fn tint_unpack_vec3_in_composite_1(in : S_tint_packed_vec3) -> S { |
| var result : S; |
| result.m = tint_unpack_vec3_in_composite(in.m); |
| return result; |
| } |
| |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S_tint_packed_vec3; |
| |
| fn f() { |
| let x = tint_unpack_vec3_in_composite_1(P); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Matrix_ReadMatrix) { |
| auto* src = R"( |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S; |
| |
| fn f() { |
| let x = P.m; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| m : array<tint_packed_vec3_f32_array_element, 3u>, |
| } |
| |
| fn tint_unpack_vec3_in_composite(in : array<tint_packed_vec3_f32_array_element, 3u>) -> mat3x3<f32> { |
| var result : mat3x3<f32>; |
| for(var i : u32; (i < 3u); i = (i + 1)) { |
| result[i] = vec3<f32>(in[i].elements); |
| } |
| return result; |
| } |
| |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S_tint_packed_vec3; |
| |
| fn f() { |
| let x = tint_unpack_vec3_in_composite(P.m); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Matrix_ReadColumn) { |
| auto* src = R"( |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S; |
| |
| fn f() { |
| let x = P.m[1]; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| m : array<tint_packed_vec3_f32_array_element, 3u>, |
| } |
| |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S_tint_packed_vec3; |
| |
| fn f() { |
| let x = vec3<f32>(P.m[1].elements); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Matrix_ReadComponent_MemberAccessChain) { |
| auto* src = R"( |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S; |
| |
| fn f() { |
| let x = P.m[1].yz.x; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| m : array<tint_packed_vec3_f32_array_element, 3u>, |
| } |
| |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S_tint_packed_vec3; |
| |
| fn f() { |
| let x = vec3<f32>(P.m[1].elements).yz.x; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Matrix_ReadComponent_IndexAccessor) { |
| auto* src = R"( |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S; |
| |
| fn f() { |
| let x = P.m[2][1]; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| m : array<tint_packed_vec3_f32_array_element, 3u>, |
| } |
| |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage> P : S_tint_packed_vec3; |
| |
| fn f() { |
| let x = P.m[2].elements[1]; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Matrix_WriteStruct_ValueRHS) { |
| auto* src = R"( |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| |
| fn f() { |
| P = S(mat3x3(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5)); |
| } |
| )"; |
| |
| auto* expect = |
| R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| m : array<tint_packed_vec3_f32_array_element, 3u>, |
| } |
| |
| fn tint_pack_vec3_in_composite(in : mat3x3<f32>) -> array<tint_packed_vec3_f32_array_element, 3u> { |
| var result : array<tint_packed_vec3_f32_array_element, 3u>; |
| for(var i : u32; (i < 3u); i = (i + 1)) { |
| result[i] = tint_packed_vec3_f32_array_element(__packed_vec3<f32>(in[i])); |
| } |
| return result; |
| } |
| |
| fn tint_pack_vec3_in_composite_1(in : S) -> S_tint_packed_vec3 { |
| var result : S_tint_packed_vec3; |
| result.m = tint_pack_vec3_in_composite(in.m); |
| return result; |
| } |
| |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| fn f() { |
| P = tint_pack_vec3_in_composite_1(S(mat3x3(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5))); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Matrix_WriteStruct_RefRHS) { |
| auto* src = R"( |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| @group(0) @binding(1) var<uniform> in : S; |
| |
| fn f() { |
| P = in; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| m : array<tint_packed_vec3_f32_array_element, 3u>, |
| } |
| |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| @group(0) @binding(1) var<uniform> in : S_tint_packed_vec3; |
| |
| fn f() { |
| P = in; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Matrix_WriteMatrix_ValueRHS) { |
| auto* src = R"( |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| |
| fn f() { |
| P.m = mat3x3(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5); |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| m : array<tint_packed_vec3_f32_array_element, 3u>, |
| } |
| |
| fn tint_pack_vec3_in_composite(in : mat3x3<f32>) -> array<tint_packed_vec3_f32_array_element, 3u> { |
| var result : array<tint_packed_vec3_f32_array_element, 3u>; |
| for(var i : u32; (i < 3u); i = (i + 1)) { |
| result[i] = tint_packed_vec3_f32_array_element(__packed_vec3<f32>(in[i])); |
| } |
| return result; |
| } |
| |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| fn f() { |
| P.m = tint_pack_vec3_in_composite(mat3x3(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5)); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Matrix_WriteMatrix_RefRHS) { |
| auto* src = R"( |
| struct S { |
| m1 : mat3x3<f32>, |
| m2 : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| @group(0) @binding(1) var<uniform> in_str : S; |
| @group(0) @binding(2) var<uniform> in_mat : mat3x3<f32>; |
| |
| fn f() { |
| P.m1 = in_str.m1; |
| P.m2 = in_mat; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| m1 : array<tint_packed_vec3_f32_array_element, 3u>, |
| @align(16) |
| m2 : array<tint_packed_vec3_f32_array_element, 3u>, |
| } |
| |
| struct S { |
| m1 : mat3x3<f32>, |
| m2 : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| @group(0) @binding(1) var<uniform> in_str : S_tint_packed_vec3; |
| |
| @group(0) @binding(2) var<uniform> in_mat : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| fn f() { |
| P.m1 = in_str.m1; |
| P.m2 = in_mat; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Matrix_WriteColumn_ValueRHS) { |
| auto* src = R"( |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| |
| fn f() { |
| P.m[1] = vec3(1.23); |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| m : array<tint_packed_vec3_f32_array_element, 3u>, |
| } |
| |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| fn f() { |
| P.m[1].elements = __packed_vec3<f32>(vec3(1.22999999999999998224)); |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Matrix_WriteColumn_RefRHS) { |
| auto* src = R"( |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| @group(0) @binding(1) var<uniform> in_str : S; |
| @group(0) @binding(2) var<uniform> in_mat : mat3x3<f32>; |
| @group(0) @binding(3) var<uniform> in_vec : vec3<f32>; |
| |
| fn f() { |
| P.m[0] = in_str.m[0]; |
| P.m[1] = in_mat[1]; |
| P.m[2] = in_vec; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| m : array<tint_packed_vec3_f32_array_element, 3u>, |
| } |
| |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| @group(0) @binding(1) var<uniform> in_str : S_tint_packed_vec3; |
| |
| @group(0) @binding(2) var<uniform> in_mat : array<tint_packed_vec3_f32_array_element, 3u>; |
| |
| @group(0) @binding(3) var<uniform> in_vec : __packed_vec3<f32>; |
| |
| fn f() { |
| P.m[0].elements = in_str.m[0].elements; |
| P.m[1].elements = in_mat[1].elements; |
| P.m[2].elements = in_vec; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(expect, str(got)); |
| } |
| |
| TEST_F(PackedVec3Test, StructMember_Matrix_WriteComponent_MemberAccessor) { |
| auto* src = R"( |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S; |
| |
| fn f() { |
| P.m[1].y = 1.23; |
| } |
| )"; |
| |
| auto* expect = R"( |
| enable chromium_internal_relaxed_uniform_layout; |
| |
| struct tint_packed_vec3_f32_array_element { |
| @align(16) |
| elements : __packed_vec3<f32>, |
| } |
| |
| struct S_tint_packed_vec3 { |
| @align(16) |
| m : array<tint_packed_vec3_f32_array_element, 3u>, |
| } |
| |
| struct S { |
| m : mat3x3<f32>, |
| } |
| |
| @group(0) @binding(0) var<storage, read_write> P : S_tint_packed_vec3; |
| |
| fn f() { |
| P.m[1].elements.y = 1.22999999999999998224; |
| } |
| )"; |
| |
| DataMap data; |
| auto got = Run<PackedVec3>(src, data); |
| |
| EXPECT_EQ(exp
|