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