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