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 similar nested ifs and loops
22 # The test passes because most of the shader does not execute; the shader writes the color red.
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
32 # vec2 injectionSwitch;
34 # layout(location = 0) out vec4 _GLF_color;
40 # float lv = (1.0 > injectionSwitch.y) ? abs(gv) : 260.0;
45 # clamp(lv, 1.0, 1.0);
47 # else if (gl_FragCoord.y < 0.0) // always false
55 # int GLF_live5_looplimiter6;
61 # if (GLF_live5_looplimiter6 >= 6)
65 # GLF_live5_looplimiter6++;
69 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
71 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
74 ; Generator: Khronos Glslang Reference Front End; 7
78 %1 = OpExtInstImport "GLSL.std.450"
79 OpMemoryModel Logical GLSL450
80 OpEntryPoint Fragment %4 "main" %50 %87
81 OpExecutionMode %4 OriginUpperLeft
86 OpMemberName %11 0 "injectionSwitch"
89 OpName %50 "gl_FragCoord"
90 OpName %70 "GLF_live5r"
91 OpName %76 "GLF_live5_looplimiter6"
92 OpName %87 "_GLF_color"
93 OpMemberDecorate %11 0 Offset 0
95 OpDecorate %13 DescriptorSet 0
96 OpDecorate %13 Binding 0
97 OpDecorate %50 BuiltIn FragCoord
98 OpDecorate %70 RelaxedPrecision
99 OpDecorate %76 RelaxedPrecision
100 OpDecorate %77 RelaxedPrecision
101 OpDecorate %83 RelaxedPrecision
102 OpDecorate %85 RelaxedPrecision
103 OpDecorate %87 Location 0
105 %3 = OpTypeFunction %2
107 %7 = OpTypePointer Function %6
109 %10 = OpTypeVector %6 2
110 %11 = OpTypeStruct %10
111 %12 = OpTypePointer Uniform %11
112 %13 = OpVariable %12 Uniform
114 %15 = OpConstant %14 0
116 %17 = OpConstant %16 1
117 %18 = OpTypePointer Uniform %6
119 %26 = OpTypePointer Private %6
120 %27 = OpVariable %26 Private
121 %31 = OpConstant %6 260
122 %35 = OpConstant %14 250
123 %41 = OpConstant %14 180
124 %48 = OpTypeVector %6 4
125 %49 = OpTypePointer Input %48
126 %50 = OpVariable %49 Input
127 %51 = OpTypePointer Input %6
128 %54 = OpConstant %6 0
129 %60 = OpConstant %14 210
130 %68 = OpConstantTrue %21
131 %69 = OpTypePointer Function %14
132 %78 = OpConstant %14 6
133 %84 = OpConstant %14 1
134 %86 = OpTypePointer Output %48
135 %87 = OpVariable %86 Output
136 %88 = OpConstantComposite %48 %9 %54 %54 %9
137 %4 = OpFunction %2 None %3
139 %8 = OpVariable %7 Function
140 %23 = OpVariable %7 Function
141 %70 = OpVariable %69 Function
142 %76 = OpVariable %69 Function
143 %19 = OpAccessChain %18 %13 %15 %17
145 %22 = OpFOrdGreaterThan %21 %9 %20
146 OpSelectionMerge %25 None
147 OpBranchConditional %22 %24 %30
150 %29 = OpExtInst %6 %1 FAbs %28
160 %34 = OpConvertFToS %14 %33
161 %36 = OpSLessThan %21 %34 %35
162 OpSelectionMerge %38 None
163 OpBranchConditional %36 %37 %38
166 %40 = OpConvertFToS %14 %39
167 %42 = OpSLessThan %21 %40 %41
168 OpSelectionMerge %44 None
169 OpBranchConditional %42 %43 %47
172 %46 = OpExtInst %6 %1 FClamp %45 %9 %9
175 %52 = OpAccessChain %51 %50 %17
177 %55 = OpFOrdLessThan %21 %53 %54
178 OpSelectionMerge %57 None
179 OpBranchConditional %55 %56 %57
182 %59 = OpConvertFToS %14 %58
183 %61 = OpSLessThan %21 %59 %60
184 OpSelectionMerge %63 None
185 OpBranchConditional %61 %62 %63
189 OpLoopMerge %66 %67 None
194 OpBranchConditional %68 %64 %66
201 OpLoopMerge %73 %74 None
204 OpBranchConditional %68 %72 %73
207 %79 = OpSGreaterThanEqual %21 %77 %78
208 OpSelectionMerge %81 None
209 OpBranchConditional %79 %80 %81
214 %85 = OpIAdd %14 %83 %84
231 # uniforms for variant
234 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
238 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
240 PIPELINE graphics variant_pipeline
241 ATTACH variant_vertex_shader
242 ATTACH variant_fragment_shader
243 FRAMEBUFFER_SIZE 256 256
244 BIND BUFFER variant_framebuffer AS color LOCATION 0
245 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
247 CLEAR_COLOR variant_pipeline 0 0 0 255
249 CLEAR variant_pipeline
250 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
252 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255