dan sinclair | 2a59901 | 2020-06-23 17:48:40 +0000 | [diff] [blame] | 1 | // Copyright 2020 The Tint Authors. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
dan sinclair | 5f81262 | 2020-09-22 14:53:03 +0000 | [diff] [blame] | 15 | #include "src/ast/stage_decoration.h" |
dan sinclair | 196e097 | 2020-11-13 18:13:24 +0000 | [diff] [blame] | 16 | #include "src/writer/msl/test_helper.h" |
dan sinclair | 2a59901 | 2020-06-23 17:48:40 +0000 | [diff] [blame] | 17 | |
| 18 | namespace tint { |
| 19 | namespace writer { |
| 20 | namespace msl { |
| 21 | namespace { |
| 22 | |
dan sinclair | 196e097 | 2020-11-13 18:13:24 +0000 | [diff] [blame] | 23 | using MslGeneratorImplTest = TestHelper; |
dan sinclair | 2a59901 | 2020-06-23 17:48:40 +0000 | [diff] [blame] | 24 | |
dan sinclair | 2dbe9aa | 2020-09-21 15:16:20 +0000 | [diff] [blame] | 25 | TEST_F(MslGeneratorImplTest, Generate) { |
Ben Clayton | 42d1e09 | 2021-02-02 14:29:15 +0000 | [diff] [blame] | 26 | Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, |
James Price | 95d4077 | 2021-03-11 17:39:32 +0000 | [diff] [blame] | 27 | ast::DecorationList{ |
Ben Clayton | 43073d8 | 2021-04-22 13:50:53 +0000 | [diff] [blame] | 28 | Stage(ast::PipelineStage::kCompute), |
Sarah | e6cb51e | 2021-06-29 18:39:44 +0000 | [diff] [blame] | 29 | WorkgroupSize(1), |
Ben Clayton | 42d1e09 | 2021-02-02 14:29:15 +0000 | [diff] [blame] | 30 | }); |
dan sinclair | 2a59901 | 2020-06-23 17:48:40 +0000 | [diff] [blame] | 31 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 32 | GeneratorImpl& gen = Build(); |
| 33 | |
dan sinclair | 196e097 | 2020-11-13 18:13:24 +0000 | [diff] [blame] | 34 | ASSERT_TRUE(gen.Generate()) << gen.error(); |
| 35 | EXPECT_EQ(gen.result(), R"(#include <metal_stdlib> |
dan sinclair | 2a59901 | 2020-06-23 17:48:40 +0000 | [diff] [blame] | 36 | |
dan sinclair | 2aaf7b5 | 2021-02-25 21:17:47 +0000 | [diff] [blame] | 37 | using namespace metal; |
dan sinclair | 987376c | 2021-01-12 04:34:53 +0000 | [diff] [blame] | 38 | kernel void my_func() { |
Ben Clayton | 7c59809 | 2021-01-13 16:34:51 +0000 | [diff] [blame] | 39 | return; |
dan sinclair | 2a59901 | 2020-06-23 17:48:40 +0000 | [diff] [blame] | 40 | } |
dan sinclair | 2dbe9aa | 2020-09-21 15:16:20 +0000 | [diff] [blame] | 41 | |
dan sinclair | 2a59901 | 2020-06-23 17:48:40 +0000 | [diff] [blame] | 42 | )"); |
| 43 | } |
| 44 | |
dan sinclair | 7caf6e5 | 2020-07-15 20:51:16 +0000 | [diff] [blame] | 45 | struct MslBuiltinData { |
| 46 | ast::Builtin builtin; |
| 47 | const char* attribute_name; |
| 48 | }; |
| 49 | inline std::ostream& operator<<(std::ostream& out, MslBuiltinData data) { |
| 50 | out << data.builtin; |
| 51 | return out; |
| 52 | } |
dan sinclair | 196e097 | 2020-11-13 18:13:24 +0000 | [diff] [blame] | 53 | using MslBuiltinConversionTest = TestParamHelper<MslBuiltinData>; |
dan sinclair | 7caf6e5 | 2020-07-15 20:51:16 +0000 | [diff] [blame] | 54 | TEST_P(MslBuiltinConversionTest, Emit) { |
| 55 | auto params = GetParam(); |
| 56 | |
Ben Clayton | f12054e | 2021-01-21 16:15:00 +0000 | [diff] [blame] | 57 | GeneratorImpl& gen = Build(); |
| 58 | |
dan sinclair | 196e097 | 2020-11-13 18:13:24 +0000 | [diff] [blame] | 59 | EXPECT_EQ(gen.builtin_to_attribute(params.builtin), |
dan sinclair | 7caf6e5 | 2020-07-15 20:51:16 +0000 | [diff] [blame] | 60 | std::string(params.attribute_name)); |
| 61 | } |
| 62 | INSTANTIATE_TEST_SUITE_P( |
| 63 | MslGeneratorImplTest, |
| 64 | MslBuiltinConversionTest, |
| 65 | testing::Values(MslBuiltinData{ast::Builtin::kPosition, "position"}, |
dan sinclair | d7335fa | 2021-01-18 15:51:13 +0000 | [diff] [blame] | 66 | MslBuiltinData{ast::Builtin::kVertexIndex, "vertex_id"}, |
| 67 | MslBuiltinData{ast::Builtin::kInstanceIndex, "instance_id"}, |
dan sinclair | 7caf6e5 | 2020-07-15 20:51:16 +0000 | [diff] [blame] | 68 | MslBuiltinData{ast::Builtin::kFrontFacing, "front_facing"}, |
dan sinclair | 7caf6e5 | 2020-07-15 20:51:16 +0000 | [diff] [blame] | 69 | MslBuiltinData{ast::Builtin::kFragDepth, "depth(any)"}, |
dan sinclair | 7caf6e5 | 2020-07-15 20:51:16 +0000 | [diff] [blame] | 70 | MslBuiltinData{ast::Builtin::kLocalInvocationId, |
| 71 | "thread_position_in_threadgroup"}, |
dan sinclair | d7335fa | 2021-01-18 15:51:13 +0000 | [diff] [blame] | 72 | MslBuiltinData{ast::Builtin::kLocalInvocationIndex, |
dan sinclair | 7caf6e5 | 2020-07-15 20:51:16 +0000 | [diff] [blame] | 73 | "thread_index_in_threadgroup"}, |
| 74 | MslBuiltinData{ast::Builtin::kGlobalInvocationId, |
James Price | 2b5acac | 2021-02-09 19:13:25 +0000 | [diff] [blame] | 75 | "thread_position_in_grid"}, |
James Price | 395b488 | 2021-04-16 19:57:34 +0000 | [diff] [blame] | 76 | MslBuiltinData{ast::Builtin::kWorkgroupId, |
| 77 | "threadgroup_position_in_grid"}, |
James Price | 922fce7 | 2021-09-13 17:11:58 +0000 | [diff] [blame] | 78 | MslBuiltinData{ast::Builtin::kNumWorkgroups, |
| 79 | "threadgroups_per_grid"}, |
James Price | e7dab3c | 2021-02-16 18:21:41 +0000 | [diff] [blame] | 80 | MslBuiltinData{ast::Builtin::kSampleIndex, "sample_id"}, |
James Price | 11e172a | 2021-08-05 16:21:59 +0000 | [diff] [blame] | 81 | MslBuiltinData{ast::Builtin::kSampleMask, "sample_mask"}, |
| 82 | MslBuiltinData{ast::Builtin::kPointSize, "point_size"})); |
dan sinclair | 7caf6e5 | 2020-07-15 20:51:16 +0000 | [diff] [blame] | 83 | |
James Price | 2c2aa2a | 2021-07-12 16:11:41 +0000 | [diff] [blame] | 84 | TEST_F(MslGeneratorImplTest, HasInvariantAttribute_True) { |
| 85 | auto* out = Structure( |
| 86 | "Out", {Member("pos", ty.vec4<f32>(), |
| 87 | {Builtin(ast::Builtin::kPosition), Invariant()})}); |
| 88 | Func("vert_main", ast::VariableList{}, ty.Of(out), |
| 89 | {Return(Construct(ty.Of(out)))}, {Stage(ast::PipelineStage::kVertex)}); |
| 90 | |
| 91 | GeneratorImpl& gen = Build(); |
| 92 | |
| 93 | ASSERT_TRUE(gen.Generate()) << gen.error(); |
| 94 | EXPECT_TRUE(gen.HasInvariant()); |
| 95 | EXPECT_EQ(gen.result(), R"(#include <metal_stdlib> |
| 96 | |
| 97 | using namespace metal; |
| 98 | struct Out { |
| 99 | float4 pos [[position]] [[invariant]]; |
| 100 | }; |
| 101 | |
| 102 | vertex Out vert_main() { |
| 103 | return {}; |
| 104 | } |
| 105 | |
| 106 | )"); |
| 107 | } |
| 108 | |
| 109 | TEST_F(MslGeneratorImplTest, HasInvariantAttribute_False) { |
| 110 | auto* out = Structure("Out", {Member("pos", ty.vec4<f32>(), |
| 111 | {Builtin(ast::Builtin::kPosition)})}); |
| 112 | Func("vert_main", ast::VariableList{}, ty.Of(out), |
| 113 | {Return(Construct(ty.Of(out)))}, {Stage(ast::PipelineStage::kVertex)}); |
| 114 | |
| 115 | GeneratorImpl& gen = Build(); |
| 116 | |
| 117 | ASSERT_TRUE(gen.Generate()) << gen.error(); |
| 118 | EXPECT_FALSE(gen.HasInvariant()); |
| 119 | EXPECT_EQ(gen.result(), R"(#include <metal_stdlib> |
| 120 | |
| 121 | using namespace metal; |
| 122 | struct Out { |
| 123 | float4 pos [[position]]; |
| 124 | }; |
| 125 | |
| 126 | vertex Out vert_main() { |
| 127 | return {}; |
| 128 | } |
| 129 | |
| 130 | )"); |
| 131 | } |
| 132 | |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 133 | TEST_F(MslGeneratorImplTest, WorkgroupMatrix) { |
| 134 | Global("m", ty.mat2x2<f32>(), ast::StorageClass::kWorkgroup); |
| 135 | Func("comp_main", ast::VariableList{}, ty.void_(), |
| 136 | {Decl(Const("x", nullptr, Expr("m")))}, |
| 137 | {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); |
| 138 | |
| 139 | GeneratorImpl& gen = SanitizeAndBuild(); |
| 140 | |
| 141 | ASSERT_TRUE(gen.Generate()) << gen.error(); |
| 142 | EXPECT_EQ(gen.result(), R"(#include <metal_stdlib> |
| 143 | |
| 144 | using namespace metal; |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 145 | struct tint_symbol_3 { |
| 146 | float2x2 m; |
| 147 | }; |
| 148 | |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 149 | void comp_main_inner(uint local_invocation_index, threadgroup float2x2* const tint_symbol) { |
| 150 | { |
| 151 | *(tint_symbol) = float2x2(); |
| 152 | } |
| 153 | threadgroup_barrier(mem_flags::mem_threadgroup); |
| 154 | float2x2 const x = *(tint_symbol); |
| 155 | } |
| 156 | |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 157 | kernel void comp_main(threadgroup tint_symbol_3* tint_symbol_2 [[threadgroup(0)]], uint local_invocation_index [[thread_index_in_threadgroup]]) { |
| 158 | comp_main_inner(local_invocation_index, &((*(tint_symbol_2)).m)); |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 159 | return; |
| 160 | } |
| 161 | |
| 162 | )"); |
| 163 | |
| 164 | auto allocations = gen.DynamicWorkgroupAllocations(); |
| 165 | ASSERT_TRUE(allocations.count("comp_main")); |
| 166 | ASSERT_EQ(allocations["comp_main"].size(), 1u); |
| 167 | EXPECT_EQ(allocations["comp_main"][0], 2u * 2u * sizeof(float)); |
| 168 | } |
| 169 | |
| 170 | TEST_F(MslGeneratorImplTest, WorkgroupMatrixInArray) { |
| 171 | Global("m", ty.array(ty.mat2x2<f32>(), 4), ast::StorageClass::kWorkgroup); |
| 172 | Func("comp_main", ast::VariableList{}, ty.void_(), |
| 173 | {Decl(Const("x", nullptr, Expr("m")))}, |
| 174 | {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); |
| 175 | |
| 176 | GeneratorImpl& gen = SanitizeAndBuild(); |
| 177 | |
| 178 | ASSERT_TRUE(gen.Generate()) << gen.error(); |
| 179 | EXPECT_EQ(gen.result(), R"(#include <metal_stdlib> |
| 180 | |
| 181 | using namespace metal; |
| 182 | struct tint_array_wrapper { |
| 183 | float2x2 arr[4]; |
| 184 | }; |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 185 | struct tint_symbol_3 { |
| 186 | tint_array_wrapper m; |
| 187 | }; |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 188 | |
| 189 | void comp_main_inner(uint local_invocation_index, threadgroup tint_array_wrapper* const tint_symbol) { |
| 190 | for(uint idx = local_invocation_index; (idx < 4u); idx = (idx + 1u)) { |
| 191 | uint const i = idx; |
| 192 | (*(tint_symbol)).arr[i] = float2x2(); |
| 193 | } |
| 194 | threadgroup_barrier(mem_flags::mem_threadgroup); |
| 195 | tint_array_wrapper const x = *(tint_symbol); |
| 196 | } |
| 197 | |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 198 | kernel void comp_main(threadgroup tint_symbol_3* tint_symbol_2 [[threadgroup(0)]], uint local_invocation_index [[thread_index_in_threadgroup]]) { |
| 199 | comp_main_inner(local_invocation_index, &((*(tint_symbol_2)).m)); |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 200 | return; |
| 201 | } |
| 202 | |
| 203 | )"); |
| 204 | |
| 205 | auto allocations = gen.DynamicWorkgroupAllocations(); |
| 206 | ASSERT_TRUE(allocations.count("comp_main")); |
| 207 | ASSERT_EQ(allocations["comp_main"].size(), 1u); |
| 208 | EXPECT_EQ(allocations["comp_main"][0], 4u * 2u * 2u * sizeof(float)); |
| 209 | } |
| 210 | |
| 211 | TEST_F(MslGeneratorImplTest, WorkgroupMatrixInStruct) { |
| 212 | Structure("S1", { |
| 213 | Member("m1", ty.mat2x2<f32>()), |
| 214 | Member("m2", ty.mat4x4<f32>()), |
| 215 | }); |
| 216 | Structure("S2", { |
| 217 | Member("s", ty.type_name("S1")), |
| 218 | }); |
| 219 | Global("s", ty.type_name("S2"), ast::StorageClass::kWorkgroup); |
| 220 | Func("comp_main", ast::VariableList{}, ty.void_(), |
| 221 | {Decl(Const("x", nullptr, Expr("s")))}, |
| 222 | {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); |
| 223 | |
| 224 | GeneratorImpl& gen = SanitizeAndBuild(); |
| 225 | |
| 226 | ASSERT_TRUE(gen.Generate()) << gen.error(); |
| 227 | EXPECT_EQ(gen.result(), R"(#include <metal_stdlib> |
| 228 | |
| 229 | using namespace metal; |
| 230 | struct S1 { |
| 231 | float2x2 m1; |
| 232 | float4x4 m2; |
| 233 | }; |
| 234 | struct S2 { |
| 235 | S1 s; |
| 236 | }; |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 237 | struct tint_symbol_4 { |
| 238 | S2 s; |
| 239 | }; |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 240 | |
| 241 | void comp_main_inner(uint local_invocation_index, threadgroup S2* const tint_symbol_1) { |
| 242 | { |
| 243 | S2 const tint_symbol = {}; |
| 244 | *(tint_symbol_1) = tint_symbol; |
| 245 | } |
| 246 | threadgroup_barrier(mem_flags::mem_threadgroup); |
| 247 | S2 const x = *(tint_symbol_1); |
| 248 | } |
| 249 | |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 250 | kernel void comp_main(threadgroup tint_symbol_4* tint_symbol_3 [[threadgroup(0)]], uint local_invocation_index [[thread_index_in_threadgroup]]) { |
| 251 | comp_main_inner(local_invocation_index, &((*(tint_symbol_3)).s)); |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 252 | return; |
| 253 | } |
| 254 | |
| 255 | )"); |
| 256 | |
| 257 | auto allocations = gen.DynamicWorkgroupAllocations(); |
| 258 | ASSERT_TRUE(allocations.count("comp_main")); |
| 259 | ASSERT_EQ(allocations["comp_main"].size(), 1u); |
| 260 | EXPECT_EQ(allocations["comp_main"][0], |
| 261 | (2 * 2 * sizeof(float)) + (4u * 4u * sizeof(float))); |
| 262 | } |
| 263 | |
| 264 | TEST_F(MslGeneratorImplTest, WorkgroupMatrix_Multiples) { |
| 265 | Global("m1", ty.mat2x2<f32>(), ast::StorageClass::kWorkgroup); |
| 266 | Global("m2", ty.mat2x3<f32>(), ast::StorageClass::kWorkgroup); |
| 267 | Global("m3", ty.mat2x4<f32>(), ast::StorageClass::kWorkgroup); |
| 268 | Global("m4", ty.mat3x2<f32>(), ast::StorageClass::kWorkgroup); |
| 269 | Global("m5", ty.mat3x3<f32>(), ast::StorageClass::kWorkgroup); |
| 270 | Global("m6", ty.mat3x4<f32>(), ast::StorageClass::kWorkgroup); |
| 271 | Global("m7", ty.mat4x2<f32>(), ast::StorageClass::kWorkgroup); |
| 272 | Global("m8", ty.mat4x3<f32>(), ast::StorageClass::kWorkgroup); |
| 273 | Global("m9", ty.mat4x4<f32>(), ast::StorageClass::kWorkgroup); |
| 274 | Func("main1", ast::VariableList{}, ty.void_(), |
| 275 | { |
| 276 | Decl(Const("a1", nullptr, Expr("m1"))), |
| 277 | Decl(Const("a2", nullptr, Expr("m2"))), |
| 278 | Decl(Const("a3", nullptr, Expr("m3"))), |
| 279 | }, |
| 280 | {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); |
| 281 | Func("main2", ast::VariableList{}, ty.void_(), |
| 282 | { |
| 283 | Decl(Const("a1", nullptr, Expr("m4"))), |
| 284 | Decl(Const("a2", nullptr, Expr("m5"))), |
| 285 | Decl(Const("a3", nullptr, Expr("m6"))), |
| 286 | }, |
| 287 | {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); |
| 288 | Func("main3", ast::VariableList{}, ty.void_(), |
| 289 | { |
| 290 | Decl(Const("a1", nullptr, Expr("m7"))), |
| 291 | Decl(Const("a2", nullptr, Expr("m8"))), |
| 292 | Decl(Const("a3", nullptr, Expr("m9"))), |
| 293 | }, |
| 294 | {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); |
| 295 | Func("main4_no_usages", ast::VariableList{}, ty.void_(), {}, |
| 296 | {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); |
| 297 | |
| 298 | GeneratorImpl& gen = SanitizeAndBuild(); |
| 299 | |
| 300 | ASSERT_TRUE(gen.Generate()) << gen.error(); |
| 301 | EXPECT_EQ(gen.result(), R"(#include <metal_stdlib> |
| 302 | |
| 303 | using namespace metal; |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 304 | struct tint_symbol_7 { |
| 305 | float2x2 m1; |
| 306 | float2x3 m2; |
| 307 | float2x4 m3; |
| 308 | }; |
| 309 | struct tint_symbol_15 { |
| 310 | float3x2 m4; |
| 311 | float3x3 m5; |
| 312 | float3x4 m6; |
| 313 | }; |
| 314 | struct tint_symbol_23 { |
| 315 | float4x2 m7; |
| 316 | float4x3 m8; |
| 317 | float4x4 m9; |
| 318 | }; |
| 319 | |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 320 | void main1_inner(uint local_invocation_index, threadgroup float2x2* const tint_symbol, threadgroup float2x3* const tint_symbol_1, threadgroup float2x4* const tint_symbol_2) { |
| 321 | { |
| 322 | *(tint_symbol) = float2x2(); |
| 323 | *(tint_symbol_1) = float2x3(); |
| 324 | *(tint_symbol_2) = float2x4(); |
| 325 | } |
| 326 | threadgroup_barrier(mem_flags::mem_threadgroup); |
| 327 | float2x2 const a1 = *(tint_symbol); |
| 328 | float2x3 const a2 = *(tint_symbol_1); |
| 329 | float2x4 const a3 = *(tint_symbol_2); |
| 330 | } |
| 331 | |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 332 | kernel void main1(threadgroup tint_symbol_7* tint_symbol_4 [[threadgroup(0)]], uint local_invocation_index [[thread_index_in_threadgroup]]) { |
| 333 | main1_inner(local_invocation_index, &((*(tint_symbol_4)).m1), &((*(tint_symbol_4)).m2), &((*(tint_symbol_4)).m3)); |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 334 | return; |
| 335 | } |
| 336 | |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 337 | void main2_inner(uint local_invocation_index_1, threadgroup float3x2* const tint_symbol_8, threadgroup float3x3* const tint_symbol_9, threadgroup float3x4* const tint_symbol_10) { |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 338 | { |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 339 | *(tint_symbol_8) = float3x2(); |
| 340 | *(tint_symbol_9) = float3x3(); |
| 341 | *(tint_symbol_10) = float3x4(); |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 342 | } |
| 343 | threadgroup_barrier(mem_flags::mem_threadgroup); |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 344 | float3x2 const a1 = *(tint_symbol_8); |
| 345 | float3x3 const a2 = *(tint_symbol_9); |
| 346 | float3x4 const a3 = *(tint_symbol_10); |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 347 | } |
| 348 | |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 349 | kernel void main2(threadgroup tint_symbol_15* tint_symbol_12 [[threadgroup(0)]], uint local_invocation_index_1 [[thread_index_in_threadgroup]]) { |
| 350 | main2_inner(local_invocation_index_1, &((*(tint_symbol_12)).m4), &((*(tint_symbol_12)).m5), &((*(tint_symbol_12)).m6)); |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 351 | return; |
| 352 | } |
| 353 | |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 354 | void main3_inner(uint local_invocation_index_2, threadgroup float4x2* const tint_symbol_16, threadgroup float4x3* const tint_symbol_17, threadgroup float4x4* const tint_symbol_18) { |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 355 | { |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 356 | *(tint_symbol_16) = float4x2(); |
| 357 | *(tint_symbol_17) = float4x3(); |
| 358 | *(tint_symbol_18) = float4x4(); |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 359 | } |
| 360 | threadgroup_barrier(mem_flags::mem_threadgroup); |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 361 | float4x2 const a1 = *(tint_symbol_16); |
| 362 | float4x3 const a2 = *(tint_symbol_17); |
| 363 | float4x4 const a3 = *(tint_symbol_18); |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 364 | } |
| 365 | |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 366 | kernel void main3(threadgroup tint_symbol_23* tint_symbol_20 [[threadgroup(0)]], uint local_invocation_index_2 [[thread_index_in_threadgroup]]) { |
| 367 | main3_inner(local_invocation_index_2, &((*(tint_symbol_20)).m7), &((*(tint_symbol_20)).m8), &((*(tint_symbol_20)).m9)); |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 368 | return; |
| 369 | } |
| 370 | |
| 371 | kernel void main4_no_usages() { |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | )"); |
| 376 | |
| 377 | auto allocations = gen.DynamicWorkgroupAllocations(); |
| 378 | ASSERT_TRUE(allocations.count("main1")); |
| 379 | ASSERT_TRUE(allocations.count("main2")); |
| 380 | ASSERT_TRUE(allocations.count("main3")); |
| 381 | EXPECT_EQ(allocations.count("main4_no_usages"), 0u); |
James Price | 1ca6fba | 2021-09-29 18:56:17 +0000 | [diff] [blame] | 382 | ASSERT_EQ(allocations["main1"].size(), 1u); |
| 383 | EXPECT_EQ(allocations["main1"][0], 20u * sizeof(float)); |
| 384 | ASSERT_EQ(allocations["main2"].size(), 1u); |
| 385 | EXPECT_EQ(allocations["main2"][0], 32u * sizeof(float)); |
| 386 | ASSERT_EQ(allocations["main3"].size(), 1u); |
| 387 | EXPECT_EQ(allocations["main3"][0], 40u * sizeof(float)); |
James Price | acaecab | 2021-09-13 19:56:01 +0000 | [diff] [blame] | 388 | } |
| 389 | |
dan sinclair | 2a59901 | 2020-06-23 17:48:40 +0000 | [diff] [blame] | 390 | } // namespace |
| 391 | } // namespace msl |
| 392 | } // namespace writer |
| 393 | } // namespace tint |