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