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