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