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