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 SPIR-V reader 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_0 _GLF_uniform_int_values[0] 30# #define _int_1 _GLF_uniform_int_values[1] 31# #define _float_1_0 _GLF_uniform_float_values[0] 32# 33# precision highp int; 34# precision highp float; 35# 36# // Contents of _GLF_uniform_int_values: [0, 1] 37# layout(set = 0, binding = 0) uniform buf0 38# { 39# int _GLF_uniform_int_values[2]; 40# }; 41# // Contents of _GLF_uniform_float_values: 1.0 42# layout(set = 0, binding = 1) uniform buf1 43# { 44# float _GLF_uniform_float_values[1]; 45# }; 46# layout(location = 0) out vec4 _GLF_color; 47# 48# // Contents of m: [1.0, 5.0, 3.0, 7.0, 9.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0] 49# layout(push_constant) uniform buf_push 50# { 51# mat4 m; 52# }; 53# 54# void main() 55# { 56# // Always true. 57# if(m[_int_0][_int_0] == _float_1_0) 58# { 59# _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1); 60# } 61# else 62# { 63# _GLF_color = vec4(_int_0); 64# } 65# } 66SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 67; SPIR-V 68; Version: 1.0 69; Generator: Khronos Glslang Reference Front End; 10 70; Bound: 61 71; Schema: 0 72 OpCapability Shader 73 %1 = OpExtInstImport "GLSL.std.450" 74 OpMemoryModel Logical GLSL450 75 OpEntryPoint Fragment %4 "main" %41 76 OpExecutionMode %4 OriginUpperLeft 77 OpSource ESSL 320 78 OpName %4 "main" 79 OpName %9 "buf_push" 80 OpMemberName %9 0 "m" 81 OpName %11 "" 82 OpName %17 "buf0" 83 OpMemberName %17 0 "_GLF_uniform_int_values" 84 OpName %19 "" 85 OpName %30 "buf1" 86 OpMemberName %30 0 "_GLF_uniform_float_values" 87 OpName %32 "" 88 OpName %41 "_GLF_color" 89 OpMemberDecorate %9 0 ColMajor 90 OpMemberDecorate %9 0 Offset 0 91 OpMemberDecorate %9 0 MatrixStride 16 92 OpDecorate %9 Block 93 OpDecorate %16 ArrayStride 16 94 OpMemberDecorate %17 0 Offset 0 95 OpDecorate %17 Block 96 OpDecorate %19 DescriptorSet 0 97 OpDecorate %19 Binding 0 98 OpDecorate %29 ArrayStride 16 99 OpMemberDecorate %30 0 Offset 0 100 OpDecorate %30 Block 101 OpDecorate %32 DescriptorSet 0 102 OpDecorate %32 Binding 1 103 OpDecorate %41 Location 0 104 %2 = OpTypeVoid 105 %3 = OpTypeFunction %2 106 %6 = OpTypeFloat 32 107 %7 = OpTypeVector %6 4 108 %8 = OpTypeMatrix %7 4 109 %9 = OpTypeStruct %8 110 %10 = OpTypePointer PushConstant %9 111 %11 = OpVariable %10 PushConstant 112 %12 = OpTypeInt 32 1 113 %13 = OpConstant %12 0 114 %14 = OpTypeInt 32 0 115 %15 = OpConstant %14 2 116 %16 = OpTypeArray %12 %15 117 %17 = OpTypeStruct %16 118 %18 = OpTypePointer Uniform %17 119 %19 = OpVariable %18 Uniform 120 %20 = OpTypePointer Uniform %12 121 %25 = OpTypePointer PushConstant %6 122 %28 = OpConstant %14 1 123 %29 = OpTypeArray %6 %28 124 %30 = OpTypeStruct %29 125 %31 = OpTypePointer Uniform %30 126 %32 = OpVariable %31 Uniform 127 %33 = OpTypePointer Uniform %6 128 %36 = OpTypeBool 129 %40 = OpTypePointer Output %7 130 %41 = OpVariable %40 Output 131 %42 = OpConstant %12 1 132 %4 = OpFunction %2 None %3 133 %5 = OpLabel 134 %21 = OpAccessChain %20 %19 %13 %13 135 %22 = OpLoad %12 %21 136 %23 = OpAccessChain %20 %19 %13 %13 137 %24 = OpLoad %12 %23 138 %26 = OpAccessChain %25 %11 %13 %22 %24 139 %27 = OpLoad %6 %26 140 %34 = OpAccessChain %33 %32 %13 %13 141 %35 = OpLoad %6 %34 142 %37 = OpFOrdEqual %36 %27 %35 143 OpSelectionMerge %39 None 144 OpBranchConditional %37 %38 %56 145 %38 = OpLabel 146 %43 = OpAccessChain %20 %19 %13 %42 147 %44 = OpLoad %12 %43 148 %45 = OpConvertSToF %6 %44 149 %46 = OpAccessChain %20 %19 %13 %13 150 %47 = OpLoad %12 %46 151 %48 = OpConvertSToF %6 %47 152 %49 = OpAccessChain %20 %19 %13 %13 153 %50 = OpLoad %12 %49 154 %51 = OpConvertSToF %6 %50 155 %52 = OpAccessChain %20 %19 %13 %42 156 %53 = OpLoad %12 %52 157 %54 = OpConvertSToF %6 %53 158 %55 = OpCompositeConstruct %7 %45 %48 %51 %54 159 OpStore %41 %55 160 OpBranch %39 161 %56 = OpLabel 162 %57 = OpAccessChain %20 %19 %13 %13 163 %58 = OpLoad %12 %57 164 %59 = OpConvertSToF %6 %58 165 %60 = OpCompositeConstruct %7 %59 %59 %59 %59 166 OpStore %41 %60 167 OpBranch %39 168 %39 = OpLabel 169 OpReturn 170 OpFunctionEnd 171END 172 173# uniforms for variant 174 175# m 176BUFFER variant_m DATA_TYPE mat4x4<float>[] STD140 DATA 177 1.0 5.0 3.0 7.0 9.0 6.0 7.0 8.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 178END 179# _GLF_uniform_float_values 180BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA 181 1.0 182END 183# _GLF_uniform_int_values 184BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 185 0 1 186END 187 188BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 189 190PIPELINE graphics variant_pipeline 191 ATTACH variant_vertex_shader 192 ATTACH variant_fragment_shader 193 FRAMEBUFFER_SIZE 256 256 194 BIND BUFFER variant_framebuffer AS color LOCATION 0 195 BIND BUFFER variant_m AS push_constant 196 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1 197 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0 198END 199CLEAR_COLOR variant_pipeline 0 0 0 255 200 201CLEAR variant_pipeline 202RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 203 204EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 205