• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# '--copy-propagate-arrays'
26# '--eliminate-dead-branches'
27# '--merge-blocks'
28# '--private-to-local'
29# '--reduce-load-size'
30# '--eliminate-dead-code-aggressive'
31# '--ccp'
32# '--reduce-load-size'
33# '--convert-local-access-chains'
34# '--eliminate-dead-branches'
35# '--merge-return'
36# '--eliminate-local-single-block'
37# '--eliminate-dead-code-aggressive'
38# '--redundancy-elimination'
39# '--eliminate-dead-branches'
40# '--merge-return'
41# '--eliminate-local-multi-store'
42# '--reduce-load-size'
43# '--inline-entry-points-exhaustive'
44# '--vector-dce'
45# '--eliminate-dead-branches'
46# '--merge-return'
47# '--eliminate-local-multi-store'
48# '--eliminate-dead-branches'
49# '--merge-blocks'
50# '--eliminate-local-single-store'
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_0 _GLF_uniform_int_values[0]
60# #define _float_1_0 _GLF_uniform_float_values[0]
61# #define _float_0_1 _GLF_uniform_float_values[1]
62# #define _float_0_0 _GLF_uniform_float_values[2]
63#
64# precision highp float;
65# precision highp int;
66#
67# // Contents of _GLF_uniform_int_values: 0
68# layout(set = 0, binding = 0) uniform buf0
69# {
70#     int _GLF_uniform_int_values[1];
71# };
72# // Contents of _GLF_uniform_float_values: [1.0, 0.1, 0.0]
73# layout(set = 0, binding = 1) uniform buf1
74# {
75#     float _GLF_uniform_float_values[3];
76# };
77#
78# const int _GLF_global_loop_bound = 10;
79# int _GLF_global_loop_count = 0;
80#
81# layout(location = 0) out vec4 _GLF_color;
82#
83# // This function always returns 1.0 or greater.
84# float func(float x)
85# {
86#     float f = _float_1_0;
87#
88#     // Always false.
89#     if(_float_1_0 < 1.0)
90#     {
91#         if(gl_FragCoord.x < _float_0_0)
92#         {
93#             return _float_1_0;
94#         }
95#     }
96#
97#     while(_GLF_global_loop_count < _GLF_global_loop_bound)
98#     {
99#         _GLF_global_loop_count++;
100#         f += _float_1_0;
101#
102#         // Always true.
103#         if(gl_FragCoord.x >= 0.0)
104#         {
105#             _GLF_color = vec4(_float_1_0);
106#         }
107#
108#         // Always false.
109#         if (x < _float_0_0)
110#         {
111#             return f;
112#         }
113#     }
114#
115#     // Never iterated as the loop bound has already been reached.
116#     while(_GLF_global_loop_count < _GLF_global_loop_bound)
117#     {
118#         _GLF_global_loop_count ++;
119#     }
120#
121#     return f;
122# }
123#
124# void main()
125# {
126#     _GLF_color = vec4(_int_0);
127#
128#     // Always false.
129#     if(gl_FragCoord.x < _float_0_1)
130#     {
131#         return;
132#     }
133#
134#     // v0 becomes (0, 0, 0, 0).
135#     vec4 v0 = _GLF_color;
136#
137#     // Always true.
138#     if(gl_FragCoord.x >= 0.0)
139#     {
140#         _GLF_color = vec4(_float_1_0);
141#     }
142#
143#     _GLF_color = v0;
144#
145#     // Always false.
146#     if(gl_FragCoord.y < _float_0_1)
147#     {
148#         return;
149#     }
150#
151#     vec4 v1 = vec4(_float_0_0);
152#     // v1 becomes (x, 0, 0, x), where x >= 1.0.
153#     v1.x = v1.w = func(gl_FragCoord.y);
154#
155#     // Always true.
156#     if(gl_FragCoord.x >= 0.0)
157#     {
158#         _GLF_color = vec4(_float_1_0);
159#     }
160#
161#     // Always false.
162#     if(gl_FragCoord.x < _float_0_0)
163#     {
164#         return;
165#     }
166#
167#     // Results clamps to (1, 0, 0, 1).
168#     _GLF_color = v1;
169# }
170SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
171; SPIR-V
172; Version: 1.0
173; Generator: Khronos Glslang Reference Front End; 10
174; Bound: 247
175; Schema: 0
176               OpCapability Shader
177          %1 = OpExtInstImport "GLSL.std.450"
178               OpMemoryModel Logical GLSL450
179               OpEntryPoint Fragment %4 "main" %35 %71
180               OpExecutionMode %4 OriginUpperLeft
181               OpSource ESSL 320
182               OpName %4 "main"
183               OpName %10 "func(f1;"
184               OpName %9 "x"
185               OpName %14 "_GLF_global_loop_count"
186               OpName %16 "f"
187               OpName %20 "buf1"
188               OpMemberName %20 0 "_GLF_uniform_float_values"
189               OpName %22 ""
190               OpName %35 "gl_FragCoord"
191               OpName %71 "_GLF_color"
192               OpName %97 "buf0"
193               OpMemberName %97 0 "_GLF_uniform_int_values"
194               OpName %99 ""
195               OpName %114 "v0"
196               OpName %133 "v1"
197               OpName %137 "param"
198               OpDecorate %19 ArrayStride 16
199               OpMemberDecorate %20 0 Offset 0
200               OpDecorate %20 Block
201               OpDecorate %22 DescriptorSet 0
202               OpDecorate %22 Binding 1
203               OpDecorate %35 BuiltIn FragCoord
204               OpDecorate %71 Location 0
205               OpDecorate %96 ArrayStride 16
206               OpMemberDecorate %97 0 Offset 0
207               OpDecorate %97 Block
208               OpDecorate %99 DescriptorSet 0
209               OpDecorate %99 Binding 0
210          %2 = OpTypeVoid
211          %3 = OpTypeFunction %2
212          %6 = OpTypeFloat 32
213          %7 = OpTypePointer Function %6
214          %8 = OpTypeFunction %6 %7
215         %12 = OpTypeInt 32 1
216         %13 = OpTypePointer Private %12
217         %14 = OpVariable %13 Private
218         %15 = OpConstant %12 0
219         %17 = OpTypeInt 32 0
220         %18 = OpConstant %17 3
221         %19 = OpTypeArray %6 %18
222         %20 = OpTypeStruct %19
223         %21 = OpTypePointer Uniform %20
224         %22 = OpVariable %21 Uniform
225         %23 = OpTypePointer Uniform %6
226         %28 = OpConstant %6 1
227         %29 = OpTypeBool
228         %33 = OpTypeVector %6 4
229         %34 = OpTypePointer Input %33
230         %35 = OpVariable %34 Input
231         %36 = OpConstant %17 0
232         %37 = OpTypePointer Input %6
233         %40 = OpConstant %12 2
234         %55 = OpConstant %12 10
235         %58 = OpConstant %12 1
236         %66 = OpConstant %6 0
237         %70 = OpTypePointer Output %33
238         %71 = OpVariable %70 Output
239         %95 = OpConstant %17 1
240         %96 = OpTypeArray %12 %95
241         %97 = OpTypeStruct %96
242         %98 = OpTypePointer Uniform %97
243         %99 = OpVariable %98 Uniform
244        %100 = OpTypePointer Uniform %12
245        %113 = OpTypePointer Function %33
246        %166 = OpConstantFalse %29
247        %167 = OpTypePointer Function %29
248        %169 = OpConstantTrue %29
249        %192 = OpUndef %6
250          %4 = OpFunction %2 None %3
251          %5 = OpLabel
252        %194 = OpVariable %167 Function %166
253        %195 = OpVariable %7 Function
254        %196 = OpVariable %7 Function
255        %197 = OpVariable %7 Function
256        %114 = OpVariable %113 Function
257        %133 = OpVariable %113 Function
258        %137 = OpVariable %7 Function
259               OpSelectionMerge %164 None
260               OpSwitch %36 %165
261        %165 = OpLabel
262               OpStore %14 %15
263        %101 = OpAccessChain %100 %99 %15 %15
264        %102 = OpLoad %12 %101
265        %103 = OpConvertSToF %6 %102
266        %104 = OpCompositeConstruct %33 %103 %103 %103 %103
267               OpStore %71 %104
268        %105 = OpAccessChain %37 %35 %36
269        %106 = OpLoad %6 %105
270        %107 = OpAccessChain %23 %22 %15 %58
271        %108 = OpLoad %6 %107
272        %109 = OpFOrdLessThan %29 %106 %108
273               OpSelectionMerge %111 None
274               OpBranchConditional %109 %110 %111
275        %110 = OpLabel
276               OpBranch %164
277        %111 = OpLabel
278        %115 = OpLoad %33 %71
279               OpStore %114 %115
280        %118 = OpFOrdGreaterThanEqual %29 %106 %66
281               OpSelectionMerge %120 None
282               OpBranchConditional %118 %119 %120
283        %119 = OpLabel
284        %121 = OpAccessChain %23 %22 %15 %15
285        %122 = OpLoad %6 %121
286        %123 = OpCompositeConstruct %33 %122 %122 %122 %122
287               OpStore %71 %123
288               OpBranch %120
289        %120 = OpLabel
290               OpStore %71 %115
291        %125 = OpAccessChain %37 %35 %95
292        %126 = OpLoad %6 %125
293        %129 = OpFOrdLessThan %29 %126 %108
294               OpSelectionMerge %131 None
295               OpBranchConditional %129 %130 %131
296        %130 = OpLabel
297               OpBranch %164
298        %131 = OpLabel
299        %134 = OpAccessChain %23 %22 %15 %40
300        %135 = OpLoad %6 %134
301        %136 = OpCompositeConstruct %33 %135 %135 %135 %135
302               OpStore %133 %136
303               OpStore %137 %126
304               OpStore %194 %166
305               OpSelectionMerge %245 None
306               OpSwitch %36 %199
307        %199 = OpLabel
308        %200 = OpAccessChain %23 %22 %15 %15
309        %201 = OpLoad %6 %200
310               OpStore %196 %201
311        %202 = OpFOrdLessThan %29 %201 %28
312               OpSelectionMerge %211 None
313               OpBranchConditional %202 %203 %211
314        %203 = OpLabel
315        %204 = OpAccessChain %37 %35 %36
316        %205 = OpLoad %6 %204
317        %206 = OpAccessChain %23 %22 %15 %40
318        %207 = OpLoad %6 %206
319        %208 = OpFOrdLessThan %29 %205 %207
320               OpSelectionMerge %210 None
321               OpBranchConditional %208 %209 %210
322        %209 = OpLabel
323               OpStore %194 %169
324               OpStore %195 %201
325               OpBranch %245
326        %210 = OpLabel
327               OpBranch %211
328        %211 = OpLabel
329               OpBranch %212
330        %212 = OpLabel
331        %213 = OpPhi %6 %201 %211 %219 %232
332        %214 = OpLoad %12 %14
333        %215 = OpSLessThan %29 %214 %55
334               OpLoopMerge %233 %232 None
335               OpBranchConditional %215 %216 %233
336        %216 = OpLabel
337        %217 = OpLoad %12 %14
338        %218 = OpIAdd %12 %217 %58
339               OpStore %14 %218
340        %219 = OpFAdd %6 %213 %201
341               OpStore %196 %219
342        %220 = OpAccessChain %37 %35 %36
343        %221 = OpLoad %6 %220
344        %222 = OpFOrdGreaterThanEqual %29 %221 %66
345               OpSelectionMerge %225 None
346               OpBranchConditional %222 %223 %225
347        %223 = OpLabel
348        %224 = OpCompositeConstruct %33 %201 %201 %201 %201
349               OpStore %71 %224
350               OpBranch %225
351        %225 = OpLabel
352        %227 = OpAccessChain %23 %22 %15 %40
353        %228 = OpLoad %6 %227
354        %229 = OpFOrdLessThan %29 %126 %228
355               OpSelectionMerge %231 None
356               OpBranchConditional %229 %230 %231
357        %230 = OpLabel
358               OpStore %194 %169
359               OpStore %195 %219
360               OpBranch %233
361        %231 = OpLabel
362               OpBranch %232
363        %232 = OpLabel
364               OpBranch %212
365        %233 = OpLabel
366        %234 = OpPhi %6 %192 %212 %219 %230
367        %235 = OpPhi %6 %213 %212 %219 %230
368        %236 = OpPhi %29 %166 %212 %169 %230
369               OpSelectionMerge %237 None
370               OpBranchConditional %236 %245 %237
371        %237 = OpLabel
372               OpBranch %238
373        %238 = OpLabel
374        %239 = OpLoad %12 %14
375        %240 = OpSLessThan %29 %239 %55
376               OpLoopMerge %244 %241 None
377               OpBranchConditional %240 %241 %244
378        %241 = OpLabel
379        %242 = OpLoad %12 %14
380        %243 = OpIAdd %12 %242 %58
381               OpStore %14 %243
382               OpBranch %238
383        %244 = OpLabel
384               OpStore %194 %169
385               OpStore %195 %235
386               OpBranch %245
387        %245 = OpLabel
388        %246 = OpPhi %6 %201 %209 %234 %233 %235 %244
389               OpStore %197 %246
390        %161 = OpCompositeInsert %33 %246 %136 3
391        %163 = OpCompositeInsert %33 %246 %161 0
392               OpStore %133 %163
393               OpSelectionMerge %147 None
394               OpBranchConditional %118 %146 %147
395        %146 = OpLabel
396        %148 = OpAccessChain %23 %22 %15 %15
397        %149 = OpLoad %6 %148
398        %150 = OpCompositeConstruct %33 %149 %149 %149 %149
399               OpStore %71 %150
400               OpBranch %147
401        %147 = OpLabel
402        %155 = OpFOrdLessThan %29 %106 %135
403               OpSelectionMerge %157 None
404               OpBranchConditional %155 %156 %157
405        %156 = OpLabel
406               OpBranch %164
407        %157 = OpLabel
408               OpStore %71 %163
409               OpBranch %164
410        %164 = OpLabel
411               OpReturn
412               OpFunctionEnd
413         %10 = OpFunction %6 None %8
414          %9 = OpFunctionParameter %7
415         %11 = OpLabel
416        %174 = OpVariable %167 Function %166
417        %171 = OpVariable %7 Function
418         %16 = OpVariable %7 Function
419               OpSelectionMerge %170 None
420               OpSwitch %36 %173
421        %173 = OpLabel
422         %24 = OpAccessChain %23 %22 %15 %15
423         %25 = OpLoad %6 %24
424               OpStore %16 %25
425         %30 = OpFOrdLessThan %29 %25 %28
426               OpSelectionMerge %32 None
427               OpBranchConditional %30 %31 %32
428         %31 = OpLabel
429         %38 = OpAccessChain %37 %35 %36
430         %39 = OpLoad %6 %38
431         %41 = OpAccessChain %23 %22 %15 %40
432         %42 = OpLoad %6 %41
433         %43 = OpFOrdLessThan %29 %39 %42
434               OpSelectionMerge %45 None
435               OpBranchConditional %43 %44 %45
436         %44 = OpLabel
437               OpStore %174 %169
438               OpStore %171 %25
439               OpBranch %170
440         %45 = OpLabel
441               OpBranch %32
442         %32 = OpLabel
443               OpBranch %49
444         %49 = OpLabel
445        %179 = OpPhi %6 %25 %32 %63 %52
446         %54 = OpLoad %12 %14
447         %56 = OpSLessThan %29 %54 %55
448               OpLoopMerge %51 %52 None
449               OpBranchConditional %56 %50 %51
450         %50 = OpLabel
451         %57 = OpLoad %12 %14
452         %59 = OpIAdd %12 %57 %58
453               OpStore %14 %59
454         %63 = OpFAdd %6 %179 %25
455               OpStore %16 %63
456         %64 = OpAccessChain %37 %35 %36
457         %65 = OpLoad %6 %64
458         %67 = OpFOrdGreaterThanEqual %29 %65 %66
459               OpSelectionMerge %69 None
460               OpBranchConditional %67 %68 %69
461         %68 = OpLabel
462         %74 = OpCompositeConstruct %33 %25 %25 %25 %25
463               OpStore %71 %74
464               OpBranch %69
465         %69 = OpLabel
466         %75 = OpLoad %6 %9
467         %76 = OpAccessChain %23 %22 %15 %40
468         %77 = OpLoad %6 %76
469         %78 = OpFOrdLessThan %29 %75 %77
470               OpSelectionMerge %80 None
471               OpBranchConditional %78 %79 %80
472         %79 = OpLabel
473               OpStore %174 %169
474               OpStore %171 %63
475               OpBranch %51
476         %80 = OpLabel
477               OpBranch %52
478         %52 = OpLabel
479               OpBranch %49
480         %51 = OpLabel
481        %189 = OpPhi %6 %192 %49 %63 %79
482        %187 = OpPhi %6 %179 %49 %63 %79
483        %182 = OpPhi %29 %166 %49 %169 %79
484               OpSelectionMerge %175 None
485               OpBranchConditional %182 %170 %175
486        %175 = OpLabel
487               OpBranch %83
488         %83 = OpLabel
489         %88 = OpLoad %12 %14
490         %89 = OpSLessThan %29 %88 %55
491               OpLoopMerge %85 %84 None
492               OpBranchConditional %89 %84 %85
493         %84 = OpLabel
494         %90 = OpLoad %12 %14
495         %91 = OpIAdd %12 %90 %58
496               OpStore %14 %91
497               OpBranch %83
498         %85 = OpLabel
499               OpStore %174 %169
500               OpStore %171 %187
501               OpBranch %170
502        %170 = OpLabel
503        %188 = OpPhi %6 %25 %44 %189 %51 %187 %85
504               OpReturnValue %188
505               OpFunctionEnd
506END
507
508# uniforms for variant
509
510# _GLF_uniform_float_values
511BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
512 1.0 0.1 0.0
513END
514# _GLF_uniform_int_values
515BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
516 0
517END
518
519BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
520
521PIPELINE graphics variant_pipeline
522  ATTACH variant_vertex_shader
523  ATTACH variant_fragment_shader
524  FRAMEBUFFER_SIZE 256 256
525  BIND BUFFER variant_framebuffer AS color LOCATION 0
526  BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1
527  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
528END
529CLEAR_COLOR variant_pipeline 0 0 0 255
530
531CLEAR variant_pipeline
532RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
533
534EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
535