1#!amber
2
3# Copyright 2021 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 the GraphicsFuzz project.
19
20# Short description: A fragment shader that covers specific LLVM code paths
21
22# The test passes because the shader always writes red.
23
24SHADER vertex variant_vertex_shader PASSTHROUGH
25
26# variant_fragment_shader is derived from the following GLSL:
27# #version 320 es
28#
29# #define _int_1 _GLF_uniform_int_values[0]
30# #define _int_0 _GLF_uniform_int_values[1]
31# #define _int_2 _GLF_uniform_int_values[2]
32# #define _int_9 _GLF_uniform_int_values[3]
33# #define _int_20 _GLF_uniform_int_values[4]
34# #define _int_29 _GLF_uniform_int_values[5]
35#
36# precision highp float;
37# precision highp int;
38#
39# // Contents of _GLF_uniform_int_values: [1, 0, 2, 9, 20, 29]
40# layout(set = 0, binding = 0) uniform buf0
41# {
42#     int _GLF_uniform_int_values[6];
43# };
44# layout(location = 0) out vec4 _GLF_color;
45#
46# // A void function that only touches local variables and returns.
47# void func()
48# {
49#     int index = _int_0;
50#
51#     while(true)
52#     {
53#         int a = int[10](_int_1, _int_2, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1)[index];
54#
55#         if(a == _int_2)
56#         {
57#             // Executed during the second iteration.
58#             return;
59#         }
60#
61#         index = _int_1;
62#     }
63# }
64# void main()
65# {
66#     int a = _int_0;
67#
68#     for(int i = _int_0; i < _int_20; i ++)
69#     {
70#         // Doesn't have any effect.
71#         func();
72#         a = i;
73#
74#         int arr[9] = int[9](_int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1);
75#
76#         // The array is never read so we don't care if the elements get incremented or not.
77#         // The loop increments a by 10 in total.
78#         for(int j = 0; j < 10; j ++)
79#         {
80#             arr[clamp(a, _int_0, 8)] = _int_1;
81#
82#             switch(i)
83#             {
84#                 case 0:
85#                     arr[clamp(a, 0, 8)]++;
86#                 case 8:
87#                     arr[clamp(a, 0, 8)]++;
88#             }
89#             a++;
90#         }
91#     }
92#
93#     // Always true.
94#     if(a == _int_29)
95#     {
96#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
97#     }
98#     else
99#     {
100#         _GLF_color = vec4(_int_0);
101#     }
102# }
103SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
104; SPIR-V
105; Version: 1.0
106; Generator: Khronos Glslang Reference Front End; 10
107; Bound: 176
108; Schema: 0
109               OpCapability Shader
110          %1 = OpExtInstImport "GLSL.std.450"
111               OpMemoryModel Logical GLSL450
112               OpEntryPoint Fragment %4 "main" %157
113               OpExecutionMode %4 OriginUpperLeft
114               OpSource ESSL 320
115               OpName %4 "main"
116               OpName %6 "func("
117               OpName %10 "index"
118               OpName %14 "buf0"
119               OpMemberName %14 0 "_GLF_uniform_int_values"
120               OpName %16 ""
121               OpName %29 "a"
122               OpName %56 "indexable"
123               OpName %68 "a"
124               OpName %71 "i"
125               OpName %89 "arr"
126               OpName %109 "j"
127               OpName %157 "_GLF_color"
128               OpDecorate %13 ArrayStride 16
129               OpMemberDecorate %14 0 Offset 0
130               OpDecorate %14 Block
131               OpDecorate %16 DescriptorSet 0
132               OpDecorate %16 Binding 0
133               OpDecorate %157 Location 0
134          %2 = OpTypeVoid
135          %3 = OpTypeFunction %2
136          %8 = OpTypeInt 32 1
137          %9 = OpTypePointer Function %8
138         %11 = OpTypeInt 32 0
139         %12 = OpConstant %11 6
140         %13 = OpTypeArray %8 %12
141         %14 = OpTypeStruct %13
142         %15 = OpTypePointer Uniform %14
143         %16 = OpVariable %15 Uniform
144         %17 = OpConstant %8 0
145         %18 = OpConstant %8 1
146         %19 = OpTypePointer Uniform %8
147         %27 = OpTypeBool
148         %28 = OpConstantTrue %27
149         %32 = OpConstant %8 2
150         %51 = OpConstant %11 10
151         %52 = OpTypeArray %8 %51
152         %55 = OpTypePointer Function %52
153         %80 = OpConstant %8 4
154         %86 = OpConstant %11 9
155         %87 = OpTypeArray %8 %86
156         %88 = OpTypePointer Function %87
157        %116 = OpConstant %8 10
158        %121 = OpConstant %8 8
159        %148 = OpConstant %8 5
160        %154 = OpTypeFloat 32
161        %155 = OpTypeVector %154 4
162        %156 = OpTypePointer Output %155
163        %157 = OpVariable %156 Output
164          %4 = OpFunction %2 None %3
165          %5 = OpLabel
166         %68 = OpVariable %9 Function
167         %71 = OpVariable %9 Function
168         %89 = OpVariable %88 Function
169        %109 = OpVariable %9 Function
170         %69 = OpAccessChain %19 %16 %17 %18
171         %70 = OpLoad %8 %69
172               OpStore %68 %70
173         %72 = OpAccessChain %19 %16 %17 %18
174         %73 = OpLoad %8 %72
175               OpStore %71 %73
176               OpBranch %74
177         %74 = OpLabel
178               OpLoopMerge %76 %77 None
179               OpBranch %78
180         %78 = OpLabel
181         %79 = OpLoad %8 %71
182         %81 = OpAccessChain %19 %16 %17 %80
183         %82 = OpLoad %8 %81
184         %83 = OpSLessThan %27 %79 %82
185               OpBranchConditional %83 %75 %76
186         %75 = OpLabel
187         %84 = OpFunctionCall %2 %6
188         %85 = OpLoad %8 %71
189               OpStore %68 %85
190         %90 = OpAccessChain %19 %16 %17 %17
191         %91 = OpLoad %8 %90
192         %92 = OpAccessChain %19 %16 %17 %17
193         %93 = OpLoad %8 %92
194         %94 = OpAccessChain %19 %16 %17 %17
195         %95 = OpLoad %8 %94
196         %96 = OpAccessChain %19 %16 %17 %17
197         %97 = OpLoad %8 %96
198         %98 = OpAccessChain %19 %16 %17 %17
199         %99 = OpLoad %8 %98
200        %100 = OpAccessChain %19 %16 %17 %17
201        %101 = OpLoad %8 %100
202        %102 = OpAccessChain %19 %16 %17 %17
203        %103 = OpLoad %8 %102
204        %104 = OpAccessChain %19 %16 %17 %17
205        %105 = OpLoad %8 %104
206        %106 = OpAccessChain %19 %16 %17 %17
207        %107 = OpLoad %8 %106
208        %108 = OpCompositeConstruct %87 %91 %93 %95 %97 %99 %101 %103 %105 %107
209               OpStore %89 %108
210               OpStore %109 %17
211               OpBranch %110
212        %110 = OpLabel
213               OpLoopMerge %112 %113 None
214               OpBranch %114
215        %114 = OpLabel
216        %115 = OpLoad %8 %109
217        %117 = OpSLessThan %27 %115 %116
218               OpBranchConditional %117 %111 %112
219        %111 = OpLabel
220        %118 = OpLoad %8 %68
221        %119 = OpAccessChain %19 %16 %17 %18
222        %120 = OpLoad %8 %119
223        %122 = OpExtInst %8 %1 SClamp %118 %120 %121
224        %123 = OpAccessChain %19 %16 %17 %17
225        %124 = OpLoad %8 %123
226        %125 = OpAccessChain %9 %89 %122
227               OpStore %125 %124
228        %126 = OpLoad %8 %71
229               OpSelectionMerge %129 None
230               OpSwitch %126 %129 0 %127 8 %128
231        %127 = OpLabel
232        %130 = OpLoad %8 %68
233        %131 = OpExtInst %8 %1 SClamp %130 %17 %121
234        %132 = OpAccessChain %9 %89 %131
235        %133 = OpLoad %8 %132
236        %134 = OpIAdd %8 %133 %18
237               OpStore %132 %134
238               OpBranch %128
239        %128 = OpLabel
240        %135 = OpLoad %8 %68
241        %136 = OpExtInst %8 %1 SClamp %135 %17 %121
242        %137 = OpAccessChain %9 %89 %136
243        %138 = OpLoad %8 %137
244        %139 = OpIAdd %8 %138 %18
245               OpStore %137 %139
246               OpBranch %129
247        %129 = OpLabel
248        %141 = OpLoad %8 %68
249        %142 = OpIAdd %8 %141 %18
250               OpStore %68 %142
251               OpBranch %113
252        %113 = OpLabel
253        %143 = OpLoad %8 %109
254        %144 = OpIAdd %8 %143 %18
255               OpStore %109 %144
256               OpBranch %110
257        %112 = OpLabel
258               OpBranch %77
259         %77 = OpLabel
260        %145 = OpLoad %8 %71
261        %146 = OpIAdd %8 %145 %18
262               OpStore %71 %146
263               OpBranch %74
264         %76 = OpLabel
265        %147 = OpLoad %8 %68
266        %149 = OpAccessChain %19 %16 %17 %148
267        %150 = OpLoad %8 %149
268        %151 = OpIEqual %27 %147 %150
269               OpSelectionMerge %153 None
270               OpBranchConditional %151 %152 %171
271        %152 = OpLabel
272        %158 = OpAccessChain %19 %16 %17 %17
273        %159 = OpLoad %8 %158
274        %160 = OpConvertSToF %154 %159
275        %161 = OpAccessChain %19 %16 %17 %18
276        %162 = OpLoad %8 %161
277        %163 = OpConvertSToF %154 %162
278        %164 = OpAccessChain %19 %16 %17 %18
279        %165 = OpLoad %8 %164
280        %166 = OpConvertSToF %154 %165
281        %167 = OpAccessChain %19 %16 %17 %17
282        %168 = OpLoad %8 %167
283        %169 = OpConvertSToF %154 %168
284        %170 = OpCompositeConstruct %155 %160 %163 %166 %169
285               OpStore %157 %170
286               OpBranch %153
287        %171 = OpLabel
288        %172 = OpAccessChain %19 %16 %17 %18
289        %173 = OpLoad %8 %172
290        %174 = OpConvertSToF %154 %173
291        %175 = OpCompositeConstruct %155 %174 %174 %174 %174
292               OpStore %157 %175
293               OpBranch %153
294        %153 = OpLabel
295               OpReturn
296               OpFunctionEnd
297          %6 = OpFunction %2 None %3
298          %7 = OpLabel
299         %10 = OpVariable %9 Function
300         %29 = OpVariable %9 Function
301         %56 = OpVariable %55 Function
302         %20 = OpAccessChain %19 %16 %17 %18
303         %21 = OpLoad %8 %20
304               OpStore %10 %21
305               OpBranch %22
306         %22 = OpLabel
307               OpLoopMerge %24 %25 None
308               OpBranch %26
309         %26 = OpLabel
310               OpBranchConditional %28 %23 %24
311         %23 = OpLabel
312         %30 = OpAccessChain %19 %16 %17 %17
313         %31 = OpLoad %8 %30
314         %33 = OpAccessChain %19 %16 %17 %32
315         %34 = OpLoad %8 %33
316         %35 = OpAccessChain %19 %16 %17 %17
317         %36 = OpLoad %8 %35
318         %37 = OpAccessChain %19 %16 %17 %17
319         %38 = OpLoad %8 %37
320         %39 = OpAccessChain %19 %16 %17 %17
321         %40 = OpLoad %8 %39
322         %41 = OpAccessChain %19 %16 %17 %17
323         %42 = OpLoad %8 %41
324         %43 = OpAccessChain %19 %16 %17 %17
325         %44 = OpLoad %8 %43
326         %45 = OpAccessChain %19 %16 %17 %17
327         %46 = OpLoad %8 %45
328         %47 = OpAccessChain %19 %16 %17 %17
329         %48 = OpLoad %8 %47
330         %49 = OpAccessChain %19 %16 %17 %17
331         %50 = OpLoad %8 %49
332         %53 = OpCompositeConstruct %52 %31 %34 %36 %38 %40 %42 %44 %46 %48 %50
333         %54 = OpLoad %8 %10
334               OpStore %56 %53
335         %57 = OpAccessChain %9 %56 %54
336         %58 = OpLoad %8 %57
337               OpStore %29 %58
338         %59 = OpLoad %8 %29
339         %60 = OpAccessChain %19 %16 %17 %32
340         %61 = OpLoad %8 %60
341         %62 = OpIEqual %27 %59 %61
342               OpSelectionMerge %64 None
343               OpBranchConditional %62 %63 %64
344         %63 = OpLabel
345               OpReturn
346         %64 = OpLabel
347         %66 = OpAccessChain %19 %16 %17 %17
348         %67 = OpLoad %8 %66
349               OpStore %10 %67
350               OpBranch %25
351         %25 = OpLabel
352               OpBranch %22
353         %24 = OpLabel
354               OpReturn
355               OpFunctionEnd
356END
357
358# uniforms for variant
359
360# _GLF_uniform_int_values
361BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
362 1 0 2 9 20 29
363END
364
365BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
366
367PIPELINE graphics variant_pipeline
368  ATTACH variant_vertex_shader
369  ATTACH variant_fragment_shader
370  FRAMEBUFFER_SIZE 16 16
371  BIND BUFFER variant_framebuffer AS color LOCATION 0
372  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
373END
374CLEAR_COLOR variant_pipeline 0 0 0 255
375
376CLEAR variant_pipeline
377RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 16 16
378
379EXPECT variant_framebuffer IDX 0 0 SIZE 16 16 EQ_RGBA 255 0 0 255
380