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