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