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 GraphicsFuzz.
20 # Short description: A fragment shader with many uses of gl_FragCoord
22 # The test passes because the shader always write red.
24 # Optimized using spirv-opt with the following arguments:
25 # '--scalar-replacement=100'
27 # '--combine-access-chains'
28 # '--convert-local-access-chains'
29 # '--eliminate-dead-code-aggressive'
30 # '--private-to-local'
31 # '--combine-access-chains'
32 # '--reduce-load-size'
33 # '--eliminate-dead-inserts'
34 # '--combine-access-chains'
35 # '--eliminate-local-single-store'
36 # '--eliminate-local-single-block'
37 # '--inline-entry-points-exhaustive'
38 # '--combine-access-chains'
39 # spirv-opt commit hash: e95fbfb1f509ad7a7fdfb72ac35fe412d72fc4a4
43 SHADER vertex variant_vertex_shader PASSTHROUGH
45 # variant_fragment_shader is derived from the following GLSL:
48 # precision highp float;
49 # precision highp int;
51 # layout(location = 0) out vec4 _GLF_color;
53 # layout(set = 0, binding = 0) uniform buf0 {
54 # // Always (0.0, 1.0).
55 # vec2 injectionSwitch;
58 # // coord is gl_FragCoord.xy.
59 # // Always returns 0.
60 # int alwaysZero(vec2 coord)
62 # // injectionSwitch.y is 1.0.
63 # float a = coord.y < 50.0 ? injectionSwitch.y : 0.0;
64 # float b = gl_FragCoord.y < 50.0 ? 1.0 : 0.0;
66 # // a == b. Thus, the condition is always true.
76 # int zero = alwaysZero(gl_FragCoord.xy);
84 # // All conditions below are true.
85 # // So _GLF_color will end up as red: (1.0, 0.0, 0.0, 1.0).
86 # _GLF_color = vec4(0.0, 1.0, 1.0, 1.0);
89 # if (gl_FragCoord.x >= injectionSwitch.x)
92 # if (gl_FragCoord.y >= 0.0)
94 # // _GLF_color.x = 1.0;
95 # _GLF_color.x = injectionSwitch.y;
100 # if (gl_FragCoord.y >= 0.0)
102 # // _GLF_color.y = 0.0;
103 # _GLF_color.y = injectionSwitch.x;
106 # vec2 temp = vec2(gl_FragCoord.xy);
111 # // _GLF_color.z = 0.0;
112 # _GLF_color.z = injectionSwitch.x;
115 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
118 ; Generator: Khronos Glslang Reference Front End; 8
122 %1 = OpExtInstImport "GLSL.std.450"
123 OpMemoryModel Logical GLSL450
124 OpEntryPoint Fragment %4 "main" %39 %68
125 OpExecutionMode %4 OriginUpperLeft
128 OpName %12 "alwaysZero(vf2;"
132 OpMemberName %26 0 "injectionSwitch"
135 OpName %39 "gl_FragCoord"
138 OpName %68 "_GLF_color"
140 OpMemberDecorate %26 0 Offset 0
142 OpDecorate %28 DescriptorSet 0
143 OpDecorate %28 Binding 0
144 OpDecorate %39 BuiltIn FragCoord
145 OpDecorate %68 Location 0
147 %3 = OpTypeFunction %2
149 %7 = OpTypeVector %6 2
150 %8 = OpTypePointer Function %7
152 %10 = OpTypeFunction %9 %8
153 %14 = OpTypePointer Function %6
155 %17 = OpConstant %16 1
156 %20 = OpConstant %6 50
158 %26 = OpTypeStruct %7
159 %27 = OpTypePointer Uniform %26
160 %28 = OpVariable %27 Uniform
161 %29 = OpConstant %9 0
162 %30 = OpTypePointer Uniform %6
163 %34 = OpConstant %6 0
164 %37 = OpTypeVector %6 4
165 %38 = OpTypePointer Input %37
166 %39 = OpVariable %38 Input
167 %40 = OpTypePointer Input %6
168 %44 = OpConstant %6 1
169 %53 = OpConstant %9 1
170 %56 = OpTypePointer Function %9
171 %67 = OpTypePointer Output %37
172 %68 = OpVariable %67 Output
173 %69 = OpConstantComposite %37 %34 %44 %44 %44
174 %70 = OpConstant %16 0
175 %85 = OpTypePointer Output %6
176 %108 = OpConstant %16 2
177 %136 = OpConstantFalse %21
178 %4 = OpFunction %2 None %3
180 %111 = OpVariable %14 Function
181 %112 = OpVariable %14 Function
182 %113 = OpVariable %14 Function
183 %114 = OpVariable %56 Function
184 %57 = OpVariable %56 Function
185 %58 = OpVariable %8 Function
186 %95 = OpVariable %8 Function
188 %60 = OpVectorShuffle %7 %59 %59 0 1
192 OpLoopMerge %116 %117 None
195 %119 = OpAccessChain %14 %58 %17
196 %120 = OpLoad %6 %119
197 %121 = OpFOrdLessThan %21 %120 %20
198 OpSelectionMerge %122 None
199 OpBranchConditional %121 %123 %124
201 %125 = OpAccessChain %30 %28 %29 %17
202 %126 = OpLoad %6 %125
209 %127 = OpLoad %6 %112
211 %128 = OpAccessChain %40 %39 %17
212 %129 = OpLoad %6 %128
213 %130 = OpFOrdLessThan %21 %129 %20
214 %131 = OpSelect %6 %130 %44 %34
216 %132 = OpFSub %6 %127 %131
217 %133 = OpFOrdLessThan %21 %132 %44
218 OpSelectionMerge %134 None
219 OpBranchConditional %133 %135 %134
227 OpBranchConditional %136 %115 %116
231 %63 = OpIEqual %21 %61 %53
232 OpSelectionMerge %65 None
233 OpBranchConditional %63 %64 %65
238 %71 = OpAccessChain %40 %39 %70
240 %73 = OpAccessChain %30 %28 %29 %70
242 %75 = OpFOrdGreaterThanEqual %21 %72 %74
243 OpSelectionMerge %77 None
244 OpBranchConditional %75 %76 %77
246 %78 = OpAccessChain %40 %39 %17
248 %80 = OpFOrdGreaterThanEqual %21 %79 %34
249 OpSelectionMerge %82 None
250 OpBranchConditional %80 %81 %82
252 %83 = OpAccessChain %30 %28 %29 %17
254 %86 = OpAccessChain %85 %68 %70
260 %87 = OpAccessChain %40 %39 %17
262 %89 = OpFOrdGreaterThanEqual %21 %88 %34
263 OpSelectionMerge %91 None
264 OpBranchConditional %89 %90 %91
266 %92 = OpAccessChain %30 %28 %29 %70
268 %94 = OpAccessChain %85 %68 %17
273 %97 = OpVectorShuffle %7 %96 %96 0 1
274 %98 = OpCompositeExtract %6 %97 0
275 %99 = OpCompositeExtract %6 %97 1
276 %100 = OpCompositeConstruct %7 %98 %99
278 %102 = OpCompositeExtract %6 %100 1
279 %103 = OpFOrdGreaterThanEqual %21 %102 %34
280 OpSelectionMerge %105 None
281 OpBranchConditional %103 %104 %105
283 %106 = OpAccessChain %30 %28 %29 %70
284 %107 = OpLoad %6 %106
285 %109 = OpAccessChain %85 %68 %108
291 %12 = OpFunction %9 None %10
292 %11 = OpFunctionParameter %8
294 %15 = OpVariable %14 Function
295 %23 = OpVariable %14 Function
296 %36 = OpVariable %14 Function
297 %18 = OpAccessChain %14 %11 %17
299 %22 = OpFOrdLessThan %21 %19 %20
300 OpSelectionMerge %25 None
301 OpBranchConditional %22 %24 %33
303 %31 = OpAccessChain %30 %28 %29 %17
313 %41 = OpAccessChain %40 %39 %17
315 %43 = OpFOrdLessThan %21 %42 %20
316 %45 = OpSelect %6 %43 %44 %34
318 %48 = OpFSub %6 %35 %45
319 %49 = OpFOrdLessThan %21 %48 %44
320 OpSelectionMerge %51 None
321 OpBranchConditional %49 %50 %51
329 # uniforms for variant
332 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
336 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
338 PIPELINE graphics variant_pipeline
339 ATTACH variant_vertex_shader
340 ATTACH variant_fragment_shader
341 FRAMEBUFFER_SIZE 256 256
342 BIND BUFFER variant_framebuffer AS color LOCATION 0
343 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
345 CLEAR_COLOR variant_pipeline 0 0 0 255
347 CLEAR variant_pipeline
348 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
350 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255