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