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 that assigns array values to other array
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# precision highp int;
30#
31# layout(location = 0) out vec4 _GLF_color;
32#
33# int data[9], temp[7];
34#
35# // Returns 1.0.
36# float func(int a)
37# {
38#     int b = 0;
39#
40#     data[0] = 5;
41#     data[2] = 0;
42#     data[4] = 0;
43#     data[6] = 0;
44#     data[8] = 0;
45#
46#     // Always true.
47#     if (gl_FragCoord.x >= 0.0)
48#     {
49#         while (b <= a)
50#         {
51#             if (b <= 5) {
52#                 // When b == 0, a value of data[0] is given to
53#                 // temp[0], making it's value 5.
54#                 temp[b] = data[b];
55#             b += 2;
56#             }
57#         }
58#     }
59#
60#     for (int i = 0; i < 3; i++)
61#     // On first iteration data[0] value is set to
62#     // temp[0] + 1, which will be: 5 + 1 == 6.
63#         data[i] = temp[0] + 1;
64#
65#     // Always true.
66#     if (temp[0] == 5 && data[0] == 6)
67#         return 1.0;
68#     else
69#         return 0.0;
70# }
71#
72# void main()
73# {
74#     for (int i = 0; i < 6; i++)
75#     {
76#         func(i);
77#
78#         // Always true.
79#         if(func(i) == 1.0)
80#             _GLF_color = vec4(1, 0, 0, 1);
81#         else
82#             _GLF_color = vec4(0);
83#     }
84# }
85SHADER fragment variant_fragment_shader SPIRV-ASM
86; SPIR-V
87; Version: 1.0
88; Generator: Khronos Glslang Reference Front End; 8
89; Bound: 123
90; Schema: 0
91               OpCapability Shader
92          %1 = OpExtInstImport "GLSL.std.450"
93               OpMemoryModel Logical GLSL450
94               OpEntryPoint Fragment %4 "main" %33 %117
95               OpExecutionMode %4 OriginUpperLeft
96               OpSource ESSL 310
97               OpName %4 "main"
98               OpName %11 "func(i1;"
99               OpName %10 "a"
100               OpName %13 "b"
101               OpName %19 "data"
102               OpName %33 "gl_FragCoord"
103               OpName %58 "temp"
104               OpName %66 "i"
105               OpName %99 "i"
106               OpName %107 "param"
107               OpName %110 "param"
108               OpName %117 "_GLF_color"
109               OpDecorate %33 BuiltIn FragCoord
110               OpDecorate %117 Location 0
111          %2 = OpTypeVoid
112          %3 = OpTypeFunction %2
113          %6 = OpTypeInt 32 1
114          %7 = OpTypePointer Function %6
115          %8 = OpTypeFloat 32
116          %9 = OpTypeFunction %8 %7
117         %14 = OpConstant %6 0
118         %15 = OpTypeInt 32 0
119         %16 = OpConstant %15 9
120         %17 = OpTypeArray %6 %16
121         %18 = OpTypePointer Private %17
122         %19 = OpVariable %18 Private
123         %20 = OpConstant %6 5
124         %21 = OpTypePointer Private %6
125         %23 = OpConstant %6 2
126         %25 = OpConstant %6 4
127         %27 = OpConstant %6 6
128         %29 = OpConstant %6 8
129         %31 = OpTypeVector %8 4
130         %32 = OpTypePointer Input %31
131         %33 = OpVariable %32 Input
132         %34 = OpConstant %15 0
133         %35 = OpTypePointer Input %8
134         %38 = OpConstant %8 0
135         %39 = OpTypeBool
136         %55 = OpConstant %15 7
137         %56 = OpTypeArray %6 %55
138         %57 = OpTypePointer Private %56
139         %58 = OpVariable %57 Private
140         %73 = OpConstant %6 3
141         %78 = OpConstant %6 1
142         %94 = OpConstant %8 1
143        %116 = OpTypePointer Output %31
144        %117 = OpVariable %116 Output
145        %118 = OpConstantComposite %31 %94 %38 %38 %94
146        %120 = OpConstantComposite %31 %38 %38 %38 %38
147          %4 = OpFunction %2 None %3
148          %5 = OpLabel
149         %99 = OpVariable %7 Function
150        %107 = OpVariable %7 Function
151        %110 = OpVariable %7 Function
152               OpStore %99 %14
153               OpBranch %100
154        %100 = OpLabel
155               OpLoopMerge %102 %103 None
156               OpBranch %104
157        %104 = OpLabel
158        %105 = OpLoad %6 %99
159        %106 = OpSLessThan %39 %105 %27
160               OpBranchConditional %106 %101 %102
161        %101 = OpLabel
162        %108 = OpLoad %6 %99
163               OpStore %107 %108
164        %109 = OpFunctionCall %8 %11 %107
165        %111 = OpLoad %6 %99
166               OpStore %110 %111
167        %112 = OpFunctionCall %8 %11 %110
168        %113 = OpFOrdEqual %39 %112 %94
169               OpSelectionMerge %115 None
170               OpBranchConditional %113 %114 %119
171        %114 = OpLabel
172               OpStore %117 %118
173               OpBranch %115
174        %119 = OpLabel
175               OpStore %117 %120
176               OpBranch %115
177        %115 = OpLabel
178               OpBranch %103
179        %103 = OpLabel
180        %121 = OpLoad %6 %99
181        %122 = OpIAdd %6 %121 %78
182               OpStore %99 %122
183               OpBranch %100
184        %102 = OpLabel
185               OpReturn
186               OpFunctionEnd
187         %11 = OpFunction %8 None %9
188         %10 = OpFunctionParameter %7
189         %12 = OpLabel
190         %13 = OpVariable %7 Function
191         %66 = OpVariable %7 Function
192               OpStore %13 %14
193         %22 = OpAccessChain %21 %19 %14
194               OpStore %22 %20
195         %24 = OpAccessChain %21 %19 %23
196               OpStore %24 %14
197         %26 = OpAccessChain %21 %19 %25
198               OpStore %26 %14
199         %28 = OpAccessChain %21 %19 %27
200               OpStore %28 %14
201         %30 = OpAccessChain %21 %19 %29
202               OpStore %30 %14
203         %36 = OpAccessChain %35 %33 %34
204         %37 = OpLoad %8 %36
205         %40 = OpFOrdGreaterThanEqual %39 %37 %38
206               OpSelectionMerge %42 None
207               OpBranchConditional %40 %41 %42
208         %41 = OpLabel
209               OpBranch %43
210         %43 = OpLabel
211               OpLoopMerge %45 %46 None
212               OpBranch %47
213         %47 = OpLabel
214         %48 = OpLoad %6 %13
215         %49 = OpLoad %6 %10
216         %50 = OpSLessThanEqual %39 %48 %49
217               OpBranchConditional %50 %44 %45
218         %44 = OpLabel
219         %51 = OpLoad %6 %13
220         %52 = OpSLessThanEqual %39 %51 %20
221               OpSelectionMerge %54 None
222               OpBranchConditional %52 %53 %54
223         %53 = OpLabel
224         %59 = OpLoad %6 %13
225         %60 = OpLoad %6 %13
226         %61 = OpAccessChain %21 %19 %60
227         %62 = OpLoad %6 %61
228         %63 = OpAccessChain %21 %58 %59
229               OpStore %63 %62
230         %64 = OpLoad %6 %13
231         %65 = OpIAdd %6 %64 %23
232               OpStore %13 %65
233               OpBranch %54
234         %54 = OpLabel
235               OpBranch %46
236         %46 = OpLabel
237               OpBranch %43
238         %45 = OpLabel
239               OpBranch %42
240         %42 = OpLabel
241               OpStore %66 %14
242               OpBranch %67
243         %67 = OpLabel
244               OpLoopMerge %69 %70 None
245               OpBranch %71
246         %71 = OpLabel
247         %72 = OpLoad %6 %66
248         %74 = OpSLessThan %39 %72 %73
249               OpBranchConditional %74 %68 %69
250         %68 = OpLabel
251         %75 = OpLoad %6 %66
252         %76 = OpAccessChain %21 %58 %14
253         %77 = OpLoad %6 %76
254         %79 = OpIAdd %6 %77 %78
255         %80 = OpAccessChain %21 %19 %75
256               OpStore %80 %79
257               OpBranch %70
258         %70 = OpLabel
259         %81 = OpLoad %6 %66
260         %82 = OpIAdd %6 %81 %78
261               OpStore %66 %82
262               OpBranch %67
263         %69 = OpLabel
264         %83 = OpAccessChain %21 %58 %14
265         %84 = OpLoad %6 %83
266         %85 = OpIEqual %39 %84 %20
267               OpSelectionMerge %87 None
268               OpBranchConditional %85 %86 %87
269         %86 = OpLabel
270         %88 = OpAccessChain %21 %19 %14
271         %89 = OpLoad %6 %88
272         %90 = OpIEqual %39 %89 %27
273               OpBranch %87
274         %87 = OpLabel
275         %91 = OpPhi %39 %85 %69 %90 %86
276               OpSelectionMerge %93 None
277               OpBranchConditional %91 %92 %96
278         %92 = OpLabel
279               OpReturnValue %94
280         %96 = OpLabel
281               OpReturnValue %38
282         %93 = OpLabel
283               OpUnreachable
284               OpFunctionEnd
285END
286
287
288BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
289
290PIPELINE graphics variant_pipeline
291  ATTACH variant_vertex_shader
292  ATTACH variant_fragment_shader
293  FRAMEBUFFER_SIZE 256 256
294  BIND BUFFER variant_framebuffer AS color LOCATION 0
295END
296CLEAR_COLOR variant_pipeline 0 0 0 255
297
298CLEAR variant_pipeline
299RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
300
301EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
302