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 GraphicsFuzz.
19
20# Short description: A fragment shader with min-mix in always false conditional
21
22# The test passes because both shaders render the same image.
23
24SHADER vertex reference_vertex_shader PASSTHROUGH
25
26# reference_fragment_shader is derived from the following GLSL:
27# #version 320 es
28# precision highp float;
29#
30# precision highp int;
31#
32# layout(location = 0) out vec4 _GLF_color;
33#
34# layout(set = 0, binding = 0) uniform buf0 {
35#  vec2 resolution;
36# };
37# const vec4 pal[16] = vec4[16](vec4(0.0, 0.0, 0.0, 1.0), vec4(0.5, 0.0, 0.0, 1.0), vec4(0.0, 0.5, 0.0, 1.0), vec4(0.5, 0.5, 0.0, 1.0), vec4(0.0, 0.0, 0.5, 1.0), vec4(0.5, 0.0, 0.5, 1.0), vec4(0.0, 0.5, 0.5, 1.0), vec4(0.5, 0.5, 0.5, 1.0), vec4(0.0, 0.0, 0.0, 1.0), vec4(1.0, 0.0, 0.0, 1.0), vec4(0.0, 1.0, 0.0, 1.0), vec4(1.0, 1.0, 0.0, 1.0), vec4(0.0, 0.0, 1.0, 1.0), vec4(1.0, 0.0, 1.0, 1.0), vec4(0.0, 1.0, 1.0, 1.0), vec4(1.0, 1.0, 1.0, 1.0));
38#
39# const vec4 picdata[8] = vec4[8](vec4(4, 4, 20, 4), vec4(4, 4, 4, 20), vec4(4, 20, 20, 4), vec4(20, 4, 4, 8), vec4(8, 6, 4, 2), vec4(2, 12, 2, 4), vec4(16, 2, 4, 4), vec4(12, 22, 4, 4));
40#
41# int index;
42#
43# int state[16];
44#
45# bool collision(vec2 pos, vec4 quad)
46# {
47#  if(pos.x < quad.x)
48#   {
49#    return false;
50#   }
51#  if(pos.y < quad.y)
52#   {
53#    return false;
54#   }
55#  if(pos.x > quad.x + quad.z)
56#   {
57#    return false;
58#   }
59#  if(pos.y > quad.y + quad.w)
60#   {
61#    return false;
62#   }
63#  return true;
64# }
65# vec4 match(vec2 pos)
66# {
67#  int i;
68#  vec4 res = vec4(0.5, 0.5, 1.0, 1.0);
69#  for( i = 0;
70#  i < 8; i ++)
71#   {
72#    if(collision(pos, picdata[i]))
73#     {
74#      res = pal[(int(picdata[i].x) * int(picdata[i].y) + i * 9 + 11) % 16];
75#     }
76#   }
77#  return res;
78# }
79# void main()
80# {
81#  vec2 lin = gl_FragCoord.xy / resolution;
82#  lin = floor(lin * 32.0);
83#  _GLF_color = match(lin.xy);
84# }
85SHADER fragment reference_fragment_shader SPIRV-ASM
86; SPIR-V
87; Version: 1.0
88; Generator: Khronos Glslang Reference Front End; 10
89; Bound: 189
90; Schema: 0
91               OpCapability Shader
92          %1 = OpExtInstImport "GLSL.std.450"
93               OpMemoryModel Logical GLSL450
94               OpEntryPoint Fragment %4 "main" %165 %180
95               OpExecutionMode %4 OriginUpperLeft
96               OpSource ESSL 320
97               OpName %4 "main"
98               OpName %15 "collision(vf2;vf4;"
99               OpName %13 "pos"
100               OpName %14 "quad"
101               OpName %19 "match(vf2;"
102               OpName %18 "pos"
103               OpName %69 "res"
104               OpName %75 "i"
105               OpName %105 "param"
106               OpName %107 "param"
107               OpName %109 "indexable"
108               OpName %135 "indexable"
109               OpName %140 "indexable"
110               OpName %154 "indexable"
111               OpName %163 "lin"
112               OpName %165 "gl_FragCoord"
113               OpName %168 "buf0"
114               OpMemberName %168 0 "resolution"
115               OpName %170 ""
116               OpName %180 "_GLF_color"
117               OpName %181 "param"
118               OpName %185 "index"
119               OpName %188 "state"
120               OpDecorate %165 BuiltIn FragCoord
121               OpMemberDecorate %168 0 Offset 0
122               OpDecorate %168 Block
123               OpDecorate %170 DescriptorSet 0
124               OpDecorate %170 Binding 0
125               OpDecorate %180 Location 0
126          %2 = OpTypeVoid
127          %3 = OpTypeFunction %2
128          %6 = OpTypeFloat 32
129          %7 = OpTypeVector %6 2
130          %8 = OpTypePointer Function %7
131          %9 = OpTypeVector %6 4
132         %10 = OpTypePointer Function %9
133         %11 = OpTypeBool
134         %12 = OpTypeFunction %11 %8 %10
135         %17 = OpTypeFunction %9 %8
136         %21 = OpTypeInt 32 0
137         %22 = OpConstant %21 0
138         %23 = OpTypePointer Function %6
139         %31 = OpConstantFalse %11
140         %33 = OpConstant %21 1
141         %46 = OpConstant %21 2
142         %58 = OpConstant %21 3
143         %66 = OpConstantTrue %11
144         %70 = OpConstant %6 0.5
145         %71 = OpConstant %6 1
146         %72 = OpConstantComposite %9 %70 %70 %71 %71
147         %73 = OpTypeInt 32 1
148         %74 = OpTypePointer Function %73
149         %76 = OpConstant %73 0
150         %83 = OpConstant %73 8
151         %85 = OpConstant %21 8
152         %86 = OpTypeArray %9 %85
153         %87 = OpConstant %6 4
154         %88 = OpConstant %6 20
155         %89 = OpConstantComposite %9 %87 %87 %88 %87
156         %90 = OpConstantComposite %9 %87 %87 %87 %88
157         %91 = OpConstantComposite %9 %87 %88 %88 %87
158         %92 = OpConstant %6 8
159         %93 = OpConstantComposite %9 %88 %87 %87 %92
160         %94 = OpConstant %6 6
161         %95 = OpConstant %6 2
162         %96 = OpConstantComposite %9 %92 %94 %87 %95
163         %97 = OpConstant %6 12
164         %98 = OpConstantComposite %9 %95 %97 %95 %87
165         %99 = OpConstant %6 16
166        %100 = OpConstantComposite %9 %99 %95 %87 %87
167        %101 = OpConstant %6 22
168        %102 = OpConstantComposite %9 %97 %101 %87 %87
169        %103 = OpConstantComposite %86 %89 %90 %91 %93 %96 %98 %100 %102
170        %108 = OpTypePointer Function %86
171        %115 = OpConstant %21 16
172        %116 = OpTypeArray %9 %115
173        %117 = OpConstant %6 0
174        %118 = OpConstantComposite %9 %117 %117 %117 %71
175        %119 = OpConstantComposite %9 %70 %117 %117 %71
176        %120 = OpConstantComposite %9 %117 %70 %117 %71
177        %121 = OpConstantComposite %9 %70 %70 %117 %71
178        %122 = OpConstantComposite %9 %117 %117 %70 %71
179        %123 = OpConstantComposite %9 %70 %117 %70 %71
180        %124 = OpConstantComposite %9 %117 %70 %70 %71
181        %125 = OpConstantComposite %9 %70 %70 %70 %71
182        %126 = OpConstantComposite %9 %71 %117 %117 %71
183        %127 = OpConstantComposite %9 %117 %71 %117 %71
184        %128 = OpConstantComposite %9 %71 %71 %117 %71
185        %129 = OpConstantComposite %9 %117 %117 %71 %71
186        %130 = OpConstantComposite %9 %71 %117 %71 %71
187        %131 = OpConstantComposite %9 %117 %71 %71 %71
188        %132 = OpConstantComposite %9 %71 %71 %71 %71
189        %133 = OpConstantComposite %116 %118 %119 %120 %121 %122 %123 %124 %125 %118 %126 %127 %128 %129 %130 %131 %132
190        %146 = OpConstant %73 9
191        %149 = OpConstant %73 11
192        %151 = OpConstant %73 16
193        %153 = OpTypePointer Function %116
194        %158 = OpConstant %73 1
195        %164 = OpTypePointer Input %9
196        %165 = OpVariable %164 Input
197        %168 = OpTypeStruct %7
198        %169 = OpTypePointer Uniform %168
199        %170 = OpVariable %169 Uniform
200        %171 = OpTypePointer Uniform %7
201        %176 = OpConstant %6 32
202        %179 = OpTypePointer Output %9
203        %180 = OpVariable %179 Output
204        %184 = OpTypePointer Private %73
205        %185 = OpVariable %184 Private
206        %186 = OpTypeArray %73 %115
207        %187 = OpTypePointer Private %186
208        %188 = OpVariable %187 Private
209          %4 = OpFunction %2 None %3
210          %5 = OpLabel
211        %163 = OpVariable %8 Function
212        %181 = OpVariable %8 Function
213        %166 = OpLoad %9 %165
214        %167 = OpVectorShuffle %7 %166 %166 0 1
215        %172 = OpAccessChain %171 %170 %76
216        %173 = OpLoad %7 %172
217        %174 = OpFDiv %7 %167 %173
218               OpStore %163 %174
219        %175 = OpLoad %7 %163
220        %177 = OpVectorTimesScalar %7 %175 %176
221        %178 = OpExtInst %7 %1 Floor %177
222               OpStore %163 %178
223        %182 = OpLoad %7 %163
224               OpStore %181 %182
225        %183 = OpFunctionCall %9 %19 %181
226               OpStore %180 %183
227               OpReturn
228               OpFunctionEnd
229         %15 = OpFunction %11 None %12
230         %13 = OpFunctionParameter %8
231         %14 = OpFunctionParameter %10
232         %16 = OpLabel
233         %24 = OpAccessChain %23 %13 %22
234         %25 = OpLoad %6 %24
235         %26 = OpAccessChain %23 %14 %22
236         %27 = OpLoad %6 %26
237         %28 = OpFOrdLessThan %11 %25 %27
238               OpSelectionMerge %30 None
239               OpBranchConditional %28 %29 %30
240         %29 = OpLabel
241               OpReturnValue %31
242         %30 = OpLabel
243         %34 = OpAccessChain %23 %13 %33
244         %35 = OpLoad %6 %34
245         %36 = OpAccessChain %23 %14 %33
246         %37 = OpLoad %6 %36
247         %38 = OpFOrdLessThan %11 %35 %37
248               OpSelectionMerge %40 None
249               OpBranchConditional %38 %39 %40
250         %39 = OpLabel
251               OpReturnValue %31
252         %40 = OpLabel
253         %42 = OpAccessChain %23 %13 %22
254         %43 = OpLoad %6 %42
255         %44 = OpAccessChain %23 %14 %22
256         %45 = OpLoad %6 %44
257         %47 = OpAccessChain %23 %14 %46
258         %48 = OpLoad %6 %47
259         %49 = OpFAdd %6 %45 %48
260         %50 = OpFOrdGreaterThan %11 %43 %49
261               OpSelectionMerge %52 None
262               OpBranchConditional %50 %51 %52
263         %51 = OpLabel
264               OpReturnValue %31
265         %52 = OpLabel
266         %54 = OpAccessChain %23 %13 %33
267         %55 = OpLoad %6 %54
268         %56 = OpAccessChain %23 %14 %33
269         %57 = OpLoad %6 %56
270         %59 = OpAccessChain %23 %14 %58
271         %60 = OpLoad %6 %59
272         %61 = OpFAdd %6 %57 %60
273         %62 = OpFOrdGreaterThan %11 %55 %61
274               OpSelectionMerge %64 None
275               OpBranchConditional %62 %63 %64
276         %63 = OpLabel
277               OpReturnValue %31
278         %64 = OpLabel
279               OpReturnValue %66
280               OpFunctionEnd
281         %19 = OpFunction %9 None %17
282         %18 = OpFunctionParameter %8
283         %20 = OpLabel
284         %69 = OpVariable %10 Function
285         %75 = OpVariable %74 Function
286        %105 = OpVariable %8 Function
287        %107 = OpVariable %10 Function
288        %109 = OpVariable %108 Function
289        %135 = OpVariable %108 Function
290        %140 = OpVariable %108 Function
291        %154 = OpVariable %153 Function
292               OpStore %69 %72
293               OpStore %75 %76
294               OpBranch %77
295         %77 = OpLabel
296               OpLoopMerge %79 %80 None
297               OpBranch %81
298         %81 = OpLabel
299         %82 = OpLoad %73 %75
300         %84 = OpSLessThan %11 %82 %83
301               OpBranchConditional %84 %78 %79
302         %78 = OpLabel
303        %104 = OpLoad %73 %75
304        %106 = OpLoad %7 %18
305               OpStore %105 %106
306               OpStore %109 %103
307        %110 = OpAccessChain %10 %109 %104
308        %111 = OpLoad %9 %110
309               OpStore %107 %111
310        %112 = OpFunctionCall %11 %15 %105 %107
311               OpSelectionMerge %114 None
312               OpBranchConditional %112 %113 %114
313        %113 = OpLabel
314        %134 = OpLoad %73 %75
315               OpStore %135 %103
316        %136 = OpAccessChain %23 %135 %134 %22
317        %137 = OpLoad %6 %136
318        %138 = OpConvertFToS %73 %137
319        %139 = OpLoad %73 %75
320               OpStore %140 %103
321        %141 = OpAccessChain %23 %140 %139 %33
322        %142 = OpLoad %6 %141
323        %143 = OpConvertFToS %73 %142
324        %144 = OpIMul %73 %138 %143
325        %145 = OpLoad %73 %75
326        %147 = OpIMul %73 %145 %146
327        %148 = OpIAdd %73 %144 %147
328        %150 = OpIAdd %73 %148 %149
329        %152 = OpSMod %73 %150 %151
330               OpStore %154 %133
331        %155 = OpAccessChain %10 %154 %152
332        %156 = OpLoad %9 %155
333               OpStore %69 %156
334               OpBranch %114
335        %114 = OpLabel
336               OpBranch %80
337         %80 = OpLabel
338        %157 = OpLoad %73 %75
339        %159 = OpIAdd %73 %157 %158
340               OpStore %75 %159
341               OpBranch %77
342         %79 = OpLabel
343        %160 = OpLoad %9 %69
344               OpReturnValue %160
345               OpFunctionEnd
346END
347
348# uniforms for reference
349
350# resolution
351BUFFER reference_resolution DATA_TYPE vec2<float> DATA
352 256.0 256.0
353END
354
355BUFFER reference_framebuffer FORMAT B8G8R8A8_UNORM
356
357PIPELINE graphics reference_pipeline
358  ATTACH reference_vertex_shader
359  ATTACH reference_fragment_shader
360  FRAMEBUFFER_SIZE 256 256
361  BIND BUFFER reference_framebuffer AS color LOCATION 0
362  BIND BUFFER reference_resolution AS uniform DESCRIPTOR_SET 0 BINDING 0
363END
364CLEAR_COLOR reference_pipeline 0 0 0 255
365
366CLEAR reference_pipeline
367RUN reference_pipeline DRAW_RECT POS 0 0 SIZE 256 256
368
369
370SHADER vertex variant_vertex_shader PASSTHROUGH
371
372# variant_fragment_shader is derived from the following GLSL:
373# #version 320 es
374# precision highp float;
375#
376# precision highp int;
377#
378# layout(location = 0) out vec4 _GLF_color;
379#
380# layout(set = 0, binding = 0) uniform buf0 {
381#  vec2 resolution;
382# };
383# const vec4 pal[16] = vec4[16](vec4(0.0, 0.0, 0.0, 1.0), vec4(0.5, 0.0, 0.0, 1.0), vec4(0.0, 0.5, 0.0, 1.0), vec4(0.5, 0.5, 0.0, 1.0), vec4(0.0, 0.0, 0.5, 1.0), vec4(0.5, 0.0, 0.5, 1.0), vec4(0.0, 0.5, 0.5, 1.0), vec4(0.5, 0.5, 0.5, 1.0), vec4(0.0, 0.0, 0.0, 1.0), vec4(1.0, 0.0, 0.0, 1.0), vec4(0.0, 1.0, 0.0, 1.0), vec4(1.0, 1.0, 0.0, 1.0), vec4(0.0, 0.0, 1.0, 1.0), vec4(1.0, 0.0, 1.0, 1.0), vec4(0.0, 1.0, 1.0, 1.0), vec4(1.0, 1.0, 1.0, 1.0));
384#
385# const vec4 picdata[8] = vec4[8](vec4(4, 4, 20, 4), vec4(4, 4, 4, 20), vec4(4, 20, 20, 4), vec4(20, 4, 4, 8), vec4(8, 6, 4, 2), vec4(2, 12, 2, 4), vec4(16, 2, 4, 4), vec4(12, 22, 4, 4));
386#
387# bool collision(vec2 pos, vec4 quad)
388# {
389#  if(pos.x < quad.x)
390#   {
391#    return false;
392#   }
393#  if(pos.y < quad.y)
394#   {
395#    return false;
396#   }
397#  if(pos.x > quad.x + quad.z)
398#   {
399#    return false;
400#   }
401#  if(pos.y > quad.y + quad.w)
402#   {
403#    return false;
404#   }
405#  return true;
406# }
407# vec4 match(vec2 pos)
408# {
409#  int i;
410#  // res == vec4 ( x, 0.5, 1.0, 1.0) where x is the result of the calculation, x == 0.5.
411#  // The end result should be the same as in reference.
412#  vec4 res = vec4(clamp(0.5, 0.5, (gl_FragCoord.x < 0.0) ? -1.0 : (min(gl_FragCoord.x >= 0.0 ? (mix(1.0, 0.5, (gl_FragCoord.x >= 0.0))) : 1.0, 0.5))), 0.5, 1.0, 1.0);
413#  for( i = 0;
414#  i < 8; i ++)
415#   {
416#    if(collision(pos, picdata[i]))
417#     {
418#      res = pal[(int(picdata[i].x) * int(picdata[i].y) + i * 9 + 11) % 16];
419#     }
420#   }
421#  return res;
422# }
423# void main()
424# {
425#  vec2 lin = gl_FragCoord.xy / resolution;
426#  lin = floor(lin * 32.0);
427#  _GLF_color = match(lin.xy);
428# }
429SHADER fragment variant_fragment_shader SPIRV-ASM
430; SPIR-V
431; Version: 1.0
432; Generator: Khronos Glslang Reference Front End; 10
433; Bound: 208
434; Schema: 0
435               OpCapability Shader
436          %1 = OpExtInstImport "GLSL.std.450"
437               OpMemoryModel Logical GLSL450
438               OpEntryPoint Fragment %4 "main" %72 %204
439               OpExecutionMode %4 OriginUpperLeft
440               OpSource ESSL 320
441               OpName %4 "main"
442               OpName %15 "collision(vf2;vf4;"
443               OpName %13 "pos"
444               OpName %14 "quad"
445               OpName %19 "match(vf2;"
446               OpName %18 "pos"
447               OpName %69 "res"
448               OpName %72 "gl_FragCoord"
449               OpName %102 "i"
450               OpName %132 "param"
451               OpName %134 "param"
452               OpName %136 "indexable"
453               OpName %161 "indexable"
454               OpName %166 "indexable"
455               OpName %180 "indexable"
456               OpName %189 "lin"
457               OpName %192 "buf0"
458               OpMemberName %192 0 "resolution"
459               OpName %194 ""
460               OpName %204 "_GLF_color"
461               OpName %205 "param"
462               OpDecorate %72 BuiltIn FragCoord
463               OpMemberDecorate %192 0 Offset 0
464               OpDecorate %192 Block
465               OpDecorate %194 DescriptorSet 0
466               OpDecorate %194 Binding 0
467               OpDecorate %204 Location 0
468          %2 = OpTypeVoid
469          %3 = OpTypeFunction %2
470          %6 = OpTypeFloat 32
471          %7 = OpTypeVector %6 2
472          %8 = OpTypePointer Function %7
473          %9 = OpTypeVector %6 4
474         %10 = OpTypePointer Function %9
475         %11 = OpTypeBool
476         %12 = OpTypeFunction %11 %8 %10
477         %17 = OpTypeFunction %9 %8
478         %21 = OpTypeInt 32 0
479         %22 = OpConstant %21 0
480         %23 = OpTypePointer Function %6
481         %31 = OpConstantFalse %11
482         %33 = OpConstant %21 1
483         %46 = OpConstant %21 2
484         %58 = OpConstant %21 3
485         %66 = OpConstantTrue %11
486         %70 = OpConstant %6 0.5
487         %71 = OpTypePointer Input %9
488         %72 = OpVariable %71 Input
489         %73 = OpTypePointer Input %6
490         %76 = OpConstant %6 0
491         %81 = OpConstant %6 -1
492         %89 = OpConstant %6 1
493        %100 = OpTypeInt 32 1
494        %101 = OpTypePointer Function %100
495        %103 = OpConstant %100 0
496        %110 = OpConstant %100 8
497        %112 = OpConstant %21 8
498        %113 = OpTypeArray %9 %112
499        %114 = OpConstant %6 4
500        %115 = OpConstant %6 20
501        %116 = OpConstantComposite %9 %114 %114 %115 %114
502        %117 = OpConstantComposite %9 %114 %114 %114 %115
503        %118 = OpConstantComposite %9 %114 %115 %115 %114
504        %119 = OpConstant %6 8
505        %120 = OpConstantComposite %9 %115 %114 %114 %119
506        %121 = OpConstant %6 6
507        %122 = OpConstant %6 2
508        %123 = OpConstantComposite %9 %119 %121 %114 %122
509        %124 = OpConstant %6 12
510        %125 = OpConstantComposite %9 %122 %124 %122 %114
511        %126 = OpConstant %6 16
512        %127 = OpConstantComposite %9 %126 %122 %114 %114
513        %128 = OpConstant %6 22
514        %129 = OpConstantComposite %9 %124 %128 %114 %114
515        %130 = OpConstantComposite %113 %116 %117 %118 %120 %123 %125 %127 %129
516        %135 = OpTypePointer Function %113
517        %142 = OpConstant %21 16
518        %143 = OpTypeArray %9 %142
519        %144 = OpConstantComposite %9 %76 %76 %76 %89
520        %145 = OpConstantComposite %9 %70 %76 %76 %89
521        %146 = OpConstantComposite %9 %76 %70 %76 %89
522        %147 = OpConstantComposite %9 %70 %70 %76 %89
523        %148 = OpConstantComposite %9 %76 %76 %70 %89
524        %149 = OpConstantComposite %9 %70 %76 %70 %89
525        %150 = OpConstantComposite %9 %76 %70 %70 %89
526        %151 = OpConstantComposite %9 %70 %70 %70 %89
527        %152 = OpConstantComposite %9 %89 %76 %76 %89
528        %153 = OpConstantComposite %9 %76 %89 %76 %89
529        %154 = OpConstantComposite %9 %89 %89 %76 %89
530        %155 = OpConstantComposite %9 %76 %76 %89 %89
531        %156 = OpConstantComposite %9 %89 %76 %89 %89
532        %157 = OpConstantComposite %9 %76 %89 %89 %89
533        %158 = OpConstantComposite %9 %89 %89 %89 %89
534        %159 = OpConstantComposite %143 %144 %145 %146 %147 %148 %149 %150 %151 %144 %152 %153 %154 %155 %156 %157 %158
535        %172 = OpConstant %100 9
536        %175 = OpConstant %100 11
537        %177 = OpConstant %100 16
538        %179 = OpTypePointer Function %143
539        %184 = OpConstant %100 1
540        %192 = OpTypeStruct %7
541        %193 = OpTypePointer Uniform %192
542        %194 = OpVariable %193 Uniform
543        %195 = OpTypePointer Uniform %7
544        %200 = OpConstant %6 32
545        %203 = OpTypePointer Output %9
546        %204 = OpVariable %203 Output
547          %4 = OpFunction %2 None %3
548          %5 = OpLabel
549        %189 = OpVariable %8 Function
550        %205 = OpVariable %8 Function
551        %190 = OpLoad %9 %72
552        %191 = OpVectorShuffle %7 %190 %190 0 1
553        %196 = OpAccessChain %195 %194 %103
554        %197 = OpLoad %7 %196
555        %198 = OpFDiv %7 %191 %197
556               OpStore %189 %198
557        %199 = OpLoad %7 %189
558        %201 = OpVectorTimesScalar %7 %199 %200
559        %202 = OpExtInst %7 %1 Floor %201
560               OpStore %189 %202
561        %206 = OpLoad %7 %189
562               OpStore %205 %206
563        %207 = OpFunctionCall %9 %19 %205
564               OpStore %204 %207
565               OpReturn
566               OpFunctionEnd
567         %15 = OpFunction %11 None %12
568         %13 = OpFunctionParameter %8
569         %14 = OpFunctionParameter %10
570         %16 = OpLabel
571         %24 = OpAccessChain %23 %13 %22
572         %25 = OpLoad %6 %24
573         %26 = OpAccessChain %23 %14 %22
574         %27 = OpLoad %6 %26
575         %28 = OpFOrdLessThan %11 %25 %27
576               OpSelectionMerge %30 None
577               OpBranchConditional %28 %29 %30
578         %29 = OpLabel
579               OpReturnValue %31
580         %30 = OpLabel
581         %34 = OpAccessChain %23 %13 %33
582         %35 = OpLoad %6 %34
583         %36 = OpAccessChain %23 %14 %33
584         %37 = OpLoad %6 %36
585         %38 = OpFOrdLessThan %11 %35 %37
586               OpSelectionMerge %40 None
587               OpBranchConditional %38 %39 %40
588         %39 = OpLabel
589               OpReturnValue %31
590         %40 = OpLabel
591         %42 = OpAccessChain %23 %13 %22
592         %43 = OpLoad %6 %42
593         %44 = OpAccessChain %23 %14 %22
594         %45 = OpLoad %6 %44
595         %47 = OpAccessChain %23 %14 %46
596         %48 = OpLoad %6 %47
597         %49 = OpFAdd %6 %45 %48
598         %50 = OpFOrdGreaterThan %11 %43 %49
599               OpSelectionMerge %52 None
600               OpBranchConditional %50 %51 %52
601         %51 = OpLabel
602               OpReturnValue %31
603         %52 = OpLabel
604         %54 = OpAccessChain %23 %13 %33
605         %55 = OpLoad %6 %54
606         %56 = OpAccessChain %23 %14 %33
607         %57 = OpLoad %6 %56
608         %59 = OpAccessChain %23 %14 %58
609         %60 = OpLoad %6 %59
610         %61 = OpFAdd %6 %57 %60
611         %62 = OpFOrdGreaterThan %11 %55 %61
612               OpSelectionMerge %64 None
613               OpBranchConditional %62 %63 %64
614         %63 = OpLabel
615               OpReturnValue %31
616         %64 = OpLabel
617               OpReturnValue %66
618               OpFunctionEnd
619         %19 = OpFunction %9 None %17
620         %18 = OpFunctionParameter %8
621         %20 = OpLabel
622         %69 = OpVariable %10 Function
623         %78 = OpVariable %23 Function
624         %86 = OpVariable %23 Function
625        %102 = OpVariable %101 Function
626        %132 = OpVariable %8 Function
627        %134 = OpVariable %10 Function
628        %136 = OpVariable %135 Function
629        %161 = OpVariable %135 Function
630        %166 = OpVariable %135 Function
631        %180 = OpVariable %179 Function
632         %74 = OpAccessChain %73 %72 %22
633         %75 = OpLoad %6 %74
634         %77 = OpFOrdLessThan %11 %75 %76
635               OpSelectionMerge %80 None
636               OpBranchConditional %77 %79 %82
637         %79 = OpLabel
638               OpStore %78 %81
639               OpBranch %80
640         %82 = OpLabel
641         %83 = OpAccessChain %73 %72 %22
642         %84 = OpLoad %6 %83
643         %85 = OpFOrdGreaterThanEqual %11 %84 %76
644               OpSelectionMerge %88 None
645               OpBranchConditional %85 %87 %94
646         %87 = OpLabel
647         %90 = OpAccessChain %73 %72 %22
648         %91 = OpLoad %6 %90
649         %92 = OpFOrdGreaterThanEqual %11 %91 %76
650         %93 = OpSelect %6 %92 %70 %89
651               OpStore %86 %93
652               OpBranch %88
653         %94 = OpLabel
654               OpStore %86 %89
655               OpBranch %88
656         %88 = OpLabel
657         %95 = OpLoad %6 %86
658         %96 = OpExtInst %6 %1 FMin %95 %70
659               OpStore %78 %96
660               OpBranch %80
661         %80 = OpLabel
662         %97 = OpLoad %6 %78
663         %98 = OpExtInst %6 %1 FClamp %70 %70 %97
664         %99 = OpCompositeConstruct %9 %98 %70 %89 %89
665               OpStore %69 %99
666               OpStore %102 %103
667               OpBranch %104
668        %104 = OpLabel
669               OpLoopMerge %106 %107 None
670               OpBranch %108
671        %108 = OpLabel
672        %109 = OpLoad %100 %102
673        %111 = OpSLessThan %11 %109 %110
674               OpBranchConditional %111 %105 %106
675        %105 = OpLabel
676        %131 = OpLoad %100 %102
677        %133 = OpLoad %7 %18
678               OpStore %132 %133
679               OpStore %136 %130
680        %137 = OpAccessChain %10 %136 %131
681        %138 = OpLoad %9 %137
682               OpStore %134 %138
683        %139 = OpFunctionCall %11 %15 %132 %134
684               OpSelectionMerge %141 None
685               OpBranchConditional %139 %140 %141
686        %140 = OpLabel
687        %160 = OpLoad %100 %102
688               OpStore %161 %130
689        %162 = OpAccessChain %23 %161 %160 %22
690        %163 = OpLoad %6 %162
691        %164 = OpConvertFToS %100 %163
692        %165 = OpLoad %100 %102
693               OpStore %166 %130
694        %167 = OpAccessChain %23 %166 %165 %33
695        %168 = OpLoad %6 %167
696        %169 = OpConvertFToS %100 %168
697        %170 = OpIMul %100 %164 %169
698        %171 = OpLoad %100 %102
699        %173 = OpIMul %100 %171 %172
700        %174 = OpIAdd %100 %170 %173
701        %176 = OpIAdd %100 %174 %175
702        %178 = OpSMod %100 %176 %177
703               OpStore %180 %159
704        %181 = OpAccessChain %10 %180 %178
705        %182 = OpLoad %9 %181
706               OpStore %69 %182
707               OpBranch %141
708        %141 = OpLabel
709               OpBranch %107
710        %107 = OpLabel
711        %183 = OpLoad %100 %102
712        %185 = OpIAdd %100 %183 %184
713               OpStore %102 %185
714               OpBranch %104
715        %106 = OpLabel
716        %186 = OpLoad %9 %69
717               OpReturnValue %186
718               OpFunctionEnd
719END
720
721# uniforms for variant
722
723# resolution
724BUFFER variant_resolution DATA_TYPE vec2<float> DATA
725 256.0 256.0
726END
727
728BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
729
730PIPELINE graphics variant_pipeline
731  ATTACH variant_vertex_shader
732  ATTACH variant_fragment_shader
733  FRAMEBUFFER_SIZE 256 256
734  BIND BUFFER variant_framebuffer AS color LOCATION 0
735  BIND BUFFER variant_resolution AS uniform DESCRIPTOR_SET 0 BINDING 0
736END
737CLEAR_COLOR variant_pipeline 0 0 0 255
738
739CLEAR variant_pipeline
740RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
741
742EXPECT reference_framebuffer EQ_HISTOGRAM_EMD_BUFFER variant_framebuffer TOLERANCE 0.005
743