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 true if in a nested do while loop
22 # The test passes because the shader always writes color red.
24 # Optimized using spirv-opt with the following arguments:
25 # '--simplify-instructions'
26 # '--private-to-local'
27 # '--eliminate-local-multi-store'
28 # '--convert-local-access-chains'
29 # '--inline-entry-points-exhaustive'
30 # '--simplify-instructions'
31 # '--eliminate-dead-inserts'
33 # '--combine-access-chains'
34 # '--convert-local-access-chains'
36 # '--private-to-local'
37 # '--eliminate-local-single-store'
38 # '--copy-propagate-arrays'
39 # spirv-opt commit hash: 230f363e6da32791f640b02205e0645cc67c3f1d
43 SHADER vertex variant_vertex_shader PASSTHROUGH
45 # variant_fragment_shader is derived from the following GLSL:
47 # precision highp float;
49 # precision highp int;
51 # layout(location = 0) out vec4 _GLF_color;
52 # layout(set = 0, binding = 0) uniform buf0
54 # vec2 injectionSwitch; // x == 0.0, y == 1.0
59 # const int loop_limit = 100;
68 # if (injectionSwitch.x < injectionSwitch.y)
73 # if (injectionSwitch.x < injectionSwitch.y)
77 # } while (loop_count < loop_limit);
78 # } while (loop_count < loop_limit);
85 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
89 # _GLF_color = vec4(1.0);
92 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
95 ; Generator: Khronos Glslang Reference Front End; 10
99 %1 = OpExtInstImport "GLSL.std.450"
100 OpMemoryModel Logical GLSL450
101 OpEntryPoint Fragment %4 "main" %65
102 OpExecutionMode %4 OriginUpperLeft
106 OpName %11 "loop_count"
108 OpMemberName %28 0 "injectionSwitch"
110 OpName %65 "_GLF_color"
111 OpMemberDecorate %28 0 Offset 0
113 OpDecorate %30 DescriptorSet 0
114 OpDecorate %30 Binding 0
115 OpDecorate %65 Location 0
117 %3 = OpTypeFunction %2
119 %7 = OpTypeFunction %6
120 %10 = OpTypePointer Function %6
121 %12 = OpConstant %6 0
122 %18 = OpConstant %6 1
124 %27 = OpTypeVector %26 2
125 %28 = OpTypeStruct %27
126 %29 = OpTypePointer Uniform %28
127 %30 = OpVariable %29 Uniform
129 %32 = OpConstant %31 0
130 %33 = OpTypePointer Uniform %26
131 %36 = OpConstant %31 1
133 %53 = OpConstant %6 100
134 %63 = OpTypeVector %26 4
135 %64 = OpTypePointer Output %63
136 %65 = OpVariable %64 Output
137 %66 = OpConstant %26 1
138 %67 = OpConstant %26 0
139 %68 = OpConstantComposite %63 %66 %67 %67 %66
140 %70 = OpConstantComposite %63 %66 %66 %66 %66
141 %4 = OpFunction %2 None %3
143 %59 = OpFunctionCall %6 %8
144 %60 = OpIEqual %39 %59 %18
145 OpSelectionMerge %62 None
146 OpBranchConditional %60 %61 %69
156 %8 = OpFunction %6 None %7
158 %11 = OpVariable %10 Function
162 %71 = OpPhi %6 %12 %9 %25 %16
163 OpLoopMerge %15 %16 None
166 %19 = OpIAdd %6 %71 %18
170 %72 = OpPhi %6 %19 %14 %25 %23
171 OpLoopMerge %22 %23 None
174 %25 = OpIAdd %6 %72 %18
176 %34 = OpAccessChain %33 %30 %12 %32
178 %37 = OpAccessChain %33 %30 %12 %36
180 %40 = OpFOrdLessThan %39 %35 %38
181 OpSelectionMerge %42 None
182 OpBranchConditional %40 %41 %42
186 %44 = OpAccessChain %33 %30 %12 %32
188 %46 = OpAccessChain %33 %30 %12 %36
190 %48 = OpFOrdLessThan %39 %45 %47
191 OpSelectionMerge %50 None
192 OpBranchConditional %48 %49 %50
198 %54 = OpSLessThan %39 %25 %53
199 OpBranchConditional %54 %20 %22
203 %56 = OpSLessThan %39 %25 %53
204 OpBranchConditional %56 %13 %15
210 # uniforms for variant
213 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> STD140 DATA
217 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
219 PIPELINE graphics variant_pipeline
220 ATTACH variant_vertex_shader
221 ATTACH variant_fragment_shader
222 FRAMEBUFFER_SIZE 256 256
223 BIND BUFFER variant_framebuffer AS color LOCATION 0
224 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
226 CLEAR_COLOR variant_pipeline 0 0 0 255
228 CLEAR variant_pipeline
229 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
231 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255