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 GraphicsFuzz. 19 20# Short description: A fragment shader that covers a specific instruction folding path. 21 22# The test passes because 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# precision highp float; 29# 30# layout(location = 0) out vec4 _GLF_color; 31# 32# void main() 33# { 34# bool b = false; 35# 36# // A single loop with i = 1. 37# for(int i = 1; i > 0; i--) 38# { 39# float a = 3.0 - float(i); 40# 41# // If condition is always true. 42# if(2.0 - a == 0.0) 43# b = true; 44# } 45# 46# // If condition is always true. 47# if (b) 48# _GLF_color = vec4(1, 0, 0, 1); 49# else 50# _GLF_color = vec4(0); 51# } 52SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 53; SPIR-V 54; Version: 1.0 55; Generator: Khronos Glslang Reference Front End; 8 56; Bound: 49 57; Schema: 0 58 OpCapability Shader 59 %1 = OpExtInstImport "GLSL.std.450" 60 OpMemoryModel Logical GLSL450 61 OpEntryPoint Fragment %4 "main" %44 62 OpExecutionMode %4 OriginUpperLeft 63 OpSource ESSL 310 64 OpName %4 "main" 65 OpName %8 "b" 66 OpName %12 "i" 67 OpName %24 "a" 68 OpName %44 "_GLF_color" 69 OpDecorate %12 RelaxedPrecision 70 OpDecorate %19 RelaxedPrecision 71 OpDecorate %26 RelaxedPrecision 72 OpDecorate %37 RelaxedPrecision 73 OpDecorate %38 RelaxedPrecision 74 OpDecorate %44 Location 0 75 %2 = OpTypeVoid 76 %3 = OpTypeFunction %2 77 %6 = OpTypeBool 78 %7 = OpTypePointer Function %6 79 %9 = OpConstantFalse %6 80 %10 = OpTypeInt 32 1 81 %11 = OpTypePointer Function %10 82 %13 = OpConstant %10 1 83 %20 = OpConstant %10 0 84 %22 = OpTypeFloat 32 85 %23 = OpTypePointer Function %22 86 %25 = OpConstant %22 3 87 %29 = OpConstant %22 2 88 %32 = OpConstant %22 0 89 %36 = OpConstantTrue %6 90 %42 = OpTypeVector %22 4 91 %43 = OpTypePointer Output %42 92 %44 = OpVariable %43 Output 93 %45 = OpConstant %22 1 94 %46 = OpConstantComposite %42 %45 %32 %32 %45 95 %48 = OpConstantComposite %42 %32 %32 %32 %32 96 %4 = OpFunction %2 None %3 97 %5 = OpLabel 98 %8 = OpVariable %7 Function 99 %12 = OpVariable %11 Function 100 %24 = OpVariable %23 Function 101 OpStore %8 %9 102 OpStore %12 %13 103 OpBranch %14 104 %14 = OpLabel 105 OpLoopMerge %16 %17 None 106 OpBranch %18 107 %18 = OpLabel 108 %19 = OpLoad %10 %12 109 %21 = OpSGreaterThan %6 %19 %20 110 OpBranchConditional %21 %15 %16 111 %15 = OpLabel 112 %26 = OpLoad %10 %12 113 %27 = OpConvertSToF %22 %26 114 %28 = OpFSub %22 %25 %27 115 OpStore %24 %28 116 %30 = OpLoad %22 %24 117 %31 = OpFSub %22 %29 %30 118 %33 = OpFOrdEqual %6 %31 %32 119 OpSelectionMerge %35 None 120 OpBranchConditional %33 %34 %35 121 %34 = OpLabel 122 OpStore %8 %36 123 OpBranch %35 124 %35 = OpLabel 125 OpBranch %17 126 %17 = OpLabel 127 %37 = OpLoad %10 %12 128 %38 = OpISub %10 %37 %13 129 OpStore %12 %38 130 OpBranch %14 131 %16 = OpLabel 132 %39 = OpLoad %6 %8 133 OpSelectionMerge %41 None 134 OpBranchConditional %39 %40 %47 135 %40 = OpLabel 136 OpStore %44 %46 137 OpBranch %41 138 %47 = OpLabel 139 OpStore %44 %48 140 OpBranch %41 141 %41 = OpLabel 142 OpReturn 143 OpFunctionEnd 144END 145 146 147BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 148 149PIPELINE graphics variant_pipeline 150 ATTACH variant_vertex_shader 151 ATTACH variant_fragment_shader 152 FRAMEBUFFER_SIZE 256 256 153 BIND BUFFER variant_framebuffer AS color LOCATION 0 154END 155CLEAR_COLOR variant_pipeline 0 0 0 255 156 157CLEAR variant_pipeline 158RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 159 160EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 161