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