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 GraphicsFuzz. 19 20# Short description: A fragment shader that covers a specific load size reduction path. 21 22# The test passes because shader always writes red. 23 24# Optimized using spirv-opt with the following arguments: 25# '-Os' 26# spirv-opt commit hash: 9215c1b7df0029f27807e8c8d7ec80532ce90a87 27 28 29 30SHADER vertex variant_vertex_shader PASSTHROUGH 31 32# variant_fragment_shader is derived from the following GLSL: 33# #version 310 es 34# precision highp float; 35# 36# layout(location = 0) out vec4 _GLF_color; 37# layout(set = 0, binding = 0) uniform buf0 38# { 39# int zero; 40# }; 41# 42# struct S 43# { 44# int x[1]; 45# }; 46# 47# // Function returns 1 or 2. 48# int func(S s, int a) 49# { 50# _GLF_color = vec4(0); 51# 52# if(s.x[zero] == a) 53# return 1; 54# 55# return 2; 56# } 57# 58# void main() 59# { 60# S s; // Uninitialized. Contents don't matter. 61# int res = func(s, s.x[0]); 62# // Always true. 63# if (res == 1 || res == 2) 64# _GLF_color = vec4(1, 0, 0, 1); 65# else 66# _GLF_color = vec4(0); 67# } 68SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 69; SPIR-V 70; Version: 1.0 71; Generator: Khronos Glslang Reference Front End; 8 72; Bound: 97 73; Schema: 0 74 OpCapability Shader 75 %1 = OpExtInstImport "GLSL.std.450" 76 OpMemoryModel Logical GLSL450 77 OpEntryPoint Fragment %4 "main" %21 78 OpExecutionMode %4 OriginUpperLeft 79 OpSource ESSL 310 80 OpName %4 "main" 81 OpName %21 "_GLF_color" 82 OpName %25 "buf0" 83 OpMemberName %25 0 "zero" 84 OpName %27 "" 85 OpDecorate %21 Location 0 86 OpMemberDecorate %25 0 RelaxedPrecision 87 OpMemberDecorate %25 0 Offset 0 88 OpDecorate %25 Block 89 OpDecorate %27 DescriptorSet 0 90 OpDecorate %27 Binding 0 91 OpDecorate %49 RelaxedPrecision 92 OpDecorate %79 RelaxedPrecision 93 OpDecorate %81 RelaxedPrecision 94 OpDecorate %88 RelaxedPrecision 95 OpDecorate %96 RelaxedPrecision 96 %2 = OpTypeVoid 97 %3 = OpTypeFunction %2 98 %6 = OpTypeInt 32 1 99 %7 = OpTypeInt 32 0 100 %8 = OpConstant %7 1 101 %9 = OpTypeArray %6 %8 102 %12 = OpTypePointer Function %6 103 %18 = OpTypeFloat 32 104 %19 = OpTypeVector %18 4 105 %20 = OpTypePointer Output %19 106 %21 = OpVariable %20 Output 107 %22 = OpConstant %18 0 108 %23 = OpConstantComposite %19 %22 %22 %22 %22 109 %24 = OpConstant %6 0 110 %25 = OpTypeStruct %6 111 %26 = OpTypePointer Uniform %25 112 %27 = OpVariable %26 Uniform 113 %28 = OpTypePointer Uniform %6 114 %34 = OpTypeBool 115 %38 = OpConstant %6 1 116 %40 = OpConstant %6 2 117 %58 = OpConstant %18 1 118 %59 = OpConstantComposite %19 %58 %22 %22 %58 119 %87 = OpTypePointer Function %9 120 %4 = OpFunction %2 None %3 121 %5 = OpLabel 122 %88 = OpVariable %87 Function 123 %89 = OpLoad %9 %88 124 %49 = OpCompositeExtract %6 %89 0 125 OpBranch %74 126 %74 = OpLabel 127 OpLoopMerge %75 %76 None 128 OpBranch %77 129 %77 = OpLabel 130 OpStore %21 %23 131 %78 = OpAccessChain %28 %27 %24 132 %79 = OpLoad %6 %78 133 %94 = OpAccessChain %12 %88 %79 134 %81 = OpLoad %6 %94 135 %83 = OpIEqual %34 %81 %49 136 OpSelectionMerge %84 None 137 OpBranchConditional %83 %85 %84 138 %85 = OpLabel 139 OpBranch %75 140 %84 = OpLabel 141 OpBranch %75 142 %76 = OpLabel 143 OpBranch %74 144 %75 = OpLabel 145 %96 = OpPhi %6 %38 %85 %40 %84 146 %52 = OpIEqual %34 %96 %38 147 %54 = OpIEqual %34 %96 %40 148 %55 = OpLogicalOr %34 %52 %54 149 OpSelectionMerge %57 None 150 OpBranchConditional %55 %56 %60 151 %60 = OpLabel 152 OpStore %21 %23 153 OpBranch %57 154 %56 = OpLabel 155 OpStore %21 %59 156 OpBranch %57 157 %57 = OpLabel 158 OpReturn 159 OpFunctionEnd 160END 161 162# uniforms for variant 163 164# zero 165BUFFER variant_zero DATA_TYPE int32 DATA 166 0 167END 168 169BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 170 171PIPELINE graphics variant_pipeline 172 ATTACH variant_vertex_shader 173 ATTACH variant_fragment_shader 174 FRAMEBUFFER_SIZE 256 256 175 BIND BUFFER variant_framebuffer AS color LOCATION 0 176 BIND BUFFER variant_zero AS uniform DESCRIPTOR_SET 0 BINDING 0 177END 178CLEAR_COLOR variant_pipeline 0 0 0 255 179 180CLEAR variant_pipeline 181RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 182 183EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 184