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_2_0 _GLF_uniform_float_values[0]
31# #define _float_5_0 _GLF_uniform_float_values[1]
32# #define _float_0_0 _GLF_uniform_float_values[2]
33#
34# precision highp float;
35# precision highp int;
36#
37# // Contents of _GLF_uniform_int_values: [1, 0]
38# layout(set = 0, binding = 0) uniform buf0
39# {
40#     int _GLF_uniform_int_values[2];
41# };
42#
43# // Contents of _GLF_uniform_float_values: [2.0, 5.0, 0.0]
44# layout(set = 0, binding = 1) uniform buf1
45# {
46#     float _GLF_uniform_float_values[3];
47# };
48#
49# // Contents of three: 3
50# layout(set = 0, binding = 2) uniform buf2
51# {
52#     int three;
53# };
54#
55# layout(location = 0) out vec4 _GLF_color;
56#
57# void main()
58# {
59#     // f = clamp(5.0, 0.0, min(bitcount(3), bitcount(3))) = clamp(5.0, 0.0, 2.0) = 2.0
60#     float f = clamp(_float_5_0, _float_0_0, float(min(bitCount(three), bitCount(three))));
61#
62#     // Always true.
63#     if(f == _float_2_0)
64#     {
65#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
66#     }
67#     else
68#     {
69#         _GLF_color = vec4(_int_0);
70#     }
71# }
72SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
73; SPIR-V
74; Version: 1.0
75; Generator: Khronos Glslang Reference Front End; 10
76; Bound: 70
77; Schema: 0
78               OpCapability Shader
79          %1 = OpExtInstImport "GLSL.std.450"
80               OpMemoryModel Logical GLSL450
81               OpEntryPoint Fragment %4 "main" %46
82               OpExecutionMode %4 OriginUpperLeft
83               OpSource ESSL 320
84               OpName %4 "main"
85               OpName %8 "f"
86               OpName %12 "buf1"
87               OpMemberName %12 0 "_GLF_uniform_float_values"
88               OpName %14 ""
89               OpName %24 "buf2"
90               OpMemberName %24 0 "three"
91               OpName %26 ""
92               OpName %46 "_GLF_color"
93               OpName %49 "buf0"
94               OpMemberName %49 0 "_GLF_uniform_int_values"
95               OpName %51 ""
96               OpDecorate %11 ArrayStride 16
97               OpMemberDecorate %12 0 Offset 0
98               OpDecorate %12 Block
99               OpDecorate %14 DescriptorSet 0
100               OpDecorate %14 Binding 1
101               OpMemberDecorate %24 0 Offset 0
102               OpDecorate %24 Block
103               OpDecorate %26 DescriptorSet 0
104               OpDecorate %26 Binding 2
105               OpDecorate %34 RelaxedPrecision
106               OpDecorate %46 Location 0
107               OpDecorate %48 ArrayStride 16
108               OpMemberDecorate %49 0 Offset 0
109               OpDecorate %49 Block
110               OpDecorate %51 DescriptorSet 0
111               OpDecorate %51 Binding 0
112          %2 = OpTypeVoid
113          %3 = OpTypeFunction %2
114          %6 = OpTypeFloat 32
115          %7 = OpTypePointer Function %6
116          %9 = OpTypeInt 32 0
117         %10 = OpConstant %9 3
118         %11 = OpTypeArray %6 %10
119         %12 = OpTypeStruct %11
120         %13 = OpTypePointer Uniform %12
121         %14 = OpVariable %13 Uniform
122         %15 = OpTypeInt 32 1
123         %16 = OpConstant %15 0
124         %17 = OpConstant %15 1
125         %18 = OpTypePointer Uniform %6
126         %21 = OpConstant %15 2
127         %24 = OpTypeStruct %15
128         %25 = OpTypePointer Uniform %24
129         %26 = OpVariable %25 Uniform
130         %27 = OpTypePointer Uniform %15
131         %40 = OpTypeBool
132         %44 = OpTypeVector %6 4
133         %45 = OpTypePointer Output %44
134         %46 = OpVariable %45 Output
135         %47 = OpConstant %9 2
136         %48 = OpTypeArray %15 %47
137         %49 = OpTypeStruct %48
138         %50 = OpTypePointer Uniform %49
139         %51 = OpVariable %50 Uniform
140          %4 = OpFunction %2 None %3
141          %5 = OpLabel
142          %8 = OpVariable %7 Function
143         %19 = OpAccessChain %18 %14 %16 %17
144         %20 = OpLoad %6 %19
145         %22 = OpAccessChain %18 %14 %16 %21
146         %23 = OpLoad %6 %22
147         %28 = OpAccessChain %27 %26 %16
148         %29 = OpLoad %15 %28
149         %30 = OpBitCount %15 %29
150         %31 = OpAccessChain %27 %26 %16
151         %32 = OpLoad %15 %31
152         %33 = OpBitCount %15 %32
153         %34 = OpExtInst %15 %1 SMin %30 %33
154         %35 = OpConvertSToF %6 %34
155         %36 = OpExtInst %6 %1 FClamp %20 %23 %35
156               OpStore %8 %36
157         %37 = OpLoad %6 %8
158         %38 = OpAccessChain %18 %14 %16 %16
159         %39 = OpLoad %6 %38
160         %41 = OpFOrdEqual %40 %37 %39
161               OpSelectionMerge %43 None
162               OpBranchConditional %41 %42 %65
163         %42 = OpLabel
164         %52 = OpAccessChain %27 %51 %16 %16
165         %53 = OpLoad %15 %52
166         %54 = OpConvertSToF %6 %53
167         %55 = OpAccessChain %27 %51 %16 %17
168         %56 = OpLoad %15 %55
169         %57 = OpConvertSToF %6 %56
170         %58 = OpAccessChain %27 %51 %16 %17
171         %59 = OpLoad %15 %58
172         %60 = OpConvertSToF %6 %59
173         %61 = OpAccessChain %27 %51 %16 %16
174         %62 = OpLoad %15 %61
175         %63 = OpConvertSToF %6 %62
176         %64 = OpCompositeConstruct %44 %54 %57 %60 %63
177               OpStore %46 %64
178               OpBranch %43
179         %65 = OpLabel
180         %66 = OpAccessChain %27 %51 %16 %17
181         %67 = OpLoad %15 %66
182         %68 = OpConvertSToF %6 %67
183         %69 = OpCompositeConstruct %44 %68 %68 %68 %68
184               OpStore %46 %69
185               OpBranch %43
186         %43 = OpLabel
187               OpReturn
188               OpFunctionEnd
189END
190
191# uniforms for variant
192
193# three
194BUFFER variant_three DATA_TYPE int32 STD140 DATA
195 3
196END
197# _GLF_uniform_float_values
198BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
199 2.0 5.0 0.0
200END
201# _GLF_uniform_int_values
202BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
203 1 0
204END
205
206BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
207
208PIPELINE graphics variant_pipeline
209  ATTACH variant_vertex_shader
210  ATTACH variant_fragment_shader
211  FRAMEBUFFER_SIZE 32 32
212  BIND BUFFER variant_framebuffer AS color LOCATION 0
213  BIND BUFFER variant_three AS uniform DESCRIPTOR_SET 0 BINDING 2
214  BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1
215  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
216END
217CLEAR_COLOR variant_pipeline 0 0 0 255
218
219CLEAR variant_pipeline
220RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
221
222EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255
223