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