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