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