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