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