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