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