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