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