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