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