1#!amber
2
3# Copyright 2020 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 GraphicsFuzz.
19
20# Short description: A fragment shader that covers a specific load size reduction path.
21
22# The test passes because shader always writes red.
23
24SHADER vertex variant_vertex_shader PASSTHROUGH
25
26# variant_fragment_shader is derived from the following GLSL:
27# #version 310 es
28# precision highp float;
29# precision highp int;
30#
31# layout(location = 0) out vec4 _GLF_color;
32# layout(set = 0, binding = 0) uniform buf0
33# {
34#     int one;
35# };
36#
37# struct S
38# {
39#     int x;
40#     int y;
41# } ;
42#
43# void func(inout S arg)
44# {
45#     arg.y = 1;
46# }
47#
48# void main()
49# {
50#     float a = 5.0;
51#
52#     do
53#     {
54#         S b[2];
55#         b[one].x = 1;
56#
57#         // Always true.
58#         if (b[1].x == 1)
59#         {
60#             // Always true.
61#             if (one == 1)
62#                 break;
63#
64#             // Unreachable code.
65#             func(b[1]);
66#             a = float(b[1].y);
67#         }
68#
69#         // Unreachable code.
70#         a = 0.0;
71#     }
72#     while(false);
73#
74#     if (a == 5.0)
75#         _GLF_color = vec4(1, 0, 0, 1);
76#     else
77#         _GLF_color = vec4(0);
78# }
79SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
80; SPIR-V
81; Version: 1.0
82; Generator: Khronos Glslang Reference Front End; 8
83; Bound: 71
84; Schema: 0
85               OpCapability Shader
86          %1 = OpExtInstImport "GLSL.std.450"
87               OpMemoryModel Logical GLSL450
88               OpEntryPoint Fragment %4 "main" %66
89               OpExecutionMode %4 OriginUpperLeft
90               OpSource ESSL 310
91               OpName %4 "main"
92               OpName %7 "S"
93               OpMemberName %7 0 "x"
94               OpMemberName %7 1 "y"
95               OpName %11 "func(struct-S-i1-i11;"
96               OpName %10 "arg"
97               OpName %18 "a"
98               OpName %28 "b"
99               OpName %29 "buf0"
100               OpMemberName %29 0 "one"
101               OpName %31 ""
102               OpName %49 "param"
103               OpName %66 "_GLF_color"
104               OpMemberDecorate %29 0 Offset 0
105               OpDecorate %29 Block
106               OpDecorate %31 DescriptorSet 0
107               OpDecorate %31 Binding 0
108               OpDecorate %66 Location 0
109          %2 = OpTypeVoid
110          %3 = OpTypeFunction %2
111          %6 = OpTypeInt 32 1
112          %7 = OpTypeStruct %6 %6
113          %8 = OpTypePointer Function %7
114          %9 = OpTypeFunction %2 %8
115         %13 = OpConstant %6 1
116         %14 = OpTypePointer Function %6
117         %16 = OpTypeFloat 32
118         %17 = OpTypePointer Function %16
119         %19 = OpConstant %16 5
120         %24 = OpTypeInt 32 0
121         %25 = OpConstant %24 2
122         %26 = OpTypeArray %7 %25
123         %27 = OpTypePointer Function %26
124         %29 = OpTypeStruct %6
125         %30 = OpTypePointer Uniform %29
126         %31 = OpVariable %30 Uniform
127         %32 = OpConstant %6 0
128         %33 = OpTypePointer Uniform %6
129         %39 = OpTypeBool
130         %58 = OpConstant %16 0
131         %59 = OpConstantFalse %39
132         %64 = OpTypeVector %16 4
133         %65 = OpTypePointer Output %64
134         %66 = OpVariable %65 Output
135         %67 = OpConstant %16 1
136         %68 = OpConstantComposite %64 %67 %58 %58 %67
137         %70 = OpConstantComposite %64 %58 %58 %58 %58
138          %4 = OpFunction %2 None %3
139          %5 = OpLabel
140         %18 = OpVariable %17 Function
141         %28 = OpVariable %27 Function
142         %49 = OpVariable %8 Function
143               OpStore %18 %19
144               OpBranch %20
145         %20 = OpLabel
146               OpLoopMerge %22 %23 None
147               OpBranch %21
148         %21 = OpLabel
149         %34 = OpAccessChain %33 %31 %32
150         %35 = OpLoad %6 %34
151         %36 = OpAccessChain %14 %28 %35 %32
152               OpStore %36 %13
153         %37 = OpAccessChain %14 %28 %13 %32
154         %38 = OpLoad %6 %37
155         %40 = OpIEqual %39 %38 %13
156               OpSelectionMerge %42 None
157               OpBranchConditional %40 %41 %42
158         %41 = OpLabel
159         %43 = OpAccessChain %33 %31 %32
160         %44 = OpLoad %6 %43
161         %45 = OpIEqual %39 %44 %13
162               OpSelectionMerge %47 None
163               OpBranchConditional %45 %46 %47
164         %46 = OpLabel
165               OpBranch %22
166         %47 = OpLabel
167         %50 = OpAccessChain %8 %28 %13
168         %51 = OpLoad %7 %50
169               OpStore %49 %51
170         %52 = OpFunctionCall %2 %11 %49
171         %53 = OpLoad %7 %49
172         %54 = OpAccessChain %8 %28 %13
173               OpStore %54 %53
174         %55 = OpAccessChain %14 %28 %13 %13
175         %56 = OpLoad %6 %55
176         %57 = OpConvertSToF %16 %56
177               OpStore %18 %57
178               OpBranch %42
179         %42 = OpLabel
180               OpStore %18 %58
181               OpBranch %23
182         %23 = OpLabel
183               OpBranchConditional %59 %20 %22
184         %22 = OpLabel
185         %60 = OpLoad %16 %18
186         %61 = OpFOrdEqual %39 %60 %19
187               OpSelectionMerge %63 None
188               OpBranchConditional %61 %62 %69
189         %62 = OpLabel
190               OpStore %66 %68
191               OpBranch %63
192         %69 = OpLabel
193               OpStore %66 %70
194               OpBranch %63
195         %63 = OpLabel
196               OpReturn
197               OpFunctionEnd
198         %11 = OpFunction %2 None %9
199         %10 = OpFunctionParameter %8
200         %12 = OpLabel
201         %15 = OpAccessChain %14 %10 %13
202               OpStore %15 %13
203               OpReturn
204               OpFunctionEnd
205END
206
207# uniforms for variant
208
209# one
210BUFFER variant_one DATA_TYPE int32 DATA
211 1
212END
213
214BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
215
216PIPELINE graphics variant_pipeline
217  ATTACH variant_vertex_shader
218  ATTACH variant_fragment_shader
219  FRAMEBUFFER_SIZE 256 256
220  BIND BUFFER variant_framebuffer AS color LOCATION 0
221  BIND BUFFER variant_one AS uniform DESCRIPTOR_SET 0 BINDING 0
222END
223CLEAR_COLOR variant_pipeline 0 0 0 255
224
225CLEAR variant_pipeline
226RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
227
228EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
229