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: A fragment shader that assigns vector values 21 22# The test passes because shader always writes red. 23 24# Optimized using spirv-opt with the following arguments: 25# '--eliminate-dead-branches' 26# '--eliminate-dead-inserts' 27# '--combine-access-chains' 28# '--eliminate-local-multi-store' 29# '--simplify-instructions' 30# '--eliminate-dead-branches' 31# '--vector-dce' 32# '--combine-access-chains' 33# '--eliminate-local-single-store' 34# '--eliminate-local-multi-store' 35# '--eliminate-dead-inserts' 36# '--if-conversion' 37# '--copy-propagate-arrays' 38# '--combine-access-chains' 39# spirv-opt commit hash: e82a428605f6ce0a07337b36f8ba3935c9f165ac 40 41 42 43SHADER vertex variant_vertex_shader PASSTHROUGH 44 45# variant_fragment_shader is derived from the following GLSL: 46# #version 310 es 47# precision highp float; 48# 49# layout(location = 0) out vec4 _GLF_color; 50# 51# int func() 52# { 53# vec4 tmp; 54# float tmp2[1]; 55# float tmp3; 56# vec2 coord = vec2(1.0); 57# 58# if (int(coord.y) < 180) // Always true 59# tmp3 = tmp2[0]; 60# else 61# discard; 62# 63# tmp = vec4(tmp3); 64# return 1; 65# } 66# 67# void main() 68# { 69# if (func() == 1) 70# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); 71# else 72# _GLF_color = vec4(0.0, 0.0, 0.0, 1.0); 73# } 74SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 75; SPIR-V 76; Version: 1.0 77; Generator: Khronos Glslang Reference Front End; 8 78; Bound: 54 79; Schema: 0 80 OpCapability Shader 81 %1 = OpExtInstImport "GLSL.std.450" 82 OpMemoryModel Logical GLSL450 83 OpEntryPoint Fragment %4 "main" %49 84 OpExecutionMode %4 OriginUpperLeft 85 OpSource ESSL 310 86 OpName %4 "main" 87 OpName %8 "func(" 88 OpName %13 "coord" 89 OpName %27 "tmp3" 90 OpName %30 "tmp2" 91 OpName %38 "tmp" 92 OpName %49 "_GLF_color" 93 OpDecorate %8 RelaxedPrecision 94 OpDecorate %44 RelaxedPrecision 95 OpDecorate %49 Location 0 96 %2 = OpTypeVoid 97 %3 = OpTypeFunction %2 98 %6 = OpTypeInt 32 1 99 %7 = OpTypeFunction %6 100 %10 = OpTypeFloat 32 101 %11 = OpTypeVector %10 2 102 %12 = OpTypePointer Function %11 103 %14 = OpConstant %10 1 104 %15 = OpConstantComposite %11 %14 %14 105 %16 = OpTypeInt 32 0 106 %17 = OpConstant %16 1 107 %18 = OpTypePointer Function %10 108 %22 = OpConstant %6 180 109 %23 = OpTypeBool 110 %28 = OpTypeArray %10 %17 111 %29 = OpTypePointer Function %28 112 %31 = OpConstant %6 0 113 %36 = OpTypeVector %10 4 114 %37 = OpTypePointer Function %36 115 %41 = OpConstant %6 1 116 %48 = OpTypePointer Output %36 117 %49 = OpVariable %48 Output 118 %50 = OpConstant %10 0 119 %51 = OpConstantComposite %36 %14 %50 %50 %14 120 %53 = OpConstantComposite %36 %50 %50 %50 %14 121 %4 = OpFunction %2 None %3 122 %5 = OpLabel 123 %44 = OpFunctionCall %6 %8 124 %45 = OpIEqual %23 %44 %41 125 OpSelectionMerge %47 None 126 OpBranchConditional %45 %46 %52 127 %46 = OpLabel 128 OpStore %49 %51 129 OpBranch %47 130 %52 = OpLabel 131 OpStore %49 %53 132 OpBranch %47 133 %47 = OpLabel 134 OpReturn 135 OpFunctionEnd 136 %8 = OpFunction %6 None %7 137 %9 = OpLabel 138 %13 = OpVariable %12 Function 139 %27 = OpVariable %18 Function 140 %30 = OpVariable %29 Function 141 %38 = OpVariable %37 Function 142 OpStore %13 %15 143 %19 = OpAccessChain %18 %13 %17 144 %20 = OpLoad %10 %19 145 %21 = OpConvertFToS %6 %20 146 %24 = OpSLessThan %23 %21 %22 147 OpSelectionMerge %26 None 148 OpBranchConditional %24 %25 %34 149 %25 = OpLabel 150 %32 = OpAccessChain %18 %30 %31 151 %33 = OpLoad %10 %32 152 OpStore %27 %33 153 OpBranch %26 154 %34 = OpLabel 155 OpKill 156 %26 = OpLabel 157 %40 = OpCompositeConstruct %36 %33 %33 %33 %33 158 OpStore %38 %40 159 OpReturnValue %41 160 OpFunctionEnd 161END 162 163 164BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 165 166PIPELINE graphics variant_pipeline 167 ATTACH variant_vertex_shader 168 ATTACH variant_fragment_shader 169 FRAMEBUFFER_SIZE 256 256 170 BIND BUFFER variant_framebuffer AS color LOCATION 0 171END 172CLEAR_COLOR variant_pipeline 0 0 0 255 173 174CLEAR variant_pipeline 175RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 176 177EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 178