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