1#!amber
2
3# Copyright 2019 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 an arr value set to itself squared
21
22# The test passes because shader always writes red.
23
24SHADER vertex variant_vertex_shader PASSTHROUGH
25
26# variant_fragment_shader is derived from the following GLSL:
27# #version 310 es
28# precision highp float;
29#
30# precision highp int;
31#
32# layout(location = 0) out vec4 _GLF_color;
33#
34# struct QuicksortObject {
35#  int numbers[10];
36# } ;
37#
38# QuicksortObject obj;
39#
40# void swap(int i, int j)
41# {
42#  int temp = obj.numbers[i];
43#  obj.numbers[i] = obj.numbers[j];
44#  obj.numbers[j] = temp;
45# }
46# int performPartition(int l, int h)
47# {
48#  int pivot = obj.numbers[h];
49#  int i = (l - 1);
50#  for(
51#      int j = l;
52#      j <= h - 1;
53#      j ++
54#  )
55#   {
56#    if(obj.numbers[j] <= pivot)
57#     {
58#      i ++;
59#      swap(i, j);
60#     }
61#   }
62#  swap(i + 1, h);
63#  return (i + 1);
64# }
65# void quicksort()
66# {
67#  int l = 0, h = 9;
68#  int stack[10];
69#  int top = - 1;
70#  stack[++ top] = l;
71#  stack[++ top] = h;
72#  while(top >= 0)
73#   {
74#    h = stack[top --];
75#    l = stack[top --];
76#    int p = performPartition(l, h);
77#    if(p - 1 > l)
78#     {
79#      stack[++ top] = l;
80#      stack[++ top] = p - 1;
81#     }
82#    if(p + 1 < h)
83#     {
84#      stack[++ top] = p + 1;
85#      stack[++ top] = h;
86#     }
87#   }
88# }
89# void main()
90# {
91#  for(
92#      int i = 0;
93#      i < 10;
94#      i ++
95#  )
96#   {
97#    obj.numbers[i] = (10 - i);
98#    obj.numbers[i] = obj.numbers[i] * obj.numbers[i];
99#   }
100#  quicksort();
101#
102#  if (obj.numbers[0] < obj.numbers[4])
103#   _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
104#  else
105#   _GLF_color = vec4(0.0, 1.0, 0.0, 1.0);
106#
107# }
108SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
109; SPIR-V
110; Version: 1.0
111; Generator: Khronos Glslang Reference Front End; 8
112; Bound: 198
113; Schema: 0
114               OpCapability Shader
115          %1 = OpExtInstImport "GLSL.std.450"
116               OpMemoryModel Logical GLSL450
117               OpEntryPoint Fragment %4 "main" %188
118               OpExecutionMode %4 OriginUpperLeft
119               OpSource ESSL 310
120               OpName %4 "main"
121               OpName %11 "swap(i1;i1;"
122               OpName %9 "i"
123               OpName %10 "j"
124               OpName %16 "performPartition(i1;i1;"
125               OpName %14 "l"
126               OpName %15 "h"
127               OpName %18 "quicksort("
128               OpName %20 "temp"
129               OpName %24 "QuicksortObject"
130               OpMemberName %24 0 "numbers"
131               OpName %26 "obj"
132               OpName %40 "pivot"
133               OpName %44 "i"
134               OpName %48 "j"
135               OpName %69 "param"
136               OpName %71 "param"
137               OpName %78 "param"
138               OpName %79 "param"
139               OpName %86 "l"
140               OpName %87 "h"
141               OpName %89 "top"
142               OpName %92 "stack"
143               OpName %116 "p"
144               OpName %117 "param"
145               OpName %119 "param"
146               OpName %152 "i"
147               OpName %188 "_GLF_color"
148               OpDecorate %188 Location 0
149          %2 = OpTypeVoid
150          %3 = OpTypeFunction %2
151          %6 = OpTypeInt 32 1
152          %7 = OpTypePointer Function %6
153          %8 = OpTypeFunction %2 %7 %7
154         %13 = OpTypeFunction %6 %7 %7
155         %21 = OpTypeInt 32 0
156         %22 = OpConstant %21 10
157         %23 = OpTypeArray %6 %22
158         %24 = OpTypeStruct %23
159         %25 = OpTypePointer Private %24
160         %26 = OpVariable %25 Private
161         %27 = OpConstant %6 0
162         %29 = OpTypePointer Private %6
163         %46 = OpConstant %6 1
164         %58 = OpTypeBool
165         %88 = OpConstant %6 9
166         %90 = OpConstant %6 -1
167         %91 = OpTypePointer Function %23
168        %159 = OpConstant %6 10
169        %179 = OpConstant %6 4
170        %185 = OpTypeFloat 32
171        %186 = OpTypeVector %185 4
172        %187 = OpTypePointer Output %186
173        %188 = OpVariable %187 Output
174        %189 = OpConstant %185 1
175        %190 = OpConstant %185 0
176        %191 = OpConstantComposite %186 %189 %190 %190 %189
177        %193 = OpConstantComposite %186 %190 %189 %190 %189
178        %194 = OpTypeVector %185 2
179          %4 = OpFunction %2 None %3
180          %5 = OpLabel
181        %152 = OpVariable %7 Function
182               OpStore %152 %27
183               OpBranch %153
184        %153 = OpLabel
185               OpLoopMerge %155 %156 None
186               OpBranch %157
187        %157 = OpLabel
188        %158 = OpLoad %6 %152
189        %160 = OpSLessThan %58 %158 %159
190               OpBranchConditional %160 %154 %155
191        %154 = OpLabel
192        %161 = OpLoad %6 %152
193        %162 = OpLoad %6 %152
194        %163 = OpISub %6 %159 %162
195        %164 = OpAccessChain %29 %26 %27 %161
196               OpStore %164 %163
197        %165 = OpLoad %6 %152
198        %166 = OpLoad %6 %152
199        %167 = OpAccessChain %29 %26 %27 %166
200        %168 = OpLoad %6 %167
201        %169 = OpLoad %6 %152
202        %170 = OpAccessChain %29 %26 %27 %169
203        %171 = OpLoad %6 %170
204        %172 = OpIMul %6 %168 %171
205        %173 = OpAccessChain %29 %26 %27 %165
206               OpStore %173 %172
207               OpBranch %156
208        %156 = OpLabel
209        %174 = OpLoad %6 %152
210        %175 = OpIAdd %6 %174 %46
211               OpStore %152 %175
212               OpBranch %153
213        %155 = OpLabel
214        %176 = OpFunctionCall %2 %18
215        %177 = OpAccessChain %29 %26 %27 %27
216        %178 = OpLoad %6 %177
217        %180 = OpAccessChain %29 %26 %27 %179
218        %181 = OpLoad %6 %180
219        %182 = OpSLessThan %58 %178 %181
220               OpSelectionMerge %184 None
221               OpBranchConditional %182 %183 %192
222        %183 = OpLabel
223               OpStore %188 %191
224               OpBranch %184
225        %192 = OpLabel
226               OpStore %188 %193
227               OpBranch %184
228        %184 = OpLabel
229               OpReturn
230               OpFunctionEnd
231         %11 = OpFunction %2 None %8
232          %9 = OpFunctionParameter %7
233         %10 = OpFunctionParameter %7
234         %12 = OpLabel
235         %20 = OpVariable %7 Function
236         %28 = OpLoad %6 %9
237         %30 = OpAccessChain %29 %26 %27 %28
238         %31 = OpLoad %6 %30
239               OpStore %20 %31
240         %32 = OpLoad %6 %9
241         %33 = OpLoad %6 %10
242         %34 = OpAccessChain %29 %26 %27 %33
243         %35 = OpLoad %6 %34
244         %36 = OpAccessChain %29 %26 %27 %32
245               OpStore %36 %35
246         %37 = OpLoad %6 %10
247         %38 = OpLoad %6 %20
248         %39 = OpAccessChain %29 %26 %27 %37
249               OpStore %39 %38
250               OpReturn
251               OpFunctionEnd
252         %16 = OpFunction %6 None %13
253         %14 = OpFunctionParameter %7
254         %15 = OpFunctionParameter %7
255         %17 = OpLabel
256         %40 = OpVariable %7 Function
257         %44 = OpVariable %7 Function
258         %48 = OpVariable %7 Function
259         %69 = OpVariable %7 Function
260         %71 = OpVariable %7 Function
261         %78 = OpVariable %7 Function
262         %79 = OpVariable %7 Function
263         %41 = OpLoad %6 %15
264         %42 = OpAccessChain %29 %26 %27 %41
265         %43 = OpLoad %6 %42
266               OpStore %40 %43
267         %45 = OpLoad %6 %14
268         %47 = OpISub %6 %45 %46
269               OpStore %44 %47
270         %49 = OpLoad %6 %14
271               OpStore %48 %49
272               OpBranch %50
273         %50 = OpLabel
274               OpLoopMerge %52 %53 None
275               OpBranch %54
276         %54 = OpLabel
277         %55 = OpLoad %6 %48
278         %56 = OpLoad %6 %15
279         %57 = OpISub %6 %56 %46
280         %59 = OpSLessThanEqual %58 %55 %57
281               OpBranchConditional %59 %51 %52
282         %51 = OpLabel
283         %60 = OpLoad %6 %48
284         %61 = OpAccessChain %29 %26 %27 %60
285         %62 = OpLoad %6 %61
286         %63 = OpLoad %6 %40
287         %64 = OpSLessThanEqual %58 %62 %63
288               OpSelectionMerge %66 None
289               OpBranchConditional %64 %65 %66
290         %65 = OpLabel
291         %67 = OpLoad %6 %44
292         %68 = OpIAdd %6 %67 %46
293               OpStore %44 %68
294         %70 = OpLoad %6 %44
295               OpStore %69 %70
296         %72 = OpLoad %6 %48
297               OpStore %71 %72
298         %73 = OpFunctionCall %2 %11 %69 %71
299               OpBranch %66
300         %66 = OpLabel
301               OpBranch %53
302         %53 = OpLabel
303         %74 = OpLoad %6 %48
304         %75 = OpIAdd %6 %74 %46
305               OpStore %48 %75
306               OpBranch %50
307         %52 = OpLabel
308         %76 = OpLoad %6 %44
309         %77 = OpIAdd %6 %76 %46
310               OpStore %78 %77
311         %80 = OpLoad %6 %15
312               OpStore %79 %80
313         %81 = OpFunctionCall %2 %11 %78 %79
314         %82 = OpLoad %6 %44
315         %83 = OpIAdd %6 %82 %46
316               OpReturnValue %83
317               OpFunctionEnd
318         %18 = OpFunction %2 None %3
319         %19 = OpLabel
320         %86 = OpVariable %7 Function
321         %87 = OpVariable %7 Function
322         %89 = OpVariable %7 Function
323         %92 = OpVariable %91 Function
324        %116 = OpVariable %7 Function
325        %117 = OpVariable %7 Function
326        %119 = OpVariable %7 Function
327               OpStore %86 %27
328               OpStore %87 %88
329               OpStore %89 %90
330         %93 = OpLoad %6 %89
331         %94 = OpIAdd %6 %93 %46
332               OpStore %89 %94
333         %95 = OpLoad %6 %86
334         %96 = OpAccessChain %7 %92 %94
335               OpStore %96 %95
336         %97 = OpLoad %6 %89
337         %98 = OpIAdd %6 %97 %46
338               OpStore %89 %98
339         %99 = OpLoad %6 %87
340        %100 = OpAccessChain %7 %92 %98
341               OpStore %100 %99
342               OpBranch %101
343        %101 = OpLabel
344               OpLoopMerge %103 %104 None
345               OpBranch %105
346        %105 = OpLabel
347        %106 = OpLoad %6 %89
348        %107 = OpSGreaterThanEqual %58 %106 %27
349               OpBranchConditional %107 %102 %103
350        %102 = OpLabel
351        %108 = OpLoad %6 %89
352        %109 = OpISub %6 %108 %46
353               OpStore %89 %109
354        %110 = OpAccessChain %7 %92 %108
355        %111 = OpLoad %6 %110
356               OpStore %87 %111
357        %112 = OpLoad %6 %89
358        %113 = OpISub %6 %112 %46
359               OpStore %89 %113
360        %114 = OpAccessChain %7 %92 %112
361        %115 = OpLoad %6 %114
362               OpStore %86 %115
363        %118 = OpLoad %6 %86
364               OpStore %117 %118
365        %120 = OpLoad %6 %87
366               OpStore %119 %120
367        %121 = OpFunctionCall %6 %16 %117 %119
368               OpStore %116 %121
369        %122 = OpLoad %6 %116
370        %123 = OpISub %6 %122 %46
371        %124 = OpLoad %6 %86
372        %125 = OpSGreaterThan %58 %123 %124
373               OpSelectionMerge %127 None
374               OpBranchConditional %125 %126 %127
375        %126 = OpLabel
376        %128 = OpLoad %6 %89
377        %129 = OpIAdd %6 %128 %46
378               OpStore %89 %129
379        %130 = OpLoad %6 %86
380        %131 = OpAccessChain %7 %92 %129
381               OpStore %131 %130
382        %132 = OpLoad %6 %89
383        %133 = OpIAdd %6 %132 %46
384               OpStore %89 %133
385        %134 = OpLoad %6 %116
386        %135 = OpISub %6 %134 %46
387        %136 = OpAccessChain %7 %92 %133
388               OpStore %136 %135
389               OpBranch %127
390        %127 = OpLabel
391        %137 = OpLoad %6 %116
392        %138 = OpIAdd %6 %137 %46
393        %139 = OpLoad %6 %87
394        %140 = OpSLessThan %58 %138 %139
395               OpSelectionMerge %142 None
396               OpBranchConditional %140 %141 %142
397        %141 = OpLabel
398        %143 = OpLoad %6 %89
399        %144 = OpIAdd %6 %143 %46
400               OpStore %89 %144
401        %145 = OpLoad %6 %116
402        %146 = OpIAdd %6 %145 %46
403        %147 = OpAccessChain %7 %92 %144
404               OpStore %147 %146
405        %148 = OpLoad %6 %89
406        %149 = OpIAdd %6 %148 %46
407               OpStore %89 %149
408        %150 = OpLoad %6 %87
409        %151 = OpAccessChain %7 %92 %149
410               OpStore %151 %150
411               OpBranch %142
412        %142 = OpLabel
413               OpBranch %104
414        %104 = OpLabel
415               OpBranch %101
416        %103 = OpLabel
417               OpReturn
418               OpFunctionEnd
419END
420
421# uniforms for variant
422
423BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
424
425PIPELINE graphics variant_pipeline
426  ATTACH variant_vertex_shader
427  ATTACH variant_fragment_shader
428  FRAMEBUFFER_SIZE 16 16
429  BIND BUFFER variant_framebuffer AS color LOCATION 0
430END
431CLEAR_COLOR variant_pipeline 0 0 0 255
432
433CLEAR variant_pipeline
434RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 16 16
435
436EXPECT variant_framebuffer IDX 0 0 SIZE 16 16 EQ_RGBA 255 0 0 255
437