1#!amber
2
3# Copyright 2022 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# #define _int_1 _GLF_uniform_int_values[0]
29# #define _int_0 _GLF_uniform_int_values[1]
30# #define _int_8 _GLF_uniform_int_values[2]
31# #define _float_0_0 _GLF_uniform_float_values[0]
32#
33# precision highp float;
34# precision highp int;
35#
36# // Contents of _GLF_uniform_int_values: [1, 0, 8]
37# layout(set = 0, binding = 0) uniform buf0
38# {
39#     int _GLF_uniform_int_values[3];
40# };
41#
42# // Contents of _GLF_uniform_float_values: 0.0
43# layout(set = 0, binding = 1) uniform buf1
44# {
45#     float _GLF_uniform_float_values[1];
46# };
47#
48# layout(location = 0) out vec4 _GLF_color;
49#
50# void main()
51# {
52#     int a = _int_0;
53#
54#     // Iterates i = 1, 2, 4, 8.
55#     for(int i = 1; i <= 10; i *= 2)
56#     {
57#         for(int j = 0; j < 10; j += i)
58#         {
59#             int b = j + i - 1;
60#             // For the last iteration of the outer loop i = 8 and j iterates values 0 and 8.
61#             // The last assignment to a is 8.
62#             a = j;
63#
64#
65#             // The condition of the while loop below can be opened as follows:
66#             // a <= b <= 1
67#             // j <= j + i - 1 <= 1
68#             //
69#             // Because j <= 1 the values for j can be 0 and 1.
70#             // Therefore j + i - 1 <= 1 gives us:
71#             // 0 + i - 1 <= 1
72#             // i <= 2
73#             // and
74#             // 1 + i - 1 <= 1
75#             // i <= 1
76#             //
77#             // i starts at one so the condition is true when i = 1 or 2 and j = 0 or 1.
78#
79#             // This condition is false during the last iteration of i = 8 and j = 8.
80#             while(a <= b && b <= 1)
81#             {
82#                 // Always false.
83#                 if(gl_FragCoord.x < _float_0_0)
84#                 {
85#                     discard;
86#                 }
87#                 a++;
88#             }
89#         }
90#     }
91#
92#     // Always true. The last iteration assigned i = 8 but didn't increment it in a while loop.
93#     if(a == _int_8)
94#     {
95#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
96#     }
97#     else
98#     {
99#         _GLF_color = vec4(_int_0);
100#     }
101# }
102SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
103; SPIR-V
104; Version: 1.0
105; Generator: Khronos Glslang Reference Front End; 10
106; Bound: 109
107; Schema: 0
108               OpCapability Shader
109          %1 = OpExtInstImport "GLSL.std.450"
110               OpMemoryModel Logical GLSL450
111               OpEntryPoint Fragment %4 "main" %58 %90
112               OpExecutionMode %4 OriginUpperLeft
113               OpSource ESSL 320
114               OpName %4 "main"
115               OpName %8 "a"
116               OpName %12 "buf0"
117               OpMemberName %12 0 "_GLF_uniform_int_values"
118               OpName %14 ""
119               OpName %20 "i"
120               OpName %30 "j"
121               OpName %38 "b"
122               OpName %58 "gl_FragCoord"
123               OpName %65 "buf1"
124               OpMemberName %65 0 "_GLF_uniform_float_values"
125               OpName %67 ""
126               OpName %90 "_GLF_color"
127               OpDecorate %11 ArrayStride 16
128               OpMemberDecorate %12 0 Offset 0
129               OpDecorate %12 Block
130               OpDecorate %14 DescriptorSet 0
131               OpDecorate %14 Binding 0
132               OpDecorate %58 BuiltIn FragCoord
133               OpDecorate %64 ArrayStride 16
134               OpMemberDecorate %65 0 Offset 0
135               OpDecorate %65 Block
136               OpDecorate %67 DescriptorSet 0
137               OpDecorate %67 Binding 1
138               OpDecorate %90 Location 0
139          %2 = OpTypeVoid
140          %3 = OpTypeFunction %2
141          %6 = OpTypeInt 32 1
142          %7 = OpTypePointer Function %6
143          %9 = OpTypeInt 32 0
144         %10 = OpConstant %9 3
145         %11 = OpTypeArray %6 %10
146         %12 = OpTypeStruct %11
147         %13 = OpTypePointer Uniform %12
148         %14 = OpVariable %13 Uniform
149         %15 = OpConstant %6 0
150         %16 = OpConstant %6 1
151         %17 = OpTypePointer Uniform %6
152         %27 = OpConstant %6 10
153         %28 = OpTypeBool
154         %55 = OpTypeFloat 32
155         %56 = OpTypeVector %55 4
156         %57 = OpTypePointer Input %56
157         %58 = OpVariable %57 Input
158         %59 = OpConstant %9 0
159         %60 = OpTypePointer Input %55
160         %63 = OpConstant %9 1
161         %64 = OpTypeArray %55 %63
162         %65 = OpTypeStruct %64
163         %66 = OpTypePointer Uniform %65
164         %67 = OpVariable %66 Uniform
165         %68 = OpTypePointer Uniform %55
166         %80 = OpConstant %6 2
167         %89 = OpTypePointer Output %56
168         %90 = OpVariable %89 Output
169          %4 = OpFunction %2 None %3
170          %5 = OpLabel
171          %8 = OpVariable %7 Function
172         %20 = OpVariable %7 Function
173         %30 = OpVariable %7 Function
174         %38 = OpVariable %7 Function
175         %18 = OpAccessChain %17 %14 %15 %16
176         %19 = OpLoad %6 %18
177               OpStore %8 %19
178               OpStore %20 %16
179               OpBranch %21
180         %21 = OpLabel
181               OpLoopMerge %23 %24 None
182               OpBranch %25
183         %25 = OpLabel
184         %26 = OpLoad %6 %20
185         %29 = OpSLessThanEqual %28 %26 %27
186               OpBranchConditional %29 %22 %23
187         %22 = OpLabel
188               OpStore %30 %15
189               OpBranch %31
190         %31 = OpLabel
191               OpLoopMerge %33 %34 None
192               OpBranch %35
193         %35 = OpLabel
194         %36 = OpLoad %6 %30
195         %37 = OpSLessThan %28 %36 %27
196               OpBranchConditional %37 %32 %33
197         %32 = OpLabel
198         %39 = OpLoad %6 %30
199         %40 = OpLoad %6 %20
200         %41 = OpIAdd %6 %39 %40
201         %42 = OpISub %6 %41 %16
202               OpStore %38 %42
203         %43 = OpLoad %6 %30
204               OpStore %8 %43
205               OpBranch %44
206         %44 = OpLabel
207               OpLoopMerge %46 %47 None
208               OpBranch %48
209         %48 = OpLabel
210         %49 = OpLoad %6 %8
211         %50 = OpLoad %6 %38
212         %51 = OpSLessThanEqual %28 %49 %50
213         %52 = OpLoad %6 %38
214         %53 = OpSLessThanEqual %28 %52 %16
215         %54 = OpLogicalAnd %28 %51 %53
216               OpBranchConditional %54 %45 %46
217         %45 = OpLabel
218         %61 = OpAccessChain %60 %58 %59
219         %62 = OpLoad %55 %61
220         %69 = OpAccessChain %68 %67 %15 %15
221         %70 = OpLoad %55 %69
222         %71 = OpFOrdLessThan %28 %62 %70
223               OpSelectionMerge %73 None
224               OpBranchConditional %71 %72 %73
225         %72 = OpLabel
226               OpKill
227         %73 = OpLabel
228         %75 = OpLoad %6 %8
229         %76 = OpIAdd %6 %75 %16
230               OpStore %8 %76
231               OpBranch %47
232         %47 = OpLabel
233               OpBranch %44
234         %46 = OpLabel
235               OpBranch %34
236         %34 = OpLabel
237         %77 = OpLoad %6 %20
238         %78 = OpLoad %6 %30
239         %79 = OpIAdd %6 %78 %77
240               OpStore %30 %79
241               OpBranch %31
242         %33 = OpLabel
243               OpBranch %24
244         %24 = OpLabel
245         %81 = OpLoad %6 %20
246         %82 = OpIMul %6 %81 %80
247               OpStore %20 %82
248               OpBranch %21
249         %23 = OpLabel
250         %83 = OpLoad %6 %8
251         %84 = OpAccessChain %17 %14 %15 %80
252         %85 = OpLoad %6 %84
253         %86 = OpIEqual %28 %83 %85
254               OpSelectionMerge %88 None
255               OpBranchConditional %86 %87 %104
256         %87 = OpLabel
257         %91 = OpAccessChain %17 %14 %15 %15
258         %92 = OpLoad %6 %91
259         %93 = OpConvertSToF %55 %92
260         %94 = OpAccessChain %17 %14 %15 %16
261         %95 = OpLoad %6 %94
262         %96 = OpConvertSToF %55 %95
263         %97 = OpAccessChain %17 %14 %15 %16
264         %98 = OpLoad %6 %97
265         %99 = OpConvertSToF %55 %98
266        %100 = OpAccessChain %17 %14 %15 %15
267        %101 = OpLoad %6 %100
268        %102 = OpConvertSToF %55 %101
269        %103 = OpCompositeConstruct %56 %93 %96 %99 %102
270               OpStore %90 %103
271               OpBranch %88
272        %104 = OpLabel
273        %105 = OpAccessChain %17 %14 %15 %16
274        %106 = OpLoad %6 %105
275        %107 = OpConvertSToF %55 %106
276        %108 = OpCompositeConstruct %56 %107 %107 %107 %107
277               OpStore %90 %108
278               OpBranch %88
279         %88 = OpLabel
280               OpReturn
281               OpFunctionEnd
282END
283
284# uniforms for variant
285
286# _GLF_uniform_float_values
287BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
288 0.0
289END
290# _GLF_uniform_int_values
291BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
292 1 0 8
293END
294
295BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
296
297PIPELINE graphics variant_pipeline
298  ATTACH variant_vertex_shader
299  ATTACH variant_fragment_shader
300  FRAMEBUFFER_SIZE 32 32
301  BIND BUFFER variant_framebuffer AS color LOCATION 0
302  BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1
303  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
304END
305CLEAR_COLOR variant_pipeline 0 0 0 255
306
307CLEAR variant_pipeline
308RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
309
310EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255
311