Debian Codegraph @

test/opt/split_combined_image_sampler_pass_test.cpp

raw
1 // Copyright (c) 2025 Google LLC
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
15 #include <array>
16 #include <iostream>
17 #include <ostream>
18
19 #include "spirv-tools/optimizer.hpp"
20 #include "test/opt/pass_fixture.h"
21 #include "test/opt/pass_utils.h"
22
23 namespace spvtools {
24 namespace opt {
25 namespace {
26
27 struct SplitCombinedImageSamplerPassTest : public PassTest<::testing::Test> {
28 virtual void SetUp() override {
29 SetTargetEnv(SPV_ENV_VULKAN_1_0);
30 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
31 SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES |
32 SPV_BINARY_TO_TEXT_OPTION_INDENT |
33 SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
34 }
35 };
36
37 struct TypeCase {
38 const char* glsl_type;
39 const char* image_type_decl;
40 };
41 std::ostream& operator<<(std::ostream& os, const TypeCase& tc) {
42 os << tc.glsl_type;
43 return os;
44 }
45
46 struct SplitCombinedImageSamplerPassTypeCaseTest
47 : public PassTest<::testing::TestWithParam<TypeCase>> {
48 virtual void SetUp() override {
49 SetTargetEnv(SPV_ENV_VULKAN_1_0);
50 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
51 SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES |
52 SPV_BINARY_TO_TEXT_OPTION_INDENT |
53 SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
54 }
55 };
56
57 std::vector<TypeCase> ImageTypeCases() {
58 return std::vector<TypeCase>{
59 {"sampler2D", "OpTypeImage %float 2D 0 0 0 1 Unknown"},
60 {"sampler2DShadow", "OpTypeImage %float 2D 1 0 0 1 Unknown"},
61 {"sampler2DArray", "OpTypeImage %float 2D 0 1 0 1 Unknown"},
62 {"sampler2DArrayShadow", "OpTypeImage %float 2D 1 1 0 1 Unknown"},
63 {"sampler2DMS", "OpTypeImage %float 2D 0 0 1 1 Unknown"},
64 {"sampler2DMSArray", "OpTypeImage %float 2D 0 1 1 1 Unknown"},
65 {"sampler3D", "OpTypeImage %float 3D 0 0 0 1 Unknown"},
66 {"samplerCube", "OpTypeImage %float Cube 0 0 0 1 Unknown"},
67 {"samplerCubeShadow", "OpTypeImage %float Cube 1 0 0 1 Unknown"},
68 {"samplerCubeArray", "OpTypeImage %float Cube 0 1 0 1 Unknown"},
69 {"samplerCubeArrayShadow", "OpTypeImage %float Cube 1 1 0 1 Unknown"},
70 {"isampler2D", "OpTypeImage %int 2D 0 0 0 1 Unknown"},
71 {"isampler2DShadow", "OpTypeImage %int 2D 1 0 0 1 Unknown"},
72 {"isampler2DArray", "OpTypeImage %int 2D 0 1 0 1 Unknown"},
73 {"isampler2DArrayShadow", "OpTypeImage %int 2D 1 1 0 1 Unknown"},
74 {"isampler2DMS", "OpTypeImage %int 2D 0 0 1 1 Unknown"},
75 {"isampler2DMSArray", "OpTypeImage %int 2D 0 1 1 1 Unknown"},
76 {"isampler3D", "OpTypeImage %int 3D 0 0 0 1 Unknown"},
77 {"isamplerCube", "OpTypeImage %int Cube 0 0 0 1 Unknown"},
78 {"isamplerCubeShadow", "OpTypeImage %int Cube 1 0 0 1 Unknown"},
79 {"isamplerCubeArray", "OpTypeImage %int Cube 0 1 0 1 Unknown"},
80 {"isamplerCubeArrayShadow", "OpTypeImage %int Cube 1 1 0 1 Unknown"},
81 {"usampler2D", "OpTypeImage %uint 2D 0 0 0 1 Unknown"},
82 {"usampler2DShadow", "OpTypeImage %uint 2D 1 0 0 1 Unknown"},
83 {"usampler2DArray", "OpTypeImage %uint 2D 0 1 0 1 Unknown"},
84 {"usampler2DArrayShadow", "OpTypeImage %uint 2D 1 1 0 1 Unknown"},
85 {"usampler2DMS", "OpTypeImage %uint 2D 0 0 1 1 Unknown"},
86 {"usampler2DMSArray", "OpTypeImage %uint 2D 0 1 1 1 Unknown"},
87 {"usampler3D", "OpTypeImage %uint 3D 0 0 0 1 Unknown"},
88 {"usamplerCube", "OpTypeImage %uint Cube 0 0 0 1 Unknown"},
89 {"usamplerCubeShadow", "OpTypeImage %uint Cube 1 0 0 1 Unknown"},
90 {"usamplerCubeArray", "OpTypeImage %uint Cube 0 1 0 1 Unknown"},
91 {"usamplerCubeArrayShadow", "OpTypeImage %uint Cube 1 1 0 1 Unknown"},
92 };
93 }
94
95 std::string Preamble(const std::string shader_interface = "") {
96 return R"( OpCapability Shader
97 OpCapability RuntimeDescriptorArray
98 OpExtension "SPV_EXT_descriptor_indexing"
99 OpMemoryModel Logical GLSL450
100 OpEntryPoint GLCompute %main "main")" +
101 shader_interface + R"(
102 OpExecutionMode %main LocalSize 1 1 1
103 OpName %main "main"
104 OpName %main_0 "main_0"
105 OpName %voidfn "voidfn"
106 )";
107 }
108
109 std::string PreambleFragment(const std::string shader_interface = "") {
110 return R"( OpCapability Shader
111 OpMemoryModel Logical GLSL450
112 OpEntryPoint Fragment %main "main")" +
113 shader_interface + R"(
114 OpExecutionMode %main OriginUpperLeft
115 OpName %main "main"
116 OpName %main_0 "main_0"
117 OpName %voidfn "voidfn"
118 )";
119 }
120
121 std::string BasicTypes() {
122 return R"( %float = OpTypeFloat 32
123 %uint = OpTypeInt 32 0
124 %int = OpTypeInt 32 1
125 %uint_0 = OpConstant %uint 0
126 %uint_1 = OpConstant %uint 1
127 %uint_3 = OpConstant %uint 3
128 %float_0 = OpConstant %float 0
129 %v2float = OpTypeVector %float 2
130 %v3float = OpTypeVector %float 3
131 %v4float = OpTypeVector %float 4
132 %13 = OpConstantNull %v2float
133 %14 = OpConstantNull %v3float
134 %15 = OpConstantNull %v4float
135 %void = OpTypeVoid
136 %voidfn = OpTypeFunction %void
137 )";
138 }
139 std::string Main() {
140 return R"(
141 %main = OpFunction %void None %voidfn
142 %main_0 = OpLabel
143 OpReturn
144 OpFunctionEnd
145 )";
146 }
147 std::string NoCheck() { return "; CHECK-NOT: nothing to see"; }
148
149 TEST_F(SplitCombinedImageSamplerPassTest, SamplerOnly_NoChange) {
150 const std::string kTest = Preamble() +
151 R"( OpDecorate %100 DescriptorSet 0
152 OpDecorate %100 Binding 0
153 )" + BasicTypes() + R"( %10 = OpTypeSampler
154 %_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
155 %100 = OpVariable %_ptr_UniformConstant_10 UniformConstant
156 %main = OpFunction %void None %voidfn
157 %main_0 = OpLabel
158 %6 = OpLoad %10 %100
159 OpReturn
160 OpFunctionEnd
161 )";
162
163 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
164 kTest + NoCheck(), /* do_validation= */ true);
165 EXPECT_EQ(status, Pass::Status::SuccessWithoutChange)
166 << "status" << kTest << "\n -> \n"
167 << disasm;
168 EXPECT_EQ(disasm, kTest) << "disasm";
169 }
170
171 TEST_F(SplitCombinedImageSamplerPassTest, ImageOnly_NoChange) {
172 const std::string kTest = Preamble() +
173 R"( OpDecorate %100 DescriptorSet 0
174 OpDecorate %100 Binding 0
175 )" + BasicTypes() + R"( %10 = OpTypeImage %float 2D 0 0 0 1 Unknown
176 %_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
177 %100 = OpVariable %_ptr_UniformConstant_10 UniformConstant
178 %main = OpFunction %void None %voidfn
179 %main_0 = OpLabel
180 %6 = OpLoad %10 %100
181 OpReturn
182 OpFunctionEnd
183 )";
184
185 SCOPED_TRACE("image only");
186 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
187 kTest + NoCheck(), /* do_validation= */ true);
188 EXPECT_EQ(status, Pass::Status::SuccessWithoutChange);
189 EXPECT_EQ(disasm, kTest);
190 }
191
192 TEST_F(SplitCombinedImageSamplerPassTest, PtrSampledImageOnly_DeletesPtrType) {
193 const std::string kTest = Preamble() + BasicTypes() + R"(
194 ; CHECK: OpCapability Shader
195 ; CHECK-NOT: OpTypePointer UniformConstant
196 ; CHECK: OpFunction %void
197 %100 = OpTypeImage %float 2D 0 0 0 1 Unknown
198 %101 = OpTypeSampledImage %100
199 %102 = OpTypePointer UniformConstant %101
200 %main = OpFunction %void None %voidfn
201 %main_0 = OpLabel
202 OpReturn
203 OpFunctionEnd
204 )";
205
206 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
207 kTest + NoCheck(), /* do_validation= */ true);
208 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << "status";
209 }
210
211 TEST_F(SplitCombinedImageSamplerPassTest,
212 PtrArraySampledImageOnly_DeletesPtrType) {
213 const std::string kTest = Preamble() + BasicTypes() + R"(
214 ; CHECK: OpCapability Shader
215 ; CHECK-NOT: OpTypePointer UniformConstant
216 ; CHECK: OpFunction %void
217 %100 = OpTypeImage %float 2D 0 0 0 1 Unknown
218 %101 = OpTypeSampledImage %100
219 %103 = OpTypeArray %101 %uint_1
220 %104 = OpTypePointer UniformConstant %103
221 %main = OpFunction %void None %voidfn
222 %main_0 = OpLabel
223 OpReturn
224 OpFunctionEnd
225 )";
226
227 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
228 kTest + NoCheck(), /* do_validation= */ true);
229 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << "status";
230 }
231
232 TEST_F(SplitCombinedImageSamplerPassTest,
233 PtrRtArraySampledImageOnly_DeletesPtrType) {
234 const std::string kTest = Preamble() + BasicTypes() + R"(
235 ; CHECK: OpCapability Shader
236 ; CHECK-NOT: OpTypePointer UniformConstant
237 ; CHECK: OpFunction %void
238 %100 = OpTypeImage %float 2D 0 0 0 1 Unknown
239 %101 = OpTypeSampledImage %100
240 %103 = OpTypeRuntimeArray %101
241 %104 = OpTypePointer UniformConstant %103
242 %main = OpFunction %void None %voidfn
243 %main_0 = OpLabel
244 OpReturn
245 OpFunctionEnd
246 )";
247
248 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
249 kTest + NoCheck(), /* do_validation= */ true);
250 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << "status";
251 }
252
253 TEST_F(SplitCombinedImageSamplerPassTest,
254 Combined_NoSampler_CreatedBeforeSampledImage) {
255 // No OpTypeSampler to begin with.
256 const std::string kTest = Preamble() +
257 R"( OpDecorate %100 DescriptorSet 0
258 OpDecorate %100 Binding 0
259
260 ; A sampler type is created and placed at the start of types.
261 ; CHECK: OpDecorate %{{\d+}} Binding 0
262 ; CHECK: OpDecorate %{{\d+}} Binding 0
263 ; CHECK-NOT: TypeSampledImage
264 ; CHECK: TypeSampler
265 ; CHECK: TypeSampledImage
266
267 )" + BasicTypes() + R"( %10 = OpTypeImage %float 2D 0 0 0 1 Unknown
268 %11 = OpTypeSampledImage %10
269 %_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
270
271 %100 = OpVariable %_ptr_UniformConstant_11 UniformConstant
272 %main = OpFunction %void None %voidfn
273 %main_0 = OpLabel
274 %6 = OpLoad %11 %100
275 OpReturn
276 OpFunctionEnd
277 )";
278 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
279 kTest, /* do_validation= */ true);
280 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
281 }
282
283 TEST_F(SplitCombinedImageSamplerPassTest, Combined_SynthesizeVarNames) {
284 // Also tests binding info is copied to both variables.
285 const std::string kTest = Preamble() +
286 R"(
287 OpName %orig_var "orig_var"
288 OpDecorate %orig_var DescriptorSet 0
289 OpDecorate %orig_var Binding 0
290
291 ; The combined image variable is replaced by an image variable and a sampler variable.
292
293 ; CHECK: OpCapability
294 ; The original name is deleted
295 ; CHECK-NOT: OpName %orig_var "
296 ; CHECK: OpName %orig_var_image "orig_var_image"
297 ; CHECK: OpName %orig_var_sampler "orig_var_sampler"
298 ; CHECK-NOT: OpName %orig_var "
299
300 ; CHECK: OpDecorate %orig_var_image DescriptorSet 0
301 ; CHECK: OpDecorate %orig_var_sampler DescriptorSet 0
302 ; CHECK: OpDecorate %orig_var_image Binding 0
303 ; CHECK: OpDecorate %orig_var_sampler Binding 0
304
305 ; CHECK: %10 = OpTypeImage %
306 ; CHECK: %[[image_ptr_ty:\w+]] = OpTypePointer UniformConstant %10
307 ; CHECK: %[[sampler_ty:\d+]] = OpTypeSampler
308 ; CHECK: %[[sampler_ptr_ty:\w+]] = OpTypePointer UniformConstant %[[sampler_ty]]
309
310
311 ; CHECK-NOT: %orig_var = OpVariable
312 ; CHECK-DAG: %orig_var_sampler = OpVariable %[[sampler_ptr_ty]] UniformConstant
313 ; CHECK-DAG: %orig_var_image = OpVariable %[[image_ptr_ty]] UniformConstant
314 ; CHECK: = OpFunction
315
316 )" + BasicTypes() + R"(
317 %10 = OpTypeImage %float 2D 0 0 0 1 Unknown
318 %11 = OpTypeSampledImage %10
319 %_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
320
321 %orig_var = OpVariable %_ptr_UniformConstant_11 UniformConstant
322 %main = OpFunction %void None %voidfn
323 %main_0 = OpLabel
324 %101 = OpLoad %11 %orig_var
325 OpReturn
326 OpFunctionEnd
327 )";
328 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
329 kTest, /* do_validation= */ true);
330 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
331 }
332
333 TEST_P(SplitCombinedImageSamplerPassTypeCaseTest, Combined_RemapLoad) {
334 // Also tests binding info is copied to both variables.
335 const std::string kTest = Preamble() +
336 R"(
337 OpName %combined "combined"
338 OpDecorate %100 DescriptorSet 0
339 OpDecorate %100 Binding 0
340
341 ; CHECK: OpName
342 ; CHECK-NOT: OpDecorate %100
343 ; CHECK: OpDecorate %[[image_var:\d+]] DescriptorSet 0
344 ; CHECK: OpDecorate %[[sampler_var:\d+]] DescriptorSet 0
345 ; CHECK: OpDecorate %[[image_var]] Binding 0
346 ; CHECK: OpDecorate %[[sampler_var]] Binding 0
347
348 ; CHECK: %10 = OpTypeImage %
349 ; CHECK: %[[image_ptr_ty:\w+]] = OpTypePointer UniformConstant %10
350 ; CHECK: %[[sampler_ty:\d+]] = OpTypeSampler
351 ; CHECK: %[[sampler_ptr_ty:\w+]] = OpTypePointer UniformConstant %[[sampler_ty]]
352
353 ; The combined image variable is replaced by an image variable and a sampler variable.
354
355 ; CHECK-NOT: %100 = OpVariable
356 ; CHECK-DAG: %[[sampler_var]] = OpVariable %[[sampler_ptr_ty]] UniformConstant
357 ; CHECK-DAG: %[[image_var]] = OpVariable %[[image_ptr_ty]] UniformConstant
358 ; CHECK: = OpFunction
359
360 ; The load of the combined image+sampler is replaced by a two loads, then
361 ; a combination operation.
362 ; CHECK: %[[im:\d+]] = OpLoad %10 %[[image_var]]
363 ; CHECK: %[[s:\d+]] = OpLoad %[[sampler_ty]] %[[sampler_var]]
364 ; CHECK: %combined = OpSampledImage %11 %[[im]] %[[s]]
365
366 )" + BasicTypes() +
367 " %10 = " + GetParam().image_type_decl + R"(
368 %11 = OpTypeSampledImage %10
369 %_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
370
371 %100 = OpVariable %_ptr_UniformConstant_11 UniformConstant
372 %main = OpFunction %void None %voidfn
373 %main_0 = OpLabel
374 %combined = OpLoad %11 %100
375
376 ; Uses of the combined image sampler are preserved.
377 ; CHECK: OpCopyObject %11 %combined
378
379 %7 = OpCopyObject %11 %combined
380 OpReturn
381 OpFunctionEnd
382 )";
383 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
384 kTest, /* do_validation= */ true);
385 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
386 }
387
388 TEST_P(SplitCombinedImageSamplerPassTypeCaseTest,
389 Combined_RemapLoad_RelaxedPrecisionOnVarCopied) {
390 // All decorations on the variable are copied. In this case, RelaxedPrecision
391 const std::string kTest = Preamble() +
392 R"(
393 OpName %combined "combined"
394 OpDecorate %100 DescriptorSet 0
395 OpDecorate %100 Binding 0
396 OpDecorate %100 RelaxedPrecision
397
398 ; CHECK: OpName
399 ; CHECK-NOT: OpDecorate %100
400 ; CHECK: OpDecorate %[[image_var:\d+]] DescriptorSet 0
401 ; CHECK: OpDecorate %[[sampler_var:\d+]] DescriptorSet 0
402 ; CHECK: OpDecorate %[[image_var]] Binding 0
403 ; CHECK: OpDecorate %[[sampler_var]] Binding 0
404 ; CHECK: OpDecorate %[[image_var:\d+]] RelaxedPrecision
405 ; CHECK: OpDecorate %[[sampler_var:\d+]] RelaxedPrecision
406
407 ; CHECK: %10 = OpTypeImage %
408 ; CHECK: %[[image_ptr_ty:\w+]] = OpTypePointer UniformConstant %10
409 ; CHECK: %[[sampler_ty:\d+]] = OpTypeSampler
410 ; CHECK: %[[sampler_ptr_ty:\w+]] = OpTypePointer UniformConstant %[[sampler_ty]]
411
412 ; The combined image variable is replaced by an image variable and a sampler variable.
413
414 ; CHECK-NOT: %100 = OpVariable
415 ; CHECK-NOT: OpVariable _ptr_UniformConstant_11
416 ; CHECK-DAG: %[[sampler_var]] = OpVariable %[[sampler_ptr_ty]] UniformConstant
417 ; CHECK-DAG: %[[image_var]] = OpVariable %[[image_ptr_ty]] UniformConstant
418 ; CHECK: = OpFunction
419
420 ; The load of the combined image+sampler is replaced by a two loads, then
421 ; a combination operation.
422 ; CHECK: %[[im:\d+]] = OpLoad %10 %[[image_var]]
423 ; CHECK: %[[s:\d+]] = OpLoad %[[sampler_ty]] %[[sampler_var]]
424 ; CHECK: %combined = OpSampledImage %11 %[[im]] %[[s]]
425
426 %bool = OpTypeBool ; location marker
427 )" + BasicTypes() +
428 " %10 = " + GetParam().image_type_decl + R"(
429 %11 = OpTypeSampledImage %10
430 %_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
431
432 %100 = OpVariable %_ptr_UniformConstant_11 UniformConstant
433 %main = OpFunction %void None %voidfn
434 %main_0 = OpLabel
435 %combined = OpLoad %11 %100
436
437 ; Uses of the combined image sampler are preserved.
438 ; CHECK: OpCopyObject %11 %combined
439
440 %7 = OpCopyObject %11 %combined
441 OpReturn
442 OpFunctionEnd
443 )";
444 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
445 kTest, /* do_validation= */ true);
446 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
447 }
448
449 TEST_P(SplitCombinedImageSamplerPassTypeCaseTest,
450 Combined_RemapLoad_RelaxedPrecisionOnLoadCopied) {
451 // Copy decorations form an OpLoad that is replaced.
452 const std::string kTest = Preamble() +
453 R"(
454 OpName %combined "combined"
455 OpDecorate %100 DescriptorSet 0
456 OpDecorate %100 Binding 0
457 OpDecorate %combined RelaxedPrecision
458
459 ; CHECK: OpName
460 ; CHECK-NOT: OpDecorate %100
461 ; CHECK: OpDecorate %[[image_var:\d+]] DescriptorSet 0
462 ; CHECK: OpDecorate %[[sampler_var:\d+]] DescriptorSet 0
463 ; CHECK: OpDecorate %[[image_var]] Binding 0
464 ; CHECK: OpDecorate %[[sampler_var]] Binding 0
465
466 ; This is what we are checking in this test.
467 ; CHECK: OpDecorate %[[im:\d+]] RelaxedPrecision
468 ; CHECK: OpDecorate %[[s:\d+]] RelaxedPrecision
469
470 ; CHECK: %10 = OpTypeImage %
471 ; CHECK: %[[image_ptr_ty:\w+]] = OpTypePointer UniformConstant %10
472 ; CHECK: %[[sampler_ty:\d+]] = OpTypeSampler
473 ; CHECK: %[[sampler_ptr_ty:\w+]] = OpTypePointer UniformConstant %[[sampler_ty]]
474
475 ; The combined image variable is replaced by an image variable and a sampler variable.
476
477 ; CHECK-NOT: %100 = OpVariable
478 ; CHECK-NOT: OpVariable _ptr_UniformConstant_11
479 ; CHECK-DAG: %[[sampler_var]] = OpVariable %[[sampler_ptr_ty]] UniformConstant
480 ; CHECK-DAG: %[[image_var]] = OpVariable %[[image_ptr_ty]] UniformConstant
481 ; CHECK: = OpFunction
482
483 ; The load of the combined image+sampler is replaced by a two loads, then
484 ; a combination operation. The new loads get the same decorations that the
485 ; original load had.
486 ; CHECK: %[[im]] = OpLoad %10 %[[image_var]]
487 ; CHECK: %[[s]] = OpLoad %[[sampler_ty]] %[[sampler_var]]
488 ; CHECK: %combined = OpSampledImage %11 %[[im]] %[[s]]
489
490 %bool = OpTypeBool ; location marker
491 )" + BasicTypes() +
492 " %10 = " + GetParam().image_type_decl + R"(
493 %11 = OpTypeSampledImage %10
494 %_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
495
496 %100 = OpVariable %_ptr_UniformConstant_11 UniformConstant
497 %main = OpFunction %void None %voidfn
498 %main_0 = OpLabel
499 %combined = OpLoad %11 %100
500
501 ; Uses of the combined image sampler are preserved.
502 ; CHECK: OpCopyObject %11 %combined
503
504 %7 = OpCopyObject %11 %combined
505 OpReturn
506 OpFunctionEnd
507 )";
508 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
509 kTest, /* do_validation= */ true);
510 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
511 }
512
513 TEST_P(SplitCombinedImageSamplerPassTypeCaseTest,
514 Combined_DeletesCopyObjectOfPtr) {
515 // OpCopyObject is deleted, and its uses updated.
516 const std::string kTest = Preamble() +
517 R"(
518 OpDecorate %100 DescriptorSet 0
519 OpDecorate %100 Binding 0
520
521 ; CHECK: OpName
522 ; CHECK-NOT: OpDecorate %100
523 ; CHECK: OpDecorate %[[image_var:\d+]] DescriptorSet 0
524 ; CHECK: OpDecorate %[[sampler_var:\d+]] DescriptorSet 0
525 ; CHECK: OpDecorate %[[image_var]] Binding 0
526 ; CHECK: OpDecorate %[[sampler_var]] Binding 0
527
528 ; CHECK: %10 = OpTypeImage %
529 ; CHECK: %[[image_ptr_ty:\w+]] = OpTypePointer UniformConstant %10
530 ; CHECK: %[[sampler_ty:\d+]] = OpTypeSampler
531 ; CHECK: %[[sampler_ptr_ty:\w+]] = OpTypePointer UniformConstant %[[sampler_ty]]
532
533 ; The combined image variable is replaced by an image variable and a sampler variable.
534
535 ; CHECK-NOT: %100 = OpVariable
536 ; CHECK-DAG: %[[sampler_var]] = OpVariable %[[sampler_ptr_ty]] UniformConstant
537 ; CHECK-DAG: %[[image_var]] = OpVariable %[[image_ptr_ty]] UniformConstant
538 ; CHECK: = OpFunction
539
540
541 )" + BasicTypes() +
542 " %10 = " + GetParam().image_type_decl + R"(
543 %11 = OpTypeSampledImage %10
544 %_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
545
546 %100 = OpVariable %_ptr_UniformConstant_11 UniformConstant
547 %main = OpFunction %void None %voidfn
548 %main_0 = OpLabel
549 %101 = OpCopyObject %_ptr_UniformConstant_11 %100
550 %102 = OpLoad %11 %101
551 %103 = OpCopyObject %_ptr_UniformConstant_11 %101
552 %104 = OpCopyObject %11 %102 ;; this copy survives
553 OpReturn
554 OpFunctionEnd
555
556 ; The OpCopyObject instructions are removed.
557 ; The load of the combined image+sampler is replaced by a two loads, then
558 ; a combination operation. The only OpCopyObject that remains is the copy
559 ; of the copy of the sampled image value.
560 ; CHECK: %[[im:\d+]] = OpLoad %10 %[[image_var]]
561 ; CHECK: %[[s:\d+]] = OpLoad %[[sampler_ty]] %[[sampler_var]]
562 ; CHECK: %[[si:\d+]] = OpSampledImage %11 %[[im]] %[[s]]
563 ; CHECK-NEXT: OpCopyObject %11 %[[si]]
564 ; CHECK-NEXT: OpReturn
565 )";
566
567 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
568 kTest, /* do_validation= */ true);
569 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
570 }
571
572 TEST_P(SplitCombinedImageSamplerPassTypeCaseTest, ArrayCombined_RemapLoad) {
573 const std::string kTest = Preamble() +
574 R"(
575 OpName %combined "combined"
576 OpDecorate %100 DescriptorSet 0
577 OpDecorate %100 Binding 0
578
579 ; CHECK: OpName
580 ; CHECK-NOT: OpDecorate %100
581 ; CHECK: OpDecorate %[[image_var:\d+]] DescriptorSet 0
582 ; CHECK: OpDecorate %[[sampler_var:\d+]] DescriptorSet 0
583 ; CHECK: OpDecorate %[[image_var]] Binding 0
584 ; CHECK: OpDecorate %[[sampler_var]] Binding 0
585
586 ; CHECK: %10 = OpTypeImage %
587 ; CHECK: %[[image_ptr_ty:\w+]] = OpTypePointer UniformConstant %10
588 ; CHECK: %[[sampler_ty:\d+]] = OpTypeSampler
589 ; CHECK: %[[sampler_ptr_ty:\w+]] = OpTypePointer UniformConstant %[[sampler_ty]]
590
591 ; The combined image variable is replaced by an image variable and a sampler variable.
592
593 ; CHECK: %[[array_image_ty:\w+]] = OpTypeArray %10 %uint_3
594 ; CHECK: %[[ptr_array_image_ty:\w+]] = OpTypePointer UniformConstant %[[array_image_ty]]
595
596 ; CHECK: %[[array_sampler_ty:\w+]] = OpTypeArray %[[sampler_ty]] %uint_3
597 ; CHECK: %[[ptr_array_sampler_ty:\w+]] = OpTypePointer UniformConstant %[[array_sampler_ty]]
598
599 ; CHECK-NOT: %100 = OpVariable
600 ; CHECK-DAG: %[[sampler_var]] = OpVariable %[[ptr_array_sampler_ty]] UniformConstant
601 ; CHECK-DAG: %[[image_var]] = OpVariable %[[ptr_array_image_ty]] UniformConstant
602 ; CHECK: = OpFunction
603
604 ; The access chain and load is replaced by two access chains, two loads, then
605 ; a combine operation.
606 ; CHECK: %[[ptr_im:\d+]] = OpAccessChain %[[image_ptr_ty]] %[[image_var]] %uint_1
607 ; CHECK: %[[ptr_s:\d+]] = OpAccessChain %[[sampler_ptr_ty]] %[[sampler_var]] %uint_1
608 ; CHECK: %[[im:\d+]] = OpLoad %10 %[[ptr_im]]
609 ; CHECK: %[[s:\d+]] = OpLoad %[[sampler_ty]] %[[ptr_s]]
610 ; CHECK: %combined = OpSampledImage %11 %[[im]] %[[s]]
611
612 )" + BasicTypes() +
613 " %10 = " + GetParam().image_type_decl + R"(
614 %11 = OpTypeSampledImage %10
615 %_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
616 %12 = OpTypeArray %11 %uint_3
617 %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
618
619 %100 = OpVariable %_ptr_UniformConstant_12 UniformConstant
620 %main = OpFunction %void None %voidfn
621 %main_0 = OpLabel
622 %ptr = OpAccessChain %_ptr_UniformConstant_11 %100 %uint_1
623 %combined = OpLoad %11 %ptr
624
625 ; Uses of the combined image sampler are preserved.
626 ; CHECK: OpCopyObject %11 %combined
627
628 %7 = OpCopyObject %11 %combined
629 OpReturn
630 OpFunctionEnd
631 )";
632
633 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
634 kTest, /* do_validation= */ true);
635 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
636 }
637
638 TEST_P(SplitCombinedImageSamplerPassTypeCaseTest, RtArrayCombined_RemapLoad) {
639 const std::string kTest = Preamble() +
640 R"(
641 OpName %combined "combined"
642 OpDecorate %100 DescriptorSet 0
643 OpDecorate %100 Binding 0
644
645 ; CHECK: OpName
646 ; CHECK-NOT: OpDecorate %100
647 ; CHECK: OpDecorate %[[image_var:\d+]] DescriptorSet 0
648 ; CHECK: OpDecorate %[[sampler_var:\d+]] DescriptorSet 0
649 ; CHECK: OpDecorate %[[image_var]] Binding 0
650 ; CHECK: OpDecorate %[[sampler_var]] Binding 0
651
652 ; CHECK: %10 = OpTypeImage %
653 ; CHECK: %[[image_ptr_ty:\w+]] = OpTypePointer UniformConstant %10
654 ; CHECK: %[[sampler_ty:\d+]] = OpTypeSampler
655 ; CHECK: %[[sampler_ptr_ty:\w+]] = OpTypePointer UniformConstant %[[sampler_ty]]
656
657 ; The combined image variable is replaced by an image variable and a sampler variable.
658
659 ; CHECK: %[[array_image_ty:\w+]] = OpTypeRuntimeArray %10
660 ; CHECK: %[[ptr_array_image_ty:\w+]] = OpTypePointer UniformConstant %[[array_image_ty]]
661
662 ; CHECK: %[[array_sampler_ty:\w+]] = OpTypeRuntimeArray %[[sampler_ty]]
663 ; CHECK: %[[ptr_array_sampler_ty:\w+]] = OpTypePointer UniformConstant %[[array_sampler_ty]]
664
665 ; CHECK-NOT: %100 = OpVariable
666 ; CHECK-DAG: %[[sampler_var]] = OpVariable %[[ptr_array_sampler_ty]] UniformConstant
667 ; CHECK-DAG: %[[image_var]] = OpVariable %[[ptr_array_image_ty]] UniformConstant
668 ; CHECK: = OpFunction
669
670 ; The access chain and load is replaced by two access chains, two loads, then
671 ; a combine operation.
672 ; CHECK: %[[ptr_im:\d+]] = OpAccessChain %[[image_ptr_ty]] %[[image_var]] %uint_1
673 ; CHECK: %[[ptr_s:\d+]] = OpAccessChain %[[sampler_ptr_ty]] %[[sampler_var]] %uint_1
674 ; CHECK: %[[im:\d+]] = OpLoad %10 %[[ptr_im]]
675 ; CHECK: %[[s:\d+]] = OpLoad %[[sampler_ty]] %[[ptr_s]]
676 ; CHECK: %combined = OpSampledImage %11 %[[im]] %[[s]]
677
678 )" + BasicTypes() +
679 " %10 = " + GetParam().image_type_decl + R"(
680 %11 = OpTypeSampledImage %10
681 %_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
682 %12 = OpTypeRuntimeArray %11
683 %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
684
685 %100 = OpVariable %_ptr_UniformConstant_12 UniformConstant
686 %main = OpFunction %void None %voidfn
687 %main_0 = OpLabel
688 %ptr = OpAccessChain %_ptr_UniformConstant_11 %100 %uint_1
689 %combined = OpLoad %11 %ptr
690
691 ; Uses of the combined image sampler are preserved.
692 ; CHECK: OpCopyObject %11 %combined
693
694 %7 = OpCopyObject %11 %combined
695 OpReturn
696 OpFunctionEnd
697 )";
698
699 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
700 kTest, /* do_validation= */ true);
701 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
702 }
703
704 INSTANTIATE_TEST_SUITE_P(AllCombinedTypes,
705 SplitCombinedImageSamplerPassTypeCaseTest,
706 ::testing::ValuesIn(ImageTypeCases()));
707
708 // Remap entry point
709
710 struct EntryPointRemapCase {
711 const spv_target_env environment = SPV_ENV_VULKAN_1_0;
712 const char* initial_interface = "";
713 const char* expected_interface = nullptr;
714 };
715
716 std::ostream& operator<<(std::ostream& os, const EntryPointRemapCase& eprc) {
717 os << "(env " << spvLogStringForEnv(eprc.environment) << ", init "
718 << eprc.initial_interface << " -> expect " << eprc.expected_interface
719 << ")";
720 return os;
721 }
722
723 struct SplitCombinedImageSamplerPassEntryPointRemapTest
724 : public PassTest<::testing::TestWithParam<EntryPointRemapCase>> {
725 virtual void SetUp() override {
726 SetTargetEnv(GetParam().environment);
727 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
728 SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES |
729 SPV_BINARY_TO_TEXT_OPTION_INDENT |
730 SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
731 }
732 };
733
734 std::vector<EntryPointRemapCase> EntryPointInterfaceCases() {
735 return std::vector<EntryPointRemapCase>{
736 {SPV_ENV_VULKAN_1_0, " %in_var %out_var", " %in_var %out_var"},
737 {SPV_ENV_VULKAN_1_4, " %combined_var",
738 " %combined_var_image %combined_var_sampler"},
739 {SPV_ENV_VULKAN_1_4, " %combined_var %in_var %out_var",
740 " %combined_var_image %in_var %out_var %combined_var_sampler"},
741 {SPV_ENV_VULKAN_1_4, " %in_var %combined_var %out_var",
742 " %in_var %combined_var_image %out_var %combined_var_sampler"},
743 {SPV_ENV_VULKAN_1_4, " %in_var %out_var %combined_var",
744 " %in_var %out_var %combined_var_image %combined_var_sampler"},
745 };
746 }
747
748 TEST_P(SplitCombinedImageSamplerPassEntryPointRemapTest,
749 EntryPoint_Combined_UsedInShader) {
750 const std::string kTest = PreambleFragment(GetParam().initial_interface) +
751 R"(
752 OpName %combined "combined"
753 OpName %combined_var "combined_var"
754 OpName %in_var "in_var"
755 OpName %out_var "out_var"
756 OpDecorate %combined_var DescriptorSet 0
757 OpDecorate %combined_var Binding 0
758 OpDecorate %in_var BuiltIn FragCoord
759 OpDecorate %out_var Location 0
760
761 ; CHECK: OpEntryPoint Fragment %main "main")" +
762 GetParam().expected_interface + R"(
763 ; These clauses ensure the expected interface is the whole interface.
764 ; CHECK-NOT: %{{\d+}}
765 ; CHECK-NOT: %in_var
766 ; CHECK-NOT: %out_var
767 ; CHECK-NOT: %combined_var
768 ; CHECK: OpExecutionMode %main OriginUpperLeft
769
770 ; Check the var names, tracing up through the types.
771 ; CHECK: %10 = OpTypeImage %float 2D 0 0 0 1 Unknown
772 ; CHECK: %[[image_ptr_ty:\w+]] = OpTypePointer UniformConstant %10
773 ; CHECK: %[[sampler_ty:\d+]] = OpTypeSampler
774 ; CHECK: %[[sampler_ptr_ty:\w+]] = OpTypePointer UniformConstant %[[sampler_ty]]
775 ; The combined image variable is replaced by an image variable and a sampler variable.
776 ; CHECK-DAG: %combined_var_sampler = OpVariable %[[sampler_ptr_ty]] UniformConstant
777 ; CHECK-DAG: %combined_var_image = OpVariable %[[image_ptr_ty]] UniformConstant
778 ; CHECK: = OpFunction
779
780 %bool = OpTypeBool
781 )" + BasicTypes() + R"( %10 = OpTypeImage %float 2D 0 0 0 1 Unknown
782 %11 = OpTypeSampledImage %10
783 %_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
784 %in_ptr_v4f = OpTypePointer Input %v4float
785 %in_var = OpVariable %in_ptr_v4f Input
786 %out_ptr_v4f = OpTypePointer Output %v4float
787 %out_var = OpVariable %out_ptr_v4f Output
788
789 %combined_var = OpVariable %_ptr_UniformConstant_11 UniformConstant
790 %main = OpFunction %void None %voidfn
791 ;CHECK: %main_0 = OpLabel
792 ;CHECK: OpLoad
793
794 %main_0 = OpLabel
795 %combined = OpLoad %11 %combined_var
796 OpReturn
797 OpFunctionEnd
798 )";
799 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
800 kTest, /* do_validation= */ true);
801 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
802 }
803
804 TEST_P(SplitCombinedImageSamplerPassEntryPointRemapTest,
805 EntryPoint_Combined_UsedOnlyInEntryPointInstruction) {
806 // If the combined var is in the interface, that is enough to trigger
807 // its replacement. Otherwise the entry point interface is untouched
808 // when the combined var is not otherwise used.
809 const bool combined_var_in_interface =
810 std::string(GetParam().initial_interface).find("%combined_var") !=
811 std::string::npos;
812 if (combined_var_in_interface) {
813 const std::string kTest = PreambleFragment(GetParam().initial_interface) +
814 R"(
815 OpName %combined_var "combined_var"
816 OpName %in_var "in_var"
817 OpName %out_var "out_var"
818 OpDecorate %combined_var DescriptorSet 0
819 OpDecorate %combined_var Binding 0
820 OpDecorate %in_var BuiltIn FragCoord
821 OpDecorate %out_var Location 0
822
823 ; CHECK: OpEntryPoint Fragment %main "main")" +
824 GetParam().expected_interface + R"(
825 ; These clauses ensure the expected interface is the whole interface.
826 ; CHECK-NOT: %{{\d+}}
827 ; CHECK-NOT: %in_var
828 ; CHECK-NOT: %out_var
829 ; CHECK-NOT: %combined_var
830 ; CHECK: OpExecutionMode %main OriginUpperLeft
831
832 %bool = OpTypeBool
833 )" + BasicTypes() + R"( %10 = OpTypeImage %float 2D 0 0 0 1 Unknown
834 %11 = OpTypeSampledImage %10
835 %_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
836 %in_ptr_v4f = OpTypePointer Input %v4float
837 %in_var = OpVariable %in_ptr_v4f Input
838 %out_ptr_v4f = OpTypePointer Output %v4float
839 %out_var = OpVariable %out_ptr_v4f Output
840
841 ; %combined_var is not used!
842 %combined_var = OpVariable %_ptr_UniformConstant_11 UniformConstant
843 %main = OpFunction %void None %voidfn
844 %main_0 = OpLabel
845 OpReturn
846 OpFunctionEnd
847 )";
848 auto [disasm, status] =
849 SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
850 kTest, /* do_validation= */ true);
851 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
852 }
853 }
854
855 TEST_P(SplitCombinedImageSamplerPassEntryPointRemapTest,
856 EntryPoint_Combined_Unused) {
857 // If the combined var is in the interface, that is enough to trigger
858 // its replacement. Otherwise the entry point interface is untouched
859 // when the combined var is not otherwise used.
860 const bool combined_var_in_interface =
861 std::string(GetParam().initial_interface).find("%combined_var") !=
862 std::string::npos;
863 if (!combined_var_in_interface) {
864 const std::string kTest = PreambleFragment(GetParam().initial_interface) +
865 R"(
866 ; CHECK: OpEntryPoint Fragment %main "main")" +
867 GetParam().initial_interface // Note this is the
868 // intial interface
869 + R"(
870 ; These clauses ensure the expected interface is the whole interface.
871 ; CHECK-NOT: %{{\d+}}
872 ; CHECK-NOT: %in_var
873 ; CHECK-NOT: %out_var
874 ; CHECK-NOT: %combined_var
875 ; CHECK: OpExecutionMode %main OriginUpperLeft
876
877 ; The variable disappears.
878 ; CHECK-NOT: %combined_var =
879 ; CHECK: OpFunctionEnd
880 OpName %combined_var "combined_var"
881 OpName %in_var "in_var"
882 OpName %out_var "out_var"
883 OpDecorate %combined_var DescriptorSet 0
884 OpDecorate %combined_var Binding 0
885 OpDecorate %in_var BuiltIn FragCoord
886 OpDecorate %out_var Location 0
887
888
889 %bool = OpTypeBool
890 )" + BasicTypes() + R"( %10 = OpTypeImage %float 2D 0 0 0 1 Unknown
891 %11 = OpTypeSampledImage %10
892 %_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
893 %in_ptr_v4f = OpTypePointer Input %v4float
894 %in_var = OpVariable %in_ptr_v4f Input
895 %out_ptr_v4f = OpTypePointer Output %v4float
896 %out_var = OpVariable %out_ptr_v4f Output
897
898 ; %combined_var is not used!
899 %combined_var = OpVariable %_ptr_UniformConstant_11 UniformConstant
900 %main = OpFunction %void None %voidfn
901 %main_0 = OpLabel
902 OpReturn
903 OpFunctionEnd
904 )";
905 auto [disasm, status] =
906 SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
907 kTest, /* do_validation= */ true);
908 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
909 }
910 }
911
912 INSTANTIATE_TEST_SUITE_P(EntryPointRemap,
913 SplitCombinedImageSamplerPassEntryPointRemapTest,
914 ::testing::ValuesIn(EntryPointInterfaceCases()));
915
916 // Remap function types
917
918 struct FunctionTypeCase {
919 const char* initial_type_params = "";
920 const char* expected_type_params = "";
921 };
922
923 std::ostream& operator<<(std::ostream& os, const FunctionTypeCase& ftc) {
924 os << "(init " << ftc.initial_type_params << " -> expect "
925 << ftc.expected_type_params << ")";
926 return os;
927 }
928
929 struct SplitCombinedImageSamplerPassFunctionTypeTest
930 : public PassTest<::testing::TestWithParam<FunctionTypeCase>> {
931 virtual void SetUp() override {
932 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
933 SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES |
934 SPV_BINARY_TO_TEXT_OPTION_INDENT |
935 SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
936 }
937 };
938
939 std::vector<FunctionTypeCase> FunctionTypeCases() {
940 return std::vector<FunctionTypeCase>{
941 {"", ""},
942 {" %image_ty", " %image_ty"},
943 {" %sampler_ty", " %sampler_ty"},
944 {" %sampled_image_ty", " %image_ty %sampler_ty"},
945 {" %uint %sampled_image_ty %float",
946 " %uint %image_ty %sampler_ty %float"},
947 {" %ptr_sampled_image_ty",
948 " %_ptr_UniformConstant_image_ty %_ptr_UniformConstant_sampler_ty"},
949 {" %uint %ptr_sampled_image_ty %float",
950 " %uint %_ptr_UniformConstant_image_ty %_ptr_UniformConstant_sampler_ty "
951 "%float"},
952 {" %uint %ptr_sampled_image_ty %ptr_sampled_image_ty %float",
953 " %uint %_ptr_UniformConstant_image_ty %_ptr_UniformConstant_sampler_ty "
954 "%_ptr_UniformConstant_image_ty %_ptr_UniformConstant_sampler_ty "
955 "%float"},
956 };
957 }
958
959 TEST_P(SplitCombinedImageSamplerPassFunctionTypeTest,
960 ReplaceCombinedImageSamplersOnly) {
961 const std::string kTest = Preamble() + +R"(
962 OpName %f_ty "f_ty"
963 OpName %sampler_ty "sampler_ty"
964 OpName %image_ty "image_ty"
965 OpName %sampled_image_ty "sampled_image_ty"
966 OpName %ptr_sampled_image_ty "sampled_image_ty"
967
968 )" + BasicTypes() + R"(
969
970 %sampler_ty = OpTypeSampler
971 %image_ty = OpTypeImage %float 2D 0 0 0 1 Unknown
972 %sampled_image_ty = OpTypeSampledImage %image_ty
973 %ptr_sampled_image_ty = OpTypePointer UniformConstant %sampled_image_ty
974
975 %f_ty = OpTypeFunction %float)" +
976 GetParam().initial_type_params + R"(
977
978 ; CHECK: %f_ty = OpTypeFunction %float)" +
979 GetParam().expected_type_params + R"(
980 )" + Main();
981
982 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
983 kTest, /* do_validation= */ true);
984 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
985 }
986
987 TEST_P(SplitCombinedImageSamplerPassFunctionTypeTest, AvoidDuplicateType) {
988 // SPIR-V does not allow duplicate non-aggregate types. That includes function
989 // types. Test that when replacing function type parameters would cause a
990 // collision, that the original function type is replaced with the new one.
991 const std::string initial_params(GetParam().initial_type_params);
992 const std::string expected_params(GetParam().expected_type_params);
993 const std::string kTest = Preamble() + +R"(
994 OpName %sampler_ty "sampler_ty"
995 OpName %image_ty "image_ty"
996 OpName %sampled_image_ty "sampled_image_ty"
997 OpName %_ptr_UniformConstant_sampler_ty "_ptr_UniformConstant_sampler_ty"
998 OpName %_ptr_UniformConstant_image_ty "_ptr_UniformConstant_image_ty"
999 OpName %ptr_sampled_image_ty "sampled_image_ty"
1000 OpName %dest_ty "dest_ty"
1001
1002 )" + BasicTypes() + R"(
1003
1004 %sampler_ty = OpTypeSampler
1005 %image_ty = OpTypeImage %float 2D 0 0 0 1 Unknown
1006 %sampled_image_ty = OpTypeSampledImage %image_ty
1007 %ptr_sampled_image_ty = OpTypePointer UniformConstant %sampled_image_ty
1008 %_ptr_UniformConstant_image_ty = OpTypePointer UniformConstant %image_ty
1009 %_ptr_UniformConstant_sampler_ty = OpTypePointer UniformConstant %sampler_ty
1010
1011 %100 = OpTypeFunction %float)" +
1012 initial_params + R"(
1013 %dest_ty = OpTypeFunction %float)" +
1014 expected_params + R"(
1015
1016 ; CHECK: OpTypeSampler
1017 ; CHECK-NOT: %100 =
1018 ; CHECK: %dest_ty = OpTypeFunction %float)" +
1019 expected_params + R"(
1020 ; CHECK-NOT: %100 =
1021 ; CHECK: %main = OpFunction
1022 )" + Main();
1023 // The original source is invalid if initial and expected params are the same,
1024 // because the type is already duplicated.
1025 // Only test when they are different.
1026 if (initial_params != expected_params) {
1027 auto [disasm, status] =
1028 SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1029 kTest, /* do_validation= */ true);
1030 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1031 }
1032 }
1033
1034 INSTANTIATE_TEST_SUITE_P(FunctionTypeRemap,
1035 SplitCombinedImageSamplerPassFunctionTypeTest,
1036 ::testing::ValuesIn(FunctionTypeCases()));
1037
1038 // Test array and runtime-array cases for function type replacement.
1039
1040 TEST_F(SplitCombinedImageSamplerPassTest, FunctionType_ReplaceSampledImageArg) {
1041 // The original module has a sampled image type, used only as a function
1042 // parameter. We still want to replace it. But no other sampled-image types
1043 // exist. This proves that the pass needs a sampled_image_used_as_param_
1044 // state variable.
1045 const std::string kTest = Preamble() + +R"(
1046 OpName %f_ty "f_ty"
1047 OpName %sampler_ty "sampler_ty"
1048 OpName %image_ty "image_ty"
1049 OpName %sampled_image_ty "sampled_image_ty"
1050
1051 )" + BasicTypes() + R"(
1052
1053 %sampler_ty = OpTypeSampler
1054 %image_ty = OpTypeImage %float 2D 0 0 0 1 Unknown
1055 %sampled_image_ty = OpTypeSampledImage %image_ty
1056
1057 %f_ty = OpTypeFunction %float %sampled_image_ty %float
1058 ; CHECK: %f_ty = OpTypeFunction %float %image_ty %sampler_ty %float
1059 )" + Main();
1060
1061 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1062 kTest, /* do_validation= */ true);
1063 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1064 }
1065
1066 TEST_F(SplitCombinedImageSamplerPassTest, FunctionType_ReplaceArrayArg) {
1067 const std::string kTest = Preamble() + +R"(
1068 OpName %f_ty "f_ty"
1069 OpName %sampler_ty "sampler_ty"
1070 OpName %image_ty "image_ty"
1071 OpName %sampled_image_ty "sampled_image_ty"
1072 OpName %ptr_array_si_ty "ptr_array_si_ty"
1073
1074 )" + BasicTypes() + R"(
1075
1076 %sampler_ty = OpTypeSampler
1077 %image_ty = OpTypeImage %float 2D 0 0 0 1 Unknown
1078 %sampled_image_ty = OpTypeSampledImage %image_ty
1079 %array_si_ty = OpTypeArray %sampled_image_ty %uint_3
1080 %ptr_array_si_ty = OpTypePointer UniformConstant %array_si_ty
1081
1082 ; CHECK: %[[array_i_ty:\w+]] = OpTypeArray %image_ty %uint_3
1083 ; CHECK: %[[ptr_array_i_ty:\w+]] = OpTypePointer UniformConstant %[[array_i_ty]]
1084 ; CHECK: %[[array_s_ty:\w+]] = OpTypeArray %sampler_ty %uint_3
1085 ; CHECK: %[[ptr_array_s_ty:\w+]] = OpTypePointer UniformConstant %[[array_s_ty]]
1086
1087 %f_ty = OpTypeFunction %float %uint %ptr_array_si_ty %float
1088 ; CHECK: %f_ty = OpTypeFunction %float %uint %[[ptr_array_i_ty]] %[[ptr_array_s_ty]] %float
1089 )" + Main();
1090
1091 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1092 kTest, /* do_validation= */ true);
1093 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1094 }
1095
1096 TEST_F(SplitCombinedImageSamplerPassTest, FunctionType_ReplaceRtArrayArg) {
1097 const std::string kTest = Preamble() + +R"(
1098 OpName %f_ty "f_ty"
1099 OpName %sampler_ty "sampler_ty"
1100 OpName %image_ty "image_ty"
1101 OpName %sampled_image_ty "sampled_image_ty"
1102 OpName %ptr_array_si_ty "ptr_array_si_ty"
1103
1104 )" + BasicTypes() + R"(
1105
1106 %sampler_ty = OpTypeSampler
1107 %image_ty = OpTypeImage %float 2D 0 0 0 1 Unknown
1108 %sampled_image_ty = OpTypeSampledImage %image_ty
1109 %array_si_ty = OpTypeRuntimeArray %sampled_image_ty
1110 %ptr_array_si_ty = OpTypePointer UniformConstant %array_si_ty
1111
1112 ; CHECK: %[[array_i_ty:\w+]] = OpTypeRuntimeArray %image_ty
1113 ; CHECK: %[[ptr_array_i_ty:\w+]] = OpTypePointer UniformConstant %[[array_i_ty]]
1114 ; CHECK: %[[array_s_ty:\w+]] = OpTypeRuntimeArray %sampler_ty
1115 ; CHECK: %[[ptr_array_s_ty:\w+]] = OpTypePointer UniformConstant %[[array_s_ty]]
1116
1117 %f_ty = OpTypeFunction %float %uint %ptr_array_si_ty %float
1118 ; CHECK: %f_ty = OpTypeFunction %float %uint %[[ptr_array_i_ty]] %[[ptr_array_s_ty]] %float
1119 )" + Main();
1120
1121 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1122 kTest, /* do_validation= */ true);
1123 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1124 }
1125
1126 // Remap function bodies
1127
1128 std::string NamedITypes() {
1129 return R"(
1130 OpName %f "f"
1131 OpName %f_ty "f_ty"
1132 OpName %i_ty "i_ty"
1133 OpName %s_ty "s_ty"
1134 OpName %p_i_ty "p_i_ty"
1135 OpName %p_s_ty "p_s_ty"
1136 )";
1137 }
1138
1139 std::string NamedCombinedTypes() {
1140 return R"(
1141 OpName %si_ty "si_ty"
1142 OpName %p_si_ty "p_si_ty"
1143 OpName %array_si_ty "array_si_ty"
1144 OpName %rtarray_si_ty "rtarray_si_ty"
1145 OpName %p_array_si_ty "p_array_si_ty"
1146 OpName %p_rtarray_si_ty "p_rtarray_si_ty"
1147 )";
1148 }
1149
1150 std::string NamedCaller() {
1151 return R"(
1152 OpName %caller_ty "caller_ty"
1153 OpName %caller "caller"
1154 OpName %caller_entry "caller_entry"
1155 OpName %caller_call "caller_call"
1156 OpName %caller_arg "caller_arg"
1157 )";
1158 }
1159
1160 std::string ITypes() {
1161 return R"(
1162 %i_ty = OpTypeImage %float 2D 0 0 0 1 Unknown
1163 %s_ty = OpTypeSampler
1164 %p_i_ty = OpTypePointer UniformConstant %i_ty
1165 %p_s_ty = OpTypePointer UniformConstant %s_ty
1166 )";
1167 }
1168
1169 std::string CombinedTypes() {
1170 return R"(
1171 %si_ty = OpTypeSampledImage %i_ty
1172 %p_si_ty = OpTypePointer UniformConstant %si_ty
1173 %array_si_ty = OpTypeArray %si_ty %uint_3
1174 %p_array_si_ty = OpTypePointer UniformConstant %array_si_ty
1175 %rtarray_si_ty = OpTypeRuntimeArray %si_ty
1176 %p_rtarray_si_ty = OpTypePointer UniformConstant %rtarray_si_ty
1177 )";
1178 }
1179
1180 TEST_F(SplitCombinedImageSamplerPassTest, FunctionBody_ScalarNoChange) {
1181 const std::string kTest = Preamble() + NamedITypes() + NamedCombinedTypes() +
1182 BasicTypes() + ITypes() + CombinedTypes() + R"(
1183
1184 ; CHECK: %f_ty = OpTypeFunction %float %i_ty %s_ty %p_i_ty %p_s_ty
1185 %f_ty = OpTypeFunction %float %i_ty %s_ty %p_i_ty %p_s_ty
1186
1187 ; CHECK: %f = OpFunction %float None %f_ty
1188 ; CHECK-NEXT: OpFunctionParameter %i_ty
1189 ; CHECK-NEXT: OpFunctionParameter %s_ty
1190 ; CHECK-NEXT: OpFunctionParameter %p_i_ty
1191 ; CHECK-NEXT: OpFunctionParameter %p_s_ty
1192 ; CHECK-NEXT: OpLabel
1193 %f = OpFunction %float None %f_ty
1194 %100 = OpFunctionParameter %i_ty
1195 %101 = OpFunctionParameter %s_ty
1196 %102 = OpFunctionParameter %p_i_ty
1197 %103 = OpFunctionParameter %p_s_ty
1198 %110 = OpLabel
1199 OpReturnValue %float_0
1200 OpFunctionEnd
1201 )" + Main();
1202
1203 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1204 kTest, /* do_validation= */ true);
1205 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1206 }
1207
1208 TEST_F(SplitCombinedImageSamplerPassTest,
1209 FunctionBody_SampledImage_OpImageSample) {
1210 const std::string kTest = Preamble() + NamedITypes() + NamedCombinedTypes() +
1211 BasicTypes() + ITypes() + CombinedTypes() + R"(
1212
1213 ; CHECK: %f_ty = OpTypeFunction %v4float %uint %i_ty %s_ty %float
1214 %f_ty = OpTypeFunction %v4float %uint %si_ty %float
1215
1216 ; CHECK: %f = OpFunction %v4float None %f_ty
1217 ; CHECK: OpFunctionParameter %uint
1218 ; CHECK-NEXT: %[[i:\w+]] = OpFunctionParameter %i_ty
1219 ; CHECK-NEXT: %[[s:\w+]] = OpFunctionParameter %s_ty
1220 ; CHECK-NEXT: OpFunctionParameter %float
1221 ; CHECK-NEXT: OpLabel
1222 ; CHECK-NEXT: %[[si:\w+]] = OpSampledImage %si_ty %[[i]] %[[s]]
1223 ; CHECK-NEXT: %200 = OpImageSampleExplicitLod %v4float %[[si]] %13 Lod %float_0
1224 ; CHECK-NEXT: OpReturnValue %200
1225
1226 %f = OpFunction %v4float None %f_ty
1227 %100 = OpFunctionParameter %uint
1228 %101 = OpFunctionParameter %si_ty ; replace this
1229 %110 = OpFunctionParameter %float
1230 %120 = OpLabel
1231 %200 = OpImageSampleExplicitLod %v4float %101 %13 Lod %float_0
1232 OpReturnValue %200
1233 OpFunctionEnd
1234
1235 )" + Main();
1236
1237 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1238 kTest, /* do_validation= */ true);
1239 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1240 }
1241
1242 TEST_F(SplitCombinedImageSamplerPassTest, FunctionBody_SampledImage_OpImage) {
1243 const std::string kTest = Preamble() + NamedITypes() + NamedCombinedTypes() +
1244 BasicTypes() + ITypes() + CombinedTypes() + R"(
1245
1246 ; CHECK: %f_ty = OpTypeFunction %void %uint %i_ty %s_ty %float
1247 %f_ty = OpTypeFunction %void %uint %si_ty %float
1248
1249 ; CHECK: %f = OpFunction %void None %f_ty
1250 ; CHECK: OpFunctionParameter %uint
1251 ; CHECK-NEXT: %[[i:\w+]] = OpFunctionParameter %i_ty
1252 ; CHECK-NEXT: %[[s:\w+]] = OpFunctionParameter %s_ty
1253 ; CHECK-NEXT: OpFunctionParameter %float
1254 ; CHECK-NEXT: OpLabel
1255 ; CHECK-NEXT: %[[si:\w+]] = OpSampledImage %si_ty %[[i]] %[[s]]
1256 ; CHECK-NEXT: %200 = OpImage %i_ty %[[si]]
1257 ; CHECK-NEXT: OpReturn
1258
1259 %f = OpFunction %void None %f_ty
1260 %100 = OpFunctionParameter %uint
1261 %101 = OpFunctionParameter %si_ty ; replace this
1262 %110 = OpFunctionParameter %float
1263 %120 = OpLabel
1264 %200 = OpImage %i_ty %101
1265 OpReturn
1266 OpFunctionEnd
1267
1268 )" + Main();
1269
1270 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1271 kTest, /* do_validation= */ true);
1272 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1273 }
1274
1275 TEST_F(SplitCombinedImageSamplerPassTest, FunctionBody_PtrSampledImage) {
1276 const std::string kTest = Preamble() + NamedITypes() + NamedCombinedTypes() +
1277 BasicTypes() + ITypes() + CombinedTypes() + R"(
1278
1279 ; CHECK: %f_ty = OpTypeFunction %v4float %uint %p_i_ty %p_s_ty %float
1280 %f_ty = OpTypeFunction %v4float %uint %p_si_ty %float
1281
1282 ; CHECK: %f = OpFunction %v4float None %f_ty
1283 ; CHECK-NEXT: OpFunctionParameter %uint
1284 ; CHECK-NEXT: %[[pi:\w+]] = OpFunctionParameter %p_i_ty
1285 ; CHECK-NEXT: %[[ps:\w+]] = OpFunctionParameter %p_s_ty
1286 ; CHECK-NEXT: OpFunctionParameter %float
1287 ; CHECK-NEXT: OpLabel
1288 ; CHECK-NEXT: %[[i:\w+]] = OpLoad %i_ty %[[pi]]
1289 ; CHECK-NEXT: %[[s:\w+]] = OpLoad %s_ty %[[ps]]
1290 ; CHECK-NEXT: %[[si:\w+]] = OpSampledImage %si_ty %[[i]] %[[s]]
1291 ; CHECK-NEXT: %200 = OpImageSampleExplicitLod %v4float %[[si]] %13 Lod %float_0
1292 ; CHECK-NEXT: OpReturnValue %200
1293
1294 %f = OpFunction %v4float None %f_ty
1295 %100 = OpFunctionParameter %uint
1296 %101 = OpFunctionParameter %p_si_ty ; replace this
1297 %110 = OpFunctionParameter %float
1298 %120 = OpLabel
1299 %121 = OpLoad %si_ty %101
1300 %200 = OpImageSampleExplicitLod %v4float %121 %13 Lod %float_0
1301 OpReturnValue %200
1302 OpFunctionEnd
1303 )" + Main();
1304
1305 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1306 kTest, /* do_validation= */ true);
1307 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1308 }
1309
1310 TEST_F(SplitCombinedImageSamplerPassTest,
1311 FunctionCall_NoImageOrSampler_NoChange) {
1312 const std::string kTest = Preamble() + NamedITypes() + NamedCaller() +
1313 BasicTypes() + ITypes() + CombinedTypes() + R"(
1314
1315 ; CHECK: %f_ty = OpTypeFunction %void %uint %float
1316 %f_ty = OpTypeFunction %void %uint %float
1317 %caller_ty = OpTypeFunction %float ; make it return non-void otherwise it's just like main
1318
1319 ; The called function does not change
1320 ; CHECK: %f = OpFunction %void None %f_ty
1321 ; CHECK-NEXT: = OpFunctionParameter %uint
1322 ; CHECK-NEXT: = OpFunctionParameter %float
1323 ; CHECK-NEXT: = OpLabel
1324 ; CHECK-NEXT: OpReturn
1325 ; CHECK-NEXT: OpFunctionEnd
1326
1327 %f = OpFunction %void None %f_ty
1328 %100 = OpFunctionParameter %uint
1329 %101 = OpFunctionParameter %float
1330 %110 = OpLabel
1331 OpReturn
1332 OpFunctionEnd
1333
1334 ; The caller does not change
1335 ; CHECK: %caller = OpFunction %float None %caller_ty
1336 ; CHECK-NEXT: %caller_entry = OpLabel
1337 ; CHECK-NEXT: %caller_arg = OpCopyObject %uint %uint_0
1338 ; CHECK-NEXT: OpFunctionCall %void %f %caller_arg %float_0
1339 ; CHECK-NEXT: OpReturnValue %float_0
1340 ; CHECK-NEXT: OpFunctionEnd
1341
1342 %caller = OpFunction %float None %caller_ty
1343 %caller_entry = OpLabel
1344 %caller_arg = OpCopyObject %uint %uint_0
1345 %caller_call = OpFunctionCall %void %f %caller_arg %float_0
1346 OpReturnValue %float_0
1347 OpFunctionEnd
1348
1349 )" + Main();
1350
1351 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1352 kTest, /* do_validation= */ true);
1353 // We still get a success-with-change result because the boilerplate included
1354 // combined types, which were removed.
1355 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1356 }
1357
1358 TEST_F(SplitCombinedImageSamplerPassTest, FunctionCall_Image_NoChange) {
1359 const std::string kTest = Preamble() + NamedITypes() + NamedCaller() +
1360 BasicTypes() + ITypes() + R"(
1361
1362 ; CHECK: %f_ty = OpTypeFunction %void %i_ty
1363 %f_ty = OpTypeFunction %void %i_ty
1364 %caller_ty = OpTypeFunction %float %i_ty
1365
1366 ; The called function does not change
1367 ; CHECK: %f = OpFunction %void None %f_ty
1368 ; CHECK-NEXT: = OpFunctionParameter %i_ty
1369 ; CHECK-NEXT: = OpLabel
1370 ; CHECK-NEXT: OpReturn
1371 ; CHECK-NEXT: OpFunctionEnd
1372
1373 %f = OpFunction %void None %f_ty
1374 %100 = OpFunctionParameter %i_ty
1375 %110 = OpLabel
1376 OpReturn
1377 OpFunctionEnd
1378
1379 ; The caller does not change
1380 ; CHECK: %caller = OpFunction %float None %caller_ty
1381 ; CHECK-NEXT: %caller_arg = OpFunctionParameter %i_ty
1382 ; CHECK-NEXT: %caller_entry = OpLabel
1383 ; CHECK-NEXT: OpFunctionCall %void %f %caller_arg
1384 ; CHECK-NEXT: OpReturnValue %float_0
1385 ; CHECK-NEXT: OpFunctionEnd
1386
1387 %caller = OpFunction %float None %caller_ty
1388 %caller_arg = OpFunctionParameter %i_ty
1389 %caller_entry = OpLabel
1390 %caller_call = OpFunctionCall %void %f %caller_arg
1391 OpReturnValue %float_0
1392 OpFunctionEnd
1393
1394 )" + Main();
1395
1396 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1397 kTest, /* do_validation= */ true);
1398 EXPECT_EQ(status, Pass::Status::SuccessWithoutChange) << disasm;
1399 }
1400
1401 TEST_F(SplitCombinedImageSamplerPassTest, FunctionCall_Sampler_NoChange) {
1402 const std::string kTest = Preamble() + NamedITypes() + NamedCaller() +
1403 BasicTypes() + ITypes() + R"(
1404
1405 ; CHECK: %f_ty = OpTypeFunction %void %s_ty
1406 %f_ty = OpTypeFunction %void %s_ty
1407 %caller_ty = OpTypeFunction %float %s_ty
1408
1409 ; The called function does not change
1410 ; CHECK: %f = OpFunction %void None %f_ty
1411 ; CHECK-NEXT: = OpFunctionParameter %s_ty
1412 ; CHECK-NEXT: = OpLabel
1413 ; CHECK-NEXT: OpReturn
1414 ; CHECK-NEXT: OpFunctionEnd
1415
1416 %f = OpFunction %void None %f_ty
1417 %100 = OpFunctionParameter %s_ty
1418 %110 = OpLabel
1419 OpReturn
1420 OpFunctionEnd
1421
1422 ; The caller does not change
1423 ; CHECK: %caller = OpFunction %float None %caller_ty
1424 ; CHECK-NEXT: %caller_arg = OpFunctionParameter %s_ty
1425 ; CHECK-NEXT: %caller_entry = OpLabel
1426 ; CHECK-NEXT: OpFunctionCall %void %f %caller_arg
1427 ; CHECK-NEXT: OpReturnValue %float_0
1428 ; CHECK-NEXT: OpFunctionEnd
1429
1430 %caller = OpFunction %float None %caller_ty
1431 %caller_arg = OpFunctionParameter %s_ty
1432 %caller_entry = OpLabel
1433 %caller_call = OpFunctionCall %void %f %caller_arg
1434 OpReturnValue %float_0
1435 OpFunctionEnd
1436
1437 )" + Main();
1438
1439 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1440 kTest, /* do_validation= */ true);
1441 EXPECT_EQ(status, Pass::Status::SuccessWithoutChange) << disasm;
1442 }
1443
1444 TEST_F(SplitCombinedImageSamplerPassTest, FunctionCall_PtrImage_NoChange) {
1445 const std::string kTest = Preamble() + NamedITypes() + NamedCaller() +
1446 BasicTypes() + ITypes() + R"(
1447
1448 ; CHECK: %f_ty = OpTypeFunction %void %p_i_ty
1449 %f_ty = OpTypeFunction %void %p_i_ty
1450 %caller_ty = OpTypeFunction %float %p_i_ty
1451
1452 ; The called function does not change
1453 ; CHECK: %f = OpFunction %void None %f_ty
1454 ; CHECK-NEXT: = OpFunctionParameter %p_i_ty
1455 ; CHECK-NEXT: = OpLabel
1456 ; CHECK-NEXT: OpReturn
1457 ; CHECK-NEXT: OpFunctionEnd
1458
1459 %f = OpFunction %void None %f_ty
1460 %100 = OpFunctionParameter %p_i_ty
1461 %110 = OpLabel
1462 OpReturn
1463 OpFunctionEnd
1464
1465 ; The caller does not change
1466 ; CHECK: %caller = OpFunction %float None %caller_ty
1467 ; CHECK-NEXT: %caller_arg = OpFunctionParameter %p_i_ty
1468 ; CHECK-NEXT: %caller_entry = OpLabel
1469 ; CHECK-NEXT: OpFunctionCall %void %f %caller_arg
1470 ; CHECK-NEXT: OpReturnValue %float_0
1471 ; CHECK-NEXT: OpFunctionEnd
1472
1473 %caller = OpFunction %float None %caller_ty
1474 %caller_arg = OpFunctionParameter %p_i_ty
1475 %caller_entry = OpLabel
1476 %caller_call = OpFunctionCall %void %f %caller_arg
1477 OpReturnValue %float_0
1478 OpFunctionEnd
1479
1480 )" + Main();
1481
1482 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1483 kTest, /* do_validation= */ true);
1484 EXPECT_EQ(status, Pass::Status::SuccessWithoutChange) << disasm;
1485 }
1486
1487 TEST_F(SplitCombinedImageSamplerPassTest, FunctionCall_PtrSampler_NoChange) {
1488 const std::string kTest = Preamble() + NamedITypes() + NamedCaller() +
1489 BasicTypes() + ITypes() + R"(
1490
1491 ; CHECK: %f_ty = OpTypeFunction %void %p_s_ty
1492 %f_ty = OpTypeFunction %void %p_s_ty
1493 %caller_ty = OpTypeFunction %float %p_s_ty
1494
1495 ; The called function does not change
1496 ; CHECK: %f = OpFunction %void None %f_ty
1497 ; CHECK-NEXT: = OpFunctionParameter %p_s_ty
1498 ; CHECK-NEXT: = OpLabel
1499 ; CHECK-NEXT: OpReturn
1500 ; CHECK-NEXT: OpFunctionEnd
1501
1502 %f = OpFunction %void None %f_ty
1503 %100 = OpFunctionParameter %p_s_ty
1504 %110 = OpLabel
1505 OpReturn
1506 OpFunctionEnd
1507
1508 ; The caller does not change
1509 ; CHECK: %caller = OpFunction %float None %caller_ty
1510 ; CHECK-NEXT: %caller_arg = OpFunctionParameter %p_s_ty
1511 ; CHECK-NEXT: %caller_entry = OpLabel
1512 ; CHECK-NEXT: OpFunctionCall %void %f %caller_arg
1513 ; CHECK-NEXT: OpReturnValue %float_0
1514 ; CHECK-NEXT: OpFunctionEnd
1515
1516 %caller = OpFunction %float None %caller_ty
1517 %caller_arg = OpFunctionParameter %p_s_ty
1518 %caller_entry = OpLabel
1519 %caller_call = OpFunctionCall %void %f %caller_arg
1520 OpReturnValue %float_0
1521 OpFunctionEnd
1522
1523 )" + Main();
1524
1525 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1526 kTest, /* do_validation= */ true);
1527 EXPECT_EQ(status, Pass::Status::SuccessWithoutChange) << disasm;
1528 }
1529
1530 TEST_F(SplitCombinedImageSamplerPassTest, FunctionCall_SampledImage_Split) {
1531 const std::string kTest = Preamble() + NamedITypes() + NamedCombinedTypes() +
1532 NamedCaller() + BasicTypes() + ITypes() +
1533 CombinedTypes() + R"(
1534
1535 ; CHECK: %f_ty = OpTypeFunction %void %i_ty %s_ty
1536 %f_ty = OpTypeFunction %void %si_ty
1537 %caller_ty = OpTypeFunction %float %si_ty
1538
1539 ; Call function arg is split. We've checked these details in other tests.
1540 ; CHECK: %f = OpFunction %void None %f_ty
1541 ; CHECK-NEXT: %[[callee_i:\w+]] = OpFunctionParameter %i_ty
1542 ; CHECK-NEXT: %[[callee_s:\w+]] = OpFunctionParameter %s_ty
1543 ; CHECK-NEXT: = OpLabel
1544 ; CHECK-NEXT: OpReturn
1545 ; CHECK-NEXT: OpFunctionEnd
1546
1547 %f = OpFunction %void None %f_ty
1548 %100 = OpFunctionParameter %si_ty
1549 %110 = OpLabel
1550 OpReturn
1551 OpFunctionEnd
1552
1553 ; CHECK: %caller = OpFunction %float None %caller_ty
1554 ; CHECK-NEXT: %[[caller_i:\w+]] = OpFunctionParameter %i_ty
1555 ; CHECK-NEXT: %[[caller_s:\w+]] = OpFunctionParameter %s_ty
1556 ; CHECK-NEXT: %caller_entry = OpLabel
1557 ; CHECK-NEXT: %caller_call = OpFunctionCall %void %f %[[caller_i]] %[[caller_s]]
1558 ; CHECK-NEXT: OpReturnValue %float_0
1559 ; CHECK-NEXT: OpFunctionEnd
1560
1561 %caller = OpFunction %float None %caller_ty
1562 %caller_arg = OpFunctionParameter %si_ty
1563 %caller_entry = OpLabel
1564 %caller_call = OpFunctionCall %void %f %caller_arg
1565 OpReturnValue %float_0
1566 OpFunctionEnd
1567
1568 )" + Main();
1569
1570 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1571 kTest, /* do_validation= */ true);
1572 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1573 }
1574
1575 TEST_F(SplitCombinedImageSamplerPassTest,
1576 FunctionCall_SampledImageDuplicatedArg_Split) {
1577 const std::string kTest = Preamble() + NamedITypes() + NamedCombinedTypes() +
1578 NamedCaller() + BasicTypes() + ITypes() +
1579 CombinedTypes() + R"(
1580
1581 ; CHECK: %f_ty = OpTypeFunction %void %i_ty %s_ty %i_ty %s_ty
1582 %f_ty = OpTypeFunction %void %si_ty %si_ty
1583 %caller_ty = OpTypeFunction %float %si_ty
1584
1585 ; Call function arg is split. We've checked these details in other tests.
1586 ; CHECK: %f = OpFunction %void None %f_ty
1587 ; CHECK-NEXT: %[[callee_i_0:\w+]] = OpFunctionParameter %i_ty
1588 ; CHECK-NEXT: %[[callee_s_0:\w+]] = OpFunctionParameter %s_ty
1589 ; CHECK-NEXT: %[[callee_i_1:\w+]] = OpFunctionParameter %i_ty
1590 ; CHECK-NEXT: %[[callee_s_1:\w+]] = OpFunctionParameter %s_ty
1591 ; CHECK-NEXT: = OpLabel
1592 ; CHECK-NEXT: OpReturn
1593 ; CHECK-NEXT: OpFunctionEnd
1594
1595 %f = OpFunction %void None %f_ty
1596 %100 = OpFunctionParameter %si_ty
1597 %101 = OpFunctionParameter %si_ty
1598 %110 = OpLabel
1599 OpReturn
1600 OpFunctionEnd
1601
1602 ; CHECK: %caller = OpFunction %float None %caller_ty
1603 ; CHECK-NEXT: %[[caller_i:\w+]] = OpFunctionParameter %i_ty
1604 ; CHECK-NEXT: %[[caller_s:\w+]] = OpFunctionParameter %s_ty
1605 ; CHECK-NEXT: %caller_entry = OpLabel
1606 ; CHECK-NEXT: %caller_call = OpFunctionCall %void %f %[[caller_i]] %[[caller_s]] %[[caller_i]] %[[caller_s]]
1607 ; CHECK-NEXT: OpReturnValue %float_0
1608 ; CHECK-NEXT: OpFunctionEnd
1609
1610 %caller = OpFunction %float None %caller_ty
1611 %caller_arg = OpFunctionParameter %si_ty
1612 %caller_entry = OpLabel
1613 %caller_call = OpFunctionCall %void %f %caller_arg %caller_arg
1614 OpReturnValue %float_0
1615 OpFunctionEnd
1616
1617 )" + Main();
1618
1619 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1620 kTest, /* do_validation= */ true);
1621 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1622 }
1623
1624 TEST_F(SplitCombinedImageSamplerPassTest,
1625 FunctionCall_SampledImageTwoDistinct_Split) {
1626 const std::string kTest = Preamble() + NamedITypes() + NamedCombinedTypes() +
1627 NamedCaller() + BasicTypes() + ITypes() +
1628 CombinedTypes() + R"(
1629
1630 ; CHECK: %f_ty = OpTypeFunction %void %i_ty %s_ty %i_ty %s_ty
1631 %f_ty = OpTypeFunction %void %si_ty %si_ty
1632 %caller_ty = OpTypeFunction %float %si_ty %si_ty
1633
1634 ; Call function arg is split. We've checked these details in other tests.
1635 ; CHECK: %f = OpFunction %void None %f_ty
1636 ; CHECK-NEXT: %[[callee_i_0:\w+]] = OpFunctionParameter %i_ty
1637 ; CHECK-NEXT: %[[callee_s_0:\w+]] = OpFunctionParameter %s_ty
1638 ; CHECK-NEXT: %[[callee_i_1:\w+]] = OpFunctionParameter %i_ty
1639 ; CHECK-NEXT: %[[callee_s_1:\w+]] = OpFunctionParameter %s_ty
1640 ; CHECK-NEXT: = OpLabel
1641 ; CHECK-NEXT: OpReturn
1642 ; CHECK-NEXT: OpFunctionEnd
1643
1644 %f = OpFunction %void None %f_ty
1645 %100 = OpFunctionParameter %si_ty
1646 %101 = OpFunctionParameter %si_ty
1647 %110 = OpLabel
1648 OpReturn
1649 OpFunctionEnd
1650
1651 ; CHECK: %caller = OpFunction %float None %caller_ty
1652 ; CHECK-NEXT: %[[caller_i_0:\w+]] = OpFunctionParameter %i_ty
1653 ; CHECK-NEXT: %[[caller_s_0:\w+]] = OpFunctionParameter %s_ty
1654 ; CHECK-NEXT: %[[caller_i_1:\w+]] = OpFunctionParameter %i_ty
1655 ; CHECK-NEXT: %[[caller_s_1:\w+]] = OpFunctionParameter %s_ty
1656 ; CHECK-NEXT: %caller_entry = OpLabel
1657 ; CHECK-NEXT: %caller_call = OpFunctionCall %void %f %[[caller_i_0]] %[[caller_s_0]] %[[caller_i_1]] %[[caller_s_1]]
1658 ; CHECK-NEXT: OpReturnValue %float_0
1659 ; CHECK-NEXT: OpFunctionEnd
1660
1661 %caller = OpFunction %float None %caller_ty
1662 %caller_arg = OpFunctionParameter %si_ty
1663 %201 = OpFunctionParameter %si_ty
1664 %caller_entry = OpLabel
1665 %caller_call = OpFunctionCall %void %f %caller_arg %201
1666 OpReturnValue %float_0
1667 OpFunctionEnd
1668
1669 )" + Main();
1670
1671 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1672 kTest, /* do_validation= */ true);
1673 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1674 }
1675
1676 TEST_F(SplitCombinedImageSamplerPassTest,
1677 FunctionCall_SampledImageAndCopy_Split) {
1678 const std::string kTest = Preamble() + NamedITypes() + NamedCombinedTypes() +
1679 NamedCaller() + BasicTypes() + ITypes() +
1680 CombinedTypes() + R"(
1681
1682 ; CHECK: %f_ty = OpTypeFunction %void %i_ty %s_ty %i_ty %s_ty
1683 %f_ty = OpTypeFunction %void %si_ty %si_ty
1684 ; CHECK: %caller_ty = OpTypeFunction %float %i_ty %s_ty
1685 %caller_ty = OpTypeFunction %float %si_ty
1686
1687 ; Call function arg is split. We've checked these details in other tests.
1688 ; CHECK: %f = OpFunction %void None %f_ty
1689 ; CHECK-NEXT: %[[callee_i_0:\w+]] = OpFunctionParameter %i_ty
1690 ; CHECK-NEXT: %[[callee_s_0:\w+]] = OpFunctionParameter %s_ty
1691 ; CHECK-NEXT: %[[callee_i_1:\w+]] = OpFunctionParameter %i_ty
1692 ; CHECK-NEXT: %[[callee_s_1:\w+]] = OpFunctionParameter %s_ty
1693 ; CHECK-NEXT: = OpLabel
1694 ; CHECK-NEXT: OpReturn
1695 ; CHECK-NEXT: OpFunctionEnd
1696
1697 %f = OpFunction %void None %f_ty
1698 %100 = OpFunctionParameter %si_ty
1699 %101 = OpFunctionParameter %si_ty
1700 %110 = OpLabel
1701 OpReturn
1702 OpFunctionEnd
1703
1704 ; CHECK: %caller = OpFunction %float None %caller_ty
1705 ; CHECK-NEXT: %[[caller_i:\w+]] = OpFunctionParameter %i_ty
1706 ; CHECK-NEXT: %[[caller_s:\w+]] = OpFunctionParameter %s_ty
1707 ; CHECK-NEXT: %caller_entry = OpLabel
1708 ; CHECK-NEXT: %caller_call = OpFunctionCall %void %f %[[caller_i]] %[[caller_s]] %[[caller_i]] %[[caller_s]]
1709 ; CHECK-NEXT: OpReturnValue %float_0
1710 ; CHECK-NEXT: OpFunctionEnd
1711
1712 %caller = OpFunction %float None %caller_ty
1713 %caller_arg = OpFunctionParameter %si_ty
1714 %caller_entry = OpLabel
1715 %copy = OpCopyObject %si_ty %caller_arg
1716 %caller_call = OpFunctionCall %void %f %caller_arg %copy
1717 OpReturnValue %float_0
1718 OpFunctionEnd
1719
1720 )" + Main();
1721
1722 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1723 kTest, /* do_validation= */ true);
1724 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1725 }
1726
1727 TEST_F(SplitCombinedImageSamplerPassTest,
1728 FunctionCall_SampledImageSurrounded_Split) {
1729 // Test indexing by surrounding the sampled image parameter with other
1730 // arguments that should not be touched.
1731 const std::string kTest = Preamble() + NamedITypes() + NamedCombinedTypes() +
1732 NamedCaller() + BasicTypes() + ITypes() +
1733 CombinedTypes() + R"(
1734
1735 ; CHECK: %f_ty = OpTypeFunction %void %float %i_ty %s_ty %uint
1736 %f_ty = OpTypeFunction %void %float %si_ty %uint
1737 ; CHECK: %caller_ty = OpTypeFunction %float %uint %i_ty %s_ty %float
1738 %caller_ty = OpTypeFunction %float %uint %si_ty %float
1739
1740 ; Call function arg is split. We've checked these details in other tests.
1741 ; CHECK: %f = OpFunction %void None %f_ty
1742 ; CHECK-NEXT: %[[callee_f:\w+]] = OpFunctionParameter %float
1743 ; CHECK-NEXT: %[[callee_i:\w+]] = OpFunctionParameter %i_ty
1744 ; CHECK-NEXT: %[[callee_s:\w+]] = OpFunctionParameter %s_ty
1745 ; CHECK-NEXT: %[[callee_u:\w+]] = OpFunctionParameter %uint
1746 ; CHECK-NEXT: = OpLabel
1747 ; CHECK-NEXT: OpReturn
1748 ; CHECK-NEXT: OpFunctionEnd
1749
1750 %f = OpFunction %void None %f_ty
1751 %99 = OpFunctionParameter %float
1752 %100 = OpFunctionParameter %si_ty
1753 %101 = OpFunctionParameter %uint
1754 %110 = OpLabel
1755 OpReturn
1756 OpFunctionEnd
1757
1758 ; CHECK: %caller = OpFunction %float None %caller_ty
1759 ; CHECK-NEXT: %[[u_param:\w+]] = OpFunctionParameter %uint
1760 ; CHECK-NEXT: %[[caller_i:\w+]] = OpFunctionParameter %i_ty
1761 ; CHECK-NEXT: %[[caller_s:\w+]] = OpFunctionParameter %s_ty
1762 ; CHECK-NEXT: %[[f_param:\w+]] = OpFunctionParameter %float
1763 ; CHECK-NEXT: %caller_entry = OpLabel
1764 ; CHECK-NEXT: %caller_call = OpFunctionCall %void %f %[[f_param]] %[[caller_i]] %[[caller_s]] %[[u_param]]
1765 ; CHECK-NEXT: OpReturnValue %float_0
1766 ; CHECK-NEXT: OpFunctionEnd
1767
1768 %caller = OpFunction %float None %caller_ty
1769 %200 = OpFunctionParameter %uint
1770 %caller_arg = OpFunctionParameter %si_ty
1771 %201 = OpFunctionParameter %float
1772 %caller_entry = OpLabel
1773 %caller_call = OpFunctionCall %void %f %201 %caller_arg %200
1774 OpReturnValue %float_0
1775 OpFunctionEnd
1776
1777 )" + Main();
1778
1779 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1780 kTest, /* do_validation= */ true);
1781 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1782 }
1783
1784 TEST_F(SplitCombinedImageSamplerPassTest, FunctionCall_PtrSampledImage_Split) {
1785 const std::string kTest = Preamble() + NamedITypes() + NamedCombinedTypes() +
1786 NamedCaller() + BasicTypes() + ITypes() +
1787 CombinedTypes() + R"(
1788
1789 ; CHECK: %f_ty = OpTypeFunction %void %p_i_ty %p_s_ty
1790 %f_ty = OpTypeFunction %void %p_si_ty
1791 %caller_ty = OpTypeFunction %float %p_si_ty
1792
1793 ; Call function arg is split. We've checked these details in other tests.
1794 ; CHECK: %f = OpFunction %void None %f_ty
1795 ; CHECK-NEXT: %[[callee_i:\w+]] = OpFunctionParameter %p_i_ty
1796 ; CHECK-NEXT: %[[callee_s:\w+]] = OpFunctionParameter %p_s_ty
1797 ; CHECK-NEXT: = OpLabel
1798 ; CHECK-NEXT: OpReturn
1799 ; CHECK-NEXT: OpFunctionEnd
1800
1801 %f = OpFunction %void None %f_ty
1802 %100 = OpFunctionParameter %p_si_ty
1803 %110 = OpLabel
1804 OpReturn
1805 OpFunctionEnd
1806
1807 ; CHECK: %caller = OpFunction %float None %caller_ty
1808 ; CHECK-NEXT: %[[caller_i:\w+]] = OpFunctionParameter %p_i_ty
1809 ; CHECK-NEXT: %[[caller_s:\w+]] = OpFunctionParameter %p_s_ty
1810 ; CHECK-NEXT: %caller_entry = OpLabel
1811 ; CHECK-NEXT: %caller_call = OpFunctionCall %void %f %[[caller_i]] %[[caller_s]]
1812 ; CHECK-NEXT: OpReturnValue %float_0
1813 ; CHECK-NEXT: OpFunctionEnd
1814
1815 %caller = OpFunction %float None %caller_ty
1816 %caller_arg = OpFunctionParameter %p_si_ty
1817 %caller_entry = OpLabel
1818 %caller_call = OpFunctionCall %void %f %caller_arg
1819 OpReturnValue %float_0
1820 OpFunctionEnd
1821
1822 )" + Main();
1823
1824 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1825 kTest, /* do_validation= */ true);
1826 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1827 }
1828
1829 TEST_F(SplitCombinedImageSamplerPassTest,
1830 FunctionCall_PtrArraySampledImage_Split) {
1831 const std::string kTest = Preamble() + NamedITypes() + NamedCombinedTypes() +
1832 NamedCaller() + BasicTypes() + ITypes() +
1833 CombinedTypes() + R"(
1834
1835 ; CHECK: %[[array_i_ty:\w+]] = OpTypeArray %i_ty %uint_3
1836 ; CHECK: %[[p_array_i_ty:\w+]] = OpTypePointer UniformConstant %[[array_i_ty]]
1837 ; CHECK: %[[array_s_ty:\w+]] = OpTypeArray %s_ty %uint_3
1838 ; CHECK: %[[p_array_s_ty:\w+]] = OpTypePointer UniformConstant %[[array_s_ty]]
1839
1840 ; CHECK: %f_ty = OpTypeFunction %void %[[p_array_i_ty]] %[[p_array_s_ty]]
1841 %f_ty = OpTypeFunction %void %p_array_si_ty
1842 %caller_ty = OpTypeFunction %float %p_array_si_ty
1843
1844 ; Call function arg is split. We've checked these details in other tests.
1845 ; CHECK: %f = OpFunction %void None %f_ty
1846 ; CHECK-NEXT: %[[callee_i:\w+]] = OpFunctionParameter %[[p_array_i_ty]]
1847 ; CHECK-NEXT: %[[callee_s:\w+]] = OpFunctionParameter %[[p_array_s_ty]]
1848 ; CHECK-NEXT: = OpLabel
1849 ; CHECK-NEXT: OpReturn
1850 ; CHECK-NEXT: OpFunctionEnd
1851
1852 %f = OpFunction %void None %f_ty
1853 %100 = OpFunctionParameter %p_array_si_ty
1854 %110 = OpLabel
1855 OpReturn
1856 OpFunctionEnd
1857
1858 ; CHECK: %caller = OpFunction %float None %caller_ty
1859 ; CHECK-NEXT: %[[caller_i:\w+]] = OpFunctionParameter %[[p_array_i_ty]]
1860 ; CHECK-NEXT: %[[caller_s:\w+]] = OpFunctionParameter %[[p_array_s_ty]]
1861 ; CHECK-NEXT: %caller_entry = OpLabel
1862 ; CHECK-NEXT: %caller_call = OpFunctionCall %void %f %[[caller_i]] %[[caller_s]]
1863 ; CHECK-NEXT: OpReturnValue %float_0
1864 ; CHECK-NEXT: OpFunctionEnd
1865
1866 %caller = OpFunction %float None %caller_ty
1867 %caller_arg = OpFunctionParameter %p_array_si_ty
1868 %caller_entry = OpLabel
1869 %caller_call = OpFunctionCall %void %f %caller_arg
1870 OpReturnValue %float_0
1871 OpFunctionEnd
1872
1873 )" + Main();
1874
1875 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1876 kTest, /* do_validation= */ true);
1877 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1878 }
1879
1880 TEST_F(SplitCombinedImageSamplerPassTest,
1881 FunctionCall_PtrRtArraySampledImage_Split) {
1882 const std::string kTest = Preamble() + NamedITypes() + NamedCombinedTypes() +
1883 NamedCaller() + BasicTypes() + ITypes() +
1884 CombinedTypes() + R"(
1885
1886 ; CHECK: %[[array_i_ty:\w+]] = OpTypeRuntimeArray %i_ty
1887 ; CHECK: %[[p_array_i_ty:\w+]] = OpTypePointer UniformConstant %[[array_i_ty]]
1888 ; CHECK: %[[array_s_ty:\w+]] = OpTypeRuntimeArray
1889 ; CHECK: %[[p_array_s_ty:\w+]] = OpTypePointer UniformConstant %[[array_s_ty]]
1890
1891 ; CHECK: %f_ty = OpTypeFunction %void %[[p_array_i_ty]] %[[p_array_s_ty]]
1892 %f_ty = OpTypeFunction %void %p_rtarray_si_ty
1893 %caller_ty = OpTypeFunction %float %p_rtarray_si_ty
1894
1895 ; Call function arg is split. We've checked these details in other tests.
1896 ; CHECK: %f = OpFunction %void None %f_ty
1897 ; CHECK-NEXT: %[[callee_i:\w+]] = OpFunctionParameter %[[p_array_i_ty]]
1898 ; CHECK-NEXT: %[[callee_s:\w+]] = OpFunctionParameter %[[p_array_s_ty]]
1899 ; CHECK-NEXT: = OpLabel
1900 ; CHECK-NEXT: OpReturn
1901 ; CHECK-NEXT: OpFunctionEnd
1902
1903 %f = OpFunction %void None %f_ty
1904 %100 = OpFunctionParameter %p_rtarray_si_ty
1905 %110 = OpLabel
1906 OpReturn
1907 OpFunctionEnd
1908
1909 ; CHECK: %caller = OpFunction %float None %caller_ty
1910 ; CHECK-NEXT: %[[caller_i:\w+]] = OpFunctionParameter %[[p_array_i_ty]]
1911 ; CHECK-NEXT: %[[caller_s:\w+]] = OpFunctionParameter %[[p_array_s_ty]]
1912 ; CHECK-NEXT: %caller_entry = OpLabel
1913 ; CHECK-NEXT: %caller_call = OpFunctionCall %void %f %[[caller_i]] %[[caller_s]]
1914 ; CHECK-NEXT: OpReturnValue %float_0
1915 ; CHECK-NEXT: OpFunctionEnd
1916
1917 %caller = OpFunction %float None %caller_ty
1918 %caller_arg = OpFunctionParameter %p_rtarray_si_ty
1919 %caller_entry = OpLabel
1920 %caller_call = OpFunctionCall %void %f %caller_arg
1921 OpReturnValue %float_0
1922 OpFunctionEnd
1923
1924 )" + Main();
1925
1926 auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
1927 kTest, /* do_validation= */ true);
1928 EXPECT_EQ(status, Pass::Status::SuccessWithChange) << disasm;
1929 }
1930
1931 } // namespace
1932 } // namespace opt
1933 } // namespace spvtools