1#!amber
2
3# Copyright 2019 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 bug found by GraphicsFuzz.
19
20# Short description: A fragment shader with an always false if function
21
22# The test passes because main always writes the color red. (Additionally the discard statement is never reached).
23
24# Optimized using spirv-opt with the following arguments:
25# '--eliminate-local-single-block'
26# '--reduce-load-size'
27# '--combine-access-chains'
28# '--eliminate-local-multi-store'
29# '--reduce-load-size'
30# '--convert-local-access-chains'
31# '--eliminate-dead-branches'
32# '--eliminate-dead-branches'
33# '--merge-return'
34# '--copy-propagate-arrays'
35# '--copy-propagate-arrays'
36# '--eliminate-dead-inserts'
37# '--merge-blocks'
38# '--copy-propagate-arrays'
39# '--combine-access-chains'
40# '--simplify-instructions'
41# '--convert-local-access-chains'
42# spirv-opt commit hash: 4a00a80c40484a6f6f72f48c9d34943cf8f180d4
43
44
45
46SHADER vertex variant_vertex_shader PASSTHROUGH
47
48# variant_fragment_shader is derived from the following GLSL:
49# #version 310 es
50#
51# // END OF GENERATED HEADER
52# precision highp float;
53#
54# layout(location = 0) out vec4 _GLF_color;
55# layout(set = 0, binding = 0) uniform buf0
56# {
57#     vec2 injectionSwitch;
58# };
59#
60# vec3 mand()
61# {
62#     for (
63#         int k = 0;
64#         k < 1000;
65#         1)
66#     {
67#         discard;
68#     }
69#     return vec3(1.0);
70# }
71# void main()
72# {
73#     if (injectionSwitch.x > injectionSwitch.y)
74#     {
75#         for (
76#             int j = 0;
77#             j < 4;
78#             1)
79#         {
80#             mand();
81#         }
82#     }
83#
84#     _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
85#
86# }
87SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
88; SPIR-V
89; Version: 1.0
90; Generator: Khronos Glslang Reference Front End; 7
91; Bound: 64
92; Schema: 0
93               OpCapability Shader
94          %1 = OpExtInstImport "GLSL.std.450"
95               OpMemoryModel Logical GLSL450
96               OpEntryPoint Fragment %4 "main" %57
97               OpExecutionMode %4 OriginUpperLeft
98               OpSource ESSL 310
99               OpName %4 "main"
100               OpName %9 "mand("
101               OpName %13 "k"
102               OpName %31 "buf0"
103               OpMemberName %31 0 "injectionSwitch"
104               OpName %33 ""
105               OpName %45 "j"
106               OpName %57 "_GLF_color"
107               OpDecorate %13 RelaxedPrecision
108               OpMemberDecorate %31 0 Offset 0
109               OpDecorate %31 Block
110               OpDecorate %33 DescriptorSet 0
111               OpDecorate %33 Binding 0
112               OpDecorate %45 RelaxedPrecision
113               OpDecorate %57 Location 0
114               OpDecorate %14 RelaxedPrecision
115          %2 = OpTypeVoid
116          %3 = OpTypeFunction %2
117          %6 = OpTypeFloat 32
118          %7 = OpTypeVector %6 3
119          %8 = OpTypeFunction %7
120         %11 = OpTypeInt 32 1
121         %12 = OpTypePointer Function %11
122         %14 = OpConstant %11 0
123         %21 = OpConstant %11 1000
124         %22 = OpTypeBool
125         %25 = OpConstant %11 1
126         %26 = OpConstant %6 1
127         %27 = OpConstantComposite %7 %26 %26 %26
128         %30 = OpTypeVector %6 2
129         %31 = OpTypeStruct %30
130         %32 = OpTypePointer Uniform %31
131         %33 = OpVariable %32 Uniform
132         %34 = OpTypeInt 32 0
133         %35 = OpConstant %34 0
134         %36 = OpTypePointer Uniform %6
135         %39 = OpConstant %34 1
136         %52 = OpConstant %11 4
137         %55 = OpTypeVector %6 4
138         %56 = OpTypePointer Output %55
139         %57 = OpVariable %56 Output
140         %58 = OpConstant %6 0
141         %59 = OpConstantComposite %55 %26 %58 %58 %26
142         %62 = OpUndef %11
143         %63 = OpConstantTrue %22
144          %4 = OpFunction %2 None %3
145          %5 = OpLabel
146         %45 = OpVariable %12 Function
147         %37 = OpAccessChain %36 %33 %14 %35
148         %38 = OpLoad %6 %37
149         %40 = OpAccessChain %36 %33 %14 %39
150         %41 = OpLoad %6 %40
151         %42 = OpFOrdGreaterThan %22 %38 %41
152               OpSelectionMerge %44 None
153               OpBranchConditional %42 %43 %44
154         %43 = OpLabel
155               OpStore %45 %14
156               OpBranch %46
157         %46 = OpLabel
158               OpLoopMerge %48 %47 None
159               OpBranchConditional %63 %47 %48
160         %47 = OpLabel
161         %54 = OpFunctionCall %7 %9
162               OpBranch %46
163         %48 = OpLabel
164               OpBranch %44
165         %44 = OpLabel
166               OpStore %57 %59
167               OpReturn
168               OpFunctionEnd
169          %9 = OpFunction %7 None %8
170         %10 = OpLabel
171         %13 = OpVariable %12 Function
172               OpStore %13 %14
173               OpBranch %15
174         %15 = OpLabel
175               OpLoopMerge %17 %18 None
176               OpBranchConditional %63 %16 %17
177         %16 = OpLabel
178               OpKill
179         %18 = OpLabel
180               OpBranch %15
181         %17 = OpLabel
182               OpReturnValue %27
183               OpFunctionEnd
184END
185
186# uniforms for variant
187
188# injectionSwitch
189BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
190 0.0 1.0
191END
192
193BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
194
195PIPELINE graphics variant_pipeline
196  ATTACH variant_vertex_shader
197  ATTACH variant_fragment_shader
198  FRAMEBUFFER_SIZE 256 256
199  BIND BUFFER variant_framebuffer AS color LOCATION 0
200  BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
201END
202CLEAR_COLOR variant_pipeline 0 0 0 255
203
204CLEAR variant_pipeline
205RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
206
207EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
208