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