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 _float_1_0 _GLF_uniform_float_values[0]
31#
32# precision highp float;
33# precision highp int;
34#
35# // Contents of _GLF_uniform_int_values: [1, 0]
36# layout(set = 0, binding = 0) uniform buf0
37# {
38#     int _GLF_uniform_int_values[2];
39# };
40#
41# // Contents of _GLF_uniform_float_values: 1.0
42# layout(set = 0, binding = 1) uniform buf1
43# {
44#     float _GLF_uniform_float_values[1];
45# };
46#
47# const int _GLF_global_loop_bound = 10;
48# int _GLF_global_loop_count = 0;
49#
50# layout(location = 0) out vec4 _GLF_color;
51#
52# int func(float x)
53# {
54#     for(int i = 1; i < 800 && _GLF_global_loop_count < _GLF_global_loop_bound; i++)
55#     {
56#         _GLF_global_loop_count++;
57#
58#         if(float(i) >= x)
59#         {
60#             return _int_1;
61#         }
62#     }
63#
64#     return 0;
65# }
66#
67# void main()
68# {
69#     // func returns one.
70#     int a = func(_float_1_0);
71#     // func returns zero because global loop count has been reached.
72#     a += func(35.61);
73#
74#     // Always true.
75#     if(a == 1)
76#     {
77#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
78#     }
79#     else
80#     {
81#         _GLF_color = vec4(_int_0);
82#     }
83# }
84SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
85; SPIR-V
86; Version: 1.0
87; Generator: Khronos Glslang Reference Front End; 10
88; Bound: 95
89; Schema: 0
90               OpCapability Shader
91          %1 = OpExtInstImport "GLSL.std.450"
92               OpMemoryModel Logical GLSL450
93               OpEntryPoint Fragment %4 "main" %76
94               OpExecutionMode %4 OriginUpperLeft
95               OpSource ESSL 320
96               OpName %4 "main"
97               OpName %11 "func(f1;"
98               OpName %10 "x"
99               OpName %14 "_GLF_global_loop_count"
100               OpName %17 "i"
101               OpName %43 "buf0"
102               OpMemberName %43 0 "_GLF_uniform_int_values"
103               OpName %45 ""
104               OpName %54 "a"
105               OpName %57 "buf1"
106               OpMemberName %57 0 "_GLF_uniform_float_values"
107               OpName %59 ""
108               OpName %60 "param"
109               OpName %66 "param"
110               OpName %76 "_GLF_color"
111               OpDecorate %42 ArrayStride 16
112               OpMemberDecorate %43 0 Offset 0
113               OpDecorate %43 Block
114               OpDecorate %45 DescriptorSet 0
115               OpDecorate %45 Binding 0
116               OpDecorate %56 ArrayStride 16
117               OpMemberDecorate %57 0 Offset 0
118               OpDecorate %57 Block
119               OpDecorate %59 DescriptorSet 0
120               OpDecorate %59 Binding 1
121               OpDecorate %76 Location 0
122          %2 = OpTypeVoid
123          %3 = OpTypeFunction %2
124          %6 = OpTypeFloat 32
125          %7 = OpTypePointer Function %6
126          %8 = OpTypeInt 32 1
127          %9 = OpTypeFunction %8 %7
128         %13 = OpTypePointer Private %8
129         %14 = OpVariable %13 Private
130         %15 = OpConstant %8 0
131         %16 = OpTypePointer Function %8
132         %18 = OpConstant %8 1
133         %25 = OpConstant %8 800
134         %26 = OpTypeBool
135         %29 = OpConstant %8 10
136         %40 = OpTypeInt 32 0
137         %41 = OpConstant %40 2
138         %42 = OpTypeArray %8 %41
139         %43 = OpTypeStruct %42
140         %44 = OpTypePointer Uniform %43
141         %45 = OpVariable %44 Uniform
142         %46 = OpTypePointer Uniform %8
143         %55 = OpConstant %40 1
144         %56 = OpTypeArray %6 %55
145         %57 = OpTypeStruct %56
146         %58 = OpTypePointer Uniform %57
147         %59 = OpVariable %58 Uniform
148         %61 = OpTypePointer Uniform %6
149         %65 = OpConstant %6 35.6100006
150         %74 = OpTypeVector %6 4
151         %75 = OpTypePointer Output %74
152         %76 = OpVariable %75 Output
153          %4 = OpFunction %2 None %3
154          %5 = OpLabel
155         %54 = OpVariable %16 Function
156         %60 = OpVariable %7 Function
157         %66 = OpVariable %7 Function
158               OpStore %14 %15
159         %62 = OpAccessChain %61 %59 %15 %15
160         %63 = OpLoad %6 %62
161               OpStore %60 %63
162         %64 = OpFunctionCall %8 %11 %60
163               OpStore %54 %64
164               OpStore %66 %65
165         %67 = OpFunctionCall %8 %11 %66
166         %68 = OpLoad %8 %54
167         %69 = OpIAdd %8 %68 %67
168               OpStore %54 %69
169         %70 = OpLoad %8 %54
170         %71 = OpIEqual %26 %70 %18
171               OpSelectionMerge %73 None
172               OpBranchConditional %71 %72 %90
173         %72 = OpLabel
174         %77 = OpAccessChain %46 %45 %15 %15
175         %78 = OpLoad %8 %77
176         %79 = OpConvertSToF %6 %78
177         %80 = OpAccessChain %46 %45 %15 %18
178         %81 = OpLoad %8 %80
179         %82 = OpConvertSToF %6 %81
180         %83 = OpAccessChain %46 %45 %15 %18
181         %84 = OpLoad %8 %83
182         %85 = OpConvertSToF %6 %84
183         %86 = OpAccessChain %46 %45 %15 %15
184         %87 = OpLoad %8 %86
185         %88 = OpConvertSToF %6 %87
186         %89 = OpCompositeConstruct %74 %79 %82 %85 %88
187               OpStore %76 %89
188               OpBranch %73
189         %90 = OpLabel
190         %91 = OpAccessChain %46 %45 %15 %18
191         %92 = OpLoad %8 %91
192         %93 = OpConvertSToF %6 %92
193         %94 = OpCompositeConstruct %74 %93 %93 %93 %93
194               OpStore %76 %94
195               OpBranch %73
196         %73 = OpLabel
197               OpReturn
198               OpFunctionEnd
199         %11 = OpFunction %8 None %9
200         %10 = OpFunctionParameter %7
201         %12 = OpLabel
202         %17 = OpVariable %16 Function
203               OpStore %17 %18
204               OpBranch %19
205         %19 = OpLabel
206               OpLoopMerge %21 %22 None
207               OpBranch %23
208         %23 = OpLabel
209         %24 = OpLoad %8 %17
210         %27 = OpSLessThan %26 %24 %25
211         %28 = OpLoad %8 %14
212         %30 = OpSLessThan %26 %28 %29
213         %31 = OpLogicalAnd %26 %27 %30
214               OpBranchConditional %31 %20 %21
215         %20 = OpLabel
216         %32 = OpLoad %8 %14
217         %33 = OpIAdd %8 %32 %18
218               OpStore %14 %33
219         %34 = OpLoad %8 %17
220         %35 = OpConvertSToF %6 %34
221         %36 = OpLoad %6 %10
222         %37 = OpFOrdGreaterThanEqual %26 %35 %36
223               OpSelectionMerge %39 None
224               OpBranchConditional %37 %38 %39
225         %38 = OpLabel
226         %47 = OpAccessChain %46 %45 %15 %15
227         %48 = OpLoad %8 %47
228               OpReturnValue %48
229         %39 = OpLabel
230               OpBranch %22
231         %22 = OpLabel
232         %50 = OpLoad %8 %17
233         %51 = OpIAdd %8 %50 %18
234               OpStore %17 %51
235               OpBranch %19
236         %21 = OpLabel
237               OpReturnValue %15
238               OpFunctionEnd
239END
240
241# uniforms for variant
242
243# _GLF_uniform_float_values
244BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
245 1.0
246END
247# _GLF_uniform_int_values
248BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
249 1 0
250END
251
252BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
253
254PIPELINE graphics variant_pipeline
255  ATTACH variant_vertex_shader
256  ATTACH variant_fragment_shader
257  FRAMEBUFFER_SIZE 32 32
258  BIND BUFFER variant_framebuffer AS color LOCATION 0
259  BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1
260  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
261END
262CLEAR_COLOR variant_pipeline 0 0 0 255
263
264CLEAR variant_pipeline
265RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
266
267EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255
268