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