3 # Copyright 2020 Google LLC
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 # A test for a bug found by the GraphicsFuzz project.
20 # Short description: A fragment shader with recurrent always false if statement
22 # The test passes because the shader always writes color red.
24 # Optimized using spirv-opt with the following arguments:
27 # '--scalar-replacement=100'
28 # '--redundancy-elimination'
29 # '--redundancy-elimination'
30 # '--eliminate-dead-branches'
31 # '--eliminate-dead-branches'
33 # '--scalar-replacement=100'
34 # '--reduce-load-size'
35 # '--copy-propagate-arrays'
36 # '--eliminate-dead-branches'
38 # '--eliminate-dead-code-aggressive'
39 # '--inline-entry-points-exhaustive'
40 # '--simplify-instructions'
41 # '--redundancy-elimination'
43 # '--eliminate-local-single-block'
44 # '--scalar-replacement=100'
45 # '--reduce-load-size'
46 # '--eliminate-local-single-block'
47 # '--reduce-load-size'
48 # '--eliminate-local-single-store'
49 # '--inline-entry-points-exhaustive'
50 # spirv-opt commit hash: 230f363e6da32791f640b02205e0645cc67c3f1d
54 SHADER vertex variant_vertex_shader PASSTHROUGH
56 # variant_fragment_shader is derived from the following GLSL:
58 # precision highp float;
60 # precision highp int;
63 # layout(location = 0) out vec4 _GLF_color;
65 # layout(set = 0, binding = 0) uniform buf0
67 # vec2 injectionSwitch; // x == 0.0, y == 1.0
71 # const int loop_limit = 100;
74 # if (injectionSwitch.x > injectionSwitch.y)
79 # gl_FragCoord.x < log(1.0);
80 # for (; loop_count < loop_limit; loop_count++)
83 # if (injectionSwitch.x > injectionSwitch.y)
88 # if (injectionSwitch.x > injectionSwitch.y)
90 # _GLF_color = vec4(1.0);
95 # if (gl_FragCoord.x < 0.0)
101 # if (injectionSwitch.x > injectionSwitch.y)
103 # _GLF_color = vec4(1.0);
107 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
110 # if (injectionSwitch.x > injectionSwitch.y)
115 # if (gl_FragCoord.x < 0.0)
117 # for (; loop_count < loop_limit; loop_count++)
122 # if(loop_count >= loop_limit)
124 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
128 # _GLF_color = vec4(1.0);
131 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
134 ; Generator: Khronos Glslang Reference Front End; 10
138 %1 = OpExtInstImport "GLSL.std.450"
139 OpMemoryModel Logical GLSL450
140 OpEntryPoint Fragment %4 "main" %30 %60
141 OpExecutionMode %4 OriginUpperLeft
144 OpName %8 "loop_count"
146 OpMemberName %12 0 "injectionSwitch"
148 OpName %30 "gl_FragCoord"
149 OpName %60 "_GLF_color"
150 OpMemberDecorate %12 0 Offset 0
152 OpDecorate %14 DescriptorSet 0
153 OpDecorate %14 Binding 0
154 OpDecorate %30 BuiltIn FragCoord
155 OpDecorate %60 Location 0
157 %3 = OpTypeFunction %2
159 %7 = OpTypePointer Function %6
162 %11 = OpTypeVector %10 2
163 %12 = OpTypeStruct %11
164 %13 = OpTypePointer Uniform %12
165 %14 = OpVariable %13 Uniform
167 %16 = OpConstant %15 0
168 %17 = OpTypePointer Uniform %10
169 %20 = OpConstant %15 1
171 %28 = OpTypeVector %10 4
172 %29 = OpTypePointer Input %28
173 %30 = OpVariable %29 Input
174 %31 = OpTypePointer Input %10
175 %34 = OpConstant %10 0
176 %42 = OpConstant %6 100
177 %59 = OpTypePointer Output %28
178 %60 = OpVariable %59 Output
179 %61 = OpConstant %10 1
180 %62 = OpConstantComposite %28 %61 %61 %61 %61
181 %78 = OpConstantComposite %28 %61 %34 %34 %61
182 %100 = OpConstant %6 1
183 %4 = OpFunction %2 None %3
185 %8 = OpVariable %7 Function
187 %18 = OpAccessChain %17 %14 %9 %16
189 %21 = OpAccessChain %17 %14 %9 %20
191 %24 = OpFOrdGreaterThan %23 %19 %22
192 OpSelectionMerge %26 None
193 OpBranchConditional %24 %25 %26
197 %32 = OpAccessChain %31 %30 %16
199 %35 = OpFOrdLessThan %23 %33 %34
203 %43 = OpSLessThan %23 %41 %42
204 OpLoopMerge %38 %39 None
205 OpBranchConditional %43 %37 %38
207 OpSelectionMerge %50 None
208 OpBranchConditional %24 %49 %50
212 OpSelectionMerge %58 None
213 OpBranchConditional %24 %57 %63
218 OpSelectionMerge %68 None
219 OpBranchConditional %35 %67 %68
225 OpSelectionMerge %76 None
226 OpBranchConditional %24 %75 %77
234 OpSelectionMerge %85 None
235 OpBranchConditional %24 %84 %85
239 OpSelectionMerge %91 None
240 OpBranchConditional %35 %90 %91
245 %98 = OpSLessThan %23 %97 %42
246 OpLoopMerge %94 %93 None
247 OpBranchConditional %98 %93 %94
250 %101 = OpIAdd %6 %99 %100
259 %103 = OpIAdd %6 %102 %100
264 %105 = OpSGreaterThanEqual %23 %104 %42
265 OpSelectionMerge %107 None
266 OpBranchConditional %105 %106 %108
278 # uniforms for variant
281 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> STD140 DATA
285 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
287 PIPELINE graphics variant_pipeline
288 ATTACH variant_vertex_shader
289 ATTACH variant_fragment_shader
290 FRAMEBUFFER_SIZE 16 16
291 BIND BUFFER variant_framebuffer AS color LOCATION 0
292 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
294 CLEAR_COLOR variant_pipeline 0 0 0 255
296 CLEAR variant_pipeline
297 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 16 16
299 EXPECT variant_framebuffer IDX 0 0 SIZE 16 16 EQ_RGBA 255 0 0 255