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