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# #define _int_1 _GLF_uniform_int_values[0]
29# #define _int_0 _GLF_uniform_int_values[1]
30# #define _float_0_0 _GLF_uniform_float_values[0]
31# #define _float_1_0 _GLF_uniform_float_values[1]
32#
33# precision highp float;
34# precision highp int;
35#
36# // Contents of _GLF_uniform_int_values: [1, 0]
37# layout(set = 0, binding = 0) uniform buf0
38# {
39#     int _GLF_uniform_int_values[2];
40# };
41#
42# // Contents of _GLF_uniform_float_values: [0.0, 1.0]
43# layout(set = 0, binding = 1) uniform buf1
44# {
45#     float _GLF_uniform_float_values[2];
46# };
47#
48# layout(location = 0) out vec4 _GLF_color;
49#
50# void main()
51# {
52#     int a;
53#     float f = _float_0_0;
54#
55#     // Always false.
56#     if(gl_FragCoord.x < _float_0_0)
57#     {
58#         // a is undefined, but this is never executed.
59#         f = ldexp(_float_1_0, (a / int(gl_FragCoord.x)));
60#     }
61#
62#     // Always true.
63#     if(f == _float_0_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: 75
77; Schema: 0
78               OpCapability Shader
79          %1 = OpExtInstImport "GLSL.std.450"
80               OpMemoryModel Logical GLSL450
81               OpEntryPoint Fragment %4 "main" %22 %51
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 %22 "gl_FragCoord"
90               OpName %37 "a"
91               OpName %51 "_GLF_color"
92               OpName %53 "buf0"
93               OpMemberName %53 0 "_GLF_uniform_int_values"
94               OpName %55 ""
95               OpDecorate %11 ArrayStride 16
96               OpMemberDecorate %12 0 Offset 0
97               OpDecorate %12 Block
98               OpDecorate %14 DescriptorSet 0
99               OpDecorate %14 Binding 1
100               OpDecorate %22 BuiltIn FragCoord
101               OpDecorate %51 Location 0
102               OpDecorate %52 ArrayStride 16
103               OpMemberDecorate %53 0 Offset 0
104               OpDecorate %53 Block
105               OpDecorate %55 DescriptorSet 0
106               OpDecorate %55 Binding 0
107          %2 = OpTypeVoid
108          %3 = OpTypeFunction %2
109          %6 = OpTypeFloat 32
110          %7 = OpTypePointer Function %6
111          %9 = OpTypeInt 32 0
112         %10 = OpConstant %9 2
113         %11 = OpTypeArray %6 %10
114         %12 = OpTypeStruct %11
115         %13 = OpTypePointer Uniform %12
116         %14 = OpVariable %13 Uniform
117         %15 = OpTypeInt 32 1
118         %16 = OpConstant %15 0
119         %17 = OpTypePointer Uniform %6
120         %20 = OpTypeVector %6 4
121         %21 = OpTypePointer Input %20
122         %22 = OpVariable %21 Input
123         %23 = OpConstant %9 0
124         %24 = OpTypePointer Input %6
125         %29 = OpTypeBool
126         %33 = OpConstant %15 1
127         %36 = OpTypePointer Function %15
128         %50 = OpTypePointer Output %20
129         %51 = OpVariable %50 Output
130         %52 = OpTypeArray %15 %10
131         %53 = OpTypeStruct %52
132         %54 = OpTypePointer Uniform %53
133         %55 = OpVariable %54 Uniform
134         %56 = OpTypePointer Uniform %15
135          %4 = OpFunction %2 None %3
136          %5 = OpLabel
137          %8 = OpVariable %7 Function
138         %37 = OpVariable %36 Function
139         %18 = OpAccessChain %17 %14 %16 %16
140         %19 = OpLoad %6 %18
141               OpStore %8 %19
142         %25 = OpAccessChain %24 %22 %23
143         %26 = OpLoad %6 %25
144         %27 = OpAccessChain %17 %14 %16 %16
145         %28 = OpLoad %6 %27
146         %30 = OpFOrdLessThan %29 %26 %28
147               OpSelectionMerge %32 None
148               OpBranchConditional %30 %31 %32
149         %31 = OpLabel
150         %34 = OpAccessChain %17 %14 %16 %33
151         %35 = OpLoad %6 %34
152         %38 = OpLoad %15 %37
153         %39 = OpAccessChain %24 %22 %23
154         %40 = OpLoad %6 %39
155         %41 = OpConvertFToS %15 %40
156         %42 = OpSDiv %15 %38 %41
157         %43 = OpExtInst %6 %1 Ldexp %35 %42
158               OpStore %8 %43
159               OpBranch %32
160         %32 = OpLabel
161         %44 = OpLoad %6 %8
162         %45 = OpAccessChain %17 %14 %16 %16
163         %46 = OpLoad %6 %45
164         %47 = OpFOrdEqual %29 %44 %46
165               OpSelectionMerge %49 None
166               OpBranchConditional %47 %48 %70
167         %48 = OpLabel
168         %57 = OpAccessChain %56 %55 %16 %16
169         %58 = OpLoad %15 %57
170         %59 = OpConvertSToF %6 %58
171         %60 = OpAccessChain %56 %55 %16 %33
172         %61 = OpLoad %15 %60
173         %62 = OpConvertSToF %6 %61
174         %63 = OpAccessChain %56 %55 %16 %33
175         %64 = OpLoad %15 %63
176         %65 = OpConvertSToF %6 %64
177         %66 = OpAccessChain %56 %55 %16 %16
178         %67 = OpLoad %15 %66
179         %68 = OpConvertSToF %6 %67
180         %69 = OpCompositeConstruct %20 %59 %62 %65 %68
181               OpStore %51 %69
182               OpBranch %49
183         %70 = OpLabel
184         %71 = OpAccessChain %56 %55 %16 %33
185         %72 = OpLoad %15 %71
186         %73 = OpConvertSToF %6 %72
187         %74 = OpCompositeConstruct %20 %73 %73 %73 %73
188               OpStore %51 %74
189               OpBranch %49
190         %49 = OpLabel
191               OpReturn
192               OpFunctionEnd
193END
194
195# uniforms for variant
196
197# _GLF_uniform_float_values
198BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
199 0.0 1.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 256 256
212  BIND BUFFER variant_framebuffer AS color LOCATION 0
213  BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1
214  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
215END
216CLEAR_COLOR variant_pipeline 0 0 0 255
217
218CLEAR variant_pipeline
219RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
220
221EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
222