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