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