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