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: Fragment shader with pair of outer loops
22 # The test passes because fragments in the top-left quadrant write red, and all other fragments are guaranteed to be discarded
24 SHADER vertex variant_vertex_shader PASSTHROUGH
26 # variant_fragment_shader is derived from the following GLSL:
28 # precision highp float;
30 # layout(set = 0, binding = 0) uniform buf0 {
31 # vec2 injectionSwitch;
33 # layout(location = 0) out vec4 _GLF_color;
37 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
38 # if (gl_FragCoord.x < 128.0 && gl_FragCoord.y < 128.0) {
42 # while(odd_index <= 1)
44 # _GLF_color.x += 0.25;
48 # while(even_index >= 0)
50 # _GLF_color.x += 0.25;
51 # if(injectionSwitch.x > injectionSwitch.y)
58 # // Guaranteed to be reached during the first loop iteration
61 # int ll; // Uninitialized, but unreachable due to the above discard
73 # if(uint(j) < uint(1))
77 # if(injectionSwitch.x > injectionSwitch.y)
82 # if(injectionSwitch.x > injectionSwitch.y)
84 # _GLF_color = vec4(1.0);
89 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
92 ; Generator: Khronos Glslang Reference Front End; 8
96 %1 = OpExtInstImport "GLSL.std.450"
97 OpMemoryModel Logical GLSL450
98 OpEntryPoint Fragment %4 "main" %9 %15
99 OpExecutionMode %4 OriginUpperLeft
102 OpName %9 "_GLF_color"
103 OpName %15 "gl_FragCoord"
104 OpName %35 "odd_index"
105 OpName %53 "even_index"
107 OpMemberName %66 0 "injectionSwitch"
111 OpDecorate %9 Location 0
112 OpDecorate %15 BuiltIn FragCoord
113 OpDecorate %35 RelaxedPrecision
114 OpDecorate %42 RelaxedPrecision
115 OpDecorate %51 RelaxedPrecision
116 OpDecorate %52 RelaxedPrecision
117 OpDecorate %53 RelaxedPrecision
118 OpDecorate %59 RelaxedPrecision
119 OpMemberDecorate %66 0 Offset 0
121 OpDecorate %68 DescriptorSet 0
122 OpDecorate %68 Binding 0
123 OpDecorate %78 RelaxedPrecision
124 OpDecorate %83 RelaxedPrecision
125 OpDecorate %90 RelaxedPrecision
126 OpDecorate %91 RelaxedPrecision
127 OpDecorate %97 RelaxedPrecision
128 OpDecorate %98 RelaxedPrecision
129 OpDecorate %99 RelaxedPrecision
130 OpDecorate %113 RelaxedPrecision
131 OpDecorate %114 RelaxedPrecision
132 OpDecorate %123 RelaxedPrecision
133 OpDecorate %124 RelaxedPrecision
135 %3 = OpTypeFunction %2
137 %7 = OpTypeVector %6 4
138 %8 = OpTypePointer Output %7
139 %9 = OpVariable %8 Output
140 %10 = OpConstant %6 1
141 %11 = OpConstant %6 0
142 %12 = OpConstantComposite %7 %10 %11 %11 %10
144 %14 = OpTypePointer Input %7
145 %15 = OpVariable %14 Input
147 %17 = OpConstant %16 0
148 %18 = OpTypePointer Input %6
149 %21 = OpConstant %6 128
150 %25 = OpConstant %16 1
152 %34 = OpTypePointer Function %33
153 %36 = OpConstant %33 0
154 %43 = OpConstant %33 1
155 %45 = OpConstant %6 0.25
156 %46 = OpTypePointer Output %6
157 %65 = OpTypeVector %6 2
158 %66 = OpTypeStruct %65
159 %67 = OpTypePointer Uniform %66
160 %68 = OpVariable %67 Uniform
161 %69 = OpTypePointer Uniform %6
162 %89 = OpConstantTrue %13
163 %92 = OpConstant %33 3
164 %122 = OpConstantComposite %7 %10 %10 %10 %10
165 %4 = OpFunction %2 None %3
167 %35 = OpVariable %34 Function
168 %53 = OpVariable %34 Function
169 %83 = OpVariable %34 Function
170 %90 = OpVariable %34 Function
172 %19 = OpAccessChain %18 %15 %17
174 %22 = OpFOrdLessThan %13 %20 %21
175 OpSelectionMerge %24 None
176 OpBranchConditional %22 %23 %24
178 %26 = OpAccessChain %18 %15 %25
180 %28 = OpFOrdLessThan %13 %27 %21
183 %29 = OpPhi %13 %22 %5 %28 %23
184 OpSelectionMerge %31 None
185 OpBranchConditional %29 %30 %31
192 OpLoopMerge %39 %40 None
196 %44 = OpSLessThanEqual %13 %42 %43
197 OpBranchConditional %44 %38 %39
199 %47 = OpAccessChain %46 %9 %17
201 %49 = OpFAdd %6 %48 %45
202 %50 = OpAccessChain %46 %9 %17
205 %52 = OpIAdd %33 %51 %43
214 OpLoopMerge %56 %57 None
218 %60 = OpSGreaterThanEqual %13 %59 %36
219 OpBranchConditional %60 %55 %56
221 %61 = OpAccessChain %46 %9 %17
223 %63 = OpFAdd %6 %62 %45
224 %64 = OpAccessChain %46 %9 %17
226 %70 = OpAccessChain %69 %68 %36 %17
228 %72 = OpAccessChain %69 %68 %36 %25
230 %74 = OpFOrdGreaterThan %13 %71 %73
231 OpSelectionMerge %76 None
232 OpBranchConditional %74 %75 %76
237 %79 = OpSGreaterThanEqual %13 %78 %43
238 OpSelectionMerge %81 None
239 OpBranchConditional %79 %80 %81
246 OpLoopMerge %86 %87 None
249 OpBranchConditional %89 %85 %86
252 %93 = OpSGreaterThanEqual %13 %91 %92
253 OpSelectionMerge %95 None
254 OpBranchConditional %93 %94 %95
259 %98 = OpIAdd %33 %97 %43
262 %100 = OpBitcast %16 %99
263 %101 = OpULessThan %13 %100 %25
264 OpSelectionMerge %103 None
265 OpBranchConditional %101 %102 %103
269 %105 = OpAccessChain %69 %68 %36 %17
270 %106 = OpLoad %6 %105
271 %107 = OpAccessChain %69 %68 %36 %25
272 %108 = OpLoad %6 %107
273 %109 = OpFOrdGreaterThan %13 %106 %108
274 OpSelectionMerge %111 None
275 OpBranchConditional %109 %110 %111
281 %113 = OpLoad %33 %83
282 %114 = OpIAdd %33 %113 %43
286 %115 = OpAccessChain %69 %68 %36 %17
287 %116 = OpLoad %6 %115
288 %117 = OpAccessChain %69 %68 %36 %25
289 %118 = OpLoad %6 %117
290 %119 = OpFOrdGreaterThan %13 %116 %118
291 OpSelectionMerge %121 None
292 OpBranchConditional %119 %120 %121
297 %123 = OpLoad %33 %53
298 %124 = OpISub %33 %123 %43
308 # uniforms for variant
311 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
315 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
317 PIPELINE graphics variant_pipeline
318 ATTACH variant_vertex_shader
319 ATTACH variant_fragment_shader
320 FRAMEBUFFER_SIZE 256 256
321 BIND BUFFER variant_framebuffer AS color LOCATION 0
322 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
324 CLEAR_COLOR variant_pipeline 0 0 0 255
326 CLEAR variant_pipeline
327 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
329 EXPECT variant_framebuffer IDX 0 0 SIZE 100 100 EQ_RGBA 255 0 0 255