1#!amber 2 3# Copyright 2022 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 LLVM code paths 21 22# The test passes because the shader always writes red. 23 24# Optimized using spirv-opt with the following arguments: 25# '-O' 26# spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af 27 28 29 30SHADER vertex variant_vertex_shader PASSTHROUGH 31 32# variant_fragment_shader is derived from the following GLSL: 33# #version 320 es 34# #define _int_0 _GLF_uniform_int_values[0] 35# #define _int_3 _GLF_uniform_int_values[1] 36# #define _int_256 _GLF_uniform_int_values[2] 37# #define _int_1 _GLF_uniform_int_values[3] 38# #define _float_1_0 _GLF_uniform_float_values[0] 39# 40# precision highp int; 41# precision highp float; 42# 43# // Contents of _GLF_uniform_float_values: 1.0 44# layout(set = 0, binding = 0) uniform buf0 45# { 46# float _GLF_uniform_float_values[1]; 47# }; 48# 49# // Contents of _GLF_uniform_int_values: [0, 3, 256, 1] 50# layout(set = 0, binding = 1) uniform buf1 51# { 52# int _GLF_uniform_int_values[4]; 53# }; 54# 55# layout(location = 0) out vec4 _GLF_color; 56# 57# void main() 58# { 59# _GLF_color = vec4(_int_0); 60# 61# for(int k = ~_int_0; k > ~_int_0 - _int_3; k--) 62# { 63# // Always true. 64# if(uint(~k) < uint(int(gl_FragCoord.y + _float_1_0) * _int_256)) 65# { 66# _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1); 67# break; 68# } 69# } 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: 87 76; Schema: 0 77 OpCapability Shader 78 %1 = OpExtInstImport "GLSL.std.450" 79 OpMemoryModel Logical GLSL450 80 OpEntryPoint Fragment %4 "main" %9 %47 81 OpExecutionMode %4 OriginUpperLeft 82 OpSource ESSL 320 83 OpName %4 "main" 84 OpName %9 "_GLF_color" 85 OpName %14 "buf1" 86 OpMemberName %14 0 "_GLF_uniform_int_values" 87 OpName %16 "" 88 OpName %47 "gl_FragCoord" 89 OpName %53 "buf0" 90 OpMemberName %53 0 "_GLF_uniform_float_values" 91 OpName %55 "" 92 OpDecorate %9 Location 0 93 OpDecorate %13 ArrayStride 16 94 OpMemberDecorate %14 0 Offset 0 95 OpDecorate %14 Block 96 OpDecorate %16 DescriptorSet 0 97 OpDecorate %16 Binding 1 98 OpDecorate %47 BuiltIn FragCoord 99 OpDecorate %52 ArrayStride 16 100 OpMemberDecorate %53 0 Offset 0 101 OpDecorate %53 Block 102 OpDecorate %55 DescriptorSet 0 103 OpDecorate %55 Binding 0 104 %2 = OpTypeVoid 105 %3 = OpTypeFunction %2 106 %6 = OpTypeFloat 32 107 %7 = OpTypeVector %6 4 108 %8 = OpTypePointer Output %7 109 %9 = OpVariable %8 Output 110 %10 = OpTypeInt 32 1 111 %11 = OpTypeInt 32 0 112 %12 = OpConstant %11 4 113 %13 = OpTypeArray %10 %12 114 %14 = OpTypeStruct %13 115 %15 = OpTypePointer Uniform %14 116 %16 = OpVariable %15 Uniform 117 %17 = OpConstant %10 0 118 %18 = OpTypePointer Uniform %10 119 %37 = OpConstant %10 1 120 %41 = OpTypeBool 121 %46 = OpTypePointer Input %7 122 %47 = OpVariable %46 Input 123 %48 = OpConstant %11 1 124 %49 = OpTypePointer Input %6 125 %52 = OpTypeArray %6 %48 126 %53 = OpTypeStruct %52 127 %54 = OpTypePointer Uniform %53 128 %55 = OpVariable %54 Uniform 129 %56 = OpTypePointer Uniform %6 130 %61 = OpConstant %10 2 131 %69 = OpConstant %10 3 132 %4 = OpFunction %2 None %3 133 %5 = OpLabel 134 %19 = OpAccessChain %18 %16 %17 %17 135 %20 = OpLoad %10 %19 136 %21 = OpConvertSToF %6 %20 137 %22 = OpCompositeConstruct %7 %21 %21 %21 %21 138 OpStore %9 %22 139 %27 = OpNot %10 %20 140 OpBranch %28 141 %28 = OpLabel 142 %86 = OpPhi %10 %27 %5 %85 %31 143 %38 = OpAccessChain %18 %16 %17 %37 144 %39 = OpLoad %10 %38 145 %40 = OpISub %10 %27 %39 146 %42 = OpSGreaterThan %41 %86 %40 147 OpLoopMerge %30 %31 None 148 OpBranchConditional %42 %29 %30 149 %29 = OpLabel 150 %44 = OpNot %10 %86 151 %45 = OpBitcast %11 %44 152 %50 = OpAccessChain %49 %47 %48 153 %51 = OpLoad %6 %50 154 %57 = OpAccessChain %56 %55 %17 %17 155 %58 = OpLoad %6 %57 156 %59 = OpFAdd %6 %51 %58 157 %60 = OpConvertFToS %10 %59 158 %62 = OpAccessChain %18 %16 %17 %61 159 %63 = OpLoad %10 %62 160 %64 = OpIMul %10 %60 %63 161 %65 = OpBitcast %11 %64 162 %66 = OpULessThan %41 %45 %65 163 OpSelectionMerge %68 None 164 OpBranchConditional %66 %67 %68 165 %67 = OpLabel 166 %70 = OpAccessChain %18 %16 %17 %69 167 %71 = OpLoad %10 %70 168 %72 = OpConvertSToF %6 %71 169 %82 = OpCompositeConstruct %7 %72 %21 %21 %72 170 OpStore %9 %82 171 OpBranch %30 172 %68 = OpLabel 173 OpBranch %31 174 %31 = OpLabel 175 %85 = OpISub %10 %86 %37 176 OpBranch %28 177 %30 = OpLabel 178 OpReturn 179 OpFunctionEnd 180END 181 182# uniforms for variant 183 184# _GLF_uniform_int_values 185BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 186 0 3 256 1 187END 188# _GLF_uniform_float_values 189BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA 190 1.0 191END 192 193BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 194 195PIPELINE graphics variant_pipeline 196 ATTACH variant_vertex_shader 197 ATTACH variant_fragment_shader 198 FRAMEBUFFER_SIZE 32 32 199 BIND BUFFER variant_framebuffer AS color LOCATION 0 200 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1 201 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0 202END 203CLEAR_COLOR variant_pipeline 0 0 0 255 204 205CLEAR variant_pipeline 206RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32 207 208EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255 209