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 24SHADER vertex variant_vertex_shader PASSTHROUGH 25 26# variant_fragment_shader is derived from the following GLSL: 27# #version 320 es 28# #define _int_0 _GLF_uniform_int_values[0] 29# #define _int_1 _GLF_uniform_int_values[1] 30# #define _int_2 _GLF_uniform_int_values[2] 31# #define _int_7 _GLF_uniform_int_values[3] 32# #define _int_8 _GLF_uniform_int_values[4] 33# 34# precision highp float; 35# precision highp int; 36# 37# // Contents of _GLF_uniform_int_values: [0, 1, 2, 7, 8] 38# layout(set = 0, binding = 0) uniform buf0 39# { 40# int _GLF_uniform_int_values[5]; 41# }; 42# 43# const int _GLF_global_loop_bound = 10; 44# int _GLF_global_loop_count = 0; 45# 46# layout(location = 0) out vec4 _GLF_color; 47# 48# void main() 49# { 50# int arr0[16] = int[16](_int_0, _int_0, _int_0, _int_0, _int_0, _int_0, _int_0, _int_0, _int_0, _int_0, _int_0, _int_0, _int_0, _int_0, _int_0, _int_0); 51# int arr1[16] = int[16](_int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1); 52# ivec2 v = ivec2(_int_1); 53# 54# // Iterates once. 55# for(int i = _int_1; i < _int_8 && _GLF_global_loop_count < _GLF_global_loop_bound; i++) 56# { 57# _GLF_global_loop_count++; 58# 59# // Iterated once. 60# for(int j = 1; _GLF_global_loop_count < _GLF_global_loop_bound; j++) 61# { 62# _GLF_global_loop_count++; 63# 64# do 65# { 66# _GLF_global_loop_count++; 67# 68# // Always true. 69# if(arr1[j + i] == _int_1) 70# { 71# v.x = _int_1; 72# int a = _int_1; 73# int b = _int_1; 74# 75# // Iterates once. 76# while(_GLF_global_loop_count < _GLF_global_loop_bound) 77# { 78# _GLF_global_loop_count++; 79# 80# // Iterates once. 81# for(int k = _int_1; k < _int_8 && _GLF_global_loop_count < _GLF_global_loop_bound; k++) 82# { 83# _GLF_global_loop_count++; 84# 85# if(b >= _int_7) 86# { 87# break; 88# } 89# b++; 90# 91# while(_GLF_global_loop_count < _GLF_global_loop_bound) 92# { 93# _GLF_global_loop_count++; 94# } 95# } 96# 97# // Always false. 98# if(arr0[_int_1] == _int_1) 99# { 100# a++; 101# } 102# 103# // Always true. 104# if(a == _int_1) 105# { 106# while(_GLF_global_loop_count < _GLF_global_loop_bound) 107# { 108# _GLF_global_loop_count++; 109# } 110# 111# arr0[a] = _int_1; 112# } 113# 114# if(a >= _int_7) 115# { 116# break; 117# } 118# a++; 119# } 120# 121# // Never iterated. 122# while(_GLF_global_loop_count < _GLF_global_loop_bound) 123# { 124# _GLF_global_loop_count++; 125# } 126# } 127# } 128# while(_GLF_global_loop_count < _GLF_global_loop_bound); 129# } 130# } 131# 132# arr1[v.x + v.y] = _int_2; 133# 134# // Always true. 135# if(arr0[_int_1] == _int_1 && arr1[_int_2] == _int_2) 136# { 137# _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1); 138# } 139# else 140# { 141# _GLF_color = vec4(_int_0); 142# } 143# } 144SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 145; SPIR-V 146; Version: 1.0 147; Generator: Khronos Glslang Reference Front End; 10 148; Bound: 304 149; Schema: 0 150 OpCapability Shader 151 %1 = OpExtInstImport "GLSL.std.450" 152 OpMemoryModel Logical GLSL450 153 OpEntryPoint Fragment %4 "main" %285 154 OpExecutionMode %4 OriginUpperLeft 155 OpSource ESSL 320 156 OpName %4 "main" 157 OpName %8 "_GLF_global_loop_count" 158 OpName %14 "arr0" 159 OpName %17 "buf0" 160 OpMemberName %17 0 "_GLF_uniform_int_values" 161 OpName %19 "" 162 OpName %54 "arr1" 163 OpName %91 "v" 164 OpName %96 "i" 165 OpName %116 "j" 166 OpName %146 "a" 167 OpName %149 "b" 168 OpName %161 "k" 169 OpName %285 "_GLF_color" 170 OpDecorate %16 ArrayStride 16 171 OpMemberDecorate %17 0 Offset 0 172 OpDecorate %17 Block 173 OpDecorate %19 DescriptorSet 0 174 OpDecorate %19 Binding 0 175 OpDecorate %285 Location 0 176 %2 = OpTypeVoid 177 %3 = OpTypeFunction %2 178 %6 = OpTypeInt 32 1 179 %7 = OpTypePointer Private %6 180 %8 = OpVariable %7 Private 181 %9 = OpConstant %6 0 182 %10 = OpTypeInt 32 0 183 %11 = OpConstant %10 16 184 %12 = OpTypeArray %6 %11 185 %13 = OpTypePointer Function %12 186 %15 = OpConstant %10 5 187 %16 = OpTypeArray %6 %15 188 %17 = OpTypeStruct %16 189 %18 = OpTypePointer Uniform %17 190 %19 = OpVariable %18 Uniform 191 %20 = OpTypePointer Uniform %6 192 %55 = OpConstant %6 1 193 %89 = OpTypeVector %6 2 194 %90 = OpTypePointer Function %89 195 %95 = OpTypePointer Function %6 196 %105 = OpConstant %6 4 197 %108 = OpTypeBool 198 %111 = OpConstant %6 10 199 %144 = OpConstant %10 0 200 %179 = OpConstant %6 3 201 %255 = OpConstant %10 1 202 %259 = OpConstant %6 2 203 %282 = OpTypeFloat 32 204 %283 = OpTypeVector %282 4 205 %284 = OpTypePointer Output %283 206 %285 = OpVariable %284 Output 207 %4 = OpFunction %2 None %3 208 %5 = OpLabel 209 %14 = OpVariable %13 Function 210 %54 = OpVariable %13 Function 211 %91 = OpVariable %90 Function 212 %96 = OpVariable %95 Function 213 %116 = OpVariable %95 Function 214 %146 = OpVariable %95 Function 215 %149 = OpVariable %95 Function 216 %161 = OpVariable %95 Function 217 OpStore %8 %9 218 %21 = OpAccessChain %20 %19 %9 %9 219 %22 = OpLoad %6 %21 220 %23 = OpAccessChain %20 %19 %9 %9 221 %24 = OpLoad %6 %23 222 %25 = OpAccessChain %20 %19 %9 %9 223 %26 = OpLoad %6 %25 224 %27 = OpAccessChain %20 %19 %9 %9 225 %28 = OpLoad %6 %27 226 %29 = OpAccessChain %20 %19 %9 %9 227 %30 = OpLoad %6 %29 228 %31 = OpAccessChain %20 %19 %9 %9 229 %32 = OpLoad %6 %31 230 %33 = OpAccessChain %20 %19 %9 %9 231 %34 = OpLoad %6 %33 232 %35 = OpAccessChain %20 %19 %9 %9 233 %36 = OpLoad %6 %35 234 %37 = OpAccessChain %20 %19 %9 %9 235 %38 = OpLoad %6 %37 236 %39 = OpAccessChain %20 %19 %9 %9 237 %40 = OpLoad %6 %39 238 %41 = OpAccessChain %20 %19 %9 %9 239 %42 = OpLoad %6 %41 240 %43 = OpAccessChain %20 %19 %9 %9 241 %44 = OpLoad %6 %43 242 %45 = OpAccessChain %20 %19 %9 %9 243 %46 = OpLoad %6 %45 244 %47 = OpAccessChain %20 %19 %9 %9 245 %48 = OpLoad %6 %47 246 %49 = OpAccessChain %20 %19 %9 %9 247 %50 = OpLoad %6 %49 248 %51 = OpAccessChain %20 %19 %9 %9 249 %52 = OpLoad %6 %51 250 %53 = OpCompositeConstruct %12 %22 %24 %26 %28 %30 %32 %34 %36 %38 %40 %42 %44 %46 %48 %50 %52 251 OpStore %14 %53 252 %56 = OpAccessChain %20 %19 %9 %55 253 %57 = OpLoad %6 %56 254 %58 = OpAccessChain %20 %19 %9 %55 255 %59 = OpLoad %6 %58 256 %60 = OpAccessChain %20 %19 %9 %55 257 %61 = OpLoad %6 %60 258 %62 = OpAccessChain %20 %19 %9 %55 259 %63 = OpLoad %6 %62 260 %64 = OpAccessChain %20 %19 %9 %55 261 %65 = OpLoad %6 %64 262 %66 = OpAccessChain %20 %19 %9 %55 263 %67 = OpLoad %6 %66 264 %68 = OpAccessChain %20 %19 %9 %55 265 %69 = OpLoad %6 %68 266 %70 = OpAccessChain %20 %19 %9 %55 267 %71 = OpLoad %6 %70 268 %72 = OpAccessChain %20 %19 %9 %55 269 %73 = OpLoad %6 %72 270 %74 = OpAccessChain %20 %19 %9 %55 271 %75 = OpLoad %6 %74 272 %76 = OpAccessChain %20 %19 %9 %55 273 %77 = OpLoad %6 %76 274 %78 = OpAccessChain %20 %19 %9 %55 275 %79 = OpLoad %6 %78 276 %80 = OpAccessChain %20 %19 %9 %55 277 %81 = OpLoad %6 %80 278 %82 = OpAccessChain %20 %19 %9 %55 279 %83 = OpLoad %6 %82 280 %84 = OpAccessChain %20 %19 %9 %55 281 %85 = OpLoad %6 %84 282 %86 = OpAccessChain %20 %19 %9 %55 283 %87 = OpLoad %6 %86 284 %88 = OpCompositeConstruct %12 %57 %59 %61 %63 %65 %67 %69 %71 %73 %75 %77 %79 %81 %83 %85 %87 285 OpStore %54 %88 286 %92 = OpAccessChain %20 %19 %9 %55 287 %93 = OpLoad %6 %92 288 %94 = OpCompositeConstruct %89 %93 %93 289 OpStore %91 %94 290 %97 = OpAccessChain %20 %19 %9 %55 291 %98 = OpLoad %6 %97 292 OpStore %96 %98 293 OpBranch %99 294 %99 = OpLabel 295 OpLoopMerge %101 %102 None 296 OpBranch %103 297 %103 = OpLabel 298 %104 = OpLoad %6 %96 299 %106 = OpAccessChain %20 %19 %9 %105 300 %107 = OpLoad %6 %106 301 %109 = OpSLessThan %108 %104 %107 302 %110 = OpLoad %6 %8 303 %112 = OpSLessThan %108 %110 %111 304 %113 = OpLogicalAnd %108 %109 %112 305 OpBranchConditional %113 %100 %101 306 %100 = OpLabel 307 %114 = OpLoad %6 %8 308 %115 = OpIAdd %6 %114 %55 309 OpStore %8 %115 310 OpStore %116 %55 311 OpBranch %117 312 %117 = OpLabel 313 OpLoopMerge %119 %120 None 314 OpBranch %121 315 %121 = OpLabel 316 %122 = OpLoad %6 %8 317 %123 = OpSLessThan %108 %122 %111 318 OpBranchConditional %123 %118 %119 319 %118 = OpLabel 320 %124 = OpLoad %6 %8 321 %125 = OpIAdd %6 %124 %55 322 OpStore %8 %125 323 OpBranch %126 324 %126 = OpLabel 325 OpLoopMerge %128 %129 None 326 OpBranch %127 327 %127 = OpLabel 328 %130 = OpLoad %6 %8 329 %131 = OpIAdd %6 %130 %55 330 OpStore %8 %131 331 %132 = OpLoad %6 %116 332 %133 = OpLoad %6 %96 333 %134 = OpIAdd %6 %132 %133 334 %135 = OpAccessChain %95 %54 %134 335 %136 = OpLoad %6 %135 336 %137 = OpAccessChain %20 %19 %9 %55 337 %138 = OpLoad %6 %137 338 %139 = OpIEqual %108 %136 %138 339 OpSelectionMerge %141 None 340 OpBranchConditional %139 %140 %141 341 %140 = OpLabel 342 %142 = OpAccessChain %20 %19 %9 %55 343 %143 = OpLoad %6 %142 344 %145 = OpAccessChain %95 %91 %144 345 OpStore %145 %143 346 %147 = OpAccessChain %20 %19 %9 %55 347 %148 = OpLoad %6 %147 348 OpStore %146 %148 349 %150 = OpAccessChain %20 %19 %9 %55 350 %151 = OpLoad %6 %150 351 OpStore %149 %151 352 OpBranch %152 353 %152 = OpLabel 354 OpLoopMerge %154 %155 None 355 OpBranch %156 356 %156 = OpLabel 357 %157 = OpLoad %6 %8 358 %158 = OpSLessThan %108 %157 %111 359 OpBranchConditional %158 %153 %154 360 %153 = OpLabel 361 %159 = OpLoad %6 %8 362 %160 = OpIAdd %6 %159 %55 363 OpStore %8 %160 364 %162 = OpAccessChain %20 %19 %9 %55 365 %163 = OpLoad %6 %162 366 OpStore %161 %163 367 OpBranch %164 368 %164 = OpLabel 369 OpLoopMerge %166 %167 None 370 OpBranch %168 371 %168 = OpLabel 372 %169 = OpLoad %6 %161 373 %170 = OpAccessChain %20 %19 %9 %105 374 %171 = OpLoad %6 %170 375 %172 = OpSLessThan %108 %169 %171 376 %173 = OpLoad %6 %8 377 %174 = OpSLessThan %108 %173 %111 378 %175 = OpLogicalAnd %108 %172 %174 379 OpBranchConditional %175 %165 %166 380 %165 = OpLabel 381 %176 = OpLoad %6 %8 382 %177 = OpIAdd %6 %176 %55 383 OpStore %8 %177 384 %178 = OpLoad %6 %149 385 %180 = OpAccessChain %20 %19 %9 %179 386 %181 = OpLoad %6 %180 387 %182 = OpSGreaterThanEqual %108 %178 %181 388 OpSelectionMerge %184 None 389 OpBranchConditional %182 %183 %184 390 %183 = OpLabel 391 OpBranch %166 392 %184 = OpLabel 393 %186 = OpLoad %6 %149 394 %187 = OpIAdd %6 %186 %55 395 OpStore %149 %187 396 OpBranch %188 397 %188 = OpLabel 398 OpLoopMerge %190 %191 None 399 OpBranch %192 400 %192 = OpLabel 401 %193 = OpLoad %6 %8 402 %194 = OpSLessThan %108 %193 %111 403 OpBranchConditional %194 %189 %190 404 %189 = OpLabel 405 %195 = OpLoad %6 %8 406 %196 = OpIAdd %6 %195 %55 407 OpStore %8 %196 408 OpBranch %191 409 %191 = OpLabel 410 OpBranch %188 411 %190 = OpLabel 412 OpBranch %167 413 %167 = OpLabel 414 %197 = OpLoad %6 %161 415 %198 = OpIAdd %6 %197 %55 416 OpStore %161 %198 417 OpBranch %164 418 %166 = OpLabel 419 %199 = OpAccessChain %20 %19 %9 %55 420 %200 = OpLoad %6 %199 421 %201 = OpAccessChain %95 %14 %200 422 %202 = OpLoad %6 %201 423 %203 = OpAccessChain %20 %19 %9 %55 424 %204 = OpLoad %6 %203 425 %205 = OpIEqual %108 %202 %204 426 OpSelectionMerge %207 None 427 OpBranchConditional %205 %206 %207 428 %206 = OpLabel 429 %208 = OpLoad %6 %146 430 %209 = OpIAdd %6 %208 %55 431 OpStore %146 %209 432 OpBranch %207 433 %207 = OpLabel 434 %210 = OpLoad %6 %146 435 %211 = OpAccessChain %20 %19 %9 %55 436 %212 = OpLoad %6 %211 437 %213 = OpIEqual %108 %210 %212 438 OpSelectionMerge %215 None 439 OpBranchConditional %213 %214 %215 440 %214 = OpLabel 441 OpBranch %216 442 %216 = OpLabel 443 OpLoopMerge %218 %219 None 444 OpBranch %220 445 %220 = OpLabel 446 %221 = OpLoad %6 %8 447 %222 = OpSLessThan %108 %221 %111 448 OpBranchConditional %222 %217 %218 449 %217 = OpLabel 450 %223 = OpLoad %6 %8 451 %224 = OpIAdd %6 %223 %55 452 OpStore %8 %224 453 OpBranch %219 454 %219 = OpLabel 455 OpBranch %216 456 %218 = OpLabel 457 %225 = OpLoad %6 %146 458 %226 = OpAccessChain %20 %19 %9 %55 459 %227 = OpLoad %6 %226 460 %228 = OpAccessChain %95 %14 %225 461 OpStore %228 %227 462 OpBranch %215 463 %215 = OpLabel 464 %229 = OpLoad %6 %146 465 %230 = OpAccessChain %20 %19 %9 %179 466 %231 = OpLoad %6 %230 467 %232 = OpSGreaterThanEqual %108 %229 %231 468 OpSelectionMerge %234 None 469 OpBranchConditional %232 %233 %234 470 %233 = OpLabel 471 OpBranch %154 472 %234 = OpLabel 473 %236 = OpLoad %6 %146 474 %237 = OpIAdd %6 %236 %55 475 OpStore %146 %237 476 OpBranch %155 477 %155 = OpLabel 478 OpBranch %152 479 %154 = OpLabel 480 OpBranch %238 481 %238 = OpLabel 482 OpLoopMerge %240 %241 None 483 OpBranch %242 484 %242 = OpLabel 485 %243 = OpLoad %6 %8 486 %244 = OpSLessThan %108 %243 %111 487 OpBranchConditional %244 %239 %240 488 %239 = OpLabel 489 %245 = OpLoad %6 %8 490 %246 = OpIAdd %6 %245 %55 491 OpStore %8 %246 492 OpBranch %241 493 %241 = OpLabel 494 OpBranch %238 495 %240 = OpLabel 496 OpBranch %141 497 %141 = OpLabel 498 OpBranch %129 499 %129 = OpLabel 500 %247 = OpLoad %6 %8 501 %248 = OpSLessThan %108 %247 %111 502 OpBranchConditional %248 %126 %128 503 %128 = OpLabel 504 OpBranch %120 505 %120 = OpLabel 506 %249 = OpLoad %6 %116 507 %250 = OpIAdd %6 %249 %55 508 OpStore %116 %250 509 OpBranch %117 510 %119 = OpLabel 511 OpBranch %102 512 %102 = OpLabel 513 %251 = OpLoad %6 %96 514 %252 = OpIAdd %6 %251 %55 515 OpStore %96 %252 516 OpBranch %99 517 %101 = OpLabel 518 %253 = OpAccessChain %95 %91 %144 519 %254 = OpLoad %6 %253 520 %256 = OpAccessChain %95 %91 %255 521 %257 = OpLoad %6 %256 522 %258 = OpIAdd %6 %254 %257 523 %260 = OpAccessChain %20 %19 %9 %259 524 %261 = OpLoad %6 %260 525 %262 = OpAccessChain %95 %54 %258 526 OpStore %262 %261 527 %263 = OpAccessChain %20 %19 %9 %55 528 %264 = OpLoad %6 %263 529 %265 = OpAccessChain %95 %14 %264 530 %266 = OpLoad %6 %265 531 %267 = OpAccessChain %20 %19 %9 %55 532 %268 = OpLoad %6 %267 533 %269 = OpIEqual %108 %266 %268 534 OpSelectionMerge %271 None 535 OpBranchConditional %269 %270 %271 536 %270 = OpLabel 537 %272 = OpAccessChain %20 %19 %9 %259 538 %273 = OpLoad %6 %272 539 %274 = OpAccessChain %95 %54 %273 540 %275 = OpLoad %6 %274 541 %276 = OpAccessChain %20 %19 %9 %259 542 %277 = OpLoad %6 %276 543 %278 = OpIEqual %108 %275 %277 544 OpBranch %271 545 %271 = OpLabel 546 %279 = OpPhi %108 %269 %101 %278 %270 547 OpSelectionMerge %281 None 548 OpBranchConditional %279 %280 %299 549 %280 = OpLabel 550 %286 = OpAccessChain %20 %19 %9 %55 551 %287 = OpLoad %6 %286 552 %288 = OpConvertSToF %282 %287 553 %289 = OpAccessChain %20 %19 %9 %9 554 %290 = OpLoad %6 %289 555 %291 = OpConvertSToF %282 %290 556 %292 = OpAccessChain %20 %19 %9 %9 557 %293 = OpLoad %6 %292 558 %294 = OpConvertSToF %282 %293 559 %295 = OpAccessChain %20 %19 %9 %55 560 %296 = OpLoad %6 %295 561 %297 = OpConvertSToF %282 %296 562 %298 = OpCompositeConstruct %283 %288 %291 %294 %297 563 OpStore %285 %298 564 OpBranch %281 565 %299 = OpLabel 566 %300 = OpAccessChain %20 %19 %9 %9 567 %301 = OpLoad %6 %300 568 %302 = OpConvertSToF %282 %301 569 %303 = OpCompositeConstruct %283 %302 %302 %302 %302 570 OpStore %285 %303 571 OpBranch %281 572 %281 = OpLabel 573 OpReturn 574 OpFunctionEnd 575END 576 577# uniforms for variant 578 579# _GLF_uniform_int_values 580BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 581 0 1 2 7 8 582END 583 584BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 585 586PIPELINE graphics variant_pipeline 587 ATTACH variant_vertex_shader 588 ATTACH variant_fragment_shader 589 FRAMEBUFFER_SIZE 32 32 590 BIND BUFFER variant_framebuffer AS color LOCATION 0 591 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0 592END 593CLEAR_COLOR variant_pipeline 0 0 0 255 594 595CLEAR variant_pipeline 596RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32 597 598EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255 599