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