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 the GraphicsFuzz project. 19 20# Short description: A fragment shader that covers specific NIR 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# '--eliminate-local-multi-store' 27# '--eliminate-local-single-store' 28# '--simplify-instructions' 29# '--eliminate-dead-branches' 30# '--copy-propagate-arrays' 31# '--copy-propagate-arrays' 32# '--eliminate-dead-inserts' 33# '--vector-dce' 34# '--vector-dce' 35# '--inline-entry-points-exhaustive' 36# '--eliminate-local-single-store' 37# '--eliminate-local-single-store' 38# '--simplify-instructions' 39# '--eliminate-local-single-block' 40# '--ccp' 41# '--private-to-local' 42# '--scalar-replacement=100' 43# '--eliminate-local-single-block' 44# '--private-to-local' 45# '--scalar-replacement=100' 46# '--simplify-instructions' 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 _float_1_0 _GLF_uniform_float_values[0] 58# #define _float_2_0 _GLF_uniform_float_values[1] 59# 60# precision highp float; 61# precision highp int; 62# 63# // Contents of _GLF_uniform_float_values: [1.0, 2.0] 64# layout(set = 0, binding = 0) uniform buf0 65# { 66# float _GLF_uniform_float_values[2]; 67# }; 68# 69# layout(location = 0) out vec4 _GLF_color; 70# 71# // Contents of zero: 0.0 72# layout(set = 0, binding = 1) uniform buf1 73# { 74# float zero; 75# }; 76# 77# void main() 78# { 79# vec2 v0 = vec2(_float_1_0); 80# vec4 v1 = vec4(v0.x); 81# 82# // Always true. 83# if(zero != _float_1_0) 84# { 85# // Always false. 86# if(zero == _float_2_0) 87# { 88# return; 89# } 90# v1.yz -= _float_1_0; 91# } 92# else 93# { 94# discard; 95# } 96# 97# _GLF_color = v1; 98# } 99SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 100; SPIR-V 101; Version: 1.0 102; Generator: Khronos Glslang Reference Front End; 10 103; Bound: 62 104; Schema: 0 105 OpCapability Shader 106 %1 = OpExtInstImport "GLSL.std.450" 107 OpMemoryModel Logical GLSL450 108 OpEntryPoint Fragment %4 "main" %61 109 OpExecutionMode %4 OriginUpperLeft 110 OpSource ESSL 320 111 OpName %4 "main" 112 OpName %9 "v0" 113 OpName %13 "buf0" 114 OpMemberName %13 0 "_GLF_uniform_float_values" 115 OpName %15 "" 116 OpName %24 "v1" 117 OpName %30 "buf1" 118 OpMemberName %30 0 "zero" 119 OpName %32 "" 120 OpName %61 "_GLF_color" 121 OpDecorate %12 ArrayStride 16 122 OpMemberDecorate %13 0 Offset 0 123 OpDecorate %13 Block 124 OpDecorate %15 DescriptorSet 0 125 OpDecorate %15 Binding 0 126 OpMemberDecorate %30 0 Offset 0 127 OpDecorate %30 Block 128 OpDecorate %32 DescriptorSet 0 129 OpDecorate %32 Binding 1 130 OpDecorate %61 Location 0 131 %2 = OpTypeVoid 132 %3 = OpTypeFunction %2 133 %6 = OpTypeFloat 32 134 %7 = OpTypeVector %6 2 135 %8 = OpTypePointer Function %7 136 %10 = OpTypeInt 32 0 137 %11 = OpConstant %10 2 138 %12 = OpTypeArray %6 %11 139 %13 = OpTypeStruct %12 140 %14 = OpTypePointer Uniform %13 141 %15 = OpVariable %14 Uniform 142 %16 = OpTypeInt 32 1 143 %17 = OpConstant %16 0 144 %18 = OpTypePointer Uniform %6 145 %22 = OpTypeVector %6 4 146 %23 = OpTypePointer Function %22 147 %25 = OpConstant %10 0 148 %26 = OpTypePointer Function %6 149 %30 = OpTypeStruct %6 150 %31 = OpTypePointer Uniform %30 151 %32 = OpVariable %31 Uniform 152 %37 = OpTypeBool 153 %43 = OpConstant %16 1 154 %60 = OpTypePointer Output %22 155 %61 = OpVariable %60 Output 156 %4 = OpFunction %2 None %3 157 %5 = OpLabel 158 %9 = OpVariable %8 Function 159 %24 = OpVariable %23 Function 160 %19 = OpAccessChain %18 %15 %17 %17 161 %20 = OpLoad %6 %19 162 %21 = OpCompositeConstruct %7 %20 %20 163 OpStore %9 %21 164 %27 = OpAccessChain %26 %9 %25 165 %28 = OpLoad %6 %27 166 %29 = OpCompositeConstruct %22 %28 %28 %28 %28 167 OpStore %24 %29 168 %33 = OpAccessChain %18 %32 %17 169 %34 = OpLoad %6 %33 170 %35 = OpAccessChain %18 %15 %17 %17 171 %36 = OpLoad %6 %35 172 %38 = OpFUnordNotEqual %37 %34 %36 173 OpSelectionMerge %40 None 174 OpBranchConditional %38 %39 %58 175 %39 = OpLabel 176 %41 = OpAccessChain %18 %32 %17 177 %42 = OpLoad %6 %41 178 %44 = OpAccessChain %18 %15 %17 %43 179 %45 = OpLoad %6 %44 180 %46 = OpFOrdEqual %37 %42 %45 181 OpSelectionMerge %48 None 182 OpBranchConditional %46 %47 %48 183 %47 = OpLabel 184 OpReturn 185 %48 = OpLabel 186 %50 = OpAccessChain %18 %15 %17 %17 187 %51 = OpLoad %6 %50 188 %53 = OpVectorShuffle %7 %29 %29 1 2 189 %54 = OpCompositeConstruct %7 %51 %51 190 %55 = OpFSub %7 %53 %54 191 %57 = OpVectorShuffle %22 %29 %55 0 4 5 3 192 OpStore %24 %57 193 OpBranch %40 194 %58 = OpLabel 195 OpKill 196 %40 = OpLabel 197 OpStore %61 %57 198 OpReturn 199 OpFunctionEnd 200END 201 202# uniforms for variant 203 204# zero 205BUFFER variant_zero DATA_TYPE float STD140 DATA 206 0.0 207END 208# _GLF_uniform_float_values 209BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA 210 1.0 2.0 211END 212 213BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 214 215PIPELINE graphics variant_pipeline 216 ATTACH variant_vertex_shader 217 ATTACH variant_fragment_shader 218 FRAMEBUFFER_SIZE 256 256 219 BIND BUFFER variant_framebuffer AS color LOCATION 0 220 BIND BUFFER variant_zero AS uniform DESCRIPTOR_SET 0 BINDING 1 221 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0 222END 223CLEAR_COLOR variant_pipeline 0 0 0 255 224 225CLEAR variant_pipeline 226RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 227 228EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 229