1#!amber 2 3# Copyright 2020 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 GraphicsFuzz. 19 20# Short description: A fragment shader that covers a specific instruction folding path. 21 22# The test passes because shader always writes red. 23 24SHADER vertex variant_vertex_shader PASSTHROUGH 25 26# variant_fragment_shader is derived from the following GLSL: 27# #version 310 es 28# precision highp float; 29# 30# layout(location = 0) out vec4 _GLF_color; 31# layout(set = 0, binding = 0) uniform buf0 32# { 33# vec2 zeroOne; 34# }; 35# 36# void main() 37# { 38# // Since zeroOne is (0, 1) the results will be (2, 5). 39# vec2 v = mix(vec2(2, 3), vec2(4, 5), zeroOne); 40# float d = distance(v, vec2(2, 5)); 41# 42# if (d < 0.1) 43# _GLF_color = vec4(v.x - 1.0, v.y - 5.0, 0, 1); 44# else 45# _GLF_color = vec4(0); 46# } 47SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 48; SPIR-V 49; Version: 1.0 50; Generator: Khronos Glslang Reference Front End; 8 51; Bound: 53 52; Schema: 0 53 OpCapability Shader 54 %1 = OpExtInstImport "GLSL.std.450" 55 OpMemoryModel Logical GLSL450 56 OpEntryPoint Fragment %4 "main" %38 57 OpExecutionMode %4 OriginUpperLeft 58 OpSource ESSL 310 59 OpName %4 "main" 60 OpName %9 "v" 61 OpName %16 "buf0" 62 OpMemberName %16 0 "zeroOne" 63 OpName %18 "" 64 OpName %26 "d" 65 OpName %38 "_GLF_color" 66 OpMemberDecorate %16 0 Offset 0 67 OpDecorate %16 Block 68 OpDecorate %18 DescriptorSet 0 69 OpDecorate %18 Binding 0 70 OpDecorate %38 Location 0 71 %2 = OpTypeVoid 72 %3 = OpTypeFunction %2 73 %6 = OpTypeFloat 32 74 %7 = OpTypeVector %6 2 75 %8 = OpTypePointer Function %7 76 %10 = OpConstant %6 2 77 %11 = OpConstant %6 3 78 %12 = OpConstantComposite %7 %10 %11 79 %13 = OpConstant %6 4 80 %14 = OpConstant %6 5 81 %15 = OpConstantComposite %7 %13 %14 82 %16 = OpTypeStruct %7 83 %17 = OpTypePointer Uniform %16 84 %18 = OpVariable %17 Uniform 85 %19 = OpTypeInt 32 1 86 %20 = OpConstant %19 0 87 %21 = OpTypePointer Uniform %7 88 %25 = OpTypePointer Function %6 89 %28 = OpConstantComposite %7 %10 %14 90 %31 = OpConstant %6 0.100000001 91 %32 = OpTypeBool 92 %36 = OpTypeVector %6 4 93 %37 = OpTypePointer Output %36 94 %38 = OpVariable %37 Output 95 %39 = OpTypeInt 32 0 96 %40 = OpConstant %39 0 97 %43 = OpConstant %6 1 98 %45 = OpConstant %39 1 99 %49 = OpConstant %6 0 100 %52 = OpConstantComposite %36 %49 %49 %49 %49 101 %4 = OpFunction %2 None %3 102 %5 = OpLabel 103 %9 = OpVariable %8 Function 104 %26 = OpVariable %25 Function 105 %22 = OpAccessChain %21 %18 %20 106 %23 = OpLoad %7 %22 107 %24 = OpExtInst %7 %1 FMix %12 %15 %23 108 OpStore %9 %24 109 %27 = OpLoad %7 %9 110 %29 = OpExtInst %6 %1 Distance %27 %28 111 OpStore %26 %29 112 %30 = OpLoad %6 %26 113 %33 = OpFOrdLessThan %32 %30 %31 114 OpSelectionMerge %35 None 115 OpBranchConditional %33 %34 %51 116 %34 = OpLabel 117 %41 = OpAccessChain %25 %9 %40 118 %42 = OpLoad %6 %41 119 %44 = OpFSub %6 %42 %43 120 %46 = OpAccessChain %25 %9 %45 121 %47 = OpLoad %6 %46 122 %48 = OpFSub %6 %47 %14 123 %50 = OpCompositeConstruct %36 %44 %48 %49 %43 124 OpStore %38 %50 125 OpBranch %35 126 %51 = OpLabel 127 OpStore %38 %52 128 OpBranch %35 129 %35 = OpLabel 130 OpReturn 131 OpFunctionEnd 132END 133 134# uniforms for variant 135 136# zeroOne 137BUFFER variant_zeroOne DATA_TYPE vec2<float> DATA 138 0.0 1.0 139END 140 141BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 142 143PIPELINE graphics variant_pipeline 144 ATTACH variant_vertex_shader 145 ATTACH variant_fragment_shader 146 FRAMEBUFFER_SIZE 256 256 147 BIND BUFFER variant_framebuffer AS color LOCATION 0 148 BIND BUFFER variant_zeroOne AS uniform DESCRIPTOR_SET 0 BINDING 0 149END 150CLEAR_COLOR variant_pipeline 0 0 0 255 151 152CLEAR variant_pipeline 153RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 154 155EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 156