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