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