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