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