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 all pixels are 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 >= 10000000.
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 (int(gl_FragCoord.x) < 10000000) {
38 # if (int(gl_FragCoord.x) < 10000000) {
40 # for (int j = 0; j < 1; j++) {
41 # for (int k = 0; k < 1; k++) {
42 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
46 # for (int l = 0; l < 1; l++) {
47 # backup = vec4(1.0, 0.0, 0.0, 1.0);
49 # _GLF_color = backup;
57 SHADER vertex variant_vertex_shader PASSTHROUGH
59 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
62 ; Generator: Khronos SPIR-V Tools Assembler; 0
66 %1 = OpExtInstImport "GLSL.std.450"
67 OpMemoryModel Logical GLSL450
68 OpEntryPoint Fragment %2 "main" %3 %4
69 OpExecutionMode %2 OriginUpperLeft
72 OpName %3 "_GLF_color"
73 OpName %4 "gl_FragCoord"
74 OpDecorate %3 Location 0
75 OpDecorate %4 BuiltIn FragCoord
77 %6 = OpTypeFunction %5
79 %8 = OpTypeVector %7 4
80 %9 = OpTypePointer Output %8
81 %3 = OpVariable %9 Output
84 %12 = OpConstantComposite %8 %10 %11 %11 %10
86 %14 = OpConstant %13 0
87 %15 = OpConstant %13 1
89 %17 = OpTypePointer Input %8
90 %4 = OpVariable %17 Input
92 %19 = OpConstant %18 0
93 %20 = OpTypePointer Input %7
94 %21 = OpConstant %13 10000000
96 %2 = OpFunction %5 None %6
101 %25 = OpPhi %8 %22 %23 %26 %27
102 %28 = OpPhi %13 %14 %23 %29 %27
103 %30 = OpSLessThan %16 %28 %15
104 OpLoopMerge %31 %27 None
105 OpBranchConditional %30 %32 %31
107 %33 = OpAccessChain %20 %4 %19
109 %35 = OpConvertFToS %13 %34
110 %36 = OpSLessThan %16 %35 %21
111 OpSelectionMerge %37 None
112 OpBranchConditional %36 %38 %39
116 OpSelectionMerge %40 None
117 OpBranchConditional %36 %41 %42
121 %44 = OpPhi %13 %14 %41 %45 %46
122 %47 = OpSLessThan %16 %44 %15
123 OpLoopMerge %48 %46 None
124 OpBranchConditional %47 %49 %48
128 %51 = OpPhi %13 %14 %49 %52 %53
129 %54 = OpSLessThan %16 %51 %15
130 OpLoopMerge %55 %53 None
131 OpBranchConditional %54 %53 %55
134 %52 = OpIAdd %13 %51 %15
139 %45 = OpIAdd %13 %44 %15
144 %57 = OpPhi %8 %25 %48 %12 %58
145 %59 = OpPhi %13 %14 %48 %60 %58
146 %61 = OpSLessThan %16 %59 %15
147 OpLoopMerge %62 %58 None
148 OpBranchConditional %61 %58 %62
150 %60 = OpIAdd %13 %59 %15
162 %26 = OpPhi %8 %25 %38 %57 %40 %22 %37
163 %29 = OpIAdd %13 %28 %15
170 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
172 PIPELINE graphics variant_pipeline
173 ATTACH variant_vertex_shader
174 ATTACH variant_fragment_shader
175 FRAMEBUFFER_SIZE 256 256
176 BIND BUFFER variant_framebuffer AS color LOCATION 0
178 CLEAR_COLOR variant_pipeline 0 0 0 255
180 CLEAR variant_pipeline
181 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
183 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255