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 a for loop containing nested ifs
22 # The test passes because the two-iteration loop only writes red to the output color variable.
24 SHADER vertex variant_vertex_shader PASSTHROUGH
26 # variant_fragment_shader is derived from the following GLSL:
28 # precision highp float;
30 # layout(location = 0) out vec4 _GLF_color;
41 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // red
47 # if (j == 5) // always false
49 # _GLF_color[0] = float(ldexp(1.0, 2));
54 # a = float(ldexp(1.0, 2));
55 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // red
61 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
64 ; Generator: Khronos Glslang Reference Front End; 7
68 %1 = OpExtInstImport "GLSL.std.450"
69 OpMemoryModel Logical GLSL450
70 OpEntryPoint Fragment %4 "main" %27
71 OpExecutionMode %4 OriginUpperLeft
75 OpName %27 "_GLF_color"
77 OpDecorate %8 RelaxedPrecision
78 OpDecorate %15 RelaxedPrecision
79 OpDecorate %19 RelaxedPrecision
80 OpDecorate %27 Location 0
81 OpDecorate %31 RelaxedPrecision
82 OpDecorate %36 RelaxedPrecision
83 OpDecorate %41 RelaxedPrecision
84 OpDecorate %55 RelaxedPrecision
85 OpDecorate %56 RelaxedPrecision
87 %3 = OpTypeFunction %2
89 %7 = OpTypePointer Function %6
95 %25 = OpTypeVector %24 4
96 %26 = OpTypePointer Output %25
97 %27 = OpVariable %26 Output
98 %28 = OpConstant %24 1
99 %29 = OpConstant %24 0
100 %30 = OpConstantComposite %25 %28 %29 %29 %28
101 %32 = OpConstant %6 3
102 %37 = OpConstant %6 4
103 %42 = OpConstant %6 5
105 %48 = OpConstant %47 0
106 %49 = OpTypePointer Output %24
107 %52 = OpTypePointer Function %24
108 %4 = OpFunction %2 None %3
110 %8 = OpVariable %7 Function
111 %53 = OpVariable %52 Function
115 OpLoopMerge %12 %13 None
119 %18 = OpSLessThan %17 %15 %16
120 OpBranchConditional %18 %11 %12
123 %21 = OpSLessThan %17 %19 %20
124 OpSelectionMerge %23 None
125 OpBranchConditional %21 %22 %23
131 %33 = OpINotEqual %17 %31 %32
132 OpSelectionMerge %35 None
133 OpBranchConditional %33 %34 %35
136 %38 = OpINotEqual %17 %36 %37
137 OpSelectionMerge %40 None
138 OpBranchConditional %38 %39 %40
141 %43 = OpIEqual %17 %41 %42
142 OpSelectionMerge %45 None
143 OpBranchConditional %43 %44 %51
145 %46 = OpExtInst %24 %1 Ldexp %28 %16
146 %50 = OpAccessChain %49 %27 %48
150 %54 = OpExtInst %24 %1 Ldexp %28 %16
162 %56 = OpIAdd %6 %55 %20
170 # uniforms for variant
173 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
175 PIPELINE graphics variant_pipeline
176 ATTACH variant_vertex_shader
177 ATTACH variant_fragment_shader
178 FRAMEBUFFER_SIZE 256 256
179 BIND BUFFER variant_framebuffer AS color LOCATION 0
181 CLEAR_COLOR variant_pipeline 0 0 0 255
183 CLEAR variant_pipeline
184 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
186 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255