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