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