3 # Copyright 2019 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 GraphicsFuzz.
20 # Short description: A fragment shader with nested loops and a switch
22 # The test passes because the fragment shader enters the outer loop, immediately breaks, and
23 # writes the color red.
25 SHADER vertex variant_vertex_shader PASSTHROUGH
27 # variant_fragment_shader is derived from the following GLSL:
29 # precision highp float;
30 # precision highp int;
32 # layout(location = 0) out vec4 _GLF_color;
34 # layout(set = 0, binding = 0) uniform buf0
36 # vec2 injectionSwitch;
44 # if (i >= int(injectionSwitch.x)) // always true
48 # if (0.0 > injectionSwitch.y)
50 # float donor_replacementGLF_dead5sums[9];
52 # int GLF_dead5cols = 2;
57 # int GLF_dead5rows = 2;
63 # GLF_dead5c < GLF_dead5cols;
68 # GLF_dead5r < GLF_dead5rows;
75 # donor_replacementGLF_dead5sums[msb10 >= 0 && msb10 < 9 ? msb10 : 0] += 1.0;
85 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
87 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
90 ; Generator: Khronos Glslang Reference Front End; 7
94 %1 = OpExtInstImport "GLSL.std.450"
95 OpMemoryModel Logical GLSL450
96 OpEntryPoint Fragment %4 "main" %115
97 OpExecutionMode %4 OriginUpperLeft
102 OpMemberName %17 0 "injectionSwitch"
104 OpName %38 "GLF_dead5cols"
105 OpName %48 "GLF_dead5rows"
106 OpName %56 "GLF_dead5c"
107 OpName %65 "GLF_dead5r"
109 OpName %81 "donor_replacementGLF_dead5sums"
110 OpName %115 "_GLF_color"
111 OpMemberDecorate %17 0 Offset 0
113 OpDecorate %19 DescriptorSet 0
114 OpDecorate %19 Binding 0
115 OpDecorate %115 Location 0
117 %3 = OpTypeFunction %2
119 %7 = OpTypePointer Function %6
122 %16 = OpTypeVector %15 2
123 %17 = OpTypeStruct %16
124 %18 = OpTypePointer Uniform %17
125 %19 = OpVariable %18 Uniform
127 %21 = OpConstant %20 0
128 %22 = OpTypePointer Uniform %15
130 %31 = OpConstant %15 0
131 %32 = OpConstant %20 1
132 %39 = OpConstant %6 2
133 %46 = OpConstant %6 4
134 %78 = OpConstant %20 9
135 %79 = OpTypeArray %15 %78
136 %80 = OpTypePointer Function %79
137 %85 = OpConstant %6 9
138 %90 = OpConstant %15 1
139 %91 = OpTypePointer Function %15
140 %98 = OpConstant %6 1
141 %111 = OpConstant %6 200
142 %113 = OpTypeVector %15 4
143 %114 = OpTypePointer Output %113
144 %115 = OpVariable %114 Output
145 %116 = OpConstantComposite %113 %90 %31 %31 %90
146 %4 = OpFunction %2 None %3
148 %8 = OpVariable %7 Function
149 %38 = OpVariable %7 Function
150 %48 = OpVariable %7 Function
151 %56 = OpVariable %7 Function
152 %65 = OpVariable %7 Function
153 %74 = OpVariable %7 Function
154 %81 = OpVariable %80 Function
158 OpLoopMerge %12 %13 None
162 %23 = OpAccessChain %22 %19 %9 %21
164 %25 = OpConvertFToS %6 %24
165 %27 = OpSGreaterThanEqual %26 %14 %25
166 OpSelectionMerge %29 None
167 OpBranchConditional %27 %28 %29
171 %33 = OpAccessChain %22 %19 %9 %32
173 %35 = OpFOrdGreaterThan %26 %31 %34
174 OpSelectionMerge %37 None
175 OpBranchConditional %35 %36 %37
180 OpLoopMerge %42 %43 None
184 %47 = OpSLessThanEqual %26 %45 %46
185 OpBranchConditional %47 %41 %42
190 OpLoopMerge %51 %52 None
194 %55 = OpSLessThanEqual %26 %54 %46
195 OpBranchConditional %55 %50 %51
200 OpLoopMerge %59 %60 None
205 %64 = OpSLessThan %26 %62 %63
206 OpBranchConditional %64 %58 %59
211 OpLoopMerge %68 %69 None
216 %73 = OpSLessThan %26 %71 %72
217 OpBranchConditional %73 %67 %68
220 OpSelectionMerge %77 None
221 OpSwitch %75 %77 1 %76 8 %76
224 %83 = OpSGreaterThanEqual %26 %82 %9
226 %86 = OpSLessThan %26 %84 %85
227 %87 = OpLogicalAnd %26 %83 %86
229 %89 = OpSelect %6 %87 %88 %9
230 %92 = OpAccessChain %91 %81 %89
232 %94 = OpFAdd %15 %93 %90
233 %95 = OpAccessChain %91 %81 %89
240 %99 = OpIAdd %6 %97 %98
247 %101 = OpIAdd %6 %100 %98
252 %103 = OpIAdd %6 %102 %98
257 %105 = OpIAdd %6 %104 %98
264 %107 = OpIAdd %6 %106 %98
271 %109 = OpIAdd %6 %108 %98
276 %112 = OpSLessThan %26 %110 %111
277 OpBranchConditional %112 %10 %12
284 # uniforms for variant
287 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
291 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
293 PIPELINE graphics variant_pipeline
294 ATTACH variant_vertex_shader
295 ATTACH variant_fragment_shader
296 FRAMEBUFFER_SIZE 256 256
297 BIND BUFFER variant_framebuffer AS color LOCATION 0
298 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
300 CLEAR_COLOR variant_pipeline 0 0 0 255
302 CLEAR variant_pipeline
303 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
305 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255