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# 29# precision highp float; 30# precision highp int; 31# 32# layout(location = 0) out vec4 _GLF_color; 33# 34# void main() 35# { 36# int a = int(gl_FragCoord.x); 37# 38# for(int i = 1; i < 3; i++) 39# { 40# // Always false. 41# if(gl_FragCoord.y < 0.0) 42# { 43# return; 44# } 45# } 46# 47# // Always false. 48# if(a < 0) 49# { 50# a = -a; 51# } 52# 53# // Loops until a is in range 0..2. 54# while(a > 2) 55# { 56# a -= 2; 57# 58# // Always false. 59# if(gl_FragCoord.y < 0.0) 60# { 61# break; 62# } 63# } 64# 65# // Correct values are at indices 0..2. 66# _GLF_color = vec4[5](vec4(1, 0, 0, 1), vec4(1, 0, 0, 1), vec4(1, 0, 0, 1), vec4(0), vec4(0))[a]; 67# } 68SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 69; SPIR-V 70; Version: 1.0 71; Generator: Khronos Glslang Reference Front End; 10 72; Bound: 77 73; Schema: 0 74 OpCapability Shader 75 %1 = OpExtInstImport "GLSL.std.450" 76 OpMemoryModel Logical GLSL450 77 OpEntryPoint Fragment %4 "main" %12 %64 78 OpExecutionMode %4 OriginUpperLeft 79 OpSource ESSL 320 80 OpName %4 "main" 81 OpName %8 "a" 82 OpName %12 "gl_FragCoord" 83 OpName %19 "i" 84 OpName %64 "_GLF_color" 85 OpName %73 "indexable" 86 OpDecorate %12 BuiltIn FragCoord 87 OpDecorate %64 Location 0 88 %2 = OpTypeVoid 89 %3 = OpTypeFunction %2 90 %6 = OpTypeInt 32 1 91 %7 = OpTypePointer Function %6 92 %9 = OpTypeFloat 32 93 %10 = OpTypeVector %9 4 94 %11 = OpTypePointer Input %10 95 %12 = OpVariable %11 Input 96 %13 = OpTypeInt 32 0 97 %14 = OpConstant %13 0 98 %15 = OpTypePointer Input %9 99 %20 = OpConstant %6 1 100 %27 = OpConstant %6 3 101 %28 = OpTypeBool 102 %30 = OpConstant %13 1 103 %33 = OpConstant %9 0 104 %41 = OpConstant %6 0 105 %53 = OpConstant %6 2 106 %63 = OpTypePointer Output %10 107 %64 = OpVariable %63 Output 108 %65 = OpConstant %13 5 109 %66 = OpTypeArray %10 %65 110 %67 = OpConstant %9 1 111 %68 = OpConstantComposite %10 %67 %33 %33 %67 112 %69 = OpConstantComposite %10 %33 %33 %33 %33 113 %70 = OpConstantComposite %66 %68 %68 %68 %69 %69 114 %72 = OpTypePointer Function %66 115 %74 = OpTypePointer Function %10 116 %4 = OpFunction %2 None %3 117 %5 = OpLabel 118 %8 = OpVariable %7 Function 119 %19 = OpVariable %7 Function 120 %73 = OpVariable %72 Function 121 %16 = OpAccessChain %15 %12 %14 122 %17 = OpLoad %9 %16 123 %18 = OpConvertFToS %6 %17 124 OpStore %8 %18 125 OpStore %19 %20 126 OpBranch %21 127 %21 = OpLabel 128 OpLoopMerge %23 %24 None 129 OpBranch %25 130 %25 = OpLabel 131 %26 = OpLoad %6 %19 132 %29 = OpSLessThan %28 %26 %27 133 OpBranchConditional %29 %22 %23 134 %22 = OpLabel 135 %31 = OpAccessChain %15 %12 %30 136 %32 = OpLoad %9 %31 137 %34 = OpFOrdLessThan %28 %32 %33 138 OpSelectionMerge %36 None 139 OpBranchConditional %34 %35 %36 140 %35 = OpLabel 141 OpReturn 142 %36 = OpLabel 143 OpBranch %24 144 %24 = OpLabel 145 %38 = OpLoad %6 %19 146 %39 = OpIAdd %6 %38 %20 147 OpStore %19 %39 148 OpBranch %21 149 %23 = OpLabel 150 %40 = OpLoad %6 %8 151 %42 = OpSLessThan %28 %40 %41 152 OpSelectionMerge %44 None 153 OpBranchConditional %42 %43 %44 154 %43 = OpLabel 155 %45 = OpLoad %6 %8 156 %46 = OpSNegate %6 %45 157 OpStore %8 %46 158 OpBranch %44 159 %44 = OpLabel 160 OpBranch %47 161 %47 = OpLabel 162 OpLoopMerge %49 %50 None 163 OpBranch %51 164 %51 = OpLabel 165 %52 = OpLoad %6 %8 166 %54 = OpSGreaterThan %28 %52 %53 167 OpBranchConditional %54 %48 %49 168 %48 = OpLabel 169 %55 = OpLoad %6 %8 170 %56 = OpISub %6 %55 %53 171 OpStore %8 %56 172 %57 = OpAccessChain %15 %12 %30 173 %58 = OpLoad %9 %57 174 %59 = OpFOrdLessThan %28 %58 %33 175 OpSelectionMerge %61 None 176 OpBranchConditional %59 %60 %61 177 %60 = OpLabel 178 OpBranch %49 179 %61 = OpLabel 180 OpBranch %50 181 %50 = OpLabel 182 OpBranch %47 183 %49 = OpLabel 184 %71 = OpLoad %6 %8 185 OpStore %73 %70 186 %75 = OpAccessChain %74 %73 %71 187 %76 = OpLoad %10 %75 188 OpStore %64 %76 189 OpReturn 190 OpFunctionEnd 191END 192 193 194BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 195 196PIPELINE graphics variant_pipeline 197 ATTACH variant_vertex_shader 198 ATTACH variant_fragment_shader 199 FRAMEBUFFER_SIZE 256 256 200 BIND BUFFER variant_framebuffer AS color LOCATION 0 201END 202CLEAR_COLOR variant_pipeline 0 0 0 255 203 204CLEAR variant_pipeline 205RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 206 207EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 208