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 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 _int_5 _GLF_uniform_int_values[2] 37# #define _int_3 _GLF_uniform_int_values[3] 38# 39# precision highp float; 40# precision highp int; 41# 42# // Contents of _GLF_uniform_int_values: [1, 0, 5, 3] 43# layout(set = 0, binding = 0) uniform buf0 44# { 45# int _GLF_uniform_int_values[4]; 46# }; 47# 48# const int _GLF_global_loop_bound = 10; 49# int _GLF_global_loop_count = 0; 50# 51# // Contents of injectionSwitch: [0.0, 1.0] 52# layout(set = 0, binding = 1) uniform buf1 53# { 54# highp vec2 injectionSwitch; 55# }; 56# 57# layout(location = 0) out vec4 _GLF_color; 58# 59# void main() 60# { 61# int a = _int_0; 62# 63# // Iterated three times. 64# while(_GLF_global_loop_count < _GLF_global_loop_bound) 65# { 66# a++; 67# 68# // Iterated four times. 69# for(int i = clamp(ivec2(1, int(injectionSwitch.y)), ivec2(0), ivec2(_int_1)).x; i < _int_5; i++) 70# { 71# _GLF_global_loop_count++; 72# } 73# } 74# 75# // Always true. 76# if(a == _int_3) 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: 102 90; Schema: 0 91 OpCapability Shader 92 %1 = OpExtInstImport "GLSL.std.450" 93 OpMemoryModel Logical GLSL450 94 OpEntryPoint Fragment %4 "main" %76 95 OpExecutionMode %4 OriginUpperLeft 96 OpSource ESSL 320 97 OpName %4 "main" 98 OpName %15 "buf0" 99 OpMemberName %15 0 "_GLF_uniform_int_values" 100 OpName %17 "" 101 OpName %76 "_GLF_color" 102 OpDecorate %14 ArrayStride 16 103 OpMemberDecorate %15 0 Offset 0 104 OpDecorate %15 Block 105 OpDecorate %17 DescriptorSet 0 106 OpDecorate %17 Binding 0 107 OpDecorate %76 Location 0 108 %2 = OpTypeVoid 109 %3 = OpTypeFunction %2 110 %6 = OpTypeInt 32 1 111 %9 = OpConstant %6 0 112 %12 = OpTypeInt 32 0 113 %13 = OpConstant %12 4 114 %14 = OpTypeArray %6 %13 115 %15 = OpTypeStruct %14 116 %16 = OpTypePointer Uniform %15 117 %17 = OpVariable %16 Uniform 118 %18 = OpConstant %6 1 119 %19 = OpTypePointer Uniform %6 120 %28 = OpConstant %6 10 121 %29 = OpTypeBool 122 %34 = OpTypeFloat 32 123 %44 = OpTypeVector %6 2 124 %46 = OpConstantComposite %44 %9 %9 125 %59 = OpConstant %6 2 126 %68 = OpConstant %6 3 127 %74 = OpTypeVector %34 4 128 %75 = OpTypePointer Output %74 129 %76 = OpVariable %75 Output 130 %101 = OpUndef %6 131 %4 = OpFunction %2 None %3 132 %5 = OpLabel 133 %20 = OpAccessChain %19 %17 %9 %18 134 %21 = OpLoad %6 %20 135 OpBranch %22 136 %22 = OpLabel 137 %96 = OpPhi %6 %21 %5 %32 %25 138 %95 = OpPhi %6 %9 %5 %98 %25 139 %30 = OpSLessThan %29 %95 %28 140 OpLoopMerge %24 %25 None 141 OpBranchConditional %30 %23 %24 142 %23 = OpLabel 143 %32 = OpIAdd %6 %96 %18 144 %45 = OpCompositeConstruct %44 %18 %101 145 %47 = OpAccessChain %19 %17 %9 %9 146 %48 = OpLoad %6 %47 147 %49 = OpCompositeConstruct %44 %48 %48 148 %50 = OpExtInst %44 %1 SClamp %45 %46 %49 149 %52 = OpCompositeExtract %6 %50 0 150 OpBranch %53 151 %53 = OpLabel 152 %98 = OpPhi %6 %95 %23 %64 %54 153 %97 = OpPhi %6 %52 %23 %66 %54 154 %60 = OpAccessChain %19 %17 %9 %59 155 %61 = OpLoad %6 %60 156 %62 = OpSLessThan %29 %97 %61 157 OpLoopMerge %55 %54 None 158 OpBranchConditional %62 %54 %55 159 %54 = OpLabel 160 %64 = OpIAdd %6 %98 %18 161 %66 = OpIAdd %6 %97 %18 162 OpBranch %53 163 %55 = OpLabel 164 OpBranch %25 165 %25 = OpLabel 166 OpBranch %22 167 %24 = OpLabel 168 %69 = OpAccessChain %19 %17 %9 %68 169 %70 = OpLoad %6 %69 170 %71 = OpIEqual %29 %96 %70 171 OpSelectionMerge %73 None 172 OpBranchConditional %71 %72 %90 173 %72 = OpLabel 174 %77 = OpAccessChain %19 %17 %9 %9 175 %78 = OpLoad %6 %77 176 %79 = OpConvertSToF %34 %78 177 %82 = OpConvertSToF %34 %21 178 %89 = OpCompositeConstruct %74 %79 %82 %82 %79 179 OpStore %76 %89 180 OpBranch %73 181 %90 = OpLabel 182 %93 = OpConvertSToF %34 %21 183 %94 = OpCompositeConstruct %74 %93 %93 %93 %93 184 OpStore %76 %94 185 OpBranch %73 186 %73 = OpLabel 187 OpReturn 188 OpFunctionEnd 189END 190 191# uniforms for variant 192 193# injectionSwitch 194BUFFER variant_injectionSwitch DATA_TYPE vec2<float> STD140 DATA 195 0.0 1.0 196END 197# _GLF_uniform_int_values 198BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 199 1 0 5 3 200END 201 202BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 203 204PIPELINE graphics variant_pipeline 205 ATTACH variant_vertex_shader 206 ATTACH variant_fragment_shader 207 FRAMEBUFFER_SIZE 256 256 208 BIND BUFFER variant_framebuffer AS color LOCATION 0 209 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 1 210 BIND BUFFER variant__GLF_uniform_int_values 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