#!amber # Copyright 2021 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # A test for a coverage-gap found by the GraphicsFuzz project. # Short description: A fragment shader that covers specific BRW code paths # The test passes because the shader always writes red. # Optimized using spirv-opt with the following arguments: # '-O' # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af SHADER vertex variant_vertex_shader PASSTHROUGH # variant_fragment_shader is derived from the following GLSL: # #version 320 es # # #define _GLF_MAKE_IN_BOUNDS_INT(IDX, SZ) clamp(IDX, 0, SZ - 1) # #define LOOP for (int i = 0; i < 1; i++) # # precision highp float; # precision highp int; # # const int _GLF_global_loop_bound = 100; # int _GLF_global_loop_count = 0; # # layout(location = 0) out vec4 _GLF_color; # # void main() # { # float arr[10] = float[10](1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0); # int index = 0; # # while(_GLF_global_loop_count < _GLF_global_loop_bound) # { # // The inner loop will be iterated just once. # LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { # LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { # LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { LOOP { # LOOP { LOOP { LOOP { LOOP { LOOP # { # _GLF_global_loop_count ++; # } # } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } # # // In the end all elemenst of arr have a value of 2.0. # arr[_GLF_MAKE_IN_BOUNDS_INT(index, 10)] = float[10](2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0)[_GLF_MAKE_IN_BOUNDS_INT(index, 10)]; # index++; # } # # // The selected indices don't matter as all have the same data of 2.0. # vec2 v = vec2(arr[_GLF_MAKE_IN_BOUNDS_INT(int(gl_FragCoord.x), 10)], arr[_GLF_MAKE_IN_BOUNDS_INT(int(gl_FragCoord.y), 10)]); # # // Always true. # if (v.x == 2.0 && v.y == 2.0) # _GLF_color = vec4(1, 0, 0, 1); # else # _GLF_color = vec4(0); # # } SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 ; SPIR-V ; Version: 1.0 ; Generator: Khronos Glslang Reference Front End; 10 ; Bound: 583 ; Schema: 0 OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %4 "main" %431 %460 OpExecutionMode %4 OriginUpperLeft OpSource ESSL 320 OpName %4 "main" OpName %15 "arr" OpName %419 "indexable" OpName %431 "gl_FragCoord" OpName %460 "_GLF_color" OpDecorate %431 BuiltIn FragCoord OpDecorate %460 Location 0 %2 = OpTypeVoid %3 = OpTypeFunction %2 %6 = OpTypeInt 32 1 %9 = OpConstant %6 0 %10 = OpTypeFloat 32 %11 = OpTypeInt 32 0 %12 = OpConstant %11 10 %13 = OpTypeArray %10 %12 %14 = OpTypePointer Function %13 %16 = OpConstant %10 1 %17 = OpConstantComposite %13 %16 %16 %16 %16 %16 %16 %16 %16 %16 %16 %26 = OpConstant %6 100 %27 = OpTypeBool %36 = OpConstant %6 1 %413 = OpConstant %6 9 %415 = OpConstant %10 2 %416 = OpConstantComposite %13 %415 %415 %415 %415 %415 %415 %415 %415 %415 %415 %420 = OpTypePointer Function %10 %429 = OpTypeVector %10 4 %430 = OpTypePointer Input %429 %431 = OpVariable %430 Input %432 = OpConstant %11 0 %433 = OpTypePointer Input %10 %440 = OpConstant %11 1 %459 = OpTypePointer Output %429 %460 = OpVariable %459 Output %461 = OpConstant %10 0 %462 = OpConstantComposite %429 %16 %461 %461 %16 %464 = OpConstantComposite %429 %461 %461 %461 %461 %4 = OpFunction %2 None %3 %5 = OpLabel %15 = OpVariable %14 Function %419 = OpVariable %14 Function OpStore %15 %17 OpBranch %20 %20 = OpLabel %470 = OpPhi %6 %9 %5 %425 %23 %467 = OpPhi %6 %9 %5 %582 %23 %28 = OpSLessThan %27 %467 %26 OpLoopMerge %22 %23 None OpBranchConditional %28 %21 %22 %21 = OpLabel OpBranch %30 %30 = OpLabel %468 = OpPhi %6 %9 %21 %411 %33 %582 = OpPhi %6 %467 %21 %581 %33 %37 = OpSLessThan %27 %468 %36 OpLoopMerge %32 %33 None OpBranchConditional %37 %31 %32 %31 = OpLabel OpBranch %39 %39 = OpLabel %471 = OpPhi %6 %9 %31 %409 %42 %581 = OpPhi %6 %582 %31 %580 %42 %45 = OpSLessThan %27 %471 %36 OpLoopMerge %41 %42 None OpBranchConditional %45 %40 %41 %40 = OpLabel OpBranch %47 %47 = OpLabel %473 = OpPhi %6 %9 %40 %407 %50 %580 = OpPhi %6 %581 %40 %579 %50 %53 = OpSLessThan %27 %473 %36 OpLoopMerge %49 %50 None OpBranchConditional %53 %48 %49 %48 = OpLabel OpBranch %55 %55 = OpLabel %475 = OpPhi %6 %9 %48 %405 %58 %579 = OpPhi %6 %580 %48 %578 %58 %61 = OpSLessThan %27 %475 %36 OpLoopMerge %57 %58 None OpBranchConditional %61 %56 %57 %56 = OpLabel OpBranch %63 %63 = OpLabel %477 = OpPhi %6 %9 %56 %403 %66 %578 = OpPhi %6 %579 %56 %577 %66 %69 = OpSLessThan %27 %477 %36 OpLoopMerge %65 %66 None OpBranchConditional %69 %64 %65 %64 = OpLabel OpBranch %71 %71 = OpLabel %479 = OpPhi %6 %9 %64 %401 %74 %577 = OpPhi %6 %578 %64 %576 %74 %77 = OpSLessThan %27 %479 %36 OpLoopMerge %73 %74 None OpBranchConditional %77 %72 %73 %72 = OpLabel OpBranch %79 %79 = OpLabel %481 = OpPhi %6 %9 %72 %399 %82 %576 = OpPhi %6 %577 %72 %575 %82 %85 = OpSLessThan %27 %481 %36 OpLoopMerge %81 %82 None OpBranchConditional %85 %80 %81 %80 = OpLabel OpBranch %87 %87 = OpLabel %483 = OpPhi %6 %9 %80 %397 %90 %575 = OpPhi %6 %576 %80 %574 %90 %93 = OpSLessThan %27 %483 %36 OpLoopMerge %89 %90 None OpBranchConditional %93 %88 %89 %88 = OpLabel OpBranch %95 %95 = OpLabel %485 = OpPhi %6 %9 %88 %395 %98 %574 = OpPhi %6 %575 %88 %573 %98 %101 = OpSLessThan %27 %485 %36 OpLoopMerge %97 %98 None OpBranchConditional %101 %96 %97 %96 = OpLabel OpBranch %103 %103 = OpLabel %487 = OpPhi %6 %9 %96 %393 %106 %573 = OpPhi %6 %574 %96 %572 %106 %109 = OpSLessThan %27 %487 %36 OpLoopMerge %105 %106 None OpBranchConditional %109 %104 %105 %104 = OpLabel OpBranch %111 %111 = OpLabel %489 = OpPhi %6 %9 %104 %391 %114 %572 = OpPhi %6 %573 %104 %571 %114 %117 = OpSLessThan %27 %489 %36 OpLoopMerge %113 %114 None OpBranchConditional %117 %112 %113 %112 = OpLabel OpBranch %119 %119 = OpLabel %491 = OpPhi %6 %9 %112 %389 %122 %571 = OpPhi %6 %572 %112 %570 %122 %125 = OpSLessThan %27 %491 %36 OpLoopMerge %121 %122 None OpBranchConditional %125 %120 %121 %120 = OpLabel OpBranch %127 %127 = OpLabel %493 = OpPhi %6 %9 %120 %387 %130 %570 = OpPhi %6 %571 %120 %569 %130 %133 = OpSLessThan %27 %493 %36 OpLoopMerge %129 %130 None OpBranchConditional %133 %128 %129 %128 = OpLabel OpBranch %135 %135 = OpLabel %495 = OpPhi %6 %9 %128 %385 %138 %569 = OpPhi %6 %570 %128 %568 %138 %141 = OpSLessThan %27 %495 %36 OpLoopMerge %137 %138 None OpBranchConditional %141 %136 %137 %136 = OpLabel OpBranch %143 %143 = OpLabel %497 = OpPhi %6 %9 %136 %383 %146 %568 = OpPhi %6 %569 %136 %567 %146 %149 = OpSLessThan %27 %497 %36 OpLoopMerge %145 %146 None OpBranchConditional %149 %144 %145 %144 = OpLabel OpBranch %151 %151 = OpLabel %499 = OpPhi %6 %9 %144 %381 %154 %567 = OpPhi %6 %568 %144 %566 %154 %157 = OpSLessThan %27 %499 %36 OpLoopMerge %153 %154 None OpBranchConditional %157 %152 %153 %152 = OpLabel OpBranch %159 %159 = OpLabel %501 = OpPhi %6 %9 %152 %379 %162 %566 = OpPhi %6 %567 %152 %565 %162 %165 = OpSLessThan %27 %501 %36 OpLoopMerge %161 %162 None OpBranchConditional %165 %160 %161 %160 = OpLabel OpBranch %167 %167 = OpLabel %503 = OpPhi %6 %9 %160 %377 %170 %565 = OpPhi %6 %566 %160 %564 %170 %173 = OpSLessThan %27 %503 %36 OpLoopMerge %169 %170 None OpBranchConditional %173 %168 %169 %168 = OpLabel OpBranch %175 %175 = OpLabel %505 = OpPhi %6 %9 %168 %375 %178 %564 = OpPhi %6 %565 %168 %563 %178 %181 = OpSLessThan %27 %505 %36 OpLoopMerge %177 %178 None OpBranchConditional %181 %176 %177 %176 = OpLabel OpBranch %183 %183 = OpLabel %507 = OpPhi %6 %9 %176 %373 %186 %563 = OpPhi %6 %564 %176 %562 %186 %189 = OpSLessThan %27 %507 %36 OpLoopMerge %185 %186 None OpBranchConditional %189 %184 %185 %184 = OpLabel OpBranch %191 %191 = OpLabel %509 = OpPhi %6 %9 %184 %371 %194 %562 = OpPhi %6 %563 %184 %561 %194 %197 = OpSLessThan %27 %509 %36 OpLoopMerge %193 %194 None OpBranchConditional %197 %192 %193 %192 = OpLabel OpBranch %199 %199 = OpLabel %511 = OpPhi %6 %9 %192 %369 %202 %561 = OpPhi %6 %562 %192 %560 %202 %205 = OpSLessThan %27 %511 %36 OpLoopMerge %201 %202 None OpBranchConditional %205 %200 %201 %200 = OpLabel OpBranch %207 %207 = OpLabel %513 = OpPhi %6 %9 %200 %367 %210 %560 = OpPhi %6 %561 %200 %559 %210 %213 = OpSLessThan %27 %513 %36 OpLoopMerge %209 %210 None OpBranchConditional %213 %208 %209 %208 = OpLabel OpBranch %215 %215 = OpLabel %515 = OpPhi %6 %9 %208 %365 %218 %559 = OpPhi %6 %560 %208 %558 %218 %221 = OpSLessThan %27 %515 %36 OpLoopMerge %217 %218 None OpBranchConditional %221 %216 %217 %216 = OpLabel OpBranch %223 %223 = OpLabel %517 = OpPhi %6 %9 %216 %363 %226 %558 = OpPhi %6 %559 %216 %557 %226 %229 = OpSLessThan %27 %517 %36 OpLoopMerge %225 %226 None OpBranchConditional %229 %224 %225 %224 = OpLabel OpBranch %231 %231 = OpLabel %519 = OpPhi %6 %9 %224 %361 %234 %557 = OpPhi %6 %558 %224 %556 %234 %237 = OpSLessThan %27 %519 %36 OpLoopMerge %233 %234 None OpBranchConditional %237 %232 %233 %232 = OpLabel OpBranch %239 %239 = OpLabel %521 = OpPhi %6 %9 %232 %359 %242 %556 = OpPhi %6 %557 %232 %555 %242 %245 = OpSLessThan %27 %521 %36 OpLoopMerge %241 %242 None OpBranchConditional %245 %240 %241 %240 = OpLabel OpBranch %247 %247 = OpLabel %523 = OpPhi %6 %9 %240 %357 %250 %555 = OpPhi %6 %556 %240 %554 %250 %253 = OpSLessThan %27 %523 %36 OpLoopMerge %249 %250 None OpBranchConditional %253 %248 %249 %248 = OpLabel OpBranch %255 %255 = OpLabel %525 = OpPhi %6 %9 %248 %355 %258 %554 = OpPhi %6 %555 %248 %553 %258 %261 = OpSLessThan %27 %525 %36 OpLoopMerge %257 %258 None OpBranchConditional %261 %256 %257 %256 = OpLabel OpBranch %263 %263 = OpLabel %527 = OpPhi %6 %9 %256 %353 %266 %553 = OpPhi %6 %554 %256 %552 %266 %269 = OpSLessThan %27 %527 %36 OpLoopMerge %265 %266 None OpBranchConditional %269 %264 %265 %264 = OpLabel OpBranch %271 %271 = OpLabel %529 = OpPhi %6 %9 %264 %351 %274 %552 = OpPhi %6 %553 %264 %551 %274 %277 = OpSLessThan %27 %529 %36 OpLoopMerge %273 %274 None OpBranchConditional %277 %272 %273 %272 = OpLabel OpBranch %279 %279 = OpLabel %531 = OpPhi %6 %9 %272 %349 %282 %551 = OpPhi %6 %552 %272 %550 %282 %285 = OpSLessThan %27 %531 %36 OpLoopMerge %281 %282 None OpBranchConditional %285 %280 %281 %280 = OpLabel OpBranch %287 %287 = OpLabel %533 = OpPhi %6 %9 %280 %347 %290 %550 = OpPhi %6 %551 %280 %549 %290 %293 = OpSLessThan %27 %533 %36 OpLoopMerge %289 %290 None OpBranchConditional %293 %288 %289 %288 = OpLabel OpBranch %295 %295 = OpLabel %535 = OpPhi %6 %9 %288 %345 %298 %549 = OpPhi %6 %550 %288 %548 %298 %301 = OpSLessThan %27 %535 %36 OpLoopMerge %297 %298 None OpBranchConditional %301 %296 %297 %296 = OpLabel OpBranch %303 %303 = OpLabel %537 = OpPhi %6 %9 %296 %343 %306 %548 = OpPhi %6 %549 %296 %547 %306 %309 = OpSLessThan %27 %537 %36 OpLoopMerge %305 %306 None OpBranchConditional %309 %304 %305 %304 = OpLabel OpBranch %311 %311 = OpLabel %539 = OpPhi %6 %9 %304 %341 %314 %547 = OpPhi %6 %548 %304 %546 %314 %317 = OpSLessThan %27 %539 %36 OpLoopMerge %313 %314 None OpBranchConditional %317 %312 %313 %312 = OpLabel OpBranch %319 %319 = OpLabel %541 = OpPhi %6 %9 %312 %339 %322 %546 = OpPhi %6 %547 %312 %545 %322 %325 = OpSLessThan %27 %541 %36 OpLoopMerge %321 %322 None OpBranchConditional %325 %320 %321 %320 = OpLabel OpBranch %327 %327 = OpLabel %545 = OpPhi %6 %546 %320 %335 %328 %543 = OpPhi %6 %9 %320 %337 %328 %333 = OpSLessThan %27 %543 %36 OpLoopMerge %329 %328 None OpBranchConditional %333 %328 %329 %328 = OpLabel %335 = OpIAdd %6 %545 %36 %337 = OpIAdd %6 %543 %36 OpBranch %327 %329 = OpLabel OpBranch %322 %322 = OpLabel %339 = OpIAdd %6 %541 %36 OpBranch %319 %321 = OpLabel OpBranch %314 %314 = OpLabel %341 = OpIAdd %6 %539 %36 OpBranch %311 %313 = OpLabel OpBranch %306 %306 = OpLabel %343 = OpIAdd %6 %537 %36 OpBranch %303 %305 = OpLabel OpBranch %298 %298 = OpLabel %345 = OpIAdd %6 %535 %36 OpBranch %295 %297 = OpLabel OpBranch %290 %290 = OpLabel %347 = OpIAdd %6 %533 %36 OpBranch %287 %289 = OpLabel OpBranch %282 %282 = OpLabel %349 = OpIAdd %6 %531 %36 OpBranch %279 %281 = OpLabel OpBranch %274 %274 = OpLabel %351 = OpIAdd %6 %529 %36 OpBranch %271 %273 = OpLabel OpBranch %266 %266 = OpLabel %353 = OpIAdd %6 %527 %36 OpBranch %263 %265 = OpLabel OpBranch %258 %258 = OpLabel %355 = OpIAdd %6 %525 %36 OpBranch %255 %257 = OpLabel OpBranch %250 %250 = OpLabel %357 = OpIAdd %6 %523 %36 OpBranch %247 %249 = OpLabel OpBranch %242 %242 = OpLabel %359 = OpIAdd %6 %521 %36 OpBranch %239 %241 = OpLabel OpBranch %234 %234 = OpLabel %361 = OpIAdd %6 %519 %36 OpBranch %231 %233 = OpLabel OpBranch %226 %226 = OpLabel %363 = OpIAdd %6 %517 %36 OpBranch %223 %225 = OpLabel OpBranch %218 %218 = OpLabel %365 = OpIAdd %6 %515 %36 OpBranch %215 %217 = OpLabel OpBranch %210 %210 = OpLabel %367 = OpIAdd %6 %513 %36 OpBranch %207 %209 = OpLabel OpBranch %202 %202 = OpLabel %369 = OpIAdd %6 %511 %36 OpBranch %199 %201 = OpLabel OpBranch %194 %194 = OpLabel %371 = OpIAdd %6 %509 %36 OpBranch %191 %193 = OpLabel OpBranch %186 %186 = OpLabel %373 = OpIAdd %6 %507 %36 OpBranch %183 %185 = OpLabel OpBranch %178 %178 = OpLabel %375 = OpIAdd %6 %505 %36 OpBranch %175 %177 = OpLabel OpBranch %170 %170 = OpLabel %377 = OpIAdd %6 %503 %36 OpBranch %167 %169 = OpLabel OpBranch %162 %162 = OpLabel %379 = OpIAdd %6 %501 %36 OpBranch %159 %161 = OpLabel OpBranch %154 %154 = OpLabel %381 = OpIAdd %6 %499 %36 OpBranch %151 %153 = OpLabel OpBranch %146 %146 = OpLabel %383 = OpIAdd %6 %497 %36 OpBranch %143 %145 = OpLabel OpBranch %138 %138 = OpLabel %385 = OpIAdd %6 %495 %36 OpBranch %135 %137 = OpLabel OpBranch %130 %130 = OpLabel %387 = OpIAdd %6 %493 %36 OpBranch %127 %129 = OpLabel OpBranch %122 %122 = OpLabel %389 = OpIAdd %6 %491 %36 OpBranch %119 %121 = OpLabel OpBranch %114 %114 = OpLabel %391 = OpIAdd %6 %489 %36 OpBranch %111 %113 = OpLabel OpBranch %106 %106 = OpLabel %393 = OpIAdd %6 %487 %36 OpBranch %103 %105 = OpLabel OpBranch %98 %98 = OpLabel %395 = OpIAdd %6 %485 %36 OpBranch %95 %97 = OpLabel OpBranch %90 %90 = OpLabel %397 = OpIAdd %6 %483 %36 OpBranch %87 %89 = OpLabel OpBranch %82 %82 = OpLabel %399 = OpIAdd %6 %481 %36 OpBranch %79 %81 = OpLabel OpBranch %74 %74 = OpLabel %401 = OpIAdd %6 %479 %36 OpBranch %71 %73 = OpLabel OpBranch %66 %66 = OpLabel %403 = OpIAdd %6 %477 %36 OpBranch %63 %65 = OpLabel OpBranch %58 %58 = OpLabel %405 = OpIAdd %6 %475 %36 OpBranch %55 %57 = OpLabel OpBranch %50 %50 = OpLabel %407 = OpIAdd %6 %473 %36 OpBranch %47 %49 = OpLabel OpBranch %42 %42 = OpLabel %409 = OpIAdd %6 %471 %36 OpBranch %39 %41 = OpLabel OpBranch %33 %33 = OpLabel %411 = OpIAdd %6 %468 %36 OpBranch %30 %32 = OpLabel %414 = OpExtInst %6 %1 SClamp %470 %9 %413 OpStore %419 %416 %421 = OpAccessChain %420 %419 %414 %422 = OpLoad %10 %421 %423 = OpAccessChain %420 %15 %414 OpStore %423 %422 %425 = OpIAdd %6 %470 %36 OpBranch %23 %23 = OpLabel OpBranch %20 %22 = OpLabel %434 = OpAccessChain %433 %431 %432 %435 = OpLoad %10 %434 %436 = OpConvertFToS %6 %435 %437 = OpExtInst %6 %1 SClamp %436 %9 %413 %438 = OpAccessChain %420 %15 %437 %439 = OpLoad %10 %438 %441 = OpAccessChain %433 %431 %440 %442 = OpLoad %10 %441 %443 = OpConvertFToS %6 %442 %444 = OpExtInst %6 %1 SClamp %443 %9 %413 %445 = OpAccessChain %420 %15 %444 %446 = OpLoad %10 %445 %450 = OpFOrdEqual %27 %439 %415 OpSelectionMerge %452 None OpBranchConditional %450 %451 %452 %451 = OpLabel %455 = OpFOrdEqual %27 %446 %415 OpBranch %452 %452 = OpLabel %456 = OpPhi %27 %450 %22 %455 %451 OpSelectionMerge %458 None OpBranchConditional %456 %457 %463 %457 = OpLabel OpStore %460 %462 OpBranch %458 %463 = OpLabel OpStore %460 %464 OpBranch %458 %458 = OpLabel OpReturn OpFunctionEnd END BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM PIPELINE graphics variant_pipeline ATTACH variant_vertex_shader ATTACH variant_fragment_shader FRAMEBUFFER_SIZE 256 256 BIND BUFFER variant_framebuffer AS color LOCATION 0 END CLEAR_COLOR variant_pipeline 0 0 0 255 CLEAR variant_pipeline RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255