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