1#!amber 2 3# Copyright 2019 Google LLC 4# 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 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 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. 16 17 18# A test for a bug found by GraphicsFuzz. 19 20# Short description: A fragment shader with nested control flow and a call 21 22# The test passes because all loops terminate or are not entered and the shader ends by writing red. 23 24SHADER vertex variant_vertex_shader PASSTHROUGH 25 26# variant_fragment_shader is derived from the following GLSL: 27# #version 310 es 28# precision highp float; 29# 30# layout(set = 0, binding = 0) uniform buf0 31# { 32# vec2 injectionSwitch; 33# }; 34# layout(location = 0) out vec4 _GLF_color; 35# 36# struct BinarySearchObject 37# { 38# int prime_numbers[10]; 39# }; 40# 41# int binarySearch(BinarySearchObject obj) 42# { 43# while (injectionSwitch.x > 1.0) // always false 44# { 45# int m = int(injectionSwitch.x); 46# if (obj.prime_numbers[m] == 1) 47# { 48# return 1; 49# } 50# } 51# return 1; 52# } 53# 54# void main() 55# { 56# BinarySearchObject obj; 57# for ( 58# int i = 0; 59# i < 10; 60# i++) 61# { 62# if (i != 3) 63# { 64# if ((i - int(injectionSwitch.x)) == 4) 65# { 66# obj.prime_numbers[i] = 11; 67# } 68# else 69# { 70# if (i == 6) 71# { 72# obj.prime_numbers[i] = 17; 73# } 74# continue; 75# } 76# } 77# do 78# { 79# } while (0.0 > injectionSwitch.y); // always false 80# } 81# binarySearch(obj); 82# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); 83# } 84SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 85; SPIR-V 86; Version: 1.0 87; Generator: Khronos Glslang Reference Front End; 7 88; Bound: 104 89; Schema: 0 90 OpCapability Shader 91 %1 = OpExtInstImport "GLSL.std.450" 92 OpMemoryModel Logical GLSL450 93 OpEntryPoint Fragment %4 "main" %102 94 OpExecutionMode %4 OriginUpperLeft 95 OpSource ESSL 310 96 OpName %4 "main" 97 OpName %10 "BinarySearchObject" 98 OpMemberName %10 0 "prime_numbers" 99 OpName %14 "binarySearch(struct-BinarySearchObject-i1[10]1;" 100 OpName %13 "obj" 101 OpName %23 "buf0" 102 OpMemberName %23 0 "injectionSwitch" 103 OpName %25 "" 104 OpName %35 "m" 105 OpName %49 "i" 106 OpName %72 "obj" 107 OpName %97 "param" 108 OpName %102 "_GLF_color" 109 OpMemberDecorate %10 0 RelaxedPrecision 110 OpDecorate %14 RelaxedPrecision 111 OpMemberDecorate %23 0 Offset 0 112 OpDecorate %23 Block 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 132 %2 = OpTypeVoid 133 %3 = OpTypeFunction %2 134 %6 = OpTypeInt 32 1 135 %7 = OpTypeInt 32 0 136 %8 = OpConstant %7 10 137 %9 = OpTypeArray %6 %8 138 %10 = OpTypeStruct %9 139 %11 = OpTypePointer Function %10 140 %12 = OpTypeFunction %6 %11 141 %21 = OpTypeFloat 32 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 150 %32 = OpTypeBool 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 166 %5 = OpLabel 167 %49 = OpVariable %34 Function 168 %72 = OpVariable %11 Function 169 %97 = OpVariable %11 Function 170 OpStore %49 %26 171 OpBranch %50 172 %50 = OpLabel 173 OpLoopMerge %52 %53 None 174 OpBranch %54 175 %54 = OpLabel 176 %55 = OpLoad %6 %49 177 %57 = OpSLessThan %32 %55 %56 178 OpBranchConditional %57 %51 %52 179 %51 = OpLabel 180 %58 = OpLoad %6 %49 181 %60 = OpINotEqual %32 %58 %59 182 OpSelectionMerge %62 None 183 OpBranchConditional %60 %61 %62 184 %61 = OpLabel 185 %63 = OpLoad %6 %49 186 %64 = OpAccessChain %28 %25 %26 %27 187 %65 = OpLoad %21 %64 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 193 %70 = OpLabel 194 %73 = OpLoad %6 %49 195 %75 = OpAccessChain %34 %72 %26 %73 196 OpStore %75 %74 197 OpBranch %71 198 %76 = OpLabel 199 %77 = OpLoad %6 %49 200 %79 = OpIEqual %32 %77 %78 201 OpSelectionMerge %81 None 202 OpBranchConditional %79 %80 %81 203 %80 = OpLabel 204 %82 = OpLoad %6 %49 205 %84 = OpAccessChain %34 %72 %26 %82 206 OpStore %84 %83 207 OpBranch %81 208 %81 = OpLabel 209 OpBranch %53 210 %71 = OpLabel 211 OpBranch %62 212 %62 = OpLabel 213 OpBranch %86 214 %86 = OpLabel 215 OpLoopMerge %88 %89 None 216 OpBranch %87 217 %87 = OpLabel 218 OpBranch %89 219 %89 = OpLabel 220 %92 = OpAccessChain %28 %25 %26 %91 221 %93 = OpLoad %21 %92 222 %94 = OpFOrdGreaterThan %32 %90 %93 223 OpBranchConditional %94 %86 %88 224 %88 = OpLabel 225 OpBranch %53 226 %53 = OpLabel 227 %95 = OpLoad %6 %49 228 %96 = OpIAdd %6 %95 %42 229 OpStore %49 %96 230 OpBranch %50 231 %52 = OpLabel 232 %98 = OpLoad %10 %72 233 OpStore %97 %98 234 %99 = OpFunctionCall %6 %14 %97 235 OpStore %102 %103 236 OpReturn 237 OpFunctionEnd 238 %14 = OpFunction %6 None %12 239 %13 = OpFunctionParameter %11 240 %15 = OpLabel 241 %35 = OpVariable %34 Function 242 OpBranch %16 243 %16 = OpLabel 244 OpLoopMerge %18 %19 None 245 OpBranch %20 246 %20 = OpLabel 247 %29 = OpAccessChain %28 %25 %26 %27 248 %30 = OpLoad %21 %29 249 %33 = OpFOrdGreaterThan %32 %30 %31 250 OpBranchConditional %33 %17 %18 251 %17 = OpLabel 252 %36 = OpAccessChain %28 %25 %26 %27 253 %37 = OpLoad %21 %36 254 %38 = OpConvertFToS %6 %37 255 OpStore %35 %38 256 %39 = OpLoad %6 %35 257 %40 = OpAccessChain %34 %13 %26 %39 258 %41 = OpLoad %6 %40 259 %43 = OpIEqual %32 %41 %42 260 OpSelectionMerge %45 None 261 OpBranchConditional %43 %44 %45 262 %44 = OpLabel 263 OpReturnValue %42 264 %45 = OpLabel 265 OpBranch %19 266 %19 = OpLabel 267 OpBranch %16 268 %18 = OpLabel 269 OpReturnValue %42 270 OpFunctionEnd 271END 272 273# uniforms for variant 274 275# injectionSwitch 276BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA 277 0.0 1.0 278END 279 280BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 281 282PIPELINE 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 288END 289CLEAR_COLOR variant_pipeline 0 0 0 255 290 291CLEAR variant_pipeline 292RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 293 294EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 295