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