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