1#!amber 2 3# Copyright 2022 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 coverage-gap found by the GraphicsFuzz project. 19 20# Short description: A fragment shader that covers specific LLVM code paths 21 22# The test passes because the shader always writes red. 23 24# Optimized using spirv-opt with the following arguments: 25# '--eliminate-dead-branches' 26# '--merge-return' 27# '--eliminate-local-multi-store' 28# '--inline-entry-points-exhaustive' 29# '--eliminate-dead-branches' 30# '--merge-return' 31# '--redundancy-elimination' 32# '--reduce-load-size' 33# '--simplify-instructions' 34# '--simplify-instructions' 35# '--eliminate-dead-branches' 36# '--merge-return' 37# spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af 38 39 40 41SHADER vertex variant_vertex_shader PASSTHROUGH 42 43# variant_fragment_shader is derived from the following GLSL: 44# #version 320 es 45# #define _int_3 _GLF_uniform_int_values[0] 46# #define _int_5 _GLF_uniform_int_values[1] 47# #define _int_2 _GLF_uniform_int_values[2] 48# #define _int_1 _GLF_uniform_int_values[3] 49# #define _int_0 _GLF_uniform_int_values[4] 50# #define _float_1_0 _GLF_uniform_float_values[0] 51# #define _float_19_0 _GLF_uniform_float_values[1] 52# 53# precision highp float; 54# precision highp int; 55# 56# // Contents of _GLF_uniform_float_values: [1.0, 19.0] 57# layout(set = 0, binding = 0) uniform buf0 58# { 59# float _GLF_uniform_float_values[2]; 60# }; 61# 62# // Contents of _GLF_uniform_int_values: [3, 5, 2, 1, 0] 63# layout(set = 0, binding = 1) uniform buf1 64# { 65# int _GLF_uniform_int_values[5]; 66# }; 67# 68# layout(location = 0) out vec4 _GLF_color; 69# 70# void main() 71# { 72# float arr[9] = float[9](_float_1_0, _float_1_0, _float_1_0, _float_1_0, _float_1_0, _float_1_0, _float_1_0, _float_1_0, _float_1_0); 73# 74# for(int i = _int_1; i < _int_5; i ++) 75# { 76# for(int j = 2; j <= 4; j ++) 77# { 78# for(int k = 0; k < j; k ++) 79# { 80# for(int l = 0; l < 2; l ++) 81# { 82# // Iterated 18 times for each value of i. 83# switch(i) 84# { 85# case 0: 86# arr[i] += _float_1_0; 87# break; 88# case 1: 89# arr[i] += _float_1_0; 90# break; 91# // Matrices only contain zero values. 92# case 2: 93# arr[i] += mat2x4(0.0)[clamp(k, _int_0, _int_1)][l]; 94# break; 95# case 3: 96# arr[i] += mat3x2(0.0)[clamp(k, _int_0, _int_2)][l]; 97# break; 98# case 4: 99# arr[i] += mat3(0.0)[clamp(k, _int_0, _int_2)][l]; 100# break; 101# // Cases below are never executed. 102# case 5: 103# arr[i] += mat3x4(0.0)[clamp(k, 0, _int_2)][l]; 104# break; 105# case 6: 106# arr[i] += mat4x2(0.0)[clamp(k, 0, 3)][l]; 107# break; 108# case 7: 109# arr[i] += mat4x3(0.0)[clamp(k, 0, 3)][l]; 110# // Fallthrough 111# case 8: 112# arr[i] += mat4(0.0)[clamp(k, 0, _int_3)][l]; 113# break; 114# } 115# } 116# } 117# } 118# } 119# 120# // Always true. 121# if(arr[_int_0] == _float_1_0 && arr[_int_1] == _float_19_0 && arr[_int_2] == _float_1_0) 122# { 123# _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1); 124# } 125# else 126# { 127# _GLF_color = vec4(_int_0); 128# } 129# } 130SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 131; SPIR-V 132; Version: 1.0 133; Generator: Khronos Glslang Reference Front End; 10 134; Bound: 307 135; Schema: 0 136 OpCapability Shader 137 %1 = OpExtInstImport "GLSL.std.450" 138 OpMemoryModel Logical GLSL450 139 OpEntryPoint Fragment %4 "main" %282 140 OpExecutionMode %4 OriginUpperLeft 141 OpSource ESSL 320 142 OpName %4 "main" 143 OpName %11 "arr" 144 OpName %14 "buf0" 145 OpMemberName %14 0 "_GLF_uniform_float_values" 146 OpName %16 "" 147 OpName %40 "i" 148 OpName %43 "buf1" 149 OpMemberName %43 0 "_GLF_uniform_int_values" 150 OpName %45 "" 151 OpName %61 "j" 152 OpName %71 "k" 153 OpName %80 "l" 154 OpName %130 "indexable" 155 OpName %151 "indexable" 156 OpName %172 "indexable" 157 OpName %189 "indexable" 158 OpName %204 "indexable" 159 OpName %219 "indexable" 160 OpName %235 "indexable" 161 OpName %282 "_GLF_color" 162 OpDecorate %13 ArrayStride 16 163 OpMemberDecorate %14 0 Offset 0 164 OpDecorate %14 Block 165 OpDecorate %16 DescriptorSet 0 166 OpDecorate %16 Binding 0 167 OpDecorate %42 ArrayStride 16 168 OpMemberDecorate %43 0 Offset 0 169 OpDecorate %43 Block 170 OpDecorate %45 DescriptorSet 0 171 OpDecorate %45 Binding 1 172 OpDecorate %282 Location 0 173 %2 = OpTypeVoid 174 %3 = OpTypeFunction %2 175 %6 = OpTypeFloat 32 176 %7 = OpTypeInt 32 0 177 %8 = OpConstant %7 9 178 %9 = OpTypeArray %6 %8 179 %10 = OpTypePointer Function %9 180 %12 = OpConstant %7 2 181 %13 = OpTypeArray %6 %12 182 %14 = OpTypeStruct %13 183 %15 = OpTypePointer Uniform %14 184 %16 = OpVariable %15 Uniform 185 %17 = OpTypeInt 32 1 186 %18 = OpConstant %17 0 187 %19 = OpTypePointer Uniform %6 188 %39 = OpTypePointer Function %17 189 %41 = OpConstant %7 5 190 %42 = OpTypeArray %17 %41 191 %43 = OpTypeStruct %42 192 %44 = OpTypePointer Uniform %43 193 %45 = OpVariable %44 Uniform 194 %46 = OpConstant %17 3 195 %47 = OpTypePointer Uniform %17 196 %56 = OpConstant %17 1 197 %59 = OpTypeBool 198 %62 = OpConstant %17 2 199 %69 = OpConstant %17 4 200 %102 = OpTypePointer Function %6 201 %117 = OpTypeVector %6 4 202 %118 = OpTypeMatrix %117 2 203 %119 = OpConstant %6 0 204 %120 = OpConstantComposite %117 %119 %119 %119 %119 205 %121 = OpConstantComposite %118 %120 %120 206 %129 = OpTypePointer Function %118 207 %139 = OpTypeVector %6 2 208 %140 = OpTypeMatrix %139 3 209 %141 = OpConstantComposite %139 %119 %119 210 %142 = OpConstantComposite %140 %141 %141 %141 211 %150 = OpTypePointer Function %140 212 %160 = OpTypeVector %6 3 213 %161 = OpTypeMatrix %160 3 214 %162 = OpConstantComposite %160 %119 %119 %119 215 %163 = OpConstantComposite %161 %162 %162 %162 216 %171 = OpTypePointer Function %161 217 %181 = OpTypeMatrix %117 3 218 %182 = OpConstantComposite %181 %120 %120 %120 219 %188 = OpTypePointer Function %181 220 %198 = OpTypeMatrix %139 4 221 %199 = OpConstantComposite %198 %141 %141 %141 %141 222 %203 = OpTypePointer Function %198 223 %213 = OpTypeMatrix %160 4 224 %214 = OpConstantComposite %213 %162 %162 %162 %162 225 %218 = OpTypePointer Function %213 226 %227 = OpTypeMatrix %117 4 227 %228 = OpConstantComposite %227 %120 %120 %120 %120 228 %234 = OpTypePointer Function %227 229 %281 = OpTypePointer Output %117 230 %282 = OpVariable %281 Output 231 %4 = OpFunction %2 None %3 232 %5 = OpLabel 233 %11 = OpVariable %10 Function 234 %40 = OpVariable %39 Function 235 %61 = OpVariable %39 Function 236 %71 = OpVariable %39 Function 237 %80 = OpVariable %39 Function 238 %130 = OpVariable %129 Function 239 %151 = OpVariable %150 Function 240 %172 = OpVariable %171 Function 241 %189 = OpVariable %188 Function 242 %204 = OpVariable %203 Function 243 %219 = OpVariable %218 Function 244 %235 = OpVariable %234 Function 245 %20 = OpAccessChain %19 %16 %18 %18 246 %21 = OpLoad %6 %20 247 %38 = OpCompositeConstruct %9 %21 %21 %21 %21 %21 %21 %21 %21 %21 248 OpStore %11 %38 249 %48 = OpAccessChain %47 %45 %18 %46 250 %49 = OpLoad %17 %48 251 OpStore %40 %49 252 OpBranch %50 253 %50 = OpLabel 254 %301 = OpPhi %17 %49 %5 %251 %53 255 OpLoopMerge %52 %53 None 256 OpBranch %54 257 %54 = OpLabel 258 %57 = OpAccessChain %47 %45 %18 %56 259 %58 = OpLoad %17 %57 260 %60 = OpSLessThan %59 %301 %58 261 OpBranchConditional %60 %51 %52 262 %51 = OpLabel 263 OpStore %61 %62 264 OpBranch %63 265 %63 = OpLabel 266 %302 = OpPhi %17 %62 %51 %249 %66 267 OpLoopMerge %65 %66 None 268 OpBranch %67 269 %67 = OpLabel 270 %70 = OpSLessThanEqual %59 %302 %69 271 OpBranchConditional %70 %64 %65 272 %64 = OpLabel 273 OpStore %71 %18 274 OpBranch %72 275 %72 = OpLabel 276 %304 = OpPhi %17 %18 %64 %247 %75 277 OpLoopMerge %74 %75 None 278 OpBranch %76 279 %76 = OpLabel 280 %79 = OpSLessThan %59 %304 %302 281 OpBranchConditional %79 %73 %74 282 %73 = OpLabel 283 OpStore %80 %18 284 OpBranch %81 285 %81 = OpLabel 286 %306 = OpPhi %17 %18 %73 %245 %84 287 OpLoopMerge %83 %84 None 288 OpBranch %85 289 %85 = OpLabel 290 %87 = OpSLessThan %59 %306 %62 291 OpBranchConditional %87 %82 %83 292 %82 = OpLabel 293 OpSelectionMerge %98 None 294 OpSwitch %301 %98 0 %89 1 %90 2 %91 3 %92 4 %93 5 %94 6 %95 7 %96 8 %97 295 %89 = OpLabel 296 %103 = OpAccessChain %102 %11 %301 297 %104 = OpLoad %6 %103 298 %105 = OpFAdd %6 %104 %21 299 OpStore %103 %105 300 OpBranch %98 301 %90 = OpLabel 302 %111 = OpAccessChain %102 %11 %301 303 %112 = OpLoad %6 %111 304 %113 = OpFAdd %6 %112 %21 305 OpStore %111 %113 306 OpBranch %98 307 %91 = OpLabel 308 %123 = OpAccessChain %47 %45 %18 %69 309 %124 = OpLoad %17 %123 310 %127 = OpExtInst %17 %1 SClamp %304 %124 %49 311 OpStore %130 %121 312 %131 = OpAccessChain %102 %130 %127 %306 313 %132 = OpLoad %6 %131 314 %133 = OpAccessChain %102 %11 %301 315 %134 = OpLoad %6 %133 316 %135 = OpFAdd %6 %134 %132 317 OpStore %133 %135 318 OpBranch %98 319 %92 = OpLabel 320 %144 = OpAccessChain %47 %45 %18 %69 321 %145 = OpLoad %17 %144 322 %146 = OpAccessChain %47 %45 %18 %62 323 %147 = OpLoad %17 %146 324 %148 = OpExtInst %17 %1 SClamp %304 %145 %147 325 OpStore %151 %142 326 %152 = OpAccessChain %102 %151 %148 %306 327 %153 = OpLoad %6 %152 328 %154 = OpAccessChain %102 %11 %301 329 %155 = OpLoad %6 %154 330 %156 = OpFAdd %6 %155 %153 331 OpStore %154 %156 332 OpBranch %98 333 %93 = OpLabel 334 %165 = OpAccessChain %47 %45 %18 %69 335 %166 = OpLoad %17 %165 336 %167 = OpAccessChain %47 %45 %18 %62 337 %168 = OpLoad %17 %167 338 %169 = OpExtInst %17 %1 SClamp %304 %166 %168 339 OpStore %172 %163 340 %173 = OpAccessChain %102 %172 %169 %306 341 %174 = OpLoad %6 %173 342 %175 = OpAccessChain %102 %11 %301 343 %176 = OpLoad %6 %175 344 %177 = OpFAdd %6 %176 %174 345 OpStore %175 %177 346 OpBranch %98 347 %94 = OpLabel 348 %184 = OpAccessChain %47 %45 %18 %62 349 %185 = OpLoad %17 %184 350 %186 = OpExtInst %17 %1 SClamp %304 %18 %185 351 OpStore %189 %182 352 %190 = OpAccessChain %102 %189 %186 %306 353 %191 = OpLoad %6 %190 354 %192 = OpAccessChain %102 %11 %301 355 %193 = OpLoad %6 %192 356 %194 = OpFAdd %6 %193 %191 357 OpStore %192 %194 358 OpBranch %98 359 %95 = OpLabel 360 %201 = OpExtInst %17 %1 SClamp %304 %18 %46 361 OpStore %204 %199 362 %205 = OpAccessChain %102 %204 %201 %306 363 %206 = OpLoad %6 %205 364 %207 = OpAccessChain %102 %11 %301 365 %208 = OpLoad %6 %207 366 %209 = OpFAdd %6 %208 %206 367 OpStore %207 %209 368 OpBranch %98 369 %96 = OpLabel 370 %216 = OpExtInst %17 %1 SClamp %304 %18 %46 371 OpStore %219 %214 372 %220 = OpAccessChain %102 %219 %216 %306 373 %221 = OpLoad %6 %220 374 %222 = OpAccessChain %102 %11 %301 375 %223 = OpLoad %6 %222 376 %224 = OpFAdd %6 %223 %221 377 OpStore %222 %224 378 OpBranch %97 379 %97 = OpLabel 380 %230 = OpAccessChain %47 %45 %18 %18 381 %231 = OpLoad %17 %230 382 %232 = OpExtInst %17 %1 SClamp %304 %18 %231 383 OpStore %235 %228 384 %236 = OpAccessChain %102 %235 %232 %306 385 %237 = OpLoad %6 %236 386 %238 = OpAccessChain %102 %11 %301 387 %239 = OpLoad %6 %238 388 %240 = OpFAdd %6 %239 %237 389 OpStore %238 %240 390 OpBranch %98 391 %98 = OpLabel 392 OpBranch %84 393 %84 = OpLabel 394 %245 = OpIAdd %17 %306 %56 395 OpStore %80 %245 396 OpBranch %81 397 %83 = OpLabel 398 OpBranch %75 399 %75 = OpLabel 400 %247 = OpIAdd %17 %304 %56 401 OpStore %71 %247 402 OpBranch %72 403 %74 = OpLabel 404 OpBranch %66 405 %66 = OpLabel 406 %249 = OpIAdd %17 %302 %56 407 OpStore %61 %249 408 OpBranch %63 409 %65 = OpLabel 410 OpBranch %53 411 %53 = OpLabel 412 %251 = OpIAdd %17 %301 %56 413 OpStore %40 %251 414 OpBranch %50 415 %52 = OpLabel 416 %252 = OpAccessChain %47 %45 %18 %69 417 %253 = OpLoad %17 %252 418 %254 = OpAccessChain %102 %11 %253 419 %255 = OpLoad %6 %254 420 %258 = OpFOrdEqual %59 %255 %21 421 OpSelectionMerge %260 None 422 OpBranchConditional %258 %259 %260 423 %259 = OpLabel 424 %263 = OpAccessChain %102 %11 %49 425 %264 = OpLoad %6 %263 426 %265 = OpAccessChain %19 %16 %18 %56 427 %266 = OpLoad %6 %265 428 %267 = OpFOrdEqual %59 %264 %266 429 OpBranch %260 430 %260 = OpLabel 431 %268 = OpPhi %59 %258 %52 %267 %259 432 OpSelectionMerge %270 None 433 OpBranchConditional %268 %269 %270 434 %269 = OpLabel 435 %271 = OpAccessChain %47 %45 %18 %62 436 %272 = OpLoad %17 %271 437 %273 = OpAccessChain %102 %11 %272 438 %274 = OpLoad %6 %273 439 %277 = OpFOrdEqual %59 %274 %21 440 OpBranch %270 441 %270 = OpLabel 442 %278 = OpPhi %59 %268 %260 %277 %269 443 OpSelectionMerge %280 None 444 OpBranchConditional %278 %279 %296 445 %279 = OpLabel 446 %285 = OpConvertSToF %6 %49 447 %288 = OpConvertSToF %6 %253 448 %295 = OpCompositeConstruct %117 %285 %288 %288 %285 449 OpStore %282 %295 450 OpBranch %280 451 %296 = OpLabel 452 %299 = OpConvertSToF %6 %253 453 %300 = OpCompositeConstruct %117 %299 %299 %299 %299 454 OpStore %282 %300 455 OpBranch %280 456 %280 = OpLabel 457 OpReturn 458 OpFunctionEnd 459END 460 461# uniforms for variant 462 463# _GLF_uniform_int_values 464BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 465 3 5 2 1 0 466END 467# _GLF_uniform_float_values 468BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA 469 1.0 19.0 470END 471 472BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 473 474PIPELINE graphics variant_pipeline 475 ATTACH variant_vertex_shader 476 ATTACH variant_fragment_shader 477 FRAMEBUFFER_SIZE 32 32 478 BIND BUFFER variant_framebuffer AS color LOCATION 0 479 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1 480 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0 481END 482CLEAR_COLOR variant_pipeline 0 0 0 255 483 484CLEAR variant_pipeline 485RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32 486 487EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255 488