• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!amber
2
3# Copyright 2020 Google LLC
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17
18# A test for a bug found by the GraphicsFuzz project.
19
20# Short description: Two shaders with diff: conditional bit shift in a clamp
21
22# The test renders two images using semantically equivalent shaders, and then
23# checks that the images are similar.
24# The test passes because the shaders have the same semantics and so the images
25# should be the same.
26
27SHADER vertex reference_vertex_shader PASSTHROUGH
28
29# reference_fragment_shader is derived from the following GLSL:
30# #version 320 es
31# precision highp float;
32#
33# precision highp int;
34#
35# layout(location = 0) out vec4 _GLF_color;
36#
37# layout(set = 0, binding = 0) uniform buf0 {
38#  vec2 injectionSwitch;
39# };
40# const int N = 10;
41#
42# int data[10], temp[10];
43#
44# void merge(int from, int mid, int to)
45# {
46#  int k = from, i = from, j = mid + 1;
47#  while(i <= mid && j <= to)
48#   {
49#    if(data[i] < data[j])
50#     {
51#      temp[k ++] = data[i ++];
52#     }
53#    else
54#     {
55#      temp[k ++] = data[j ++];
56#     }
57#   }
58#  while(i < N && i <= mid)
59#   {
60#    temp[k ++] = data[i ++];
61#   }
62#  for(int i = from; i <= to; i ++)
63#   {
64#    data[i] = temp[i];
65#   }
66# }
67# void mergeSort()
68# {
69#  int low = 0;
70#  int high = N - 1;
71#  for(int m = 1; m <= high; m = 2 * m)
72#   {
73#    for(int i = low; i < high; i += 2 * m)
74#     {
75#      int from = i;
76#      int mid = i + m - 1;
77#      int to = min(i + 2 * m - 1, high);
78#      merge(from, mid, to);
79#     }
80#   }
81# }
82# void main()
83# {
84#  int i = int(injectionSwitch.x);
85#  do
86#   {
87#    switch(i)
88#     {
89#      case 0:
90#      data[i] = 4;
91#      break;
92#      case 1:
93#      data[i] = 3;
94#      break;
95#      case 2:
96#      data[i] = 2;
97#      break;
98#      case 3:
99#      data[i] = 1;
100#      break;
101#      case 4:
102#      data[i] = 0;
103#      break;
104#      case 5:
105#      data[i] = - 1;
106#      break;
107#      case 6:
108#      data[i] = - 2;
109#      break;
110#      case 7:
111#      data[i] = - 3;
112#      break;
113#      case 8:
114#      data[i] = - 4;
115#      break;
116#      case 9:
117#      data[i] = - 5;
118#      break;
119#     }
120#    i ++;
121#   }
122#  while(i < 10);
123#  for(int j = 0; j < 10; j ++)
124#   {
125#    temp[j] = data[j];
126#   }
127#  mergeSort();
128#  float grey;
129#  if(int(gl_FragCoord[1]) < 30)
130#   {
131#    grey = 0.5 + float(data[0]) / 10.0;
132#   }
133#  else
134#   {
135#    if(int(gl_FragCoord[1]) < 60)
136#     {
137#      grey = 0.5 + float(data[1]) / 10.0;
138#     }
139#    else
140#     {
141#      if(int(gl_FragCoord[1]) < 90)
142#       {
143#        grey = 0.5 + float(data[2]) / 10.0;
144#       }
145#      else
146#       {
147#        if(int(gl_FragCoord[1]) < 120)
148#         {
149#          grey = 0.5 + float(data[3]) / 10.0;
150#         }
151#        else
152#         {
153#          if(int(gl_FragCoord[1]) < 150)
154#           {
155#            discard;
156#           }
157#          else
158#           {
159#            if(int(gl_FragCoord[1]) < 180)
160#             {
161#              grey = 0.5 + float(data[5]) / 10.0;
162#             }
163#            else
164#             {
165#              if(int(gl_FragCoord[1]) < 210)
166#               {
167#                grey = 0.5 + float(data[6]) / 10.0;
168#               }
169#              else
170#               {
171#                if(int(gl_FragCoord[1]) < 240)
172#                 {
173#                  grey = 0.5 + float(data[7]) / 10.0;
174#                 }
175#                else
176#                 {
177#                  if(int(gl_FragCoord[1]) < 270)
178#                   {
179#                    grey = 0.5 + float(data[8]) / 10.0;
180#                   }
181#                  else
182#                   {
183#                    discard;
184#                   }
185#                 }
186#               }
187#             }
188#           }
189#         }
190#       }
191#     }
192#   }
193#  _GLF_color = vec4(vec3(grey), 1.0);
194# }
195SHADER fragment reference_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
196; SPIR-V
197; Version: 1.0
198; Generator: Khronos Glslang Reference Front End; 10
199; Bound: 378
200; Schema: 0
201               OpCapability Shader
202          %1 = OpExtInstImport "GLSL.std.450"
203               OpMemoryModel Logical GLSL450
204               OpEntryPoint Fragment %4 "main" %243 %369
205               OpExecutionMode %4 OriginUpperLeft
206               OpSource ESSL 320
207               OpName %4 "main"
208               OpName %12 "merge(i1;i1;i1;"
209               OpName %9 "from"
210               OpName %10 "mid"
211               OpName %11 "to"
212               OpName %14 "mergeSort("
213               OpName %16 "k"
214               OpName %18 "i"
215               OpName %20 "j"
216               OpName %41 "data"
217               OpName %52 "temp"
218               OpName %87 "i"
219               OpName %104 "low"
220               OpName %106 "high"
221               OpName %108 "m"
222               OpName %117 "i"
223               OpName %127 "from"
224               OpName %129 "mid"
225               OpName %134 "to"
226               OpName %143 "param"
227               OpName %145 "param"
228               OpName %147 "param"
229               OpName %156 "i"
230               OpName %159 "buf0"
231               OpMemberName %159 0 "injectionSwitch"
232               OpName %161 ""
233               OpName %225 "j"
234               OpName %243 "gl_FragCoord"
235               OpName %254 "grey"
236               OpName %369 "_GLF_color"
237               OpMemberDecorate %159 0 Offset 0
238               OpDecorate %159 Block
239               OpDecorate %161 DescriptorSet 0
240               OpDecorate %161 Binding 0
241               OpDecorate %243 BuiltIn FragCoord
242               OpDecorate %369 Location 0
243          %2 = OpTypeVoid
244          %3 = OpTypeFunction %2
245          %6 = OpTypeInt 32 1
246          %7 = OpTypePointer Function %6
247          %8 = OpTypeFunction %2 %7 %7 %7
248         %22 = OpConstant %6 1
249         %31 = OpTypeBool
250         %37 = OpTypeInt 32 0
251         %38 = OpConstant %37 10
252         %39 = OpTypeArray %6 %38
253         %40 = OpTypePointer Private %39
254         %41 = OpVariable %40 Private
255         %43 = OpTypePointer Private %6
256         %52 = OpVariable %40 Private
257         %74 = OpConstant %6 10
258        %105 = OpConstant %6 0
259        %107 = OpConstant %6 9
260        %136 = OpConstant %6 2
261        %157 = OpTypeFloat 32
262        %158 = OpTypeVector %157 2
263        %159 = OpTypeStruct %158
264        %160 = OpTypePointer Uniform %159
265        %161 = OpVariable %160 Uniform
266        %162 = OpConstant %37 0
267        %163 = OpTypePointer Uniform %157
268        %184 = OpConstant %6 4
269        %188 = OpConstant %6 3
270        %201 = OpConstant %6 -1
271        %205 = OpConstant %6 -2
272        %209 = OpConstant %6 -3
273        %213 = OpConstant %6 -4
274        %217 = OpConstant %6 -5
275        %241 = OpTypeVector %157 4
276        %242 = OpTypePointer Input %241
277        %243 = OpVariable %242 Input
278        %244 = OpConstant %37 1
279        %245 = OpTypePointer Input %157
280        %249 = OpConstant %6 30
281        %253 = OpTypePointer Function %157
282        %255 = OpConstant %157 0.5
283        %259 = OpConstant %157 10
284        %266 = OpConstant %6 60
285        %279 = OpConstant %6 90
286        %292 = OpConstant %6 120
287        %305 = OpConstant %6 150
288        %314 = OpConstant %6 180
289        %318 = OpConstant %6 5
290        %328 = OpConstant %6 210
291        %332 = OpConstant %6 6
292        %342 = OpConstant %6 240
293        %346 = OpConstant %6 7
294        %356 = OpConstant %6 270
295        %360 = OpConstant %6 8
296        %368 = OpTypePointer Output %241
297        %369 = OpVariable %368 Output
298        %371 = OpTypeVector %157 3
299        %373 = OpConstant %157 1
300          %4 = OpFunction %2 None %3
301          %5 = OpLabel
302        %156 = OpVariable %7 Function
303        %225 = OpVariable %7 Function
304        %254 = OpVariable %253 Function
305        %164 = OpAccessChain %163 %161 %105 %162
306        %165 = OpLoad %157 %164
307        %166 = OpConvertFToS %6 %165
308               OpStore %156 %166
309               OpBranch %167
310        %167 = OpLabel
311               OpLoopMerge %169 %170 None
312               OpBranch %168
313        %168 = OpLabel
314        %171 = OpLoad %6 %156
315               OpSelectionMerge %182 None
316               OpSwitch %171 %182 0 %172 1 %173 2 %174 3 %175 4 %176 5 %177 6 %178 7 %179 8 %180 9 %181
317        %172 = OpLabel
318        %183 = OpLoad %6 %156
319        %185 = OpAccessChain %43 %41 %183
320               OpStore %185 %184
321               OpBranch %182
322        %173 = OpLabel
323        %187 = OpLoad %6 %156
324        %189 = OpAccessChain %43 %41 %187
325               OpStore %189 %188
326               OpBranch %182
327        %174 = OpLabel
328        %191 = OpLoad %6 %156
329        %192 = OpAccessChain %43 %41 %191
330               OpStore %192 %136
331               OpBranch %182
332        %175 = OpLabel
333        %194 = OpLoad %6 %156
334        %195 = OpAccessChain %43 %41 %194
335               OpStore %195 %22
336               OpBranch %182
337        %176 = OpLabel
338        %197 = OpLoad %6 %156
339        %198 = OpAccessChain %43 %41 %197
340               OpStore %198 %105
341               OpBranch %182
342        %177 = OpLabel
343        %200 = OpLoad %6 %156
344        %202 = OpAccessChain %43 %41 %200
345               OpStore %202 %201
346               OpBranch %182
347        %178 = OpLabel
348        %204 = OpLoad %6 %156
349        %206 = OpAccessChain %43 %41 %204
350               OpStore %206 %205
351               OpBranch %182
352        %179 = OpLabel
353        %208 = OpLoad %6 %156
354        %210 = OpAccessChain %43 %41 %208
355               OpStore %210 %209
356               OpBranch %182
357        %180 = OpLabel
358        %212 = OpLoad %6 %156
359        %214 = OpAccessChain %43 %41 %212
360               OpStore %214 %213
361               OpBranch %182
362        %181 = OpLabel
363        %216 = OpLoad %6 %156
364        %218 = OpAccessChain %43 %41 %216
365               OpStore %218 %217
366               OpBranch %182
367        %182 = OpLabel
368        %221 = OpLoad %6 %156
369        %222 = OpIAdd %6 %221 %22
370               OpStore %156 %222
371               OpBranch %170
372        %170 = OpLabel
373        %223 = OpLoad %6 %156
374        %224 = OpSLessThan %31 %223 %74
375               OpBranchConditional %224 %167 %169
376        %169 = OpLabel
377               OpStore %225 %105
378               OpBranch %226
379        %226 = OpLabel
380               OpLoopMerge %228 %229 None
381               OpBranch %230
382        %230 = OpLabel
383        %231 = OpLoad %6 %225
384        %232 = OpSLessThan %31 %231 %74
385               OpBranchConditional %232 %227 %228
386        %227 = OpLabel
387        %233 = OpLoad %6 %225
388        %234 = OpLoad %6 %225
389        %235 = OpAccessChain %43 %41 %234
390        %236 = OpLoad %6 %235
391        %237 = OpAccessChain %43 %52 %233
392               OpStore %237 %236
393               OpBranch %229
394        %229 = OpLabel
395        %238 = OpLoad %6 %225
396        %239 = OpIAdd %6 %238 %22
397               OpStore %225 %239
398               OpBranch %226
399        %228 = OpLabel
400        %240 = OpFunctionCall %2 %14
401        %246 = OpAccessChain %245 %243 %244
402        %247 = OpLoad %157 %246
403        %248 = OpConvertFToS %6 %247
404        %250 = OpSLessThan %31 %248 %249
405               OpSelectionMerge %252 None
406               OpBranchConditional %250 %251 %262
407        %251 = OpLabel
408        %256 = OpAccessChain %43 %41 %105
409        %257 = OpLoad %6 %256
410        %258 = OpConvertSToF %157 %257
411        %260 = OpFDiv %157 %258 %259
412        %261 = OpFAdd %157 %255 %260
413               OpStore %254 %261
414               OpBranch %252
415        %262 = OpLabel
416        %263 = OpAccessChain %245 %243 %244
417        %264 = OpLoad %157 %263
418        %265 = OpConvertFToS %6 %264
419        %267 = OpSLessThan %31 %265 %266
420               OpSelectionMerge %269 None
421               OpBranchConditional %267 %268 %275
422        %268 = OpLabel
423        %270 = OpAccessChain %43 %41 %22
424        %271 = OpLoad %6 %270
425        %272 = OpConvertSToF %157 %271
426        %273 = OpFDiv %157 %272 %259
427        %274 = OpFAdd %157 %255 %273
428               OpStore %254 %274
429               OpBranch %269
430        %275 = OpLabel
431        %276 = OpAccessChain %245 %243 %244
432        %277 = OpLoad %157 %276
433        %278 = OpConvertFToS %6 %277
434        %280 = OpSLessThan %31 %278 %279
435               OpSelectionMerge %282 None
436               OpBranchConditional %280 %281 %288
437        %281 = OpLabel
438        %283 = OpAccessChain %43 %41 %136
439        %284 = OpLoad %6 %283
440        %285 = OpConvertSToF %157 %284
441        %286 = OpFDiv %157 %285 %259
442        %287 = OpFAdd %157 %255 %286
443               OpStore %254 %287
444               OpBranch %282
445        %288 = OpLabel
446        %289 = OpAccessChain %245 %243 %244
447        %290 = OpLoad %157 %289
448        %291 = OpConvertFToS %6 %290
449        %293 = OpSLessThan %31 %291 %292
450               OpSelectionMerge %295 None
451               OpBranchConditional %293 %294 %301
452        %294 = OpLabel
453        %296 = OpAccessChain %43 %41 %188
454        %297 = OpLoad %6 %296
455        %298 = OpConvertSToF %157 %297
456        %299 = OpFDiv %157 %298 %259
457        %300 = OpFAdd %157 %255 %299
458               OpStore %254 %300
459               OpBranch %295
460        %301 = OpLabel
461        %302 = OpAccessChain %245 %243 %244
462        %303 = OpLoad %157 %302
463        %304 = OpConvertFToS %6 %303
464        %306 = OpSLessThan %31 %304 %305
465               OpSelectionMerge %308 None
466               OpBranchConditional %306 %307 %310
467        %307 = OpLabel
468               OpKill
469        %310 = OpLabel
470        %311 = OpAccessChain %245 %243 %244
471        %312 = OpLoad %157 %311
472        %313 = OpConvertFToS %6 %312
473        %315 = OpSLessThan %31 %313 %314
474               OpSelectionMerge %317 None
475               OpBranchConditional %315 %316 %324
476        %316 = OpLabel
477        %319 = OpAccessChain %43 %41 %318
478        %320 = OpLoad %6 %319
479        %321 = OpConvertSToF %157 %320
480        %322 = OpFDiv %157 %321 %259
481        %323 = OpFAdd %157 %255 %322
482               OpStore %254 %323
483               OpBranch %317
484        %324 = OpLabel
485        %325 = OpAccessChain %245 %243 %244
486        %326 = OpLoad %157 %325
487        %327 = OpConvertFToS %6 %326
488        %329 = OpSLessThan %31 %327 %328
489               OpSelectionMerge %331 None
490               OpBranchConditional %329 %330 %338
491        %330 = OpLabel
492        %333 = OpAccessChain %43 %41 %332
493        %334 = OpLoad %6 %333
494        %335 = OpConvertSToF %157 %334
495        %336 = OpFDiv %157 %335 %259
496        %337 = OpFAdd %157 %255 %336
497               OpStore %254 %337
498               OpBranch %331
499        %338 = OpLabel
500        %339 = OpAccessChain %245 %243 %244
501        %340 = OpLoad %157 %339
502        %341 = OpConvertFToS %6 %340
503        %343 = OpSLessThan %31 %341 %342
504               OpSelectionMerge %345 None
505               OpBranchConditional %343 %344 %352
506        %344 = OpLabel
507        %347 = OpAccessChain %43 %41 %346
508        %348 = OpLoad %6 %347
509        %349 = OpConvertSToF %157 %348
510        %350 = OpFDiv %157 %349 %259
511        %351 = OpFAdd %157 %255 %350
512               OpStore %254 %351
513               OpBranch %345
514        %352 = OpLabel
515        %353 = OpAccessChain %245 %243 %244
516        %354 = OpLoad %157 %353
517        %355 = OpConvertFToS %6 %354
518        %357 = OpSLessThan %31 %355 %356
519               OpSelectionMerge %359 None
520               OpBranchConditional %357 %358 %366
521        %358 = OpLabel
522        %361 = OpAccessChain %43 %41 %360
523        %362 = OpLoad %6 %361
524        %363 = OpConvertSToF %157 %362
525        %364 = OpFDiv %157 %363 %259
526        %365 = OpFAdd %157 %255 %364
527               OpStore %254 %365
528               OpBranch %359
529        %366 = OpLabel
530               OpKill
531        %359 = OpLabel
532               OpBranch %345
533        %345 = OpLabel
534               OpBranch %331
535        %331 = OpLabel
536               OpBranch %317
537        %317 = OpLabel
538               OpBranch %308
539        %308 = OpLabel
540               OpBranch %295
541        %295 = OpLabel
542               OpBranch %282
543        %282 = OpLabel
544               OpBranch %269
545        %269 = OpLabel
546               OpBranch %252
547        %252 = OpLabel
548        %370 = OpLoad %157 %254
549        %372 = OpCompositeConstruct %371 %370 %370 %370
550        %374 = OpCompositeExtract %157 %372 0
551        %375 = OpCompositeExtract %157 %372 1
552        %376 = OpCompositeExtract %157 %372 2
553        %377 = OpCompositeConstruct %241 %374 %375 %376 %373
554               OpStore %369 %377
555               OpReturn
556               OpFunctionEnd
557         %12 = OpFunction %2 None %8
558          %9 = OpFunctionParameter %7
559         %10 = OpFunctionParameter %7
560         %11 = OpFunctionParameter %7
561         %13 = OpLabel
562         %16 = OpVariable %7 Function
563         %18 = OpVariable %7 Function
564         %20 = OpVariable %7 Function
565         %87 = OpVariable %7 Function
566         %17 = OpLoad %6 %9
567               OpStore %16 %17
568         %19 = OpLoad %6 %9
569               OpStore %18 %19
570         %21 = OpLoad %6 %10
571         %23 = OpIAdd %6 %21 %22
572               OpStore %20 %23
573               OpBranch %24
574         %24 = OpLabel
575               OpLoopMerge %26 %27 None
576               OpBranch %28
577         %28 = OpLabel
578         %29 = OpLoad %6 %18
579         %30 = OpLoad %6 %10
580         %32 = OpSLessThanEqual %31 %29 %30
581         %33 = OpLoad %6 %20
582         %34 = OpLoad %6 %11
583         %35 = OpSLessThanEqual %31 %33 %34
584         %36 = OpLogicalAnd %31 %32 %35
585               OpBranchConditional %36 %25 %26
586         %25 = OpLabel
587         %42 = OpLoad %6 %18
588         %44 = OpAccessChain %43 %41 %42
589         %45 = OpLoad %6 %44
590         %46 = OpLoad %6 %20
591         %47 = OpAccessChain %43 %41 %46
592         %48 = OpLoad %6 %47
593         %49 = OpSLessThan %31 %45 %48
594               OpSelectionMerge %51 None
595               OpBranchConditional %49 %50 %60
596         %50 = OpLabel
597         %53 = OpLoad %6 %16
598         %54 = OpIAdd %6 %53 %22
599               OpStore %16 %54
600         %55 = OpLoad %6 %18
601         %56 = OpIAdd %6 %55 %22
602               OpStore %18 %56
603         %57 = OpAccessChain %43 %41 %55
604         %58 = OpLoad %6 %57
605         %59 = OpAccessChain %43 %52 %53
606               OpStore %59 %58
607               OpBranch %51
608         %60 = OpLabel
609         %61 = OpLoad %6 %16
610         %62 = OpIAdd %6 %61 %22
611               OpStore %16 %62
612         %63 = OpLoad %6 %20
613         %64 = OpIAdd %6 %63 %22
614               OpStore %20 %64
615         %65 = OpAccessChain %43 %41 %63
616         %66 = OpLoad %6 %65
617         %67 = OpAccessChain %43 %52 %61
618               OpStore %67 %66
619               OpBranch %51
620         %51 = OpLabel
621               OpBranch %27
622         %27 = OpLabel
623               OpBranch %24
624         %26 = OpLabel
625               OpBranch %68
626         %68 = OpLabel
627               OpLoopMerge %70 %71 None
628               OpBranch %72
629         %72 = OpLabel
630         %73 = OpLoad %6 %18
631         %75 = OpSLessThan %31 %73 %74
632         %76 = OpLoad %6 %18
633         %77 = OpLoad %6 %10
634         %78 = OpSLessThanEqual %31 %76 %77
635         %79 = OpLogicalAnd %31 %75 %78
636               OpBranchConditional %79 %69 %70
637         %69 = OpLabel
638         %80 = OpLoad %6 %16
639         %81 = OpIAdd %6 %80 %22
640               OpStore %16 %81
641         %82 = OpLoad %6 %18
642         %83 = OpIAdd %6 %82 %22
643               OpStore %18 %83
644         %84 = OpAccessChain %43 %41 %82
645         %85 = OpLoad %6 %84
646         %86 = OpAccessChain %43 %52 %80
647               OpStore %86 %85
648               OpBranch %71
649         %71 = OpLabel
650               OpBranch %68
651         %70 = OpLabel
652         %88 = OpLoad %6 %9
653               OpStore %87 %88
654               OpBranch %89
655         %89 = OpLabel
656               OpLoopMerge %91 %92 None
657               OpBranch %93
658         %93 = OpLabel
659         %94 = OpLoad %6 %87
660         %95 = OpLoad %6 %11
661         %96 = OpSLessThanEqual %31 %94 %95
662               OpBranchConditional %96 %90 %91
663         %90 = OpLabel
664         %97 = OpLoad %6 %87
665         %98 = OpLoad %6 %87
666         %99 = OpAccessChain %43 %52 %98
667        %100 = OpLoad %6 %99
668        %101 = OpAccessChain %43 %41 %97
669               OpStore %101 %100
670               OpBranch %92
671         %92 = OpLabel
672        %102 = OpLoad %6 %87
673        %103 = OpIAdd %6 %102 %22
674               OpStore %87 %103
675               OpBranch %89
676         %91 = OpLabel
677               OpReturn
678               OpFunctionEnd
679         %14 = OpFunction %2 None %3
680         %15 = OpLabel
681        %104 = OpVariable %7 Function
682        %106 = OpVariable %7 Function
683        %108 = OpVariable %7 Function
684        %117 = OpVariable %7 Function
685        %127 = OpVariable %7 Function
686        %129 = OpVariable %7 Function
687        %134 = OpVariable %7 Function
688        %143 = OpVariable %7 Function
689        %145 = OpVariable %7 Function
690        %147 = OpVariable %7 Function
691               OpStore %104 %105
692               OpStore %106 %107
693               OpStore %108 %22
694               OpBranch %109
695        %109 = OpLabel
696               OpLoopMerge %111 %112 None
697               OpBranch %113
698        %113 = OpLabel
699        %114 = OpLoad %6 %108
700        %115 = OpLoad %6 %106
701        %116 = OpSLessThanEqual %31 %114 %115
702               OpBranchConditional %116 %110 %111
703        %110 = OpLabel
704        %118 = OpLoad %6 %104
705               OpStore %117 %118
706               OpBranch %119
707        %119 = OpLabel
708               OpLoopMerge %121 %122 None
709               OpBranch %123
710        %123 = OpLabel
711        %124 = OpLoad %6 %117
712        %125 = OpLoad %6 %106
713        %126 = OpSLessThan %31 %124 %125
714               OpBranchConditional %126 %120 %121
715        %120 = OpLabel
716        %128 = OpLoad %6 %117
717               OpStore %127 %128
718        %130 = OpLoad %6 %117
719        %131 = OpLoad %6 %108
720        %132 = OpIAdd %6 %130 %131
721        %133 = OpISub %6 %132 %22
722               OpStore %129 %133
723        %135 = OpLoad %6 %117
724        %137 = OpLoad %6 %108
725        %138 = OpIMul %6 %136 %137
726        %139 = OpIAdd %6 %135 %138
727        %140 = OpISub %6 %139 %22
728        %141 = OpLoad %6 %106
729        %142 = OpExtInst %6 %1 SMin %140 %141
730               OpStore %134 %142
731        %144 = OpLoad %6 %127
732               OpStore %143 %144
733        %146 = OpLoad %6 %129
734               OpStore %145 %146
735        %148 = OpLoad %6 %134
736               OpStore %147 %148
737        %149 = OpFunctionCall %2 %12 %143 %145 %147
738               OpBranch %122
739        %122 = OpLabel
740        %150 = OpLoad %6 %108
741        %151 = OpIMul %6 %136 %150
742        %152 = OpLoad %6 %117
743        %153 = OpIAdd %6 %152 %151
744               OpStore %117 %153
745               OpBranch %119
746        %121 = OpLabel
747               OpBranch %112
748        %112 = OpLabel
749        %154 = OpLoad %6 %108
750        %155 = OpIMul %6 %136 %154
751               OpStore %108 %155
752               OpBranch %109
753        %111 = OpLabel
754               OpReturn
755               OpFunctionEnd
756END
757
758# uniforms for reference
759
760# injectionSwitch
761BUFFER reference_injectionSwitch DATA_TYPE vec2<float> STD140 DATA
762 0.0 1.0
763END
764
765BUFFER reference_framebuffer FORMAT B8G8R8A8_UNORM
766
767PIPELINE graphics reference_pipeline
768  ATTACH reference_vertex_shader
769  ATTACH reference_fragment_shader
770  FRAMEBUFFER_SIZE 256 256
771  BIND BUFFER reference_framebuffer AS color LOCATION 0
772  BIND BUFFER reference_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
773END
774CLEAR_COLOR reference_pipeline 0 0 0 255
775
776CLEAR reference_pipeline
777RUN reference_pipeline DRAW_RECT POS 0 0 SIZE 256 256
778
779
780SHADER vertex variant_vertex_shader PASSTHROUGH
781
782# variant_fragment_shader is derived from the following GLSL:
783# #version 320 es
784# precision highp float;
785#
786# precision highp int;
787#
788# layout(location = 0) out vec4 _GLF_color;
789#
790# layout(set = 0, binding = 0) uniform buf0 {
791#  vec2 injectionSwitch;
792# };
793# const int N = 10;
794#
795# int data[10], temp[10];
796#
797# void merge(int from, int mid, int to)
798# {
799#  int k = from, i = from, j = mid + 1;
800#  while(i <= mid && j <= to)
801#   {
802#    if(data[i] < data[j])
803#     {
804#      temp[k ++] = data[i ++];
805#     }
806#    else
807#     {
808#      temp[k ++] = data[j ++];
809#     }
810#   }
811#  while(i < N && i <= mid)
812#   {
813#    temp[k ++] = data[i ++];
814#   }
815#  for(int i = from; i <= to; i ++)
816#   {
817#    data[i] = temp[i];
818#   }
819# }
820# int func(int m, int high)
821# {
822#   // int x == 1, bitshifted to left by 4, x == 16.
823#   int x = (gl_FragCoord.x >= 0.0) ? 1 << ((false ? ((high) << 0) : 4)) : 1;
824#   // int x == 16, bitshifted to right by 4, x == 1.
825#   x = x >> int(4);
826#   // returns 2 * m.
827#   return clamp(2 * m, 2 * m, (2 * m) / x);
828# }
829# void mergeSort()
830# {
831#  int low = 0;
832#  int high = N - 1;
833#  for(int m = 1; m <= high; m = 2 * m)
834#   {
835#    for(int i = low; i < high; i += func(m, high))
836#     {
837#      int from = i;
838#      int mid = i + m - 1;
839#      int to = min(i + 2 * m - 1, high);
840#      merge(from, mid, to);
841#     }
842#   }
843# }
844# void main()
845# {
846#  int i = int(injectionSwitch.x);
847#  do
848#   {
849#    switch(i)
850#     {
851#      case 0:
852#      data[i] = 4;
853#      break;
854#      case 1:
855#      data[i] = 3;
856#      break;
857#      case 2:
858#      data[i] = 2;
859#      break;
860#      case 3:
861#      data[i] = 1;
862#      break;
863#      case 4:
864#      data[i] = 0;
865#      break;
866#      case 5:
867#      data[i] = - 1;
868#      break;
869#      case 6:
870#      data[i] = - 2;
871#      break;
872#      case 7:
873#      data[i] = - 3;
874#      break;
875#      case 8:
876#      data[i] = - 4;
877#      break;
878#      case 9:
879#      data[i] = - 5;
880#      break;
881#     }
882#    i ++;
883#   }
884#  while(i < 10);
885#  for(int j = 0; j < 10; j ++)
886#   {
887#    temp[j] = data[j];
888#   }
889#  mergeSort();
890#  float grey;
891#  if(int(gl_FragCoord[1]) < 30)
892#   {
893#    grey = 0.5 + float(data[0]) / 10.0;
894#   }
895#  else
896#   {
897#    if(int(gl_FragCoord[1]) < 60)
898#     {
899#      grey = 0.5 + float(data[1]) / 10.0;
900#     }
901#    else
902#     {
903#      if(int(gl_FragCoord[1]) < 90)
904#       {
905#        grey = 0.5 + float(data[2]) / 10.0;
906#       }
907#      else
908#       {
909#        if(int(gl_FragCoord[1]) < 120)
910#         {
911#          grey = 0.5 + float(data[3]) / 10.0;
912#         }
913#        else
914#         {
915#          if(int(gl_FragCoord[1]) < 150)
916#           {
917#            discard;
918#           }
919#          else
920#           {
921#            if(int(gl_FragCoord[1]) < 180)
922#             {
923#              grey = 0.5 + float(data[5]) / 10.0;
924#             }
925#            else
926#             {
927#              if(int(gl_FragCoord[1]) < 210)
928#               {
929#                grey = 0.5 + float(data[6]) / 10.0;
930#               }
931#              else
932#               {
933#                if(int(gl_FragCoord[1]) < 240)
934#                 {
935#                  grey = 0.5 + float(data[7]) / 10.0;
936#                 }
937#                else
938#                 {
939#                  if(int(gl_FragCoord[1]) < 270)
940#                   {
941#                    grey = 0.5 + float(data[8]) / 10.0;
942#                   }
943#                  else
944#                   {
945#                    discard;
946#                   }
947#                 }
948#               }
949#             }
950#           }
951#         }
952#       }
953#     }
954#   }
955#  _GLF_color = vec4(vec3(grey), 1.0);
956# }
957SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
958; SPIR-V
959; Version: 1.0
960; Generator: Khronos Glslang Reference Front End; 10
961; Bound: 418
962; Schema: 0
963               OpCapability Shader
964          %1 = OpExtInstImport "GLSL.std.450"
965               OpMemoryModel Logical GLSL450
966               OpEntryPoint Fragment %4 "main" %113 %409
967               OpExecutionMode %4 OriginUpperLeft
968               OpSource ESSL 320
969               OpName %4 "main"
970               OpName %12 "merge(i1;i1;i1;"
971               OpName %9 "from"
972               OpName %10 "mid"
973               OpName %11 "to"
974               OpName %17 "func(i1;i1;"
975               OpName %15 "m"
976               OpName %16 "high"
977               OpName %19 "mergeSort("
978               OpName %21 "k"
979               OpName %23 "i"
980               OpName %25 "j"
981               OpName %46 "data"
982               OpName %57 "temp"
983               OpName %92 "i"
984               OpName %109 "x"
985               OpName %113 "gl_FragCoord"
986               OpName %150 "low"
987               OpName %151 "high"
988               OpName %153 "m"
989               OpName %162 "i"
990               OpName %172 "from"
991               OpName %174 "mid"
992               OpName %179 "to"
993               OpName %187 "param"
994               OpName %189 "param"
995               OpName %191 "param"
996               OpName %194 "param"
997               OpName %196 "param"
998               OpName %203 "i"
999               OpName %205 "buf0"
1000               OpMemberName %205 0 "injectionSwitch"
1001               OpName %207 ""
1002               OpName %269 "j"
1003               OpName %294 "grey"
1004               OpName %409 "_GLF_color"
1005               OpDecorate %113 BuiltIn FragCoord
1006               OpMemberDecorate %205 0 Offset 0
1007               OpDecorate %205 Block
1008               OpDecorate %207 DescriptorSet 0
1009               OpDecorate %207 Binding 0
1010               OpDecorate %409 Location 0
1011          %2 = OpTypeVoid
1012          %3 = OpTypeFunction %2
1013          %6 = OpTypeInt 32 1
1014          %7 = OpTypePointer Function %6
1015          %8 = OpTypeFunction %2 %7 %7 %7
1016         %14 = OpTypeFunction %6 %7 %7
1017         %27 = OpConstant %6 1
1018         %36 = OpTypeBool
1019         %42 = OpTypeInt 32 0
1020         %43 = OpConstant %42 10
1021         %44 = OpTypeArray %6 %43
1022         %45 = OpTypePointer Private %44
1023         %46 = OpVariable %45 Private
1024         %48 = OpTypePointer Private %6
1025         %57 = OpVariable %45 Private
1026         %79 = OpConstant %6 10
1027        %110 = OpTypeFloat 32
1028        %111 = OpTypeVector %110 4
1029        %112 = OpTypePointer Input %111
1030        %113 = OpVariable %112 Input
1031        %114 = OpConstant %42 0
1032        %115 = OpTypePointer Input %110
1033        %118 = OpConstant %110 0
1034        %123 = OpConstantFalse %36
1035        %128 = OpConstant %6 0
1036        %131 = OpConstant %6 4
1037        %138 = OpConstant %6 2
1038        %152 = OpConstant %6 9
1039        %204 = OpTypeVector %110 2
1040        %205 = OpTypeStruct %204
1041        %206 = OpTypePointer Uniform %205
1042        %207 = OpVariable %206 Uniform
1043        %208 = OpTypePointer Uniform %110
1044        %232 = OpConstant %6 3
1045        %245 = OpConstant %6 -1
1046        %249 = OpConstant %6 -2
1047        %253 = OpConstant %6 -3
1048        %257 = OpConstant %6 -4
1049        %261 = OpConstant %6 -5
1050        %285 = OpConstant %42 1
1051        %289 = OpConstant %6 30
1052        %293 = OpTypePointer Function %110
1053        %295 = OpConstant %110 0.5
1054        %299 = OpConstant %110 10
1055        %306 = OpConstant %6 60
1056        %319 = OpConstant %6 90
1057        %332 = OpConstant %6 120
1058        %345 = OpConstant %6 150
1059        %354 = OpConstant %6 180
1060        %358 = OpConstant %6 5
1061        %368 = OpConstant %6 210
1062        %372 = OpConstant %6 6
1063        %382 = OpConstant %6 240
1064        %386 = OpConstant %6 7
1065        %396 = OpConstant %6 270
1066        %400 = OpConstant %6 8
1067        %408 = OpTypePointer Output %111
1068        %409 = OpVariable %408 Output
1069        %411 = OpTypeVector %110 3
1070        %413 = OpConstant %110 1
1071          %4 = OpFunction %2 None %3
1072          %5 = OpLabel
1073        %203 = OpVariable %7 Function
1074        %269 = OpVariable %7 Function
1075        %294 = OpVariable %293 Function
1076        %209 = OpAccessChain %208 %207 %128 %114
1077        %210 = OpLoad %110 %209
1078        %211 = OpConvertFToS %6 %210
1079               OpStore %203 %211
1080               OpBranch %212
1081        %212 = OpLabel
1082               OpLoopMerge %214 %215 None
1083               OpBranch %213
1084        %213 = OpLabel
1085        %216 = OpLoad %6 %203
1086               OpSelectionMerge %227 None
1087               OpSwitch %216 %227 0 %217 1 %218 2 %219 3 %220 4 %221 5 %222 6 %223 7 %224 8 %225 9 %226
1088        %217 = OpLabel
1089        %228 = OpLoad %6 %203
1090        %229 = OpAccessChain %48 %46 %228
1091               OpStore %229 %131
1092               OpBranch %227
1093        %218 = OpLabel
1094        %231 = OpLoad %6 %203
1095        %233 = OpAccessChain %48 %46 %231
1096               OpStore %233 %232
1097               OpBranch %227
1098        %219 = OpLabel
1099        %235 = OpLoad %6 %203
1100        %236 = OpAccessChain %48 %46 %235
1101               OpStore %236 %138
1102               OpBranch %227
1103        %220 = OpLabel
1104        %238 = OpLoad %6 %203
1105        %239 = OpAccessChain %48 %46 %238
1106               OpStore %239 %27
1107               OpBranch %227
1108        %221 = OpLabel
1109        %241 = OpLoad %6 %203
1110        %242 = OpAccessChain %48 %46 %241
1111               OpStore %242 %128
1112               OpBranch %227
1113        %222 = OpLabel
1114        %244 = OpLoad %6 %203
1115        %246 = OpAccessChain %48 %46 %244
1116               OpStore %246 %245
1117               OpBranch %227
1118        %223 = OpLabel
1119        %248 = OpLoad %6 %203
1120        %250 = OpAccessChain %48 %46 %248
1121               OpStore %250 %249
1122               OpBranch %227
1123        %224 = OpLabel
1124        %252 = OpLoad %6 %203
1125        %254 = OpAccessChain %48 %46 %252
1126               OpStore %254 %253
1127               OpBranch %227
1128        %225 = OpLabel
1129        %256 = OpLoad %6 %203
1130        %258 = OpAccessChain %48 %46 %256
1131               OpStore %258 %257
1132               OpBranch %227
1133        %226 = OpLabel
1134        %260 = OpLoad %6 %203
1135        %262 = OpAccessChain %48 %46 %260
1136               OpStore %262 %261
1137               OpBranch %227
1138        %227 = OpLabel
1139        %265 = OpLoad %6 %203
1140        %266 = OpIAdd %6 %265 %27
1141               OpStore %203 %266
1142               OpBranch %215
1143        %215 = OpLabel
1144        %267 = OpLoad %6 %203
1145        %268 = OpSLessThan %36 %267 %79
1146               OpBranchConditional %268 %212 %214
1147        %214 = OpLabel
1148               OpStore %269 %128
1149               OpBranch %270
1150        %270 = OpLabel
1151               OpLoopMerge %272 %273 None
1152               OpBranch %274
1153        %274 = OpLabel
1154        %275 = OpLoad %6 %269
1155        %276 = OpSLessThan %36 %275 %79
1156               OpBranchConditional %276 %271 %272
1157        %271 = OpLabel
1158        %277 = OpLoad %6 %269
1159        %278 = OpLoad %6 %269
1160        %279 = OpAccessChain %48 %46 %278
1161        %280 = OpLoad %6 %279
1162        %281 = OpAccessChain %48 %57 %277
1163               OpStore %281 %280
1164               OpBranch %273
1165        %273 = OpLabel
1166        %282 = OpLoad %6 %269
1167        %283 = OpIAdd %6 %282 %27
1168               OpStore %269 %283
1169               OpBranch %270
1170        %272 = OpLabel
1171        %284 = OpFunctionCall %2 %19
1172        %286 = OpAccessChain %115 %113 %285
1173        %287 = OpLoad %110 %286
1174        %288 = OpConvertFToS %6 %287
1175        %290 = OpSLessThan %36 %288 %289
1176               OpSelectionMerge %292 None
1177               OpBranchConditional %290 %291 %302
1178        %291 = OpLabel
1179        %296 = OpAccessChain %48 %46 %128
1180        %297 = OpLoad %6 %296
1181        %298 = OpConvertSToF %110 %297
1182        %300 = OpFDiv %110 %298 %299
1183        %301 = OpFAdd %110 %295 %300
1184               OpStore %294 %301
1185               OpBranch %292
1186        %302 = OpLabel
1187        %303 = OpAccessChain %115 %113 %285
1188        %304 = OpLoad %110 %303
1189        %305 = OpConvertFToS %6 %304
1190        %307 = OpSLessThan %36 %305 %306
1191               OpSelectionMerge %309 None
1192               OpBranchConditional %307 %308 %315
1193        %308 = OpLabel
1194        %310 = OpAccessChain %48 %46 %27
1195        %311 = OpLoad %6 %310
1196        %312 = OpConvertSToF %110 %311
1197        %313 = OpFDiv %110 %312 %299
1198        %314 = OpFAdd %110 %295 %313
1199               OpStore %294 %314
1200               OpBranch %309
1201        %315 = OpLabel
1202        %316 = OpAccessChain %115 %113 %285
1203        %317 = OpLoad %110 %316
1204        %318 = OpConvertFToS %6 %317
1205        %320 = OpSLessThan %36 %318 %319
1206               OpSelectionMerge %322 None
1207               OpBranchConditional %320 %321 %328
1208        %321 = OpLabel
1209        %323 = OpAccessChain %48 %46 %138
1210        %324 = OpLoad %6 %323
1211        %325 = OpConvertSToF %110 %324
1212        %326 = OpFDiv %110 %325 %299
1213        %327 = OpFAdd %110 %295 %326
1214               OpStore %294 %327
1215               OpBranch %322
1216        %328 = OpLabel
1217        %329 = OpAccessChain %115 %113 %285
1218        %330 = OpLoad %110 %329
1219        %331 = OpConvertFToS %6 %330
1220        %333 = OpSLessThan %36 %331 %332
1221               OpSelectionMerge %335 None
1222               OpBranchConditional %333 %334 %341
1223        %334 = OpLabel
1224        %336 = OpAccessChain %48 %46 %232
1225        %337 = OpLoad %6 %336
1226        %338 = OpConvertSToF %110 %337
1227        %339 = OpFDiv %110 %338 %299
1228        %340 = OpFAdd %110 %295 %339
1229               OpStore %294 %340
1230               OpBranch %335
1231        %341 = OpLabel
1232        %342 = OpAccessChain %115 %113 %285
1233        %343 = OpLoad %110 %342
1234        %344 = OpConvertFToS %6 %343
1235        %346 = OpSLessThan %36 %344 %345
1236               OpSelectionMerge %348 None
1237               OpBranchConditional %346 %347 %350
1238        %347 = OpLabel
1239               OpKill
1240        %350 = OpLabel
1241        %351 = OpAccessChain %115 %113 %285
1242        %352 = OpLoad %110 %351
1243        %353 = OpConvertFToS %6 %352
1244        %355 = OpSLessThan %36 %353 %354
1245               OpSelectionMerge %357 None
1246               OpBranchConditional %355 %356 %364
1247        %356 = OpLabel
1248        %359 = OpAccessChain %48 %46 %358
1249        %360 = OpLoad %6 %359
1250        %361 = OpConvertSToF %110 %360
1251        %362 = OpFDiv %110 %361 %299
1252        %363 = OpFAdd %110 %295 %362
1253               OpStore %294 %363
1254               OpBranch %357
1255        %364 = OpLabel
1256        %365 = OpAccessChain %115 %113 %285
1257        %366 = OpLoad %110 %365
1258        %367 = OpConvertFToS %6 %366
1259        %369 = OpSLessThan %36 %367 %368
1260               OpSelectionMerge %371 None
1261               OpBranchConditional %369 %370 %378
1262        %370 = OpLabel
1263        %373 = OpAccessChain %48 %46 %372
1264        %374 = OpLoad %6 %373
1265        %375 = OpConvertSToF %110 %374
1266        %376 = OpFDiv %110 %375 %299
1267        %377 = OpFAdd %110 %295 %376
1268               OpStore %294 %377
1269               OpBranch %371
1270        %378 = OpLabel
1271        %379 = OpAccessChain %115 %113 %285
1272        %380 = OpLoad %110 %379
1273        %381 = OpConvertFToS %6 %380
1274        %383 = OpSLessThan %36 %381 %382
1275               OpSelectionMerge %385 None
1276               OpBranchConditional %383 %384 %392
1277        %384 = OpLabel
1278        %387 = OpAccessChain %48 %46 %386
1279        %388 = OpLoad %6 %387
1280        %389 = OpConvertSToF %110 %388
1281        %390 = OpFDiv %110 %389 %299
1282        %391 = OpFAdd %110 %295 %390
1283               OpStore %294 %391
1284               OpBranch %385
1285        %392 = OpLabel
1286        %393 = OpAccessChain %115 %113 %285
1287        %394 = OpLoad %110 %393
1288        %395 = OpConvertFToS %6 %394
1289        %397 = OpSLessThan %36 %395 %396
1290               OpSelectionMerge %399 None
1291               OpBranchConditional %397 %398 %406
1292        %398 = OpLabel
1293        %401 = OpAccessChain %48 %46 %400
1294        %402 = OpLoad %6 %401
1295        %403 = OpConvertSToF %110 %402
1296        %404 = OpFDiv %110 %403 %299
1297        %405 = OpFAdd %110 %295 %404
1298               OpStore %294 %405
1299               OpBranch %399
1300        %406 = OpLabel
1301               OpKill
1302        %399 = OpLabel
1303               OpBranch %385
1304        %385 = OpLabel
1305               OpBranch %371
1306        %371 = OpLabel
1307               OpBranch %357
1308        %357 = OpLabel
1309               OpBranch %348
1310        %348 = OpLabel
1311               OpBranch %335
1312        %335 = OpLabel
1313               OpBranch %322
1314        %322 = OpLabel
1315               OpBranch %309
1316        %309 = OpLabel
1317               OpBranch %292
1318        %292 = OpLabel
1319        %410 = OpLoad %110 %294
1320        %412 = OpCompositeConstruct %411 %410 %410 %410
1321        %414 = OpCompositeExtract %110 %412 0
1322        %415 = OpCompositeExtract %110 %412 1
1323        %416 = OpCompositeExtract %110 %412 2
1324        %417 = OpCompositeConstruct %111 %414 %415 %416 %413
1325               OpStore %409 %417
1326               OpReturn
1327               OpFunctionEnd
1328         %12 = OpFunction %2 None %8
1329          %9 = OpFunctionParameter %7
1330         %10 = OpFunctionParameter %7
1331         %11 = OpFunctionParameter %7
1332         %13 = OpLabel
1333         %21 = OpVariable %7 Function
1334         %23 = OpVariable %7 Function
1335         %25 = OpVariable %7 Function
1336         %92 = OpVariable %7 Function
1337         %22 = OpLoad %6 %9
1338               OpStore %21 %22
1339         %24 = OpLoad %6 %9
1340               OpStore %23 %24
1341         %26 = OpLoad %6 %10
1342         %28 = OpIAdd %6 %26 %27
1343               OpStore %25 %28
1344               OpBranch %29
1345         %29 = OpLabel
1346               OpLoopMerge %31 %32 None
1347               OpBranch %33
1348         %33 = OpLabel
1349         %34 = OpLoad %6 %23
1350         %35 = OpLoad %6 %10
1351         %37 = OpSLessThanEqual %36 %34 %35
1352         %38 = OpLoad %6 %25
1353         %39 = OpLoad %6 %11
1354         %40 = OpSLessThanEqual %36 %38 %39
1355         %41 = OpLogicalAnd %36 %37 %40
1356               OpBranchConditional %41 %30 %31
1357         %30 = OpLabel
1358         %47 = OpLoad %6 %23
1359         %49 = OpAccessChain %48 %46 %47
1360         %50 = OpLoad %6 %49
1361         %51 = OpLoad %6 %25
1362         %52 = OpAccessChain %48 %46 %51
1363         %53 = OpLoad %6 %52
1364         %54 = OpSLessThan %36 %50 %53
1365               OpSelectionMerge %56 None
1366               OpBranchConditional %54 %55 %65
1367         %55 = OpLabel
1368         %58 = OpLoad %6 %21
1369         %59 = OpIAdd %6 %58 %27
1370               OpStore %21 %59
1371         %60 = OpLoad %6 %23
1372         %61 = OpIAdd %6 %60 %27
1373               OpStore %23 %61
1374         %62 = OpAccessChain %48 %46 %60
1375         %63 = OpLoad %6 %62
1376         %64 = OpAccessChain %48 %57 %58
1377               OpStore %64 %63
1378               OpBranch %56
1379         %65 = OpLabel
1380         %66 = OpLoad %6 %21
1381         %67 = OpIAdd %6 %66 %27
1382               OpStore %21 %67
1383         %68 = OpLoad %6 %25
1384         %69 = OpIAdd %6 %68 %27
1385               OpStore %25 %69
1386         %70 = OpAccessChain %48 %46 %68
1387         %71 = OpLoad %6 %70
1388         %72 = OpAccessChain %48 %57 %66
1389               OpStore %72 %71
1390               OpBranch %56
1391         %56 = OpLabel
1392               OpBranch %32
1393         %32 = OpLabel
1394               OpBranch %29
1395         %31 = OpLabel
1396               OpBranch %73
1397         %73 = OpLabel
1398               OpLoopMerge %75 %76 None
1399               OpBranch %77
1400         %77 = OpLabel
1401         %78 = OpLoad %6 %23
1402         %80 = OpSLessThan %36 %78 %79
1403         %81 = OpLoad %6 %23
1404         %82 = OpLoad %6 %10
1405         %83 = OpSLessThanEqual %36 %81 %82
1406         %84 = OpLogicalAnd %36 %80 %83
1407               OpBranchConditional %84 %74 %75
1408         %74 = OpLabel
1409         %85 = OpLoad %6 %21
1410         %86 = OpIAdd %6 %85 %27
1411               OpStore %21 %86
1412         %87 = OpLoad %6 %23
1413         %88 = OpIAdd %6 %87 %27
1414               OpStore %23 %88
1415         %89 = OpAccessChain %48 %46 %87
1416         %90 = OpLoad %6 %89
1417         %91 = OpAccessChain %48 %57 %85
1418               OpStore %91 %90
1419               OpBranch %76
1420         %76 = OpLabel
1421               OpBranch %73
1422         %75 = OpLabel
1423         %93 = OpLoad %6 %9
1424               OpStore %92 %93
1425               OpBranch %94
1426         %94 = OpLabel
1427               OpLoopMerge %96 %97 None
1428               OpBranch %98
1429         %98 = OpLabel
1430         %99 = OpLoad %6 %92
1431        %100 = OpLoad %6 %11
1432        %101 = OpSLessThanEqual %36 %99 %100
1433               OpBranchConditional %101 %95 %96
1434         %95 = OpLabel
1435        %102 = OpLoad %6 %92
1436        %103 = OpLoad %6 %92
1437        %104 = OpAccessChain %48 %57 %103
1438        %105 = OpLoad %6 %104
1439        %106 = OpAccessChain %48 %46 %102
1440               OpStore %106 %105
1441               OpBranch %97
1442         %97 = OpLabel
1443        %107 = OpLoad %6 %92
1444        %108 = OpIAdd %6 %107 %27
1445               OpStore %92 %108
1446               OpBranch %94
1447         %96 = OpLabel
1448               OpReturn
1449               OpFunctionEnd
1450         %17 = OpFunction %6 None %14
1451         %15 = OpFunctionParameter %7
1452         %16 = OpFunctionParameter %7
1453         %18 = OpLabel
1454        %109 = OpVariable %7 Function
1455        %120 = OpVariable %7 Function
1456        %124 = OpVariable %7 Function
1457        %116 = OpAccessChain %115 %113 %114
1458        %117 = OpLoad %110 %116
1459        %119 = OpFOrdGreaterThanEqual %36 %117 %118
1460               OpSelectionMerge %122 None
1461               OpBranchConditional %119 %121 %134
1462        %121 = OpLabel
1463               OpSelectionMerge %126 None
1464               OpBranchConditional %123 %125 %130
1465        %125 = OpLabel
1466        %127 = OpLoad %6 %16
1467        %129 = OpShiftLeftLogical %6 %127 %128
1468               OpStore %124 %129
1469               OpBranch %126
1470        %130 = OpLabel
1471               OpStore %124 %131
1472               OpBranch %126
1473        %126 = OpLabel
1474        %132 = OpLoad %6 %124
1475        %133 = OpShiftLeftLogical %6 %27 %132
1476               OpStore %120 %133
1477               OpBranch %122
1478        %134 = OpLabel
1479               OpStore %120 %27
1480               OpBranch %122
1481        %122 = OpLabel
1482        %135 = OpLoad %6 %120
1483               OpStore %109 %135
1484        %136 = OpLoad %6 %109
1485        %137 = OpShiftRightArithmetic %6 %136 %131
1486               OpStore %109 %137
1487        %139 = OpLoad %6 %15
1488        %140 = OpIMul %6 %138 %139
1489        %141 = OpLoad %6 %15
1490        %142 = OpIMul %6 %138 %141
1491        %143 = OpLoad %6 %15
1492        %144 = OpIMul %6 %138 %143
1493        %145 = OpLoad %6 %109
1494        %146 = OpSDiv %6 %144 %145
1495        %147 = OpExtInst %6 %1 SClamp %140 %142 %146
1496               OpReturnValue %147
1497               OpFunctionEnd
1498         %19 = OpFunction %2 None %3
1499         %20 = OpLabel
1500        %150 = OpVariable %7 Function
1501        %151 = OpVariable %7 Function
1502        %153 = OpVariable %7 Function
1503        %162 = OpVariable %7 Function
1504        %172 = OpVariable %7 Function
1505        %174 = OpVariable %7 Function
1506        %179 = OpVariable %7 Function
1507        %187 = OpVariable %7 Function
1508        %189 = OpVariable %7 Function
1509        %191 = OpVariable %7 Function
1510        %194 = OpVariable %7 Function
1511        %196 = OpVariable %7 Function
1512               OpStore %150 %128
1513               OpStore %151 %152
1514               OpStore %153 %27
1515               OpBranch %154
1516        %154 = OpLabel
1517               OpLoopMerge %156 %157 None
1518               OpBranch %158
1519        %158 = OpLabel
1520        %159 = OpLoad %6 %153
1521        %160 = OpLoad %6 %151
1522        %161 = OpSLessThanEqual %36 %159 %160
1523               OpBranchConditional %161 %155 %156
1524        %155 = OpLabel
1525        %163 = OpLoad %6 %150
1526               OpStore %162 %163
1527               OpBranch %164
1528        %164 = OpLabel
1529               OpLoopMerge %166 %167 None
1530               OpBranch %168
1531        %168 = OpLabel
1532        %169 = OpLoad %6 %162
1533        %170 = OpLoad %6 %151
1534        %171 = OpSLessThan %36 %169 %170
1535               OpBranchConditional %171 %165 %166
1536        %165 = OpLabel
1537        %173 = OpLoad %6 %162
1538               OpStore %172 %173
1539        %175 = OpLoad %6 %162
1540        %176 = OpLoad %6 %153
1541        %177 = OpIAdd %6 %175 %176
1542        %178 = OpISub %6 %177 %27
1543               OpStore %174 %178
1544        %180 = OpLoad %6 %162
1545        %181 = OpLoad %6 %153
1546        %182 = OpIMul %6 %138 %181
1547        %183 = OpIAdd %6 %180 %182
1548        %184 = OpISub %6 %183 %27
1549        %185 = OpLoad %6 %151
1550        %186 = OpExtInst %6 %1 SMin %184 %185
1551               OpStore %179 %186
1552        %188 = OpLoad %6 %172
1553               OpStore %187 %188
1554        %190 = OpLoad %6 %174
1555               OpStore %189 %190
1556        %192 = OpLoad %6 %179
1557               OpStore %191 %192
1558        %193 = OpFunctionCall %2 %12 %187 %189 %191
1559               OpBranch %167
1560        %167 = OpLabel
1561        %195 = OpLoad %6 %153
1562               OpStore %194 %195
1563        %197 = OpLoad %6 %151
1564               OpStore %196 %197
1565        %198 = OpFunctionCall %6 %17 %194 %196
1566        %199 = OpLoad %6 %162
1567        %200 = OpIAdd %6 %199 %198
1568               OpStore %162 %200
1569               OpBranch %164
1570        %166 = OpLabel
1571               OpBranch %157
1572        %157 = OpLabel
1573        %201 = OpLoad %6 %153
1574        %202 = OpIMul %6 %138 %201
1575               OpStore %153 %202
1576               OpBranch %154
1577        %156 = OpLabel
1578               OpReturn
1579               OpFunctionEnd
1580END
1581
1582# uniforms for variant
1583
1584# injectionSwitch
1585BUFFER variant_injectionSwitch DATA_TYPE vec2<float> STD140 DATA
1586 0.0 1.0
1587END
1588
1589BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
1590
1591PIPELINE graphics variant_pipeline
1592  ATTACH variant_vertex_shader
1593  ATTACH variant_fragment_shader
1594  FRAMEBUFFER_SIZE 256 256
1595  BIND BUFFER variant_framebuffer AS color LOCATION 0
1596  BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
1597END
1598CLEAR_COLOR variant_pipeline 0 0 0 255
1599
1600CLEAR variant_pipeline
1601RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
1602
1603EXPECT reference_framebuffer EQ_HISTOGRAM_EMD_BUFFER variant_framebuffer TOLERANCE 0.005
1604