3 # Copyright 2018 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.
17 # A test for a bug found by GraphicsFuzz.
19 # A fragment shader that uses FragCoord and somewhat complex control flow.
20 # Derived from the following GLSL fragment shader.
21 # We check that the top-left pixel is red. The test passes because _GLF_color is
22 # initially set to red, all other writes to _GLF_color write red, and the discard
23 # statement only executes for pixels with an x coordinate >= 180.
27 # precision highp float;
28 # precision highp int;
30 # layout(location=0) out vec4 _GLF_color;
33 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
34 # for (int i = 0; i < 1; i++) {
35 # if (1.0 < gl_FragCoord.x) {
38 # if (gl_FragCoord.x < 0.0) {
43 # if (gl_FragCoord.x < 40.0) {
44 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
46 # if (gl_FragCoord.x < 140.0) {
48 # for (int j = 1; j > 0; j--) {
49 # if (gl_FragCoord.x < 160.0) {
50 # for (int k = 1; k > 0; k--) {
51 # if (gl_FragCoord.y < 0.0) {
53 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
57 # if (gl_FragCoord.x < 180.0) {
58 # for (int l = 1; l != 0; l--) {
59 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
62 # if (gl_FragCoord.x < 180.0) {
63 # for (int m = 0; m != 1; m++) {
64 # for (int n = 0; n < 1; n++) {
65 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
69 # for (int o = 1; o != 0; o--) {
70 # backup = vec4(1.0, 0.0, 0.0, 1.0);
72 # _GLF_color = backup;
85 SHADER vertex variant_vertex_shader PASSTHROUGH
87 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
90 ; Generator: Khronos SPIR-V Tools Assembler; 0
94 %1 = OpExtInstImport "GLSL.std.450"
95 OpMemoryModel Logical GLSL450
96 OpEntryPoint Fragment %2 "main" %3 %4
97 OpExecutionMode %2 OriginUpperLeft
100 OpName %3 "_GLF_color"
101 OpName %4 "gl_FragCoord"
102 OpDecorate %3 Location 0
103 OpDecorate %4 BuiltIn FragCoord
105 %6 = OpTypeFunction %5
107 %8 = OpTypeVector %7 4
108 %9 = OpTypePointer Output %8
109 %3 = OpVariable %9 Output
110 %10 = OpConstant %7 1
111 %11 = OpConstant %7 0
112 %12 = OpConstantComposite %8 %10 %11 %11 %10
114 %14 = OpConstant %13 0
115 %15 = OpConstant %13 1
117 %17 = OpTypePointer Input %8
118 %4 = OpVariable %17 Input
120 %19 = OpConstant %18 0
121 %20 = OpTypePointer Input %7
122 %21 = OpConstant %7 40
123 %22 = OpConstant %7 140
124 %23 = OpConstant %7 160
125 %24 = OpConstant %18 1
126 %25 = OpConstant %7 180
127 %26 = OpConstantFalse %16
128 %27 = OpConstantTrue %16
130 %2 = OpFunction %5 None %6
135 OpLoopMerge %31 %32 None
138 %34 = OpPhi %13 %14 %30 %35 %36
139 %37 = OpSLessThan %16 %34 %15
140 OpLoopMerge %38 %36 None
141 OpBranchConditional %37 %39 %38
143 %40 = OpAccessChain %20 %4 %19
145 %42 = OpFOrdLessThan %16 %10 %41
146 OpSelectionMerge %43 None
147 OpBranchConditional %42 %44 %43
151 %45 = OpFOrdLessThan %16 %41 %11
152 OpSelectionMerge %46 None
153 OpBranchConditional %45 %47 %36
159 %35 = OpIAdd %13 %34 %15
162 %48 = OpPhi %16 %26 %33 %26 %44 %27 %47
163 OpSelectionMerge %49 None
164 OpBranchConditional %48 %31 %49
168 OpLoopMerge %51 %52 None
171 %54 = OpAccessChain %20 %4 %19
173 %56 = OpFOrdLessThan %16 %55 %21
174 OpSelectionMerge %57 None
175 OpBranchConditional %56 %52 %58
180 OpBranchConditional %26 %50 %51
182 %59 = OpFOrdLessThan %16 %55 %22
183 OpSelectionMerge %60 None
184 OpBranchConditional %59 %61 %62
190 %64 = OpPhi %8 %28 %62 %65 %66
191 %67 = OpPhi %13 %15 %62 %68 %66
192 %69 = OpSGreaterThan %16 %67 %14
193 OpLoopMerge %70 %66 None
194 OpBranchConditional %69 %71 %70
196 %72 = OpFOrdLessThan %16 %55 %23
197 OpSelectionMerge %73 None
198 OpBranchConditional %72 %74 %75
202 %77 = OpPhi %13 %15 %74 %78 %79
203 %80 = OpSGreaterThan %16 %77 %14
204 OpLoopMerge %81 %79 None
205 OpBranchConditional %80 %82 %81
207 %83 = OpAccessChain %20 %4 %24
209 %85 = OpFOrdLessThan %16 %84 %11
210 OpSelectionMerge %86 None
211 OpBranchConditional %85 %87 %88
220 %78 = OpISub %13 %77 %15
225 %89 = OpFOrdLessThan %16 %55 %25
226 OpSelectionMerge %90 None
227 OpBranchConditional %89 %91 %92
231 %94 = OpPhi %13 %15 %91 %95 %96
232 %97 = OpINotEqual %16 %94 %14
233 OpLoopMerge %98 %96 None
234 OpBranchConditional %97 %96 %98
237 %95 = OpISub %13 %94 %15
242 OpSelectionMerge %99 None
243 OpBranchConditional %89 %100 %101
247 %103 = OpPhi %13 %14 %100 %104 %105
248 %106 = OpINotEqual %16 %103 %15
249 OpLoopMerge %107 %105 None
250 OpBranchConditional %106 %108 %107
254 %110 = OpPhi %13 %14 %108 %111 %112
255 %113 = OpSLessThan %16 %110 %15
256 OpLoopMerge %114 %112 None
257 OpBranchConditional %113 %112 %114
260 %111 = OpIAdd %13 %110 %15
265 %104 = OpIAdd %13 %103 %15
270 %116 = OpPhi %8 %64 %107 %12 %117
271 %118 = OpPhi %13 %15 %107 %119 %117
272 %120 = OpINotEqual %16 %118 %14
273 OpLoopMerge %121 %117 None
274 OpBranchConditional %120 %117 %121
276 %119 = OpISub %13 %118 %15
286 %122 = OpPhi %8 %64 %98 %116 %99
291 %65 = OpPhi %8 %64 %81 %122 %90 %28 %73
292 %68 = OpISub %13 %67 %15
299 %123 = OpPhi %16 %27 %60 %48 %52
300 OpSelectionMerge %124 None
301 OpBranchConditional %123 %31 %124
311 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
313 PIPELINE graphics variant_pipeline
314 ATTACH variant_vertex_shader
315 ATTACH variant_fragment_shader
316 FRAMEBUFFER_SIZE 256 256
317 BIND BUFFER variant_framebuffer AS color LOCATION 0
319 CLEAR_COLOR variant_pipeline 0 0 0 255
321 CLEAR variant_pipeline
322 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
324 EXPECT variant_framebuffer IDX 0 0 SIZE 1 1 EQ_RGBA 255 0 0 255