Debian Codegraph @

test/opt/canonicalize_ids_test.cpp

raw
1 // Copyright (c) 2025 LunarG Inc.
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 "gmock/gmock.h"
16 #include "test/opt/pass_fixture.h"
17
18 namespace spvtools {
19 namespace opt {
20 namespace {
21
22 using CanonicalizeIdsTest = PassTest<::testing::Test>;
23
24 // ported from remap.basic.everything.frag
25 TEST_F(CanonicalizeIdsTest, remap_basic) {
26 const std::string before =
27 R"(OpCapability Shader
28 %1 = OpExtInstImport "GLSL.std.450"
29 OpMemoryModel Logical GLSL450
30 OpEntryPoint Fragment %4 "main" %9 %11
31 OpExecutionMode %4 OriginUpperLeft
32 OpSource GLSL 450
33 OpName %4 "main"
34 OpName %9 "outf4"
35 OpName %11 "inf"
36 OpDecorate %9 Location 0
37 OpDecorate %11 Location 0
38 %2 = OpTypeVoid
39 %3 = OpTypeFunction %2
40 %6 = OpTypeFloat 32
41 %7 = OpTypeVector %6 4
42 %8 = OpTypePointer Output %7
43 %9 = OpVariable %8 Output
44 %10 = OpTypePointer Input %6
45 %11 = OpVariable %10 Input
46 %4 = OpFunction %2 None %3
47 %5 = OpLabel
48 %12 = OpLoad %6 %11
49 %13 = OpCompositeConstruct %7 %12 %12 %12 %12
50 OpStore %9 %13
51 OpReturn
52 OpFunctionEnd
53 )";
54
55 const std::string after =
56 R"(OpCapability Shader
57 %1 = OpExtInstImport "GLSL.std.450"
58 OpMemoryModel Logical GLSL450
59 OpEntryPoint Fragment %5663 "main" %4539 %3773
60 OpExecutionMode %5663 OriginUpperLeft
61 OpSource GLSL 450
62 OpName %5663 "main"
63 OpName %4539 "outf4"
64 OpName %3773 "inf"
65 OpDecorate %4539 Location 0
66 OpDecorate %3773 Location 0
67 %8 = OpTypeVoid
68 %1282 = OpTypeFunction %8
69 %13 = OpTypeFloat 32
70 %29 = OpTypeVector %13 4
71 %666 = OpTypePointer Output %29
72 %4539 = OpVariable %666 Output
73 %650 = OpTypePointer Input %13
74 %3773 = OpVariable %650 Input
75 %5663 = OpFunction %8 None %1282
76 %24968 = OpLabel
77 %17486 = OpLoad %13 %3773
78 %17691 = OpCompositeConstruct %29 %17486 %17486 %17486 %17486
79 OpStore %4539 %17691
80 OpReturn
81 OpFunctionEnd
82 )";
83
84 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
85 SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
86 SinglePassRunAndCheck<CanonicalizeIdsPass>(before, after, false, false);
87 }
88
89 // ported from remap.hlsl.sample.basic.everything.frag
90 TEST_F(CanonicalizeIdsTest, remap_hlsl_sample_basic) {
91 const std::string before =
92 R"(OpCapability Shader
93 OpCapability Sampled1D
94 %1 = OpExtInstImport "GLSL.std.450"
95 OpMemoryModel Logical GLSL450
96 OpEntryPoint Fragment %4 "main" %188 %192
97 OpExecutionMode %4 OriginUpperLeft
98 OpExecutionMode %4 DepthReplacing
99 OpSource HLSL 500
100 OpName %4 "main"
101 OpName %8 "PS_OUTPUT"
102 OpMemberName %8 0 "Color"
103 OpMemberName %8 1 "Depth"
104 OpName %10 "@main("
105 OpName %13 "MemberTest"
106 OpMemberName %13 0 "Sample"
107 OpMemberName %13 1 "CalculateLevelOfDetail"
108 OpMemberName %13 2 "CalculateLevelOfDetailUnclamped"
109 OpMemberName %13 3 "Gather"
110 OpMemberName %13 4 "GetDimensions"
111 OpMemberName %13 5 "GetSamplePosition"
112 OpMemberName %13 6 "Load"
113 OpMemberName %13 7 "SampleBias"
114 OpMemberName %13 8 "SampleCmp"
115 OpMemberName %13 9 "SampleCmpLevelZero"
116 OpMemberName %13 10 "SampleGrad"
117 OpMemberName %13 11 "SampleLevel"
118 OpName %15 "mtest"
119 OpName %54 "txval10"
120 OpName %45 "g_tTex1df4"
121 OpName %49 "g_sSamp"
122 OpName %66 "txval11"
123 OpName %60 "g_tTex1di4"
124 OpName %79 "txval12"
125 OpName %73 "g_tTex1du4"
126 OpName %90 "txval20"
127 OpName %83 "g_tTex2df4"
128 OpName %101 "txval21"
129 OpName %94 "g_tTex2di4"
130 OpName %113 "txval22"
131 OpName %105 "g_tTex2du4"
132 OpName %124 "txval30"
133 OpName %117 "g_tTex3df4"
134 OpName %134 "txval31"
135 OpName %128 "g_tTex3di4"
136 OpName %147 "txval32"
137 OpName %138 "g_tTex3du4"
138 OpName %156 "txval40"
139 OpName %151 "g_tTexcdf4"
140 OpName %165 "txval41"
141 OpName %160 "g_tTexcdi4"
142 OpName %174 "txval42"
143 OpName %169 "g_tTexcdu4"
144 OpName %176 "psout"
145 OpName %185 "flattenTemp"
146 OpName %188 "@entryPointOutput.Color"
147 OpName %192 "@entryPointOutput.Depth"
148 OpDecorate %45 Binding 0
149 OpDecorate %45 DescriptorSet 0
150 OpDecorate %49 Binding 0
151 OpDecorate %49 DescriptorSet 0
152 OpDecorate %60 Binding 2
153 OpDecorate %60 DescriptorSet 0
154 OpDecorate %73 Binding 3
155 OpDecorate %73 DescriptorSet 0
156 OpDecorate %83 Binding 4
157 OpDecorate %83 DescriptorSet 0
158 OpDecorate %94 Binding 5
159 OpDecorate %94 DescriptorSet 0
160 OpDecorate %105 Binding 6
161 OpDecorate %105 DescriptorSet 0
162 OpDecorate %117 Binding 7
163 OpDecorate %117 DescriptorSet 0
164 OpDecorate %128 Binding 8
165 OpDecorate %128 DescriptorSet 0
166 OpDecorate %138 Binding 9
167 OpDecorate %138 DescriptorSet 0
168 OpDecorate %151 Binding 10
169 OpDecorate %151 DescriptorSet 0
170 OpDecorate %160 Binding 11
171 OpDecorate %160 DescriptorSet 0
172 OpDecorate %169 Binding 12
173 OpDecorate %169 DescriptorSet 0
174 OpDecorate %188 Location 0
175 OpDecorate %192 BuiltIn FragDepth
176 %2 = OpTypeVoid
177 %3 = OpTypeFunction %2
178 %6 = OpTypeFloat 32
179 %7 = OpTypeVector %6 4
180 %8 = OpTypeStruct %7 %6
181 %9 = OpTypeFunction %8
182 %12 = OpTypeInt 32 1
183 %13 = OpTypeStruct %12 %12 %12 %12 %12 %12 %12 %12 %12 %12 %12 %12
184 %14 = OpTypePointer Function %13
185 %16 = OpConstant %12 1
186 %17 = OpTypePointer Function %12
187 %19 = OpConstant %12 2
188 %21 = OpConstant %12 3
189 %23 = OpConstant %12 4
190 %25 = OpConstant %12 5
191 %27 = OpConstant %12 6
192 %29 = OpConstant %12 0
193 %31 = OpConstant %12 7
194 %33 = OpConstant %12 8
195 %35 = OpConstant %12 9
196 %37 = OpConstant %12 10
197 %39 = OpConstant %12 11
198 %41 = OpTypePointer Function %7
199 %43 = OpTypeImage %6 1D 0 0 0 1 Unknown
200 %44 = OpTypePointer UniformConstant %43
201 %45 = OpVariable %44 UniformConstant
202 %47 = OpTypeSampler
203 %48 = OpTypePointer UniformConstant %47
204 %49 = OpVariable %48 UniformConstant
205 %51 = OpTypeSampledImage %43
206 %53 = OpConstant %6 0.100000001
207 %55 = OpTypeVector %12 4
208 %58 = OpTypeImage %12 1D 0 0 0 1 Unknown
209 %59 = OpTypePointer UniformConstant %58
210 %60 = OpVariable %59 UniformConstant
211 %63 = OpTypeSampledImage %58
212 %65 = OpConstant %6 0.200000003
213 %67 = OpTypeInt 32 0
214 %68 = OpTypeVector %67 4
215 %71 = OpTypeImage %67 1D 0 0 0 1 Unknown
216 %72 = OpTypePointer UniformConstant %71
217 %73 = OpVariable %72 UniformConstant
218 %76 = OpTypeSampledImage %71
219 %78 = OpConstant %6 0.300000012
220 %81 = OpTypeImage %6 2D 0 0 0 1 Unknown
221 %82 = OpTypePointer UniformConstant %81
222 %83 = OpVariable %82 UniformConstant
223 %86 = OpTypeSampledImage %81
224 %88 = OpTypeVector %6 2
225 %89 = OpConstantComposite %88 %53 %65
226 %92 = OpTypeImage %12 2D 0 0 0 1 Unknown
227 %93 = OpTypePointer UniformConstant %92
228 %94 = OpVariable %93 UniformConstant
229 %97 = OpTypeSampledImage %92
230 %99 = OpConstant %6 0.400000006
231 %100 = OpConstantComposite %88 %78 %99
232 %103 = OpTypeImage %67 2D 0 0 0 1 Unknown
233 %104 = OpTypePointer UniformConstant %103
234 %105 = OpVariable %104 UniformConstant
235 %108 = OpTypeSampledImage %103
236 %110 = OpConstant %6 0.5
237 %111 = OpConstant %6 0.600000024
238 %112 = OpConstantComposite %88 %110 %111
239 %115 = OpTypeImage %6 3D 0 0 0 1 Unknown
240 %116 = OpTypePointer UniformConstant %115
241 %117 = OpVariable %116 UniformConstant
242 %120 = OpTypeSampledImage %115
243 %122 = OpTypeVector %6 3
244 %123 = OpConstantComposite %122 %53 %65 %78
245 %126 = OpTypeImage %12 3D 0 0 0 1 Unknown
246 %127 = OpTypePointer UniformConstant %126
247 %128 = OpVariable %127 UniformConstant
248 %131 = OpTypeSampledImage %126
249 %133 = OpConstantComposite %122 %99 %110 %111
250 %136 = OpTypeImage %67 3D 0 0 0 1 Unknown
251 %137 = OpTypePointer UniformConstant %136
252 %138 = OpVariable %137 UniformConstant
253 %141 = OpTypeSampledImage %136
254 %143 = OpConstant %6 0.699999988
255 %144 = OpConstant %6 0.800000012
256 %145 = OpConstant %6 0.899999976
257 %146 = OpConstantComposite %122 %143 %144 %145
258 %149 = OpTypeImage %6 Cube 0 0 0 1 Unknown
259 %150 = OpTypePointer UniformConstant %149
260 %151 = OpVariable %150 UniformConstant
261 %154 = OpTypeSampledImage %149
262 %158 = OpTypeImage %12 Cube 0 0 0 1 Unknown
263 %159 = OpTypePointer UniformConstant %158
264 %160 = OpVariable %159 UniformConstant
265 %163 = OpTypeSampledImage %158
266 %167 = OpTypeImage %67 Cube 0 0 0 1 Unknown
267 %168 = OpTypePointer UniformConstant %167
268 %169 = OpVariable %168 UniformConstant
269 %172 = OpTypeSampledImage %167
270 %175 = OpTypePointer Function %8
271 %177 = OpConstant %6 1
272 %178 = OpConstantComposite %7 %177 %177 %177 %177
273 %180 = OpTypePointer Function %6
274 %187 = OpTypePointer Output %7
275 %188 = OpVariable %187 Output
276 %191 = OpTypePointer Output %6
277 %192 = OpVariable %191 Output
278 %4 = OpFunction %2 None %3
279 %5 = OpLabel
280 %185 = OpVariable %175 Function
281 %186 = OpFunctionCall %8 %10
282 OpStore %185 %186
283 %189 = OpAccessChain %41 %185 %29
284 %190 = OpLoad %7 %189
285 OpStore %188 %190
286 %193 = OpAccessChain %180 %185 %16
287 %194 = OpLoad %6 %193
288 OpStore %192 %194
289 OpReturn
290 OpFunctionEnd
291 %10 = OpFunction %8 None %9
292 %11 = OpLabel
293 %15 = OpVariable %14 Function
294 %176 = OpVariable %175 Function
295 %18 = OpAccessChain %17 %15 %16
296 OpStore %18 %16
297 %20 = OpAccessChain %17 %15 %19
298 OpStore %20 %16
299 %22 = OpAccessChain %17 %15 %21
300 OpStore %22 %16
301 %24 = OpAccessChain %17 %15 %23
302 OpStore %24 %16
303 %26 = OpAccessChain %17 %15 %25
304 OpStore %26 %16
305 %28 = OpAccessChain %17 %15 %27
306 OpStore %28 %16
307 %30 = OpAccessChain %17 %15 %29
308 OpStore %30 %16
309 %32 = OpAccessChain %17 %15 %31
310 OpStore %32 %16
311 %34 = OpAccessChain %17 %15 %33
312 OpStore %34 %16
313 %36 = OpAccessChain %17 %15 %35
314 OpStore %36 %16
315 %38 = OpAccessChain %17 %15 %37
316 OpStore %38 %16
317 %40 = OpAccessChain %17 %15 %39
318 OpStore %40 %16
319 %46 = OpLoad %43 %45
320 %50 = OpLoad %47 %49
321 %52 = OpSampledImage %51 %46 %50
322 %54 = OpImageSampleImplicitLod %7 %52 %53
323 %61 = OpLoad %58 %60
324 %62 = OpLoad %47 %49
325 %64 = OpSampledImage %63 %61 %62
326 %66 = OpImageSampleImplicitLod %55 %64 %65
327 %74 = OpLoad %71 %73
328 %75 = OpLoad %47 %49
329 %77 = OpSampledImage %76 %74 %75
330 %79 = OpImageSampleImplicitLod %68 %77 %78
331 %84 = OpLoad %81 %83
332 %85 = OpLoad %47 %49
333 %87 = OpSampledImage %86 %84 %85
334 %90 = OpImageSampleImplicitLod %7 %87 %89
335 %95 = OpLoad %92 %94
336 %96 = OpLoad %47 %49
337 %98 = OpSampledImage %97 %95 %96
338 %101 = OpImageSampleImplicitLod %55 %98 %100
339 %106 = OpLoad %103 %105
340 %107 = OpLoad %47 %49
341 %109 = OpSampledImage %108 %106 %107
342 %113 = OpImageSampleImplicitLod %68 %109 %112
343 %118 = OpLoad %115 %117
344 %119 = OpLoad %47 %49
345 %121 = OpSampledImage %120 %118 %119
346 %124 = OpImageSampleImplicitLod %7 %121 %123
347 %129 = OpLoad %126 %128
348 %130 = OpLoad %47 %49
349 %132 = OpSampledImage %131 %129 %130
350 %134 = OpImageSampleImplicitLod %55 %132 %133
351 %139 = OpLoad %136 %138
352 %140 = OpLoad %47 %49
353 %142 = OpSampledImage %141 %139 %140
354 %147 = OpImageSampleImplicitLod %68 %142 %146
355 %152 = OpLoad %149 %151
356 %153 = OpLoad %47 %49
357 %155 = OpSampledImage %154 %152 %153
358 %156 = OpImageSampleImplicitLod %7 %155 %123
359 %161 = OpLoad %158 %160
360 %162 = OpLoad %47 %49
361 %164 = OpSampledImage %163 %161 %162
362 %165 = OpImageSampleImplicitLod %55 %164 %133
363 %170 = OpLoad %167 %169
364 %171 = OpLoad %47 %49
365 %173 = OpSampledImage %172 %170 %171
366 %174 = OpImageSampleImplicitLod %68 %173 %146
367 %179 = OpAccessChain %41 %176 %29
368 OpStore %179 %178
369 %181 = OpAccessChain %180 %176 %16
370 OpStore %181 %177
371 %182 = OpLoad %8 %176
372 OpReturnValue %182
373 OpFunctionEnd
374 )";
375
376 const std::string after =
377 R"(OpCapability Shader
378 OpCapability Sampled1D
379 %1 = OpExtInstImport "GLSL.std.450"
380 OpMemoryModel Logical GLSL450
381 OpEntryPoint Fragment %5663 "main" %4253 %3709
382 OpExecutionMode %5663 OriginUpperLeft
383 OpExecutionMode %5663 DepthReplacing
384 OpSource HLSL 500
385 OpName %5663 "main"
386 OpName %1032 "PS_OUTPUT"
387 OpMemberName %1032 0 "Color"
388 OpMemberName %1032 1 "Depth"
389 OpName %3317 "@main("
390 OpName %1335 "MemberTest"
391 OpMemberName %1335 0 "Sample"
392 OpMemberName %1335 1 "CalculateLevelOfDetail"
393 OpMemberName %1335 2 "CalculateLevelOfDetailUnclamped"
394 OpMemberName %1335 3 "Gather"
395 OpMemberName %1335 4 "GetDimensions"
396 OpMemberName %1335 5 "GetSamplePosition"
397 OpMemberName %1335 6 "Load"
398 OpMemberName %1335 7 "SampleBias"
399 OpMemberName %1335 8 "SampleCmp"
400 OpMemberName %1335 9 "SampleCmpLevelZero"
401 OpMemberName %1335 10 "SampleGrad"
402 OpMemberName %1335 11 "SampleLevel"
403 OpName %5830 "mtest"
404 OpName %3559 "txval10"
405 OpName %4727 "g_tTex1df4"
406 OpName %3305 "g_sSamp"
407 OpName %3560 "txval11"
408 OpName %4743 "g_tTex1di4"
409 OpName %3561 "txval12"
410 OpName %4807 "g_tTex1du4"
411 OpName %4568 "txval20"
412 OpName %5042 "g_tTex2df4"
413 OpName %4569 "txval21"
414 OpName %5058 "g_tTex2di4"
415 OpName %4570 "txval22"
416 OpName %5122 "g_tTex2du4"
417 OpName %5577 "txval30"
418 OpName %3967 "g_tTex3df4"
419 OpName %5578 "txval31"
420 OpName %3983 "g_tTex3di4"
421 OpName %5579 "txval32"
422 OpName %4047 "g_tTex3du4"
423 OpName %3575 "txval40"
424 OpName %3789 "g_tTexcdf4"
425 OpName %3576 "txval41"
426 OpName %3805 "g_tTexcdi4"
427 OpName %3577 "txval42"
428 OpName %3869 "g_tTexcdu4"
429 OpName %5072 "psout"
430 OpName %4104 "flattenTemp"
431 OpName %4253 "@entryPointOutput.Color"
432 OpName %3709 "@entryPointOutput.Depth"
433 OpDecorate %4727 Binding 0
434 OpDecorate %4727 DescriptorSet 0
435 OpDecorate %3305 Binding 0
436 OpDecorate %3305 DescriptorSet 0
437 OpDecorate %4743 Binding 2
438 OpDecorate %4743 DescriptorSet 0
439 OpDecorate %4807 Binding 3
440 OpDecorate %4807 DescriptorSet 0
441 OpDecorate %5042 Binding 4
442 OpDecorate %5042 DescriptorSet 0
443 OpDecorate %5058 Binding 5
444 OpDecorate %5058 DescriptorSet 0
445 OpDecorate %5122 Binding 6
446 OpDecorate %5122 DescriptorSet 0
447 OpDecorate %3967 Binding 7
448 OpDecorate %3967 DescriptorSet 0
449 OpDecorate %3983 Binding 8
450 OpDecorate %3983 DescriptorSet 0
451 OpDecorate %4047 Binding 9
452 OpDecorate %4047 DescriptorSet 0
453 OpDecorate %3789 Binding 10
454 OpDecorate %3789 DescriptorSet 0
455 OpDecorate %3805 Binding 11
456 OpDecorate %3805 DescriptorSet 0
457 OpDecorate %3869 Binding 12
458 OpDecorate %3869 DescriptorSet 0
459 OpDecorate %4253 Location 0
460 OpDecorate %3709 BuiltIn FragDepth
461 %8 = OpTypeVoid
462 %1282 = OpTypeFunction %8
463 %13 = OpTypeFloat 32
464 %29 = OpTypeVector %13 4
465 %1032 = OpTypeStruct %29 %13
466 %319 = OpTypeFunction %1032
467 %12 = OpTypeInt 32 1
468 %1335 = OpTypeStruct %12 %12 %12 %12 %12 %12 %12 %12 %12 %12 %12 %12
469 %1972 = OpTypePointer Function %1335
470 %2574 = OpConstant %12 1
471 %649 = OpTypePointer Function %12
472 %2577 = OpConstant %12 2
473 %2580 = OpConstant %12 3
474 %2583 = OpConstant %12 4
475 %2586 = OpConstant %12 5
476 %2589 = OpConstant %12 6
477 %2571 = OpConstant %12 0
478 %2592 = OpConstant %12 7
479 %2595 = OpConstant %12 8
480 %2598 = OpConstant %12 9
481 %2601 = OpConstant %12 10
482 %2604 = OpConstant %12 11
483 %666 = OpTypePointer Function %29
484 %149 = OpTypeImage %13 1D 0 0 0 1 Unknown
485 %786 = OpTypePointer UniformConstant %149
486 %4727 = OpVariable %786 UniformConstant
487 %508 = OpTypeSampler
488 %1145 = OpTypePointer UniformConstant %508
489 %3305 = OpVariable %1145 UniformConstant
490 %510 = OpTypeSampledImage %149
491 %2935 = OpConstant %13 0.100000001
492 %26 = OpTypeVector %12 4
493 %148 = OpTypeImage %12 1D 0 0 0 1 Unknown
494 %785 = OpTypePointer UniformConstant %148
495 %4743 = OpVariable %785 UniformConstant
496 %511 = OpTypeSampledImage %148
497 %2821 = OpConstant %13 0.200000003
498 %11 = OpTypeInt 32 0
499 %23 = OpTypeVector %11 4
500 %147 = OpTypeImage %11 1D 0 0 0 1 Unknown
501 %784 = OpTypePointer UniformConstant %147
502 %4807 = OpVariable %784 UniformConstant
503 %512 = OpTypeSampledImage %147
504 %2151 = OpConstant %13 0.300000012
505 %150 = OpTypeImage %13 2D 0 0 0 1 Unknown
506 %787 = OpTypePointer UniformConstant %150
507 %5042 = OpVariable %787 UniformConstant
508 %513 = OpTypeSampledImage %150
509 %19 = OpTypeVector %13 2
510 %1825 = OpConstantComposite %19 %2935 %2821
511 %151 = OpTypeImage %12 2D 0 0 0 1 Unknown
512 %788 = OpTypePointer UniformConstant %151
513 %5058 = OpVariable %788 UniformConstant
514 %514 = OpTypeSampledImage %151
515 %2707 = OpConstant %13 0.400000006
516 %2028 = OpConstantComposite %19 %2151 %2707
517 %152 = OpTypeImage %11 2D 0 0 0 1 Unknown
518 %789 = OpTypePointer UniformConstant %152
519 %5122 = OpVariable %789 UniformConstant
520 %515 = OpTypeSampledImage %152
521 %252 = OpConstant %13 0.5
522 %2037 = OpConstant %13 0.600000024
523 %2684 = OpConstantComposite %19 %252 %2037
524 %153 = OpTypeImage %13 3D 0 0 0 1 Unknown
525 %790 = OpTypePointer UniformConstant %153
526 %3967 = OpVariable %790 UniformConstant
527 %516 = OpTypeSampledImage %153
528 %24 = OpTypeVector %13 3
529 %1660 = OpConstantComposite %24 %2935 %2821 %2151
530 %154 = OpTypeImage %12 3D 0 0 0 1 Unknown
531 %791 = OpTypePointer UniformConstant %154
532 %3983 = OpVariable %791 UniformConstant
533 %517 = OpTypeSampledImage %154
534 %2174 = OpConstantComposite %24 %2707 %252 %2037
535 %155 = OpTypeImage %11 3D 0 0 0 1 Unknown
536 %792 = OpTypePointer UniformConstant %155
537 %4047 = OpVariable %792 UniformConstant
538 %518 = OpTypeSampledImage %155
539 %808 = OpConstant %13 0.699999988
540 %2593 = OpConstant %13 0.800000012
541 %1364 = OpConstant %13 0.899999976
542 %2476 = OpConstantComposite %24 %808 %2593 %1364
543 %156 = OpTypeImage %13 Cube 0 0 0 1 Unknown
544 %793 = OpTypePointer UniformConstant %156
545 %3789 = OpVariable %793 UniformConstant
546 %519 = OpTypeSampledImage %156
547 %157 = OpTypeImage %12 Cube 0 0 0 1 Unknown
548 %794 = OpTypePointer UniformConstant %157
549 %3805 = OpVariable %794 UniformConstant
550 %520 = OpTypeSampledImage %157
551 %158 = OpTypeImage %11 Cube 0 0 0 1 Unknown
552 %795 = OpTypePointer UniformConstant %158
553 %3869 = OpVariable %795 UniformConstant
554 %521 = OpTypeSampledImage %158
555 %1669 = OpTypePointer Function %1032
556 %138 = OpConstant %13 1
557 %1284 = OpConstantComposite %29 %138 %138 %138 %138
558 %650 = OpTypePointer Function %13
559 %667 = OpTypePointer Output %29
560 %4253 = OpVariable %667 Output
561 %651 = OpTypePointer Output %13
562 %3709 = OpVariable %651 Output
563 %5663 = OpFunction %8 None %1282
564 %24877 = OpLabel
565 %4104 = OpVariable %1669 Function
566 %18803 = OpFunctionCall %1032 %3317
567 OpStore %4104 %18803
568 %13396 = OpAccessChain %666 %4104 %2571
569 %7967 = OpLoad %29 %13396
570 OpStore %4253 %7967
571 %16622 = OpAccessChain %650 %4104 %2574
572 %11539 = OpLoad %13 %16622
573 OpStore %3709 %11539
574 OpReturn
575 OpFunctionEnd
576 %3317 = OpFunction %1032 None %319
577 %12442 = OpLabel
578 %5830 = OpVariable %1972 Function
579 %5072 = OpVariable %1669 Function
580 %22671 = OpAccessChain %649 %5830 %2574
581 OpStore %22671 %2574
582 %20306 = OpAccessChain %649 %5830 %2577
583 OpStore %20306 %2574
584 %20307 = OpAccessChain %649 %5830 %2580
585 OpStore %20307 %2574
586 %20308 = OpAccessChain %649 %5830 %2583
587 OpStore %20308 %2574
588 %20309 = OpAccessChain %649 %5830 %2586
589 OpStore %20309 %2574
590 %20310 = OpAccessChain %649 %5830 %2589
591 OpStore %20310 %2574
592 %20311 = OpAccessChain %649 %5830 %2571
593 OpStore %20311 %2574
594 %20312 = OpAccessChain %649 %5830 %2592
595 OpStore %20312 %2574
596 %20313 = OpAccessChain %649 %5830 %2595
597 OpStore %20313 %2574
598 %20314 = OpAccessChain %649 %5830 %2598
599 OpStore %20314 %2574
600 %20315 = OpAccessChain %649 %5830 %2601
601 OpStore %20315 %2574
602 %20230 = OpAccessChain %649 %5830 %2604
603 OpStore %20230 %2574
604 %15508 = OpLoad %149 %4727
605 %12260 = OpLoad %508 %3305
606 %12514 = OpSampledImage %510 %15508 %12260
607 %3559 = OpImageSampleImplicitLod %29 %12514 %2935
608 %9477 = OpLoad %148 %4743
609 %16280 = OpLoad %508 %3305
610 %12515 = OpSampledImage %511 %9477 %16280
611 %3560 = OpImageSampleImplicitLod %26 %12515 %2821
612 %9478 = OpLoad %147 %4807
613 %16281 = OpLoad %508 %3305
614 %12516 = OpSampledImage %512 %9478 %16281
615 %3561 = OpImageSampleImplicitLod %23 %12516 %2151
616 %9479 = OpLoad %150 %5042
617 %16282 = OpLoad %508 %3305
618 %12517 = OpSampledImage %513 %9479 %16282
619 %4568 = OpImageSampleImplicitLod %29 %12517 %1825
620 %9480 = OpLoad %151 %5058
621 %16283 = OpLoad %508 %3305
622 %12518 = OpSampledImage %514 %9480 %16283
623 %4569 = OpImageSampleImplicitLod %26 %12518 %2028
624 %9481 = OpLoad %152 %5122
625 %16284 = OpLoad %508 %3305
626 %12519 = OpSampledImage %515 %9481 %16284
627 %4570 = OpImageSampleImplicitLod %23 %12519 %2684
628 %9482 = OpLoad %153 %3967
629 %16285 = OpLoad %508 %3305
630 %12520 = OpSampledImage %516 %9482 %16285
631 %5577 = OpImageSampleImplicitLod %29 %12520 %1660
632 %9483 = OpLoad %154 %3983
633 %16286 = OpLoad %508 %3305
634 %12521 = OpSampledImage %517 %9483 %16286
635 %5578 = OpImageSampleImplicitLod %26 %12521 %2174
636 %9484 = OpLoad %155 %4047
637 %16287 = OpLoad %508 %3305
638 %12522 = OpSampledImage %518 %9484 %16287
639 %5579 = OpImageSampleImplicitLod %23 %12522 %2476
640 %9485 = OpLoad %156 %3789
641 %16288 = OpLoad %508 %3305
642 %12523 = OpSampledImage %519 %9485 %16288
643 %3575 = OpImageSampleImplicitLod %29 %12523 %1660
644 %9486 = OpLoad %157 %3805
645 %16289 = OpLoad %508 %3305
646 %12524 = OpSampledImage %520 %9486 %16289
647 %3576 = OpImageSampleImplicitLod %26 %12524 %2174
648 %9487 = OpLoad %158 %3869
649 %16290 = OpLoad %508 %3305
650 %12590 = OpSampledImage %521 %9487 %16290
651 %3577 = OpImageSampleImplicitLod %23 %12590 %2476
652 %14275 = OpAccessChain %666 %5072 %2571
653 OpStore %14275 %1284
654 %20231 = OpAccessChain %650 %5072 %2574
655 OpStore %20231 %138
656 %8692 = OpLoad %1032 %5072
657 OpReturnValue %8692
658 OpFunctionEnd
659 )";
660
661 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
662 SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
663 SinglePassRunAndCheck<CanonicalizeIdsPass>(before, after, false, false);
664 }
665
666 // ported from remap.hlsl.templatetypes.everything.frag
667 TEST_F(CanonicalizeIdsTest, remap_hlsl_templatetypes) {
668 const std::string before =
669 R"(OpCapability Shader
670 OpCapability Float64
671 %1 = OpExtInstImport "GLSL.std.450"
672 OpMemoryModel Logical GLSL450
673 OpEntryPoint Fragment %4 "main" %153 %156
674 OpExecutionMode %4 OriginUpperLeft
675 OpSource HLSL 500
676 OpName %4 "main"
677 OpName %11 "@main(vf4;"
678 OpName %10 "input"
679 OpName %18 "r00"
680 OpName %21 "r01"
681 OpName %25 "r12"
682 OpName %29 "r13"
683 OpName %14 "r14"
684 OpName %35 "r15"
685 OpName %39 "r16"
686 OpName %44 "r20"
687 OpName %49 "r21"
688 OpName %53 "r22"
689 OpName %58 "r23"
690 OpName %63 "r24"
691 OpName %67 "r30"
692 OpName %72 "r31"
693 OpName %76 "r32"
694 OpName %81 "r33"
695 OpName %86 "r34"
696 OpName %90 "r40"
697 OpName %95 "r41"
698 OpName %18 "r42"
699 OpName %101 "r43"
700 OpName %106 "r44"
701 OpName %125 "r50"
702 OpName %125 "r51"
703 OpName %131 "r61"
704 OpName %137 "r62"
705 OpName %142 "r65"
706 OpName %148 "r66"
707 OpName %154 "input"
708 OpName %153 "input"
709 OpName %156 "@entryPointOutput"
710 OpName %157 "param"
711 OpDecorate %153 Location 0
712 OpDecorate %156 Location 0
713 %2 = OpTypeVoid
714 %3 = OpTypeFunction %2
715 %6 = OpTypeFloat 32
716 %7 = OpTypeVector %6 4
717 %8 = OpTypePointer Function %7
718 %9 = OpTypeFunction %6 %8
719 %14 = OpConstant %6 1
720 %15 = OpConstant %6 2
721 %16 = OpConstant %6 3
722 %17 = OpConstant %6 4
723 %18 = OpConstantComposite %7 %14 %15 %16 %17
724 %20 = OpConstant %6 5
725 %21 = OpConstantComposite %7 %15 %16 %17 %20
726 %22 = OpTypeBool
727 %25 = OpConstantFalse %22
728 %26 = OpTypeInt 32 1
729 %29 = OpConstant %26 1
730 %32 = OpTypeFloat 64
731 %35 = OpConstant %32 1
732 %36 = OpTypeInt 32 0
733 %39 = OpConstant %36 1
734 %40 = OpTypeVector %22 2
735 %43 = OpConstantTrue %22
736 %44 = OpConstantComposite %40 %25 %43
737 %45 = OpTypeVector %26 2
738 %48 = OpConstant %26 2
739 %49 = OpConstantComposite %45 %29 %48
740 %50 = OpTypeVector %6 2
741 %53 = OpConstantComposite %50 %14 %15
742 %54 = OpTypeVector %32 2
743 %57 = OpConstant %32 2
744 %58 = OpConstantComposite %54 %35 %57
745 %59 = OpTypeVector %36 2
746 %62 = OpConstant %36 2
747 %63 = OpConstantComposite %59 %39 %62
748 %64 = OpTypeVector %22 3
749 %67 = OpConstantComposite %64 %25 %43 %43
750 %68 = OpTypeVector %26 3
751 %71 = OpConstant %26 3
752 %72 = OpConstantComposite %68 %29 %48 %71
753 %73 = OpTypeVector %6 3
754 %76 = OpConstantComposite %73 %14 %15 %16
755 %77 = OpTypeVector %32 3
756 %80 = OpConstant %32 3
757 %81 = OpConstantComposite %77 %35 %57 %80
758 %82 = OpTypeVector %36 3
759 %85 = OpConstant %36 3
760 %86 = OpConstantComposite %82 %39 %62 %85
761 %87 = OpTypeVector %22 4
762 %90 = OpConstantComposite %87 %25 %43 %43 %25
763 %91 = OpTypeVector %26 4
764 %94 = OpConstant %26 4
765 %95 = OpConstantComposite %91 %29 %48 %71 %94
766 %97 = OpTypeVector %32 4
767 %100 = OpConstant %32 4
768 %101 = OpConstantComposite %97 %35 %57 %80 %100
769 %102 = OpTypeVector %36 4
770 %105 = OpConstant %36 4
771 %106 = OpConstantComposite %102 %39 %62 %85 %105
772 %107 = OpTypeMatrix %7 4
773 %110 = OpConstant %6 0
774 %111 = OpConstantComposite %7 %110 %14 %15 %16
775 %112 = OpConstant %6 6
776 %113 = OpConstant %6 7
777 %114 = OpConstantComposite %7 %17 %20 %112 %113
778 %115 = OpConstant %6 8
779 %116 = OpConstant %6 9
780 %117 = OpConstant %6 10
781 %118 = OpConstant %6 11
782 %119 = OpConstantComposite %7 %115 %116 %117 %118
783 %120 = OpConstant %6 12
784 %121 = OpConstant %6 13
785 %122 = OpConstant %6 14
786 %123 = OpConstant %6 15
787 %124 = OpConstantComposite %7 %120 %121 %122 %123
788 %125 = OpConstantComposite %107 %111 %114 %119 %124
789 %127 = OpTypeMatrix %73 2
790 %130 = OpConstantComposite %73 %17 %20 %112
791 %131 = OpConstantComposite %127 %76 %130
792 %132 = OpTypeMatrix %50 3
793 %135 = OpConstantComposite %50 %16 %17
794 %136 = OpConstantComposite %50 %20 %112
795 %137 = OpConstantComposite %132 %53 %135 %136
796 %138 = OpTypeMatrix %50 4
797 %141 = OpConstantComposite %50 %113 %115
798 %142 = OpConstantComposite %138 %53 %135 %136 %141
799 %143 = OpTypeMatrix %73 4
800 %146 = OpConstantComposite %73 %113 %115 %116
801 %147 = OpConstantComposite %73 %117 %118 %120
802 %148 = OpConstantComposite %143 %76 %130 %146 %147
803 %152 = OpTypePointer Input %7
804 %153 = OpVariable %152 Input
805 %155 = OpTypePointer Output %6
806 %156 = OpVariable %155 Output
807 %4 = OpFunction %2 None %3
808 %5 = OpLabel
809 %157 = OpVariable %8 Function
810 %154 = OpLoad %7 %153
811 OpStore %157 %154
812 %159 = OpFunctionCall %6 %11 %157
813 OpStore %156 %159
814 OpReturn
815 OpFunctionEnd
816 %11 = OpFunction %6 None %9
817 %10 = OpFunctionParameter %8
818 %12 = OpLabel
819 OpReturnValue %110
820 OpFunctionEnd
821 )";
822
823 const std::string after =
824 R"(OpCapability Shader
825 OpCapability Float64
826 %1 = OpExtInstImport "GLSL.std.450"
827 OpMemoryModel Logical GLSL450
828 OpEntryPoint Fragment %5663 "main" %4872 %4045
829 OpExecutionMode %5663 OriginUpperLeft
830 OpSource HLSL 500
831 OpName %5663 "main"
832 OpName %3917 "@main(vf4;"
833 OpName %10636 "input"
834 OpName %1616 "r00"
835 OpName %590 "r01"
836 OpName %1927 "r12"
837 OpName %2574 "r13"
838 OpName %138 "r14"
839 OpName %1201 "r15"
840 OpName %2573 "r16"
841 OpName %311 "r20"
842 OpName %1848 "r21"
843 OpName %312 "r22"
844 OpName %490 "r23"
845 OpName %1840 "r24"
846 OpName %869 "r30"
847 OpName %2668 "r31"
848 OpName %1271 "r32"
849 OpName %1108 "r33"
850 OpName %2654 "r34"
851 OpName %340 "r40"
852 OpName %56 "r41"
853 OpName %1616 "r42"
854 OpName %1328 "r43"
855 OpName %35 "r44"
856 OpName %1294 "r50"
857 OpName %1294 "r51"
858 OpName %1207 "r61"
859 OpName %162 "r62"
860 OpName %2695 "r65"
861 OpName %55 "r66"
862 OpName %24021 "input"
863 OpName %4872 "input"
864 OpName %4045 "@entryPointOutput"
865 OpName %5786 "param"
866 OpDecorate %4872 Location 0
867 OpDecorate %4045 Location 0
868 %8 = OpTypeVoid
869 %1282 = OpTypeFunction %8
870 %13 = OpTypeFloat 32
871 %29 = OpTypeVector %13 4
872 %666 = OpTypePointer Function %29
873 %255 = OpTypeFunction %13 %666
874 %138 = OpConstant %13 1
875 %24 = OpConstant %13 2
876 %2978 = OpConstant %13 3
877 %2921 = OpConstant %13 4
878 %1616 = OpConstantComposite %29 %138 %24 %2978 %2921
879 %1387 = OpConstant %13 5
880 %590 = OpConstantComposite %29 %24 %2978 %2921 %1387
881 %9 = OpTypeBool
882 %1927 = OpConstantFalse %9
883 %12 = OpTypeInt 32 1
884 %2574 = OpConstant %12 1
885 %14 = OpTypeFloat 64
886 %1201 = OpConstant %14 1
887 %11 = OpTypeInt 32 0
888 %2573 = OpConstant %11 1
889 %15 = OpTypeVector %9 2
890 %1926 = OpConstantTrue %9
891 %311 = OpConstantComposite %15 %1927 %1926
892 %18 = OpTypeVector %12 2
893 %2577 = OpConstant %12 2
894 %1848 = OpConstantComposite %18 %2574 %2577
895 %19 = OpTypeVector %13 2
896 %312 = OpConstantComposite %19 %138 %24
897 %20 = OpTypeVector %14 2
898 %2572 = OpConstant %14 2
899 %490 = OpConstantComposite %20 %1201 %2572
900 %17 = OpTypeVector %11 2
901 %2576 = OpConstant %11 2
902 %1840 = OpConstantComposite %17 %2573 %2576
903 %16 = OpTypeVector %9 3
904 %869 = OpConstantComposite %16 %1927 %1926 %1926
905 %22 = OpTypeVector %12 3
906 %2580 = OpConstant %12 3
907 %2668 = OpConstantComposite %22 %2574 %2577 %2580
908 %25 = OpTypeVector %13 3
909 %1271 = OpConstantComposite %25 %138 %24 %2978
910 %26 = OpTypeVector %14 3
911 %1057 = OpConstant %14 3
912 %1108 = OpConstantComposite %26 %1201 %2572 %1057
913 %21 = OpTypeVector %11 3
914 %2579 = OpConstant %11 3
915 %2654 = OpConstantComposite %21 %2573 %2576 %2579
916 %23 = OpTypeVector %9 4
917 %340 = OpConstantComposite %23 %1927 %1926 %1926 %1927
918 %27 = OpTypeVector %12 4
919 %2583 = OpConstant %12 4
920 %56 = OpConstantComposite %27 %2574 %2577 %2580 %2583
921 %30 = OpTypeVector %14 4
922 %2553 = OpConstant %14 4
923 %1328 = OpConstantComposite %30 %1201 %2572 %1057 %2553
924 %28 = OpTypeVector %11 4
925 %2582 = OpConstant %11 4
926 %35 = OpConstantComposite %28 %2573 %2576 %2579 %2582
927 %101 = OpTypeMatrix %29 4
928 %2575 = OpConstant %13 0
929 %1199 = OpConstantComposite %29 %2575 %138 %24 %2978
930 %2864 = OpConstant %13 6
931 %1330 = OpConstant %13 7
932 %2290 = OpConstantComposite %29 %2921 %1387 %2864 %1330
933 %2807 = OpConstant %13 8
934 %2040 = OpConstant %13 9
935 %1273 = OpConstant %13 10
936 %506 = OpConstant %13 11
937 %694 = OpConstantComposite %29 %2807 %2040 %1273 %506
938 %2750 = OpConstant %13 12
939 %1983 = OpConstant %13 13
940 %1216 = OpConstant %13 14
941 %449 = OpConstant %13 15
942 %2679 = OpConstantComposite %29 %2750 %1983 %1216 %449
943 %1294 = OpConstantComposite %101 %1199 %2290 %694 %2679
944 %54 = OpTypeMatrix %25 2
945 %837 = OpConstantComposite %25 %2921 %1387 %2864
946 %1207 = OpConstantComposite %54 %1271 %837
947 %60 = OpTypeMatrix %19 3
948 %2354 = OpConstantComposite %19 %2978 %2921
949 %364 = OpConstantComposite %19 %1387 %2864
950 %162 = OpConstantComposite %60 %312 %2354 %364
951 %71 = OpTypeMatrix %19 4
952 %2976 = OpConstantComposite %19 %1330 %2807
953 %2695 = OpConstantComposite %71 %312 %2354 %364 %2976
954 %86 = OpTypeMatrix %25 4
955 %635 = OpConstantComposite %25 %1330 %2807 %2040
956 %832 = OpConstantComposite %25 %1273 %506 %2750
957 %55 = OpConstantComposite %86 %1271 %837 %635 %832
958 %667 = OpTypePointer Input %29
959 %4872 = OpVariable %667 Input
960 %650 = OpTypePointer Output %13
961 %4045 = OpVariable %650 Output
962 %5663 = OpFunction %8 None %1282
963 %24953 = OpLabel
964 %5786 = OpVariable %666 Function
965 %24021 = OpLoad %29 %4872
966 OpStore %5786 %24021
967 %9338 = OpFunctionCall %13 %3917 %5786
968 OpStore %4045 %9338
969 OpReturn
970 OpFunctionEnd
971 %3917 = OpFunction %13 None %255
972 %10636 = OpFunctionParameter %666
973 %10637 = OpLabel
974 OpReturnValue %2575
975 OpFunctionEnd
976 )";
977
978 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
979 SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
980 SinglePassRunAndCheck<CanonicalizeIdsPass>(before, after, false, false);
981 }
982
983 // ported from remap.if.everything.frag
984 TEST_F(CanonicalizeIdsTest, remap_if) {
985 const std::string before =
986 R"(OpCapability Shader
987 %1 = OpExtInstImport "GLSL.std.450"
988 OpMemoryModel Logical GLSL450
989 OpEntryPoint Fragment %4 "main" %8 %17
990 OpExecutionMode %4 OriginUpperLeft
991 OpSource GLSL 450
992 OpName %4 "main"
993 OpName %8 "inf"
994 OpName %17 "outf4"
995 OpDecorate %8 Location 0
996 OpDecorate %17 Location 0
997 %2 = OpTypeVoid
998 %3 = OpTypeFunction %2
999 %6 = OpTypeFloat 32
1000 %7 = OpTypePointer Input %6
1001 %8 = OpVariable %7 Input
1002 %10 = OpConstant %6 2
1003 %11 = OpTypeBool
1004 %15 = OpTypeVector %6 4
1005 %16 = OpTypePointer Output %15
1006 %17 = OpVariable %16 Output
1007 %22 = OpConstant %6 -0.5
1008 %4 = OpFunction %2 None %3
1009 %5 = OpLabel
1010 %9 = OpLoad %6 %8
1011 %12 = OpFOrdGreaterThan %11 %9 %10
1012 OpSelectionMerge %14 None
1013 OpBranchConditional %12 %13 %20
1014 %13 = OpLabel
1015 %18 = OpLoad %6 %8
1016 %19 = OpCompositeConstruct %15 %18 %18 %18 %18
1017 OpStore %17 %19
1018 OpBranch %14
1019 %20 = OpLabel
1020 %21 = OpLoad %6 %8
1021 %23 = OpFAdd %6 %21 %22
1022 %24 = OpCompositeConstruct %15 %23 %23 %23 %23
1023 OpStore %17 %24
1024 OpBranch %14
1025 %14 = OpLabel
1026 OpReturn
1027 OpFunctionEnd
1028 )";
1029
1030 const std::string after =
1031 R"(OpCapability Shader
1032 %1 = OpExtInstImport "GLSL.std.450"
1033 OpMemoryModel Logical GLSL450
1034 OpEntryPoint Fragment %5663 "main" %3773 %4539
1035 OpExecutionMode %5663 OriginUpperLeft
1036 OpSource GLSL 450
1037 OpName %5663 "main"
1038 OpName %3773 "inf"
1039 OpName %4539 "outf4"
1040 OpDecorate %3773 Location 0
1041 OpDecorate %4539 Location 0
1042 %8 = OpTypeVoid
1043 %1282 = OpTypeFunction %8
1044 %13 = OpTypeFloat 32
1045 %650 = OpTypePointer Input %13
1046 %3773 = OpVariable %650 Input
1047 %24 = OpConstant %13 2
1048 %9 = OpTypeBool
1049 %29 = OpTypeVector %13 4
1050 %666 = OpTypePointer Output %29
1051 %4539 = OpVariable %666 Output
1052 %947 = OpConstant %13 -0.5
1053 %5663 = OpFunction %8 None %1282
1054 %7911 = OpLabel
1055 %21734 = OpLoad %13 %3773
1056 %13508 = OpFOrdGreaterThan %9 %21734 %24
1057 OpSelectionMerge %19578 None
1058 OpBranchConditional %13508 %13182 %10142
1059 %13182 = OpLabel
1060 %9496 = OpLoad %13 %3773
1061 %17615 = OpCompositeConstruct %29 %9496 %9496 %9496 %9496
1062 OpStore %4539 %17615
1063 OpBranch %19578
1064 %10142 = OpLabel
1065 %22854 = OpLoad %13 %3773
1066 %9982 = OpFAdd %13 %22854 %947
1067 %12421 = OpCompositeConstruct %29 %9982 %9982 %9982 %9982
1068 OpStore %4539 %12421
1069 OpBranch %19578
1070 %19578 = OpLabel
1071 OpReturn
1072 OpFunctionEnd
1073 )";
1074
1075 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1076 SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
1077 SinglePassRunAndCheck<CanonicalizeIdsPass>(before, after, false, false);
1078 }
1079
1080 // ported from remap.similar_1a.everything.frag
1081 TEST_F(CanonicalizeIdsTest, remap_similar_1a) {
1082 const std::string before =
1083 R"(OpCapability Shader
1084 %1 = OpExtInstImport "GLSL.std.450"
1085 OpMemoryModel Logical GLSL450
1086 OpEntryPoint Fragment %4 "main" %53 %73 %75
1087 OpExecutionMode %4 OriginUpperLeft
1088 OpSource GLSL 450
1089 OpName %4 "main"
1090 OpName %11 "Test1(i1;"
1091 OpName %10 "bound"
1092 OpName %14 "Test2(i1;"
1093 OpName %13 "bound"
1094 OpName %17 "r"
1095 OpName %19 "x"
1096 OpName %44 "param"
1097 OpName %53 "ini4"
1098 OpName %73 "outf4"
1099 OpName %75 "inf"
1100 OpName %78 "param"
1101 OpName %82 "param"
1102 OpDecorate %53 Flat
1103 OpDecorate %53 Location 1
1104 OpDecorate %73 Location 0
1105 OpDecorate %75 Location 0
1106 %2 = OpTypeVoid
1107 %3 = OpTypeFunction %2
1108 %6 = OpTypeInt 32 1
1109 %7 = OpTypePointer Function %6
1110 %8 = OpTypeFloat 32
1111 %9 = OpTypeFunction %8 %7
1112 %16 = OpTypePointer Function %8
1113 %18 = OpConstant %8 0
1114 %20 = OpConstant %6 0
1115 %28 = OpTypeBool
1116 %30 = OpConstant %8 0.5
1117 %34 = OpConstant %6 1
1118 %40 = OpConstant %6 2
1119 %51 = OpTypeVector %6 4
1120 %52 = OpTypePointer Input %51
1121 %53 = OpVariable %52 Input
1122 %54 = OpTypeInt 32 0
1123 %55 = OpConstant %54 1
1124 %56 = OpTypePointer Input %6
1125 %59 = OpConstant %54 2
1126 %64 = OpConstant %54 0
1127 %71 = OpTypeVector %8 4
1128 %72 = OpTypePointer Output %71
1129 %73 = OpVariable %72 Output
1130 %74 = OpTypePointer Input %8
1131 %75 = OpVariable %74 Input
1132 %4 = OpFunction %2 None %3
1133 %5 = OpLabel
1134 %78 = OpVariable %7 Function
1135 %82 = OpVariable %7 Function
1136 %76 = OpLoad %8 %75
1137 %77 = OpConvertFToS %6 %76
1138 OpStore %78 %77
1139 %79 = OpFunctionCall %8 %11 %78
1140 %80 = OpLoad %8 %75
1141 %81 = OpConvertFToS %6 %80
1142 OpStore %82 %81
1143 %83 = OpFunctionCall %8 %14 %82
1144 %84 = OpFAdd %8 %79 %83
1145 %85 = OpCompositeConstruct %71 %84 %84 %84 %84
1146 OpStore %73 %85
1147 OpReturn
1148 OpFunctionEnd
1149 %11 = OpFunction %8 None %9
1150 %10 = OpFunctionParameter %7
1151 %12 = OpLabel
1152 %17 = OpVariable %16 Function
1153 %19 = OpVariable %7 Function
1154 OpStore %17 %18
1155 OpStore %19 %20
1156 OpBranch %21
1157 %21 = OpLabel
1158 OpLoopMerge %23 %24 None
1159 OpBranch %25
1160 %25 = OpLabel
1161 %26 = OpLoad %6 %19
1162 %27 = OpLoad %6 %10
1163 %29 = OpSLessThan %28 %26 %27
1164 OpBranchConditional %29 %22 %23
1165 %22 = OpLabel
1166 %31 = OpLoad %8 %17
1167 %32 = OpFAdd %8 %31 %30
1168 OpStore %17 %32
1169 OpBranch %24
1170 %24 = OpLabel
1171 %33 = OpLoad %6 %19
1172 %35 = OpIAdd %6 %33 %34
1173 OpStore %19 %35
1174 OpBranch %21
1175 %23 = OpLabel
1176 %36 = OpLoad %8 %17
1177 OpReturnValue %36
1178 OpFunctionEnd
1179 %14 = OpFunction %8 None %9
1180 %13 = OpFunctionParameter %7
1181 %15 = OpLabel
1182 %44 = OpVariable %7 Function
1183 %39 = OpLoad %6 %13
1184 %41 = OpSGreaterThan %28 %39 %40
1185 OpSelectionMerge %43 None
1186 OpBranchConditional %41 %42 %48
1187 %42 = OpLabel
1188 %45 = OpLoad %6 %13
1189 OpStore %44 %45
1190 %46 = OpFunctionCall %8 %11 %44
1191 OpReturnValue %46
1192 %48 = OpLabel
1193 %49 = OpLoad %6 %13
1194 %50 = OpIMul %6 %49 %40
1195 %57 = OpAccessChain %56 %53 %55
1196 %58 = OpLoad %6 %57
1197 %60 = OpAccessChain %56 %53 %59
1198 %61 = OpLoad %6 %60
1199 %62 = OpIMul %6 %58 %61
1200 %63 = OpIAdd %6 %50 %62
1201 %65 = OpAccessChain %56 %53 %64
1202 %66 = OpLoad %6 %65
1203 %67 = OpIAdd %6 %63 %66
1204 %68 = OpConvertSToF %8 %67
1205 OpReturnValue %68
1206 %43 = OpLabel
1207 OpUnreachable
1208 OpFunctionEnd
1209 )";
1210
1211 const std::string after =
1212 R"(OpCapability Shader
1213 %1 = OpExtInstImport "GLSL.std.450"
1214 OpMemoryModel Logical GLSL450
1215 OpEntryPoint Fragment %5663 "main" %4201 %4539 %3773
1216 OpExecutionMode %5663 OriginUpperLeft
1217 OpSource GLSL 450
1218 OpName %5663 "main"
1219 OpName %3782 "Test1(i1;"
1220 OpName %6931 "bound"
1221 OpName %3836 "Test2(i1;"
1222 OpName %4408 "bound"
1223 OpName %4292 "r"
1224 OpName %4298 "x"
1225 OpName %22102 "param"
1226 OpName %4201 "ini4"
1227 OpName %4539 "outf4"
1228 OpName %3773 "inf"
1229 OpName %18415 "param"
1230 OpName %5786 "param"
1231 OpDecorate %4201 Flat
1232 OpDecorate %4201 Location 1
1233 OpDecorate %4539 Location 0
1234 OpDecorate %3773 Location 0
1235 %8 = OpTypeVoid
1236 %1282 = OpTypeFunction %8
1237 %12 = OpTypeInt 32 1
1238 %649 = OpTypePointer Function %12
1239 %13 = OpTypeFloat 32
1240 %204 = OpTypeFunction %13 %649
1241 %650 = OpTypePointer Function %13
1242 %2572 = OpConstant %13 0
1243 %2571 = OpConstant %12 0
1244 %9 = OpTypeBool
1245 %252 = OpConstant %13 0.5
1246 %2574 = OpConstant %12 1
1247 %2577 = OpConstant %12 2
1248 %26 = OpTypeVector %12 4
1249 %663 = OpTypePointer Input %26
1250 %4201 = OpVariable %663 Input
1251 %11 = OpTypeInt 32 0
1252 %2573 = OpConstant %11 1
1253 %651 = OpTypePointer Input %12
1254 %2576 = OpConstant %11 2
1255 %2570 = OpConstant %11 0
1256 %29 = OpTypeVector %13 4
1257 %666 = OpTypePointer Output %29
1258 %4539 = OpVariable %666 Output
1259 %652 = OpTypePointer Input %13
1260 %3773 = OpVariable %652 Input
1261 %5663 = OpFunction %8 None %1282
1262 %24915 = OpLabel
1263 %18415 = OpVariable %649 Function
1264 %5786 = OpVariable %649 Function
1265 %8366 = OpLoad %13 %3773
1266 %8654 = OpConvertFToS %12 %8366
1267 OpStore %18415 %8654
1268 %17256 = OpFunctionCall %13 %3782 %18415
1269 %14512 = OpLoad %13 %3773
1270 %7041 = OpConvertFToS %12 %14512
1271 OpStore %5786 %7041
1272 %23993 = OpFunctionCall %13 %3836 %5786
1273 %9180 = OpFAdd %13 %17256 %23993
1274 %15728 = OpCompositeConstruct %29 %9180 %9180 %9180 %9180
1275 OpStore %4539 %15728
1276 OpReturn
1277 OpFunctionEnd
1278 %3782 = OpFunction %13 None %204
1279 %6931 = OpFunctionParameter %649
1280 %12220 = OpLabel
1281 %4292 = OpVariable %650 Function
1282 %4298 = OpVariable %649 Function
1283 OpStore %4292 %2572
1284 OpStore %4298 %2571
1285 OpBranch %14924
1286 %14924 = OpLabel
1287 OpLoopMerge %8882 %6488 None
1288 OpBranch %11857
1289 %11857 = OpLabel
1290 %13755 = OpLoad %12 %4298
1291 %22731 = OpLoad %12 %6931
1292 %20007 = OpSLessThan %9 %13755 %22731
1293 OpBranchConditional %20007 %24750 %8882
1294 %24750 = OpLabel
1295 %22912 = OpLoad %13 %4292
1296 %19471 = OpFAdd %13 %22912 %252
1297 OpStore %4292 %19471
1298 OpBranch %6488
1299 %6488 = OpLabel
1300 %19050 = OpLoad %12 %4298
1301 %8593 = OpIAdd %12 %19050 %2574
1302 OpStore %4298 %8593
1303 OpBranch %14924
1304 %8882 = OpLabel
1305 %11601 = OpLoad %13 %4292
1306 OpReturnValue %11601
1307 OpFunctionEnd
1308 %3836 = OpFunction %13 None %204
1309 %4408 = OpFunctionParameter %649
1310 %12143 = OpLabel
1311 %22102 = OpVariable %649 Function
1312 %24151 = OpLoad %12 %4408
1313 %13868 = OpSGreaterThan %9 %24151 %2577
1314 OpSelectionMerge %14966 None
1315 OpBranchConditional %13868 %9492 %17416
1316 %9492 = OpLabel
1317 %15624 = OpLoad %12 %4408
1318 OpStore %22102 %15624
1319 %17278 = OpFunctionCall %13 %3782 %22102
1320 OpReturnValue %17278
1321 %17416 = OpLabel
1322 %19506 = OpLoad %12 %4408
1323 %22773 = OpIMul %12 %19506 %2577
1324 %13472 = OpAccessChain %651 %4201 %2573
1325 %15280 = OpLoad %12 %13472
1326 %18079 = OpAccessChain %651 %4201 %2576
1327 %15199 = OpLoad %12 %18079
1328 %9343 = OpIMul %12 %15280 %15199
1329 %11462 = OpIAdd %12 %22773 %9343
1330 %11885 = OpAccessChain %651 %4201 %2570
1331 %21176 = OpLoad %12 %11885
1332 %10505 = OpIAdd %12 %11462 %21176
1333 %14626 = OpConvertSToF %13 %10505
1334 OpReturnValue %14626
1335 %14966 = OpLabel
1336 OpUnreachable
1337 OpFunctionEnd
1338 )";
1339
1340 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1341 SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
1342 SinglePassRunAndCheck<CanonicalizeIdsPass>(before, after, false, false);
1343 }
1344
1345 // ported from remap.similar_1b.everything.frag
1346 TEST_F(CanonicalizeIdsTest, remap_similar_1b) {
1347 const std::string before =
1348 R"(OpCapability Shader
1349 %1 = OpExtInstImport "GLSL.std.450"
1350 OpMemoryModel Logical GLSL450
1351 OpEntryPoint Fragment %4 "main" %58 %78 %80
1352 OpExecutionMode %4 OriginUpperLeft
1353 OpSource GLSL 450
1354 OpName %4 "main"
1355 OpName %11 "Test1(i1;"
1356 OpName %10 "bound"
1357 OpName %14 "Test2(i1;"
1358 OpName %13 "bound"
1359 OpName %17 "r"
1360 OpName %19 "x"
1361 OpName %49 "param"
1362 OpName %58 "ini4"
1363 OpName %78 "outf4"
1364 OpName %80 "inf"
1365 OpName %83 "param"
1366 OpName %87 "param"
1367 OpDecorate %58 Flat
1368 OpDecorate %58 Location 0
1369 OpDecorate %78 Location 0
1370 OpDecorate %80 Location 1
1371 %2 = OpTypeVoid
1372 %3 = OpTypeFunction %2
1373 %6 = OpTypeInt 32 1
1374 %7 = OpTypePointer Function %6
1375 %8 = OpTypeFloat 32
1376 %9 = OpTypeFunction %8 %7
1377 %16 = OpTypePointer Function %8
1378 %18 = OpConstant %8 0
1379 %20 = OpConstant %6 0
1380 %28 = OpTypeBool
1381 %30 = OpConstant %8 0.5
1382 %34 = OpConstant %6 1
1383 %36 = OpConstant %8 0.200000003
1384 %43 = OpConstant %6 2
1385 %54 = OpConstant %6 4
1386 %56 = OpTypeVector %6 4
1387 %57 = OpTypePointer Input %56
1388 %58 = OpVariable %57 Input
1389 %59 = OpTypeInt 32 0
1390 %60 = OpConstant %59 1
1391 %61 = OpTypePointer Input %6
1392 %64 = OpConstant %59 2
1393 %69 = OpConstant %59 0
1394 %76 = OpTypeVector %8 4
1395 %77 = OpTypePointer Output %76
1396 %78 = OpVariable %77 Output
1397 %79 = OpTypePointer Input %8
1398 %80 = OpVariable %79 Input
1399 %4 = OpFunction %2 None %3
1400 %5 = OpLabel
1401 %83 = OpVariable %7 Function
1402 %87 = OpVariable %7 Function
1403 %81 = OpLoad %8 %80
1404 %82 = OpConvertFToS %6 %81
1405 OpStore %83 %82
1406 %84 = OpFunctionCall %8 %11 %83
1407 %85 = OpLoad %8 %80
1408 %86 = OpConvertFToS %6 %85
1409 OpStore %87 %86
1410 %88 = OpFunctionCall %8 %14 %87
1411 %89 = OpFAdd %8 %84 %88
1412 %90 = OpCompositeConstruct %76 %89 %89 %89 %89
1413 OpStore %78 %90
1414 OpReturn
1415 OpFunctionEnd
1416 %11 = OpFunction %8 None %9
1417 %10 = OpFunctionParameter %7
1418 %12 = OpLabel
1419 %17 = OpVariable %16 Function
1420 %19 = OpVariable %7 Function
1421 OpStore %17 %18
1422 OpStore %19 %20
1423 OpBranch %21
1424 %21 = OpLabel
1425 OpLoopMerge %23 %24 None
1426 OpBranch %25
1427 %25 = OpLabel
1428 %26 = OpLoad %6 %19
1429 %27 = OpLoad %6 %10
1430 %29 = OpSLessThan %28 %26 %27
1431 OpBranchConditional %29 %22 %23
1432 %22 = OpLabel
1433 %31 = OpLoad %8 %17
1434 %32 = OpFAdd %8 %31 %30
1435 OpStore %17 %32
1436 OpBranch %24
1437 %24 = OpLabel
1438 %33 = OpLoad %6 %19
1439 %35 = OpIAdd %6 %33 %34
1440 OpStore %19 %35
1441 OpBranch %21
1442 %23 = OpLabel
1443 %37 = OpLoad %8 %17
1444 %38 = OpFAdd %8 %37 %36
1445 OpStore %17 %38
1446 %39 = OpLoad %8 %17
1447 OpReturnValue %39
1448 OpFunctionEnd
1449 %14 = OpFunction %8 None %9
1450 %13 = OpFunctionParameter %7
1451 %15 = OpLabel
1452 %49 = OpVariable %7 Function
1453 %42 = OpLoad %6 %13
1454 %44 = OpSGreaterThan %28 %42 %43
1455 OpSelectionMerge %46 None
1456 OpBranchConditional %44 %45 %52
1457 %45 = OpLabel
1458 %47 = OpLoad %6 %13
1459 %48 = OpIMul %6 %47 %43
1460 OpStore %49 %48
1461 %50 = OpFunctionCall %8 %11 %49
1462 OpReturnValue %50
1463 %52 = OpLabel
1464 %53 = OpLoad %6 %13
1465 %55 = OpIMul %6 %53 %54
1466 %62 = OpAccessChain %61 %58 %60
1467 %63 = OpLoad %6 %62
1468 %65 = OpAccessChain %61 %58 %64
1469 %66 = OpLoad %6 %65
1470 %67 = OpIMul %6 %63 %66
1471 %68 = OpIAdd %6 %55 %67
1472 %70 = OpAccessChain %61 %58 %69
1473 %71 = OpLoad %6 %70
1474 %72 = OpIAdd %6 %68 %71
1475 %73 = OpConvertSToF %8 %72
1476 OpReturnValue %73
1477 %46 = OpLabel
1478 OpUnreachable
1479 OpFunctionEnd
1480 )";
1481
1482 const std::string after =
1483 R"(OpCapability Shader
1484 %1 = OpExtInstImport "GLSL.std.450"
1485 OpMemoryModel Logical GLSL450
1486 OpEntryPoint Fragment %5663 "main" %4201 %4539 %3773
1487 OpExecutionMode %5663 OriginUpperLeft
1488 OpSource GLSL 450
1489 OpName %5663 "main"
1490 OpName %3782 "Test1(i1;"
1491 OpName %6931 "bound"
1492 OpName %3836 "Test2(i1;"
1493 OpName %4408 "bound"
1494 OpName %4292 "r"
1495 OpName %4298 "x"
1496 OpName %22102 "param"
1497 OpName %4201 "ini4"
1498 OpName %4539 "outf4"
1499 OpName %3773 "inf"
1500 OpName %18415 "param"
1501 OpName %5786 "param"
1502 OpDecorate %4201 Flat
1503 OpDecorate %4201 Location 0
1504 OpDecorate %4539 Location 0
1505 OpDecorate %3773 Location 1
1506 %8 = OpTypeVoid
1507 %1282 = OpTypeFunction %8
1508 %12 = OpTypeInt 32 1
1509 %649 = OpTypePointer Function %12
1510 %13 = OpTypeFloat 32
1511 %204 = OpTypeFunction %13 %649
1512 %650 = OpTypePointer Function %13
1513 %2572 = OpConstant %13 0
1514 %2571 = OpConstant %12 0
1515 %9 = OpTypeBool
1516 %252 = OpConstant %13 0.5
1517 %2574 = OpConstant %12 1
1518 %2821 = OpConstant %13 0.200000003
1519 %2577 = OpConstant %12 2
1520 %2583 = OpConstant %12 4
1521 %26 = OpTypeVector %12 4
1522 %663 = OpTypePointer Input %26
1523 %4201 = OpVariable %663 Input
1524 %11 = OpTypeInt 32 0
1525 %2573 = OpConstant %11 1
1526 %651 = OpTypePointer Input %12
1527 %2576 = OpConstant %11 2
1528 %2570 = OpConstant %11 0
1529 %29 = OpTypeVector %13 4
1530 %666 = OpTypePointer Output %29
1531 %4539 = OpVariable %666 Output
1532 %652 = OpTypePointer Input %13
1533 %3773 = OpVariable %652 Input
1534 %5663 = OpFunction %8 None %1282
1535 %24915 = OpLabel
1536 %18415 = OpVariable %649 Function
1537 %5786 = OpVariable %649 Function
1538 %8366 = OpLoad %13 %3773
1539 %8654 = OpConvertFToS %12 %8366
1540 OpStore %18415 %8654
1541 %17256 = OpFunctionCall %13 %3782 %18415
1542 %14512 = OpLoad %13 %3773
1543 %7041 = OpConvertFToS %12 %14512
1544 OpStore %5786 %7041
1545 %23993 = OpFunctionCall %13 %3836 %5786
1546 %9180 = OpFAdd %13 %17256 %23993
1547 %15728 = OpCompositeConstruct %29 %9180 %9180 %9180 %9180
1548 OpStore %4539 %15728
1549 OpReturn
1550 OpFunctionEnd
1551 %3782 = OpFunction %13 None %204
1552 %6931 = OpFunctionParameter %649
1553 %12220 = OpLabel
1554 %4292 = OpVariable %650 Function
1555 %4298 = OpVariable %649 Function
1556 OpStore %4292 %2572
1557 OpStore %4298 %2571
1558 OpBranch %14924
1559 %14924 = OpLabel
1560 OpLoopMerge %6507 %6488 None
1561 OpBranch %11857
1562 %11857 = OpLabel
1563 %13755 = OpLoad %12 %4298
1564 %22731 = OpLoad %12 %6931
1565 %20007 = OpSLessThan %9 %13755 %22731
1566 OpBranchConditional %20007 %24750 %6507
1567 %24750 = OpLabel
1568 %22912 = OpLoad %13 %4292
1569 %19471 = OpFAdd %13 %22912 %252
1570 OpStore %4292 %19471
1571 OpBranch %6488
1572 %6488 = OpLabel
1573 %19050 = OpLoad %12 %4298
1574 %8593 = OpIAdd %12 %19050 %2574
1575 OpStore %4298 %8593
1576 OpBranch %14924
1577 %6507 = OpLabel
1578 %18877 = OpLoad %13 %4292
1579 %15899 = OpFAdd %13 %18877 %2821
1580 OpStore %4292 %15899
1581 %20342 = OpLoad %13 %4292
1582 OpReturnValue %20342
1583 OpFunctionEnd
1584 %3836 = OpFunction %13 None %204
1585 %4408 = OpFunctionParameter %649
1586 %12143 = OpLabel
1587 %22102 = OpVariable %649 Function
1588 %24151 = OpLoad %12 %4408
1589 %13868 = OpSGreaterThan %9 %24151 %2577
1590 OpSelectionMerge %14966 None
1591 OpBranchConditional %13868 %10822 %17416
1592 %10822 = OpLabel
1593 %22680 = OpLoad %12 %4408
1594 %23216 = OpIMul %12 %22680 %2577
1595 OpStore %22102 %23216
1596 %7042 = OpFunctionCall %13 %3782 %22102
1597 OpReturnValue %7042
1598 %17416 = OpLabel
1599 %19506 = OpLoad %12 %4408
1600 %22773 = OpIMul %12 %19506 %2583
1601 %13472 = OpAccessChain %651 %4201 %2573
1602 %15280 = OpLoad %12 %13472
1603 %18079 = OpAccessChain %651 %4201 %2576
1604 %15199 = OpLoad %12 %18079
1605 %9343 = OpIMul %12 %15280 %15199
1606 %11462 = OpIAdd %12 %22773 %9343
1607 %11885 = OpAccessChain %651 %4201 %2570
1608 %21176 = OpLoad %12 %11885
1609 %10505 = OpIAdd %12 %11462 %21176
1610 %14626 = OpConvertSToF %13 %10505
1611 OpReturnValue %14626
1612 %14966 = OpLabel
1613 OpUnreachable
1614 OpFunctionEnd
1615 )";
1616
1617 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1618 SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
1619 SinglePassRunAndCheck<CanonicalizeIdsPass>(before, after, false, false);
1620 }
1621
1622 // ported from remap.specconst.comp
1623 TEST_F(CanonicalizeIdsTest, remap_specconst) {
1624 const std::string before =
1625 R"(OpCapability Shader
1626 %1 = OpExtInstImport "GLSL.std.450"
1627 OpMemoryModel Logical GLSL450
1628 OpEntryPoint GLCompute %4 "main"
1629 OpExecutionMode %4 LocalSize 1 1 1
1630 OpSource GLSL 450
1631 OpName %4 "main"
1632 OpDecorate %7 SpecId 0
1633 OpDecorate %8 SpecId 1
1634 OpDecorate %9 SpecId 2
1635 OpDecorate %11 BuiltIn WorkgroupSize
1636 %2 = OpTypeVoid
1637 %3 = OpTypeFunction %2
1638 %6 = OpTypeInt 32 0
1639 %7 = OpSpecConstant %6 1
1640 %8 = OpSpecConstant %6 1
1641 %9 = OpSpecConstant %6 1
1642 %10 = OpTypeVector %6 3
1643 %11 = OpSpecConstantComposite %10 %7 %8 %9
1644 %14 = OpSpecConstantOp %6 CompositeExtract %11 0
1645 %16 = OpSpecConstantOp %6 CompositeExtract %11 1
1646 %18 = OpSpecConstantOp %6 CompositeExtract %11 2
1647 %19 = OpSpecConstantOp %6 IMul %16 %18
1648 %20 = OpSpecConstantOp %6 IAdd %14 %19
1649 %4 = OpFunction %2 None %3
1650 %5 = OpLabel
1651 OpReturn
1652 OpFunctionEnd
1653 )";
1654
1655 const std::string after =
1656 R"(OpCapability Shader
1657 %1 = OpExtInstImport "GLSL.std.450"
1658 OpMemoryModel Logical GLSL450
1659 OpEntryPoint GLCompute %5663 "main"
1660 OpExecutionMode %5663 LocalSize 1 1 1
1661 OpSource GLSL 450
1662 OpName %5663 "main"
1663 OpDecorate %2 SpecId 0
1664 OpDecorate %3 SpecId 1
1665 OpDecorate %4 SpecId 2
1666 OpDecorate %5 BuiltIn WorkgroupSize
1667 %8 = OpTypeVoid
1668 %1282 = OpTypeFunction %8
1669 %11 = OpTypeInt 32 0
1670 %2 = OpSpecConstant %11 1
1671 %3 = OpSpecConstant %11 1
1672 %4 = OpSpecConstant %11 1
1673 %20 = OpTypeVector %11 3
1674 %5 = OpSpecConstantComposite %20 %2 %3 %4
1675 %6 = OpSpecConstantOp %11 CompositeExtract %5 0
1676 %7 = OpSpecConstantOp %11 CompositeExtract %5 1
1677 %9 = OpSpecConstantOp %11 CompositeExtract %5 2
1678 %10 = OpSpecConstantOp %11 IMul %7 %9
1679 %12 = OpSpecConstantOp %11 IAdd %6 %10
1680 %5663 = OpFunction %8 None %1282
1681 %16103 = OpLabel
1682 OpReturn
1683 OpFunctionEnd
1684 )";
1685
1686 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1687 SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
1688 SinglePassRunAndCheck<CanonicalizeIdsPass>(before, after, false, false);
1689 }
1690
1691 // ported from remap.switch.everything.frag
1692 TEST_F(CanonicalizeIdsTest, remap_switch) {
1693 const std::string before =
1694 R"(OpCapability Shader
1695 %1 = OpExtInstImport "GLSL.std.450"
1696 OpMemoryModel Logical GLSL450
1697 OpEntryPoint Fragment %4 "main" %9 %23
1698 OpExecutionMode %4 OriginUpperLeft
1699 OpSource GLSL 450
1700 OpName %4 "main"
1701 OpName %9 "in0"
1702 OpName %23 "FragColor"
1703 OpDecorate %9 Location 0
1704 OpDecorate %23 RelaxedPrecision
1705 OpDecorate %23 Location 0
1706 OpDecorate %29 RelaxedPrecision
1707 OpDecorate %36 RelaxedPrecision
1708 OpDecorate %43 RelaxedPrecision
1709 %2 = OpTypeVoid
1710 %3 = OpTypeFunction %2
1711 %6 = OpTypeFloat 32
1712 %7 = OpTypeVector %6 4
1713 %8 = OpTypePointer Input %7
1714 %9 = OpVariable %8 Input
1715 %10 = OpTypeInt 32 0
1716 %11 = OpConstant %10 3
1717 %12 = OpTypePointer Input %6
1718 %15 = OpTypeInt 32 1
1719 %22 = OpTypePointer Output %7
1720 %23 = OpVariable %22 Output
1721 %24 = OpConstant %10 0
1722 %27 = OpConstant %6 0
1723 %31 = OpConstant %10 1
1724 %34 = OpConstant %6 1
1725 %38 = OpConstant %10 2
1726 %41 = OpConstant %6 2
1727 %45 = OpConstant %6 -1
1728 %46 = OpConstantComposite %7 %45 %45 %45 %45
1729 %4 = OpFunction %2 None %3
1730 %5 = OpLabel
1731 %13 = OpAccessChain %12 %9 %11
1732 %14 = OpLoad %6 %13
1733 %16 = OpConvertFToS %15 %14
1734 OpSelectionMerge %21 None
1735 OpSwitch %16 %20 0 %17 1 %18 2 %19
1736 %20 = OpLabel
1737 OpStore %23 %46
1738 OpBranch %21
1739 %17 = OpLabel
1740 %25 = OpAccessChain %12 %9 %24
1741 %26 = OpLoad %6 %25
1742 %28 = OpFAdd %6 %26 %27
1743 %29 = OpCompositeConstruct %7 %28 %28 %28 %28
1744 OpStore %23 %29
1745 OpBranch %21
1746 %18 = OpLabel
1747 %32 = OpAccessChain %12 %9 %31
1748 %33 = OpLoad %6 %32
1749 %35 = OpFAdd %6 %33 %34
1750 %36 = OpCompositeConstruct %7 %35 %35 %35 %35
1751 OpStore %23 %36
1752 OpBranch %21
1753 %19 = OpLabel
1754 %39 = OpAccessChain %12 %9 %38
1755 %40 = OpLoad %6 %39
1756 %42 = OpFAdd %6 %40 %41
1757 %43 = OpCompositeConstruct %7 %42 %42 %42 %42
1758 OpStore %23 %43
1759 OpBranch %21
1760 %21 = OpLabel
1761 OpReturn
1762 OpFunctionEnd
1763 )";
1764
1765 const std::string after =
1766 R"(OpCapability Shader
1767 %1 = OpExtInstImport "GLSL.std.450"
1768 OpMemoryModel Logical GLSL450
1769 OpEntryPoint Fragment %5663 "main" %3719 %3994
1770 OpExecutionMode %5663 OriginUpperLeft
1771 OpSource GLSL 450
1772 OpName %5663 "main"
1773 OpName %3719 "in0"
1774 OpName %3994 "FragColor"
1775 OpDecorate %3719 Location 0
1776 OpDecorate %3994 RelaxedPrecision
1777 OpDecorate %3994 Location 0
1778 OpDecorate %12421 RelaxedPrecision
1779 OpDecorate %12422 RelaxedPrecision
1780 OpDecorate %12423 RelaxedPrecision
1781 %8 = OpTypeVoid
1782 %1282 = OpTypeFunction %8
1783 %13 = OpTypeFloat 32
1784 %29 = OpTypeVector %13 4
1785 %666 = OpTypePointer Input %29
1786 %3719 = OpVariable %666 Input
1787 %11 = OpTypeInt 32 0
1788 %2579 = OpConstant %11 3
1789 %650 = OpTypePointer Input %13
1790 %12 = OpTypeInt 32 1
1791 %667 = OpTypePointer Output %29
1792 %3994 = OpVariable %667 Output
1793 %2570 = OpConstant %11 0
1794 %2572 = OpConstant %13 0
1795 %2573 = OpConstant %11 1
1796 %138 = OpConstant %13 1
1797 %2576 = OpConstant %11 2
1798 %24 = OpConstant %13 2
1799 %833 = OpConstant %13 -1
1800 %1284 = OpConstantComposite %29 %833 %833 %833 %833
1801 %5663 = OpFunction %8 None %1282
1802 %23915 = OpLabel
1803 %7984 = OpAccessChain %650 %3719 %2579
1804 %11376 = OpLoad %13 %7984
1805 %16859 = OpConvertFToS %12 %11376
1806 OpSelectionMerge %19578 None
1807 OpSwitch %16859 %15971 0 %8158 1 %8159 2 %8160
1808 %15971 = OpLabel
1809 OpStore %3994 %1284
1810 OpBranch %19578
1811 %8158 = OpLabel
1812 %21848 = OpAccessChain %650 %3719 %2570
1813 %23987 = OpLoad %13 %21848
1814 %19989 = OpFAdd %13 %23987 %2572
1815 %12421 = OpCompositeConstruct %29 %19989 %19989 %19989 %19989
1816 OpStore %3994 %12421
1817 OpBranch %19578
1818 %8159 = OpLabel
1819 %21849 = OpAccessChain %650 %3719 %2573
1820 %23988 = OpLoad %13 %21849
1821 %19990 = OpFAdd %13 %23988 %138
1822 %12422 = OpCompositeConstruct %29 %19990 %19990 %19990 %19990
1823 OpStore %3994 %12422
1824 OpBranch %19578
1825 %8160 = OpLabel
1826 %21850 = OpAccessChain %650 %3719 %2576
1827 %23989 = OpLoad %13 %21850
1828 %19991 = OpFAdd %13 %23989 %24
1829 %12423 = OpCompositeConstruct %29 %19991 %19991 %19991 %19991
1830 OpStore %3994 %12423
1831 OpBranch %19578
1832 %19578 = OpLabel
1833 OpReturn
1834 OpFunctionEnd
1835 )";
1836
1837 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1838 SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
1839 SinglePassRunAndCheck<CanonicalizeIdsPass>(before, after, false, false);
1840 }
1841
1842 // ported from remap.uniformarray.everything.frag
1843 TEST_F(CanonicalizeIdsTest, remap_uniformarray) {
1844 const std::string before =
1845 R"(OpCapability Shader
1846 %1 = OpExtInstImport "GLSL.std.450"
1847 OpMemoryModel Logical GLSL450
1848 OpEntryPoint Fragment %4 "main" %14 %25 %43 %54
1849 OpExecutionMode %4 OriginUpperLeft
1850 OpSource GLSL 140
1851 OpName %4 "main"
1852 OpName %9 "texColor"
1853 OpName %14 "color"
1854 OpName %25 "inColor"
1855 OpName %43 "alpha"
1856 OpName %54 "gl_FragColor"
1857 OpDecorate %14 Location 1
1858 OpDecorate %25 Location 0
1859 OpDecorate %43 Location 7
1860 OpDecorate %54 Location 0
1861 %2 = OpTypeVoid
1862 %3 = OpTypeFunction %2
1863 %6 = OpTypeFloat 32
1864 %7 = OpTypeVector %6 4
1865 %8 = OpTypePointer Function %7
1866 %10 = OpTypeInt 32 0
1867 %11 = OpConstant %10 6
1868 %12 = OpTypeArray %7 %11
1869 %13 = OpTypePointer Input %12
1870 %14 = OpVariable %13 Input
1871 %15 = OpTypeInt 32 1
1872 %16 = OpConstant %15 1
1873 %17 = OpTypePointer Input %7
1874 %23 = OpTypeVector %6 3
1875 %24 = OpTypePointer Input %23
1876 %25 = OpVariable %24 Input
1877 %30 = OpConstant %10 0
1878 %31 = OpTypePointer Function %6
1879 %34 = OpConstant %10 1
1880 %37 = OpConstant %10 2
1881 %40 = OpConstant %10 16
1882 %41 = OpTypeArray %6 %40
1883 %42 = OpTypePointer Input %41
1884 %43 = OpVariable %42 Input
1885 %44 = OpConstant %15 12
1886 %45 = OpTypePointer Input %6
1887 %48 = OpConstant %10 3
1888 %53 = OpTypePointer Output %7
1889 %54 = OpVariable %53 Output
1890 %4 = OpFunction %2 None %3
1891 %5 = OpLabel
1892 %9 = OpVariable %8 Function
1893 %18 = OpAccessChain %17 %14 %16
1894 %19 = OpLoad %7 %18
1895 %20 = OpAccessChain %17 %14 %16
1896 %21 = OpLoad %7 %20
1897 %22 = OpFAdd %7 %19 %21
1898 OpStore %9 %22
1899 %26 = OpLoad %23 %25
1900 %27 = OpLoad %7 %9
1901 %28 = OpVectorShuffle %23 %27 %27 0 1 2
1902 %29 = OpFAdd %23 %28 %26
1903 %32 = OpAccessChain %31 %9 %30
1904 %33 = OpCompositeExtract %6 %29 0
1905 OpStore %32 %33
1906 %35 = OpAccessChain %31 %9 %34
1907 %36 = OpCompositeExtract %6 %29 1
1908 OpStore %35 %36
1909 %38 = OpAccessChain %31 %9 %37
1910 %39 = OpCompositeExtract %6 %29 2
1911 OpStore %38 %39
1912 %46 = OpAccessChain %45 %43 %44
1913 %47 = OpLoad %6 %46
1914 %49 = OpAccessChain %31 %9 %48
1915 %50 = OpLoad %6 %49
1916 %51 = OpFAdd %6 %50 %47
1917 %52 = OpAccessChain %31 %9 %48
1918 OpStore %52 %51
1919 %55 = OpLoad %7 %9
1920 OpStore %54 %55
1921 OpReturn
1922 OpFunctionEnd
1923 )";
1924
1925 const std::string after =
1926 R"(OpCapability Shader
1927 %1 = OpExtInstImport "GLSL.std.450"
1928 OpMemoryModel Logical GLSL450
1929 OpEntryPoint Fragment %5663 "main" %3608 %4957 %4339 %5139
1930 OpExecutionMode %5663 OriginUpperLeft
1931 OpSource GLSL 140
1932 OpName %5663 "main"
1933 OpName %4902 "texColor"
1934 OpName %3608 "color"
1935 OpName %4957 "inColor"
1936 OpName %4339 "alpha"
1937 OpName %5139 "gl_FragColor"
1938 OpDecorate %3608 Location 1
1939 OpDecorate %4957 Location 0
1940 OpDecorate %4339 Location 7
1941 OpDecorate %5139 Location 0
1942 %8 = OpTypeVoid
1943 %1282 = OpTypeFunction %8
1944 %13 = OpTypeFloat 32
1945 %29 = OpTypeVector %13 4
1946 %666 = OpTypePointer Function %29
1947 %11 = OpTypeInt 32 0
1948 %2588 = OpConstant %11 6
1949 %740 = OpTypeArray %29 %2588
1950 %1377 = OpTypePointer Input %740
1951 %3608 = OpVariable %1377 Input
1952 %12 = OpTypeInt 32 1
1953 %2574 = OpConstant %12 1
1954 %667 = OpTypePointer Input %29
1955 %24 = OpTypeVector %13 3
1956 %661 = OpTypePointer Input %24
1957 %4957 = OpVariable %661 Input
1958 %2570 = OpConstant %11 0
1959 %650 = OpTypePointer Function %13
1960 %2573 = OpConstant %11 1
1961 %2576 = OpConstant %11 2
1962 %2618 = OpConstant %11 16
1963 %709 = OpTypeArray %13 %2618
1964 %1346 = OpTypePointer Input %709
1965 %4339 = OpVariable %1346 Input
1966 %2607 = OpConstant %12 12
1967 %651 = OpTypePointer Input %13
1968 %2579 = OpConstant %11 3
1969 %668 = OpTypePointer Output %29
1970 %5139 = OpVariable %668 Output
1971 %5663 = OpFunction %8 None %1282
1972 %25029 = OpLabel
1973 %4902 = OpVariable %666 Function
1974 %10645 = OpAccessChain %667 %3608 %2574
1975 %8181 = OpLoad %29 %10645
1976 %21370 = OpAccessChain %667 %3608 %2574
1977 %11355 = OpLoad %29 %21370
1978 %23084 = OpFAdd %29 %8181 %11355
1979 OpStore %4902 %23084
1980 %21218 = OpLoad %24 %4957
1981 %13695 = OpLoad %29 %4902
1982 %23959 = OpVectorShuffle %24 %13695 %13695 0 1 2
1983 %14937 = OpFAdd %24 %23959 %21218
1984 %15653 = OpAccessChain %650 %4902 %2570
1985 %21354 = OpCompositeExtract %13 %14937 0
1986 OpStore %15653 %21354
1987 %16378 = OpAccessChain %650 %4902 %2573
1988 %15746 = OpCompositeExtract %13 %14937 1
1989 OpStore %16378 %15746
1990 %16379 = OpAccessChain %650 %4902 %2576
1991 %15747 = OpCompositeExtract %13 %14937 2
1992 OpStore %16379 %15747
1993 %19895 = OpAccessChain %651 %4339 %2607
1994 %7372 = OpLoad %13 %19895
1995 %21371 = OpAccessChain %650 %4902 %2579
1996 %11412 = OpLoad %13 %21371
1997 %22584 = OpFAdd %13 %11412 %7372
1998 %17318 = OpAccessChain %650 %4902 %2579
1999 OpStore %17318 %22584
2000 %17934 = OpLoad %29 %4902
2001 OpStore %5139 %17934
2002 OpReturn
2003 OpFunctionEnd
2004 )";
2005
2006 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
2007 SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
2008 SinglePassRunAndCheck<CanonicalizeIdsPass>(before, after, false, false);
2009 }
2010
2011 TEST_F(CanonicalizeIdsTest, NonSemanticDebugInfo) {
2012 std::string before = R"(
2013 OpCapability Shader
2014 OpExtension "SPV_KHR_non_semantic_info"
2015 OpExtension "SPV_KHR_storage_buffer_storage_class"
2016 %1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
2017 OpMemoryModel Logical GLSL450
2018 OpEntryPoint GLCompute %2 "main"
2019 OpExecutionMode %2 LocalSize 1 1 1
2020 %4 = OpString ""
2021 OpDecorate %6 ArrayStride 4
2022 OpDecorate %7 Block
2023 OpMemberDecorate %7 0 Offset 0
2024 OpDecorate %3 Binding 0
2025 OpDecorate %3 DescriptorSet 0
2026 %8 = OpTypeVoid
2027 %9 = OpTypeInt 32 0
2028 %10 = OpConstant %9 100
2029 %11 = OpTypeFunction %8
2030 %12 = OpTypeInt 32 1
2031 %13 = OpConstant %12 0
2032 %14 = OpTypeFloat 32
2033 %5 = OpTypePointer StorageBuffer %14
2034 %6 = OpTypeRuntimeArray %14
2035 %7 = OpTypeStruct %6
2036 %15 = OpTypePointer StorageBuffer %7
2037 %16 = OpConstant %14 0
2038 %3 = OpVariable %15 StorageBuffer
2039 %17 = OpExtInst %8 %1 DebugInfoNone
2040 %18 = OpExtInst %8 %1 DebugSource %4 %4
2041 %19 = OpExtInst %8 %1 DebugCompilationUnit %10 %10 %18 %10
2042 %20 = OpExtInst %8 %1 DebugTypeFunction %10 %8
2043 %21 = OpExtInst %8 %1 DebugFunction %4 %20 %18 %10 %10 %19 %4 %10 %10
2044 %22 = OpExtInst %8 %1 DebugEntryPoint %21 %19 %4 %4
2045 %23 = OpExtInst %8 %1 DebugTypeBasic %4 %10 %10 %10
2046 %24 = OpExtInst %8 %1 DebugTypeArray %23 %10
2047 %25 = OpExtInst %8 %1 DebugTypeMember %4 %24 %18 %10 %10 %10 %10 %10
2048 %26 = OpExtInst %8 %1 DebugTypeComposite %4 %10 %18 %10 %10 %19 %4 %10 %10 %25
2049 %27 = OpExtInst %8 %1 DebugGlobalVariable %4 %26 %18 %10 %10 %19 %4 %3 %10
2050 %2 = OpFunction %8 None %11
2051 %28 = OpLabel
2052 %29 = OpExtInst %8 %1 DebugFunctionDefinition %21 %2
2053 %30 = OpExtInst %8 %1 DebugScope %21
2054 %31 = OpExtInst %8 %1 DebugLine %18 %10 %10 %10 %10
2055 %32 = OpAccessChain %5 %3 %13 %13
2056 OpStore %32 %16
2057 OpReturn
2058 %33 = OpExtInst %8 %1 DebugNoScope
2059 OpFunctionEnd
2060 )";
2061
2062 std::string after = R"(OpCapability Shader
2063 OpExtension "SPV_KHR_non_semantic_info"
2064 OpExtension "SPV_KHR_storage_buffer_storage_class"
2065 %1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
2066 OpMemoryModel Logical GLSL450
2067 OpEntryPoint GLCompute %10742 "main"
2068 OpExecutionMode %10742 LocalSize 1 1 1
2069 %3 = OpString ""
2070 OpDecorate %2002 ArrayStride 4
2071 OpDecorate %1952 Block
2072 OpMemberDecorate %1952 0 Offset 0
2073 OpDecorate %2 Binding 0
2074 OpDecorate %2 DescriptorSet 0
2075 %8 = OpTypeVoid
2076 %11 = OpTypeInt 32 0
2077 %2870 = OpConstant %11 100
2078 %1282 = OpTypeFunction %8
2079 %12 = OpTypeInt 32 1
2080 %2571 = OpConstant %12 0
2081 %13 = OpTypeFloat 32
2082 %650 = OpTypePointer StorageBuffer %13
2083 %2002 = OpTypeRuntimeArray %13
2084 %1952 = OpTypeStruct %2002
2085 %2589 = OpTypePointer StorageBuffer %1952
2086 %2572 = OpConstant %13 0
2087 %2 = OpVariable %2589 StorageBuffer
2088 %4 = OpExtInst %8 %1 DebugInfoNone
2089 %5 = OpExtInst %8 %1 DebugSource %3 %3
2090 %6 = OpExtInst %8 %1 DebugCompilationUnit %2870 %2870 %5 %2870
2091 %7 = OpExtInst %8 %1 DebugTypeFunction %2870 %8
2092 %9 = OpExtInst %8 %1 DebugFunction %3 %7 %5 %2870 %2870 %6 %3 %2870 %2870
2093 %10 = OpExtInst %8 %1 DebugEntryPoint %9 %6 %3 %3
2094 %14 = OpExtInst %8 %1 DebugTypeBasic %3 %2870 %2870 %2870
2095 %15 = OpExtInst %8 %1 DebugTypeArray %14 %2870
2096 %16 = OpExtInst %8 %1 DebugTypeMember %3 %15 %5 %2870 %2870 %2870 %2870 %2870
2097 %17 = OpExtInst %8 %1 DebugTypeComposite %3 %2870 %5 %2870 %2870 %6 %3 %2870 %2870 %16
2098 %18 = OpExtInst %8 %1 DebugGlobalVariable %3 %17 %5 %2870 %2870 %6 %3 %2 %2870
2099 %10742 = OpFunction %8 None %1282
2100 %9442 = OpLabel
2101 %15450 = OpExtInst %8 %1 DebugFunctionDefinition %9 %10742
2102 %20275 = OpExtInst %8 %1 DebugScope %9
2103 %19 = OpExtInst %8 %1 DebugLine %5 %2870 %2870 %2870 %2870
2104 %20274 = OpAccessChain %650 %2 %2571 %2571
2105 OpStore %20274 %2572
2106 OpReturn
2107 %20276 = OpExtInst %8 %1 DebugNoScope
2108 OpFunctionEnd
2109 )";
2110
2111 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
2112 SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
2113 SinglePassRunAndCheck<CanonicalizeIdsPass>(before, after, false, true);
2114 }
2115
2116 } // namespace
2117 } // namespace opt
2118 } // namespace spvtools