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