1#!amber 2 3# Copyright 2019 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 bug found by GraphicsFuzz. 19 20# Short description: Calls a function containing a discard 21 22# The test passes because main always writes the color red. 23 24# Optimized using spirv-opt with the following arguments: 25# '--eliminate-dead-branches' 26# '--merge-return' 27# '--eliminate-dead-branches' 28# '--merge-blocks' 29# '--eliminate-local-single-block' 30# '--eliminate-dead-branches' 31# '--merge-return' 32# '--ccp' 33# '--scalar-replacement=100' 34# '--eliminate-local-single-block' 35# '--simplify-instructions' 36# '--redundancy-elimination' 37# '--eliminate-local-multi-store' 38# '--private-to-local' 39# '--if-conversion' 40# '--private-to-local' 41# spirv-opt commit hash: 18b3b94567a9251a6f8491a6d07c4422abadd22c 42 43 44 45SHADER vertex variant_vertex_shader PASSTHROUGH 46 47# variant_fragment_shader is derived from the following GLSL: 48# #version 310 es 49# precision highp float; 50# 51# layout(location = 0) out vec4 _GLF_color; 52# 53# layout(set = 0, binding = 0) uniform buf0 54# { 55# float one; 56# }; 57# 58# void func() 59# { 60# if (1.0 > one) // Always false 61# { 62# discard; 63# } 64# } 65# 66# void main() 67# { 68# _GLF_color = vec4(0); 69# do 70# { 71# func(); 72# } while (false); 73# _GLF_color = vec4(1, 0, 0, 1); 74# } 75SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 76; SPIR-V 77; Version: 1.0 78; Generator: Khronos Glslang Reference Front End; 8 79; Bound: 35 80; Schema: 0 81 OpCapability Shader 82 %1 = OpExtInstImport "GLSL.std.450" 83 OpMemoryModel Logical GLSL450 84 OpEntryPoint Fragment %4 "main" %25 85 OpExecutionMode %4 OriginUpperLeft 86 OpSource ESSL 310 87 OpName %4 "main" 88 OpName %6 "func(" 89 OpName %10 "buf0" 90 OpMemberName %10 0 "one" 91 OpName %12 "" 92 OpName %25 "_GLF_color" 93 OpMemberDecorate %10 0 Offset 0 94 OpDecorate %10 Block 95 OpDecorate %12 DescriptorSet 0 96 OpDecorate %12 Binding 0 97 OpDecorate %25 Location 0 98 %2 = OpTypeVoid 99 %3 = OpTypeFunction %2 100 %8 = OpTypeFloat 32 101 %9 = OpConstant %8 1 102 %10 = OpTypeStruct %8 103 %11 = OpTypePointer Uniform %10 104 %12 = OpVariable %11 Uniform 105 %13 = OpTypeInt 32 1 106 %14 = OpConstant %13 0 107 %15 = OpTypePointer Uniform %8 108 %18 = OpTypeBool 109 %23 = OpTypeVector %8 4 110 %24 = OpTypePointer Output %23 111 %25 = OpVariable %24 Output 112 %26 = OpConstant %8 0 113 %27 = OpConstantComposite %23 %26 %26 %26 %26 114 %33 = OpConstantFalse %18 115 %34 = OpConstantComposite %23 %9 %26 %26 %9 116 %4 = OpFunction %2 None %3 117 %5 = OpLabel 118 OpStore %25 %27 119 OpBranch %28 120 %28 = OpLabel 121 %32 = OpFunctionCall %2 %6 122 OpLoopMerge %30 %28 None 123 OpBranchConditional %33 %28 %30 124 %30 = OpLabel 125 OpStore %25 %34 126 OpReturn 127 OpFunctionEnd 128 %6 = OpFunction %2 None %3 129 %7 = OpLabel 130 %16 = OpAccessChain %15 %12 %14 131 %17 = OpLoad %8 %16 132 %19 = OpFOrdGreaterThan %18 %9 %17 133 OpSelectionMerge %21 None 134 OpBranchConditional %19 %20 %21 135 %20 = OpLabel 136 OpKill 137 %21 = OpLabel 138 OpReturn 139 OpFunctionEnd 140END 141 142# uniforms for variant 143 144# one 145BUFFER variant_one DATA_TYPE float DATA 146 1.0 147END 148 149BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 150 151PIPELINE graphics variant_pipeline 152 ATTACH variant_vertex_shader 153 ATTACH variant_fragment_shader 154 FRAMEBUFFER_SIZE 256 256 155 BIND BUFFER variant_framebuffer AS color LOCATION 0 156 BIND BUFFER variant_one AS uniform DESCRIPTOR_SET 0 BINDING 0 157END 158CLEAR_COLOR variant_pipeline 0 0 0 255 159 160CLEAR variant_pipeline 161RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 162 163EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 164