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