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