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 GraphicsFuzz. 19 20# Short description: A fragment shader that covers a specific constant folding path 21 22# The test passes because 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# precision highp float; 29# precision highp int; 30# 31# layout(location = 0) out vec4 _GLF_color; 32# 33# layout(set = 0, binding = 0) uniform buf0 34# { 35# int zero; 36# }; 37# 38# void main() 39# { 40# int data[2]; 41# int highSigned = 1; 42# uint highUnsigned = 2u; 43# 44# for(int i = 0; i < min(10, highSigned) + zero; i++) 45# data[i] = 5; 46# 47# for(uint i = 1u; i < min(10u, highUnsigned) + uint(zero); i++) 48# data[i] = 6; 49# 50# if (data[0] == 5 && data[1] == 6) 51# _GLF_color = vec4(1, 0, 0, 1); 52# else 53# _GLF_color = vec4(0); 54# } 55SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 56; SPIR-V 57; Version: 1.0 58; Generator: Khronos Glslang Reference Front End; 8 59; Bound: 83 60; Schema: 0 61 OpCapability Shader 62 %1 = OpExtInstImport "GLSL.std.450" 63 OpMemoryModel Logical GLSL450 64 OpEntryPoint Fragment %4 "main" %77 65 OpExecutionMode %4 OriginUpperLeft 66 OpSource ESSL 310 67 OpName %4 "main" 68 OpName %8 "highSigned" 69 OpName %12 "highUnsigned" 70 OpName %14 "i" 71 OpName %25 "buf0" 72 OpMemberName %25 0 "zero" 73 OpName %27 "" 74 OpName %36 "data" 75 OpName %42 "i" 76 OpName %77 "_GLF_color" 77 OpMemberDecorate %25 0 Offset 0 78 OpDecorate %25 Block 79 OpDecorate %27 DescriptorSet 0 80 OpDecorate %27 Binding 0 81 OpDecorate %77 Location 0 82 %2 = OpTypeVoid 83 %3 = OpTypeFunction %2 84 %6 = OpTypeInt 32 1 85 %7 = OpTypePointer Function %6 86 %9 = OpConstant %6 1 87 %10 = OpTypeInt 32 0 88 %11 = OpTypePointer Function %10 89 %13 = OpConstant %10 2 90 %15 = OpConstant %6 0 91 %22 = OpConstant %6 10 92 %25 = OpTypeStruct %6 93 %26 = OpTypePointer Uniform %25 94 %27 = OpVariable %26 Uniform 95 %28 = OpTypePointer Uniform %6 96 %32 = OpTypeBool 97 %34 = OpTypeArray %6 %13 98 %35 = OpTypePointer Function %34 99 %38 = OpConstant %6 5 100 %43 = OpConstant %10 1 101 %50 = OpConstant %10 10 102 %59 = OpConstant %6 6 103 %74 = OpTypeFloat 32 104 %75 = OpTypeVector %74 4 105 %76 = OpTypePointer Output %75 106 %77 = OpVariable %76 Output 107 %78 = OpConstant %74 1 108 %79 = OpConstant %74 0 109 %80 = OpConstantComposite %75 %78 %79 %79 %78 110 %82 = OpConstantComposite %75 %79 %79 %79 %79 111 %4 = OpFunction %2 None %3 112 %5 = OpLabel 113 %8 = OpVariable %7 Function 114 %12 = OpVariable %11 Function 115 %14 = OpVariable %7 Function 116 %36 = OpVariable %35 Function 117 %42 = OpVariable %11 Function 118 OpStore %8 %9 119 OpStore %12 %13 120 OpStore %14 %15 121 OpBranch %16 122 %16 = OpLabel 123 OpLoopMerge %18 %19 None 124 OpBranch %20 125 %20 = OpLabel 126 %21 = OpLoad %6 %14 127 %23 = OpLoad %6 %8 128 %24 = OpExtInst %6 %1 SMin %22 %23 129 %29 = OpAccessChain %28 %27 %15 130 %30 = OpLoad %6 %29 131 %31 = OpIAdd %6 %24 %30 132 %33 = OpSLessThan %32 %21 %31 133 OpBranchConditional %33 %17 %18 134 %17 = OpLabel 135 %37 = OpLoad %6 %14 136 %39 = OpAccessChain %7 %36 %37 137 OpStore %39 %38 138 OpBranch %19 139 %19 = OpLabel 140 %40 = OpLoad %6 %14 141 %41 = OpIAdd %6 %40 %9 142 OpStore %14 %41 143 OpBranch %16 144 %18 = OpLabel 145 OpStore %42 %43 146 OpBranch %44 147 %44 = OpLabel 148 OpLoopMerge %46 %47 None 149 OpBranch %48 150 %48 = OpLabel 151 %49 = OpLoad %10 %42 152 %51 = OpLoad %10 %12 153 %52 = OpExtInst %10 %1 UMin %50 %51 154 %53 = OpAccessChain %28 %27 %15 155 %54 = OpLoad %6 %53 156 %55 = OpBitcast %10 %54 157 %56 = OpIAdd %10 %52 %55 158 %57 = OpULessThan %32 %49 %56 159 OpBranchConditional %57 %45 %46 160 %45 = OpLabel 161 %58 = OpLoad %10 %42 162 %60 = OpAccessChain %7 %36 %58 163 OpStore %60 %59 164 OpBranch %47 165 %47 = OpLabel 166 %61 = OpLoad %10 %42 167 %62 = OpIAdd %10 %61 %9 168 OpStore %42 %62 169 OpBranch %44 170 %46 = OpLabel 171 %63 = OpAccessChain %7 %36 %15 172 %64 = OpLoad %6 %63 173 %65 = OpIEqual %32 %64 %38 174 OpSelectionMerge %67 None 175 OpBranchConditional %65 %66 %67 176 %66 = OpLabel 177 %68 = OpAccessChain %7 %36 %9 178 %69 = OpLoad %6 %68 179 %70 = OpIEqual %32 %69 %59 180 OpBranch %67 181 %67 = OpLabel 182 %71 = OpPhi %32 %65 %46 %70 %66 183 OpSelectionMerge %73 None 184 OpBranchConditional %71 %72 %81 185 %72 = OpLabel 186 OpStore %77 %80 187 OpBranch %73 188 %81 = OpLabel 189 OpStore %77 %82 190 OpBranch %73 191 %73 = OpLabel 192 OpReturn 193 OpFunctionEnd 194END 195 196# uniforms for variant 197 198# zero 199BUFFER variant_zero DATA_TYPE int32 DATA 200 0 201END 202 203BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 204 205PIPELINE graphics variant_pipeline 206 ATTACH variant_vertex_shader 207 ATTACH variant_fragment_shader 208 FRAMEBUFFER_SIZE 256 256 209 BIND BUFFER variant_framebuffer AS color LOCATION 0 210 BIND BUFFER variant_zero AS uniform DESCRIPTOR_SET 0 BINDING 0 211END 212CLEAR_COLOR variant_pipeline 0 0 0 255 213 214CLEAR variant_pipeline 215RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 216 217EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 218