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