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