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 nested control flow and a call
22 # The test passes because all loops terminate or are not entered and the shader ends by writing 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;
36 # struct BinarySearchObject
38 # int prime_numbers[10];
41 # int binarySearch(BinarySearchObject obj)
43 # while (injectionSwitch.x > 1.0) // always false
45 # int m = int(injectionSwitch.x);
46 # if (obj.prime_numbers[m] == 1)
56 # BinarySearchObject obj;
64 # if ((i - int(injectionSwitch.x)) == 4)
66 # obj.prime_numbers[i] = 11;
72 # obj.prime_numbers[i] = 17;
79 # } while (0.0 > injectionSwitch.y); // always false
82 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
84 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
87 ; Generator: Khronos Glslang Reference Front End; 7
91 %1 = OpExtInstImport "GLSL.std.450"
92 OpMemoryModel Logical GLSL450
93 OpEntryPoint Fragment %4 "main" %102
94 OpExecutionMode %4 OriginUpperLeft
97 OpName %10 "BinarySearchObject"
98 OpMemberName %10 0 "prime_numbers"
99 OpName %14 "binarySearch(struct-BinarySearchObject-i1[10]1;"
102 OpMemberName %23 0 "injectionSwitch"
108 OpName %102 "_GLF_color"
109 OpMemberDecorate %10 0 RelaxedPrecision
110 OpDecorate %14 RelaxedPrecision
111 OpMemberDecorate %23 0 Offset 0
113 OpDecorate %25 DescriptorSet 0
114 OpDecorate %25 Binding 0
115 OpDecorate %35 RelaxedPrecision
116 OpDecorate %38 RelaxedPrecision
117 OpDecorate %39 RelaxedPrecision
118 OpDecorate %41 RelaxedPrecision
119 OpDecorate %49 RelaxedPrecision
120 OpDecorate %55 RelaxedPrecision
121 OpDecorate %58 RelaxedPrecision
122 OpDecorate %63 RelaxedPrecision
123 OpDecorate %66 RelaxedPrecision
124 OpDecorate %67 RelaxedPrecision
125 OpDecorate %73 RelaxedPrecision
126 OpDecorate %77 RelaxedPrecision
127 OpDecorate %82 RelaxedPrecision
128 OpDecorate %95 RelaxedPrecision
129 OpDecorate %96 RelaxedPrecision
130 OpDecorate %99 RelaxedPrecision
131 OpDecorate %102 Location 0
133 %3 = OpTypeFunction %2
136 %8 = OpConstant %7 10
137 %9 = OpTypeArray %6 %8
138 %10 = OpTypeStruct %9
139 %11 = OpTypePointer Function %10
140 %12 = OpTypeFunction %6 %11
142 %22 = OpTypeVector %21 2
143 %23 = OpTypeStruct %22
144 %24 = OpTypePointer Uniform %23
145 %25 = OpVariable %24 Uniform
146 %26 = OpConstant %6 0
147 %27 = OpConstant %7 0
148 %28 = OpTypePointer Uniform %21
149 %31 = OpConstant %21 1
151 %34 = OpTypePointer Function %6
152 %42 = OpConstant %6 1
153 %56 = OpConstant %6 10
154 %59 = OpConstant %6 3
155 %68 = OpConstant %6 4
156 %74 = OpConstant %6 11
157 %78 = OpConstant %6 6
158 %83 = OpConstant %6 17
159 %90 = OpConstant %21 0
160 %91 = OpConstant %7 1
161 %100 = OpTypeVector %21 4
162 %101 = OpTypePointer Output %100
163 %102 = OpVariable %101 Output
164 %103 = OpConstantComposite %100 %31 %90 %90 %31
165 %4 = OpFunction %2 None %3
167 %49 = OpVariable %34 Function
168 %72 = OpVariable %11 Function
169 %97 = OpVariable %11 Function
173 OpLoopMerge %52 %53 None
177 %57 = OpSLessThan %32 %55 %56
178 OpBranchConditional %57 %51 %52
181 %60 = OpINotEqual %32 %58 %59
182 OpSelectionMerge %62 None
183 OpBranchConditional %60 %61 %62
186 %64 = OpAccessChain %28 %25 %26 %27
188 %66 = OpConvertFToS %6 %65
189 %67 = OpISub %6 %63 %66
190 %69 = OpIEqual %32 %67 %68
191 OpSelectionMerge %71 None
192 OpBranchConditional %69 %70 %76
195 %75 = OpAccessChain %34 %72 %26 %73
200 %79 = OpIEqual %32 %77 %78
201 OpSelectionMerge %81 None
202 OpBranchConditional %79 %80 %81
205 %84 = OpAccessChain %34 %72 %26 %82
215 OpLoopMerge %88 %89 None
220 %92 = OpAccessChain %28 %25 %26 %91
222 %94 = OpFOrdGreaterThan %32 %90 %93
223 OpBranchConditional %94 %86 %88
228 %96 = OpIAdd %6 %95 %42
234 %99 = OpFunctionCall %6 %14 %97
238 %14 = OpFunction %6 None %12
239 %13 = OpFunctionParameter %11
241 %35 = OpVariable %34 Function
244 OpLoopMerge %18 %19 None
247 %29 = OpAccessChain %28 %25 %26 %27
249 %33 = OpFOrdGreaterThan %32 %30 %31
250 OpBranchConditional %33 %17 %18
252 %36 = OpAccessChain %28 %25 %26 %27
254 %38 = OpConvertFToS %6 %37
257 %40 = OpAccessChain %34 %13 %26 %39
259 %43 = OpIEqual %32 %41 %42
260 OpSelectionMerge %45 None
261 OpBranchConditional %43 %44 %45
273 # uniforms for variant
276 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
280 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
282 PIPELINE graphics variant_pipeline
283 ATTACH variant_vertex_shader
284 ATTACH variant_fragment_shader
285 FRAMEBUFFER_SIZE 256 256
286 BIND BUFFER variant_framebuffer AS color LOCATION 0
287 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
289 CLEAR_COLOR variant_pipeline 0 0 0 255
291 CLEAR variant_pipeline
292 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
294 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255