1#!amber 2 3# Copyright 2020 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 GraphicsFuzz. 19 20# Short description: A fragment shader that covers a specific OpKill wrapping code path 21 22# The test passes because shader always writes red. 23 24# Optimized using spirv-opt with the following arguments: 25# '--vector-dce' 26# '--combine-access-chains' 27# '--eliminate-local-multi-store' 28# '--scalar-replacement=100' 29# '--simplify-instructions' 30# '--eliminate-dead-branches' 31# '--merge-return' 32# '--combine-access-chains' 33# '--simplify-instructions' 34# '--eliminate-dead-branches' 35# '--merge-blocks' 36# spirv-opt commit hash: 9215c1b7df0029f27807e8c8d7ec80532ce90a87 37 38 39 40SHADER vertex variant_vertex_shader PASSTHROUGH 41 42# variant_fragment_shader is derived from the following GLSL: 43# #version 310 es 44# precision highp float; 45# precision highp int; 46# 47# layout(location = 0) out vec4 _GLF_color; 48# 49# layout(set = 0, binding = 0) uniform buf0 50# { 51# int zero; 52# }; 53# 54# void func(int x) 55# { 56# // Always false. 57# if (x < zero) 58# discard; 59# 60# if (x > 8) 61# _GLF_color = vec4(1, 0, 0, 1); 62# else 63# _GLF_color = vec4(0); 64# } 65# 66# void main() 67# { 68# _GLF_color = vec4(0); 69# 70# for (int i = 0; i < 10 + zero; i++) 71# func(i); 72# } 73SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 74; SPIR-V 75; Version: 1.0 76; Generator: Khronos Glslang Reference Front End; 8 77; Bound: 58 78; Schema: 0 79 OpCapability Shader 80 %1 = OpExtInstImport "GLSL.std.450" 81 OpMemoryModel Logical GLSL450 82 OpEntryPoint Fragment %4 "main" %33 83 OpExecutionMode %4 OriginUpperLeft 84 OpSource ESSL 310 85 OpName %4 "main" 86 OpName %10 "func(i1;" 87 OpName %9 "x" 88 OpName %13 "buf0" 89 OpMemberName %13 0 "zero" 90 OpName %15 "" 91 OpName %33 "_GLF_color" 92 OpName %39 "i" 93 OpName %51 "param" 94 OpMemberDecorate %13 0 Offset 0 95 OpDecorate %13 Block 96 OpDecorate %15 DescriptorSet 0 97 OpDecorate %15 Binding 0 98 OpDecorate %33 Location 0 99 %2 = OpTypeVoid 100 %3 = OpTypeFunction %2 101 %6 = OpTypeInt 32 1 102 %7 = OpTypePointer Function %6 103 %8 = OpTypeFunction %2 %7 104 %13 = OpTypeStruct %6 105 %14 = OpTypePointer Uniform %13 106 %15 = OpVariable %14 Uniform 107 %16 = OpConstant %6 0 108 %17 = OpTypePointer Uniform %6 109 %20 = OpTypeBool 110 %26 = OpConstant %6 8 111 %30 = OpTypeFloat 32 112 %31 = OpTypeVector %30 4 113 %32 = OpTypePointer Output %31 114 %33 = OpVariable %32 Output 115 %34 = OpConstant %30 1 116 %35 = OpConstant %30 0 117 %36 = OpConstantComposite %31 %34 %35 %35 %34 118 %38 = OpConstantComposite %31 %35 %35 %35 %35 119 %46 = OpConstant %6 10 120 %55 = OpConstant %6 1 121 %4 = OpFunction %2 None %3 122 %5 = OpLabel 123 %39 = OpVariable %7 Function 124 %51 = OpVariable %7 Function 125 OpStore %33 %38 126 OpStore %39 %16 127 OpBranch %40 128 %40 = OpLabel 129 %57 = OpPhi %6 %16 %5 %56 %41 130 %47 = OpAccessChain %17 %15 %16 131 %48 = OpLoad %6 %47 132 %49 = OpIAdd %6 %46 %48 133 %50 = OpSLessThan %20 %57 %49 134 OpLoopMerge %42 %41 None 135 OpBranchConditional %50 %41 %42 136 %41 = OpLabel 137 OpStore %51 %57 138 %53 = OpFunctionCall %2 %10 %51 139 %56 = OpIAdd %6 %57 %55 140 OpStore %39 %56 141 OpBranch %40 142 %42 = OpLabel 143 OpReturn 144 OpFunctionEnd 145 %10 = OpFunction %2 None %8 146 %9 = OpFunctionParameter %7 147 %11 = OpLabel 148 %12 = OpLoad %6 %9 149 %18 = OpAccessChain %17 %15 %16 150 %19 = OpLoad %6 %18 151 %21 = OpSLessThan %20 %12 %19 152 OpSelectionMerge %23 None 153 OpBranchConditional %21 %22 %23 154 %22 = OpLabel 155 OpKill 156 %23 = OpLabel 157 %25 = OpLoad %6 %9 158 %27 = OpSGreaterThan %20 %25 %26 159 OpSelectionMerge %29 None 160 OpBranchConditional %27 %28 %37 161 %28 = OpLabel 162 OpStore %33 %36 163 OpBranch %29 164 %37 = OpLabel 165 OpStore %33 %38 166 OpBranch %29 167 %29 = OpLabel 168 OpReturn 169 OpFunctionEnd 170END 171 172# uniforms for variant 173 174# zero 175BUFFER variant_zero DATA_TYPE int32 DATA 176 0 177END 178 179BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 180 181PIPELINE graphics variant_pipeline 182 ATTACH variant_vertex_shader 183 ATTACH variant_fragment_shader 184 FRAMEBUFFER_SIZE 256 256 185 BIND BUFFER variant_framebuffer AS color LOCATION 0 186 BIND BUFFER variant_zero AS uniform DESCRIPTOR_SET 0 BINDING 0 187END 188CLEAR_COLOR variant_pipeline 0 0 0 255 189 190CLEAR variant_pipeline 191RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 192 193EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 194