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 _float_0_0 _GLF_uniform_float_values[0] 31# #define _float_5_0 _GLF_uniform_float_values[1] 32# 33# precision highp int; 34# precision highp float; 35# 36# // Contents of _GLF_uniform_int_values: [1, 0] 37# layout(set = 0, binding = 0) uniform buf0 38# { 39# int _GLF_uniform_int_values[2]; 40# }; 41# 42# // Contents of _GLF_uniform_float_values: [0.0, 5.0] 43# layout(set = 0, binding = 1) uniform buf1 44# { 45# float _GLF_uniform_float_values[2]; 46# }; 47# 48# layout(location = 0) out vec4 _GLF_color; 49# 50# void main() 51# { 52# // Trunc returns either 0.0 or 1.0. Fract will return zero for both. 53# float f = fract(trunc(gl_FragCoord.y < _float_5_0 ? 0.1 : 1.0)); 54# 55# // Always true. 56# if(f == _float_0_0) 57# { 58# _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1); 59# } 60# else 61# { 62# _GLF_color = vec4(_int_0); 63# } 64# } 65SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 66; SPIR-V 67; Version: 1.0 68; Generator: Khronos Glslang Reference Front End; 10 69; Bound: 66 70; Schema: 0 71 OpCapability Shader 72 %1 = OpExtInstImport "GLSL.std.450" 73 OpMemoryModel Logical GLSL450 74 OpEntryPoint Fragment %4 "main" %11 %42 75 OpExecutionMode %4 OriginUpperLeft 76 OpSource ESSL 320 77 OpName %4 "main" 78 OpName %8 "f" 79 OpName %11 "gl_FragCoord" 80 OpName %19 "buf1" 81 OpMemberName %19 0 "_GLF_uniform_float_values" 82 OpName %21 "" 83 OpName %42 "_GLF_color" 84 OpName %44 "buf0" 85 OpMemberName %44 0 "_GLF_uniform_int_values" 86 OpName %46 "" 87 OpDecorate %11 BuiltIn FragCoord 88 OpDecorate %18 ArrayStride 16 89 OpMemberDecorate %19 0 Offset 0 90 OpDecorate %19 Block 91 OpDecorate %21 DescriptorSet 0 92 OpDecorate %21 Binding 1 93 OpDecorate %42 Location 0 94 OpDecorate %43 ArrayStride 16 95 OpMemberDecorate %44 0 Offset 0 96 OpDecorate %44 Block 97 OpDecorate %46 DescriptorSet 0 98 OpDecorate %46 Binding 0 99 %2 = OpTypeVoid 100 %3 = OpTypeFunction %2 101 %6 = OpTypeFloat 32 102 %7 = OpTypePointer Function %6 103 %9 = OpTypeVector %6 4 104 %10 = OpTypePointer Input %9 105 %11 = OpVariable %10 Input 106 %12 = OpTypeInt 32 0 107 %13 = OpConstant %12 1 108 %14 = OpTypePointer Input %6 109 %17 = OpConstant %12 2 110 %18 = OpTypeArray %6 %17 111 %19 = OpTypeStruct %18 112 %20 = OpTypePointer Uniform %19 113 %21 = OpVariable %20 Uniform 114 %22 = OpTypeInt 32 1 115 %23 = OpConstant %22 0 116 %24 = OpConstant %22 1 117 %25 = OpTypePointer Uniform %6 118 %28 = OpTypeBool 119 %30 = OpConstant %6 0.100000001 120 %31 = OpConstant %6 1 121 %41 = OpTypePointer Output %9 122 %42 = OpVariable %41 Output 123 %43 = OpTypeArray %22 %17 124 %44 = OpTypeStruct %43 125 %45 = OpTypePointer Uniform %44 126 %46 = OpVariable %45 Uniform 127 %47 = OpTypePointer Uniform %22 128 %4 = OpFunction %2 None %3 129 %5 = OpLabel 130 %8 = OpVariable %7 Function 131 %15 = OpAccessChain %14 %11 %13 132 %16 = OpLoad %6 %15 133 %26 = OpAccessChain %25 %21 %23 %24 134 %27 = OpLoad %6 %26 135 %29 = OpFOrdLessThan %28 %16 %27 136 %32 = OpSelect %6 %29 %30 %31 137 %33 = OpExtInst %6 %1 Trunc %32 138 %34 = OpExtInst %6 %1 Fract %33 139 OpStore %8 %34 140 %35 = OpLoad %6 %8 141 %36 = OpAccessChain %25 %21 %23 %23 142 %37 = OpLoad %6 %36 143 %38 = OpFOrdEqual %28 %35 %37 144 OpSelectionMerge %40 None 145 OpBranchConditional %38 %39 %61 146 %39 = OpLabel 147 %48 = OpAccessChain %47 %46 %23 %23 148 %49 = OpLoad %22 %48 149 %50 = OpConvertSToF %6 %49 150 %51 = OpAccessChain %47 %46 %23 %24 151 %52 = OpLoad %22 %51 152 %53 = OpConvertSToF %6 %52 153 %54 = OpAccessChain %47 %46 %23 %24 154 %55 = OpLoad %22 %54 155 %56 = OpConvertSToF %6 %55 156 %57 = OpAccessChain %47 %46 %23 %23 157 %58 = OpLoad %22 %57 158 %59 = OpConvertSToF %6 %58 159 %60 = OpCompositeConstruct %9 %50 %53 %56 %59 160 OpStore %42 %60 161 OpBranch %40 162 %61 = OpLabel 163 %62 = OpAccessChain %47 %46 %23 %24 164 %63 = OpLoad %22 %62 165 %64 = OpConvertSToF %6 %63 166 %65 = OpCompositeConstruct %9 %64 %64 %64 %64 167 OpStore %42 %65 168 OpBranch %40 169 %40 = OpLabel 170 OpReturn 171 OpFunctionEnd 172END 173 174# uniforms for variant 175 176# _GLF_uniform_float_values 177BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA 178 0.0 5.0 179END 180# _GLF_uniform_int_values 181BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 182 1 0 183END 184 185BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 186 187PIPELINE graphics variant_pipeline 188 ATTACH variant_vertex_shader 189 ATTACH variant_fragment_shader 190 FRAMEBUFFER_SIZE 256 256 191 BIND BUFFER variant_framebuffer AS color LOCATION 0 192 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1 193 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0 194END 195CLEAR_COLOR variant_pipeline 0 0 0 255 196 197CLEAR variant_pipeline 198RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 199 200EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 201