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