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