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