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