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