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# '--eliminate-local-single-store' 26# '--convert-local-access-chains' 27# '--if-conversion' 28# '--eliminate-local-single-block' 29# '--simplify-instructions' 30# '--inline-entry-points-exhaustive' 31# '--private-to-local' 32# '--convert-local-access-chains' 33# '--eliminate-dead-branches' 34# '--merge-return' 35# '--combine-access-chains' 36# '--reduce-load-size' 37# '--reduce-load-size' 38# '--combine-access-chains' 39# '--vector-dce' 40# '--eliminate-dead-branches' 41# '--redundancy-elimination' 42# '--inline-entry-points-exhaustive' 43# '--eliminate-dead-branches' 44# '--merge-blocks' 45# '--eliminate-dead-branches' 46# '--eliminate-local-single-block' 47# '--inline-entry-points-exhaustive' 48# '--if-conversion' 49# spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af 50 51 52 53SHADER vertex variant_vertex_shader PASSTHROUGH 54 55# variant_fragment_shader is derived from the following GLSL: 56# #version 320 es 57# #define _int_3 _GLF_uniform_int_values[0] 58# #define _int_1 _GLF_uniform_int_values[1] 59# #define _int_0 _GLF_uniform_int_values[2] 60# 61# precision highp float; 62# precision highp int; 63# 64# // Contents of _GLF_uniform_int_values: [3, 1, 0] 65# layout(set = 0, binding = 0) uniform buf0 { 66# int _GLF_uniform_int_values[3]; 67# }; 68# layout(location = 0) out vec4 _GLF_color; 69# 70# void main() 71# { 72# // f = (0, 1) * max((1, 1), (2, 3)) = (0, 1) * (2, 3) = 0 * 2 + 1 * 3 = 3 73# float f = dot(vec2(0, 1), max(vec2(_int_1, 1), vec2(2, 3))); 74# 75# // Always true. 76# if(int(f) == _int_3) 77# { 78# _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1); 79# } 80# else 81# { 82# _GLF_color = vec4(0); 83# } 84# } 85SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 86; SPIR-V 87; Version: 1.0 88; Generator: Khronos Glslang Reference Front End; 10 89; Bound: 60 90; Schema: 0 91 OpCapability Shader 92 %1 = OpExtInstImport "GLSL.std.450" 93 OpMemoryModel Logical GLSL450 94 OpEntryPoint Fragment %4 "main" %42 95 OpExecutionMode %4 OriginUpperLeft 96 OpSource ESSL 320 97 OpName %4 "main" 98 OpName %8 "f" 99 OpName %17 "buf0" 100 OpMemberName %17 0 "_GLF_uniform_int_values" 101 OpName %19 "" 102 OpName %42 "_GLF_color" 103 OpDecorate %16 ArrayStride 16 104 OpMemberDecorate %17 0 Offset 0 105 OpDecorate %17 Block 106 OpDecorate %19 DescriptorSet 0 107 OpDecorate %19 Binding 0 108 OpDecorate %42 Location 0 109 %2 = OpTypeVoid 110 %3 = OpTypeFunction %2 111 %6 = OpTypeFloat 32 112 %7 = OpTypePointer Function %6 113 %9 = OpTypeVector %6 2 114 %10 = OpConstant %6 0 115 %11 = OpConstant %6 1 116 %12 = OpConstantComposite %9 %10 %11 117 %13 = OpTypeInt 32 1 118 %14 = OpTypeInt 32 0 119 %15 = OpConstant %14 3 120 %16 = OpTypeArray %13 %15 121 %17 = OpTypeStruct %16 122 %18 = OpTypePointer Uniform %17 123 %19 = OpVariable %18 Uniform 124 %20 = OpConstant %13 0 125 %21 = OpConstant %13 1 126 %22 = OpTypePointer Uniform %13 127 %27 = OpConstant %6 2 128 %28 = OpConstant %6 3 129 %29 = OpConstantComposite %9 %27 %28 130 %36 = OpTypeBool 131 %40 = OpTypeVector %6 4 132 %41 = OpTypePointer Output %40 133 %42 = OpVariable %41 Output 134 %46 = OpConstant %13 2 135 %58 = OpConstantComposite %40 %10 %10 %10 %10 136 %59 = OpUndef %6 137 %4 = OpFunction %2 None %3 138 %5 = OpLabel 139 %8 = OpVariable %7 Function 140 %23 = OpAccessChain %22 %19 %20 %21 141 %24 = OpLoad %13 %23 142 %26 = OpCompositeConstruct %9 %59 %11 143 %30 = OpExtInst %9 %1 FMax %26 %29 144 %31 = OpCompositeExtract %6 %30 1 145 OpStore %8 %31 146 %33 = OpConvertFToS %13 %31 147 %34 = OpAccessChain %22 %19 %20 %20 148 %35 = OpLoad %13 %34 149 %37 = OpIEqual %36 %33 %35 150 OpSelectionMerge %39 None 151 OpBranchConditional %37 %38 %57 152 %38 = OpLabel 153 %45 = OpConvertSToF %6 %24 154 %47 = OpAccessChain %22 %19 %20 %46 155 %48 = OpLoad %13 %47 156 %49 = OpConvertSToF %6 %48 157 %56 = OpCompositeConstruct %40 %45 %49 %49 %45 158 OpStore %42 %56 159 OpBranch %39 160 %57 = OpLabel 161 OpStore %42 %58 162 OpBranch %39 163 %39 = OpLabel 164 OpReturn 165 OpFunctionEnd 166END 167 168# uniforms for variant 169 170# _GLF_uniform_int_values 171BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 172 3 1 0 173END 174 175BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 176 177PIPELINE graphics variant_pipeline 178 ATTACH variant_vertex_shader 179 ATTACH variant_fragment_shader 180 FRAMEBUFFER_SIZE 32 32 181 BIND BUFFER variant_framebuffer AS color LOCATION 0 182 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0 183END 184CLEAR_COLOR variant_pipeline 0 0 0 255 185 186CLEAR variant_pipeline 187RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32 188 189EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255 190