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