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