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