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