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# #define _int_3 _GLF_uniform_int_values[0] 30# #define _int_1 _GLF_uniform_int_values[1] 31# #define _int_0 _GLF_uniform_int_values[2] 32# #define _float_1_0 _GLF_uniform_float_values[0] 33# #define _float_256_0 _GLF_uniform_float_values[1] 34# 35# precision highp float; 36# precision highp int; 37# 38# // Contents of _GLF_uniform_float_values: [1.0, 256.0] 39# layout(set = 0, binding = 0) uniform buf0 40# { 41# float _GLF_uniform_float_values[2]; 42# }; 43# 44# // Contents of _GLF_uniform_int_values: [3, 1, 0] 45# layout(set = 0, binding = 1) uniform buf1 46# { 47# int _GLF_uniform_int_values[3]; 48# }; 49# 50# layout(location = 0) out vec4 _GLF_color; 51# 52# void main() 53# { 54# // Always false. 55# if(gl_FragCoord.x < 0.0) 56# { 57# discard; 58# } 59# 60# float a = _float_1_0; 61# float b = _float_1_0; 62# float c = _float_1_0; 63# vec3 v = vec3(_int_0); 64# 65# // Always false. 66# if(gl_FragCoord.y < 0.0) 67# { 68# a++; 69# } 70# 71# // Iterates three times. 72# for(int i = _int_0; i < _int_3; i++) 73# { 74# // Always false. 75# if(gl_FragCoord.x < 0.0) 76# { 77# } 78# else 79# { 80# // Never iterated. 81# while(gl_FragCoord.y < 0.0) 82# { 83# } 84# } 85# 86# // Always false. 87# if(gl_FragCoord.y < 0.0) 88# { 89# } 90# else 91# { 92# // No effect as b is already one. 93# b = 1.0; 94# } 95# 96# // c becomes zero. 97# c *= 1.0 - b; 98# // No effect: 1 * 256 = 1. 99# b *= _float_256_0; 100# // v[i] becomes 1 + 0 = 1. 101# v[i] = a + c; 102# } 103# 104# // Always true. 105# if(v == vec3(_int_1)) 106# { 107# _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1); 108# } 109# else 110# { 111# _GLF_color = vec4(_int_0); 112# } 113# } 114SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 115; SPIR-V 116; Version: 1.0 117; Generator: Khronos Glslang Reference Front End; 10 118; Bound: 141 119; Schema: 0 120 OpCapability Shader 121 %1 = OpExtInstImport "GLSL.std.450" 122 OpMemoryModel Logical GLSL450 123 OpEntryPoint Fragment %4 "main" %9 %122 124 OpExecutionMode %4 OriginUpperLeft 125 OpSource ESSL 320 126 OpName %4 "main" 127 OpName %9 "gl_FragCoord" 128 OpName %22 "a" 129 OpName %25 "buf0" 130 OpMemberName %25 0 "_GLF_uniform_float_values" 131 OpName %27 "" 132 OpName %33 "b" 133 OpName %36 "c" 134 OpName %41 "v" 135 OpName %44 "buf1" 136 OpMemberName %44 0 "_GLF_uniform_int_values" 137 OpName %46 "" 138 OpName %63 "i" 139 OpName %122 "_GLF_color" 140 OpDecorate %9 BuiltIn FragCoord 141 OpDecorate %24 ArrayStride 16 142 OpMemberDecorate %25 0 Offset 0 143 OpDecorate %25 Block 144 OpDecorate %27 DescriptorSet 0 145 OpDecorate %27 Binding 0 146 OpDecorate %43 ArrayStride 16 147 OpMemberDecorate %44 0 Offset 0 148 OpDecorate %44 Block 149 OpDecorate %46 DescriptorSet 0 150 OpDecorate %46 Binding 1 151 OpDecorate %122 Location 0 152 %2 = OpTypeVoid 153 %3 = OpTypeFunction %2 154 %6 = OpTypeFloat 32 155 %7 = OpTypeVector %6 4 156 %8 = OpTypePointer Input %7 157 %9 = OpVariable %8 Input 158 %10 = OpTypeInt 32 0 159 %11 = OpConstant %10 0 160 %12 = OpTypePointer Input %6 161 %15 = OpConstant %6 0 162 %16 = OpTypeBool 163 %21 = OpTypePointer Function %6 164 %23 = OpConstant %10 2 165 %24 = OpTypeArray %6 %23 166 %25 = OpTypeStruct %24 167 %26 = OpTypePointer Uniform %25 168 %27 = OpVariable %26 Uniform 169 %28 = OpTypeInt 32 1 170 %29 = OpConstant %28 0 171 %30 = OpTypePointer Uniform %6 172 %39 = OpTypeVector %6 3 173 %40 = OpTypePointer Function %39 174 %42 = OpConstant %10 3 175 %43 = OpTypeArray %28 %42 176 %44 = OpTypeStruct %43 177 %45 = OpTypePointer Uniform %44 178 %46 = OpVariable %45 Uniform 179 %47 = OpConstant %28 2 180 %48 = OpTypePointer Uniform %28 181 %53 = OpConstant %10 1 182 %60 = OpConstant %6 1 183 %62 = OpTypePointer Function %28 184 %99 = OpConstant %28 1 185 %116 = OpTypeVector %16 3 186 %121 = OpTypePointer Output %7 187 %122 = OpVariable %121 Output 188 %4 = OpFunction %2 None %3 189 %5 = OpLabel 190 %22 = OpVariable %21 Function 191 %33 = OpVariable %21 Function 192 %36 = OpVariable %21 Function 193 %41 = OpVariable %40 Function 194 %63 = OpVariable %62 Function 195 %13 = OpAccessChain %12 %9 %11 196 %14 = OpLoad %6 %13 197 %17 = OpFOrdLessThan %16 %14 %15 198 OpSelectionMerge %19 None 199 OpBranchConditional %17 %18 %19 200 %18 = OpLabel 201 OpKill 202 %19 = OpLabel 203 %31 = OpAccessChain %30 %27 %29 %29 204 %32 = OpLoad %6 %31 205 OpStore %22 %32 206 %34 = OpAccessChain %30 %27 %29 %29 207 %35 = OpLoad %6 %34 208 OpStore %33 %35 209 %37 = OpAccessChain %30 %27 %29 %29 210 %38 = OpLoad %6 %37 211 OpStore %36 %38 212 %49 = OpAccessChain %48 %46 %29 %47 213 %50 = OpLoad %28 %49 214 %51 = OpConvertSToF %6 %50 215 %52 = OpCompositeConstruct %39 %51 %51 %51 216 OpStore %41 %52 217 %54 = OpAccessChain %12 %9 %53 218 %55 = OpLoad %6 %54 219 %56 = OpFOrdLessThan %16 %55 %15 220 OpSelectionMerge %58 None 221 OpBranchConditional %56 %57 %58 222 %57 = OpLabel 223 %59 = OpLoad %6 %22 224 %61 = OpFAdd %6 %59 %60 225 OpStore %22 %61 226 OpBranch %58 227 %58 = OpLabel 228 %64 = OpAccessChain %48 %46 %29 %47 229 %65 = OpLoad %28 %64 230 OpStore %63 %65 231 OpBranch %66 232 %66 = OpLabel 233 OpLoopMerge %68 %69 None 234 OpBranch %70 235 %70 = OpLabel 236 %71 = OpLoad %28 %63 237 %72 = OpAccessChain %48 %46 %29 %29 238 %73 = OpLoad %28 %72 239 %74 = OpSLessThan %16 %71 %73 240 OpBranchConditional %74 %67 %68 241 %67 = OpLabel 242 %75 = OpAccessChain %12 %9 %11 243 %76 = OpLoad %6 %75 244 %77 = OpFOrdLessThan %16 %76 %15 245 OpSelectionMerge %79 None 246 OpBranchConditional %77 %78 %80 247 %78 = OpLabel 248 OpBranch %79 249 %80 = OpLabel 250 OpBranch %81 251 %81 = OpLabel 252 OpLoopMerge %83 %84 None 253 OpBranch %85 254 %85 = OpLabel 255 %86 = OpAccessChain %12 %9 %53 256 %87 = OpLoad %6 %86 257 %88 = OpFOrdLessThan %16 %87 %15 258 OpBranchConditional %88 %82 %83 259 %82 = OpLabel 260 OpBranch %84 261 %84 = OpLabel 262 OpBranch %81 263 %83 = OpLabel 264 OpBranch %79 265 %79 = OpLabel 266 %89 = OpAccessChain %12 %9 %53 267 %90 = OpLoad %6 %89 268 %91 = OpFOrdLessThan %16 %90 %15 269 OpSelectionMerge %93 None 270 OpBranchConditional %91 %92 %94 271 %92 = OpLabel 272 OpBranch %93 273 %94 = OpLabel 274 OpStore %33 %60 275 OpBranch %93 276 %93 = OpLabel 277 %95 = OpLoad %6 %33 278 %96 = OpFSub %6 %60 %95 279 %97 = OpLoad %6 %36 280 %98 = OpFMul %6 %97 %96 281 OpStore %36 %98 282 %100 = OpAccessChain %30 %27 %29 %99 283 %101 = OpLoad %6 %100 284 %102 = OpLoad %6 %33 285 %103 = OpFMul %6 %102 %101 286 OpStore %33 %103 287 %104 = OpLoad %28 %63 288 %105 = OpLoad %6 %22 289 %106 = OpLoad %6 %36 290 %107 = OpFAdd %6 %105 %106 291 %108 = OpAccessChain %21 %41 %104 292 OpStore %108 %107 293 OpBranch %69 294 %69 = OpLabel 295 %109 = OpLoad %28 %63 296 %110 = OpIAdd %28 %109 %99 297 OpStore %63 %110 298 OpBranch %66 299 %68 = OpLabel 300 %111 = OpLoad %39 %41 301 %112 = OpAccessChain %48 %46 %29 %99 302 %113 = OpLoad %28 %112 303 %114 = OpConvertSToF %6 %113 304 %115 = OpCompositeConstruct %39 %114 %114 %114 305 %117 = OpFOrdEqual %116 %111 %115 306 %118 = OpAll %16 %117 307 OpSelectionMerge %120 None 308 OpBranchConditional %118 %119 %136 309 %119 = OpLabel 310 %123 = OpAccessChain %48 %46 %29 %99 311 %124 = OpLoad %28 %123 312 %125 = OpConvertSToF %6 %124 313 %126 = OpAccessChain %48 %46 %29 %47 314 %127 = OpLoad %28 %126 315 %128 = OpConvertSToF %6 %127 316 %129 = OpAccessChain %48 %46 %29 %47 317 %130 = OpLoad %28 %129 318 %131 = OpConvertSToF %6 %130 319 %132 = OpAccessChain %48 %46 %29 %99 320 %133 = OpLoad %28 %132 321 %134 = OpConvertSToF %6 %133 322 %135 = OpCompositeConstruct %7 %125 %128 %131 %134 323 OpStore %122 %135 324 OpBranch %120 325 %136 = OpLabel 326 %137 = OpAccessChain %48 %46 %29 %47 327 %138 = OpLoad %28 %137 328 %139 = OpConvertSToF %6 %138 329 %140 = OpCompositeConstruct %7 %139 %139 %139 %139 330 OpStore %122 %140 331 OpBranch %120 332 %120 = OpLabel 333 OpReturn 334 OpFunctionEnd 335END 336 337# uniforms for variant 338 339# _GLF_uniform_int_values 340BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 341 3 1 0 342END 343# _GLF_uniform_float_values 344BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA 345 1.0 256.0 346END 347 348BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 349 350PIPELINE graphics variant_pipeline 351 ATTACH variant_vertex_shader 352 ATTACH variant_fragment_shader 353 FRAMEBUFFER_SIZE 32 32 354 BIND BUFFER variant_framebuffer AS color LOCATION 0 355 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1 356 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0 357END 358CLEAR_COLOR variant_pipeline 0 0 0 255 359 360CLEAR variant_pipeline 361RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32 362 363EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255 364