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 bug found by GraphicsFuzz. 19 20# Short description: A fragment shader that uses a struct with an array of size one 21 22# The test passes because the shader always writes red. 23 24# Optimized using spirv-opt with the following arguments: 25# '--wrap-opkill' 26# '--eliminate-dead-branches' 27# '--merge-return' 28# '--inline-entry-points-exhaustive' 29# '--eliminate-dead-functions' 30# '--private-to-local' 31# '--scalar-replacement=0' 32# '--ssa-rewrite' 33# '--ccp' 34# '--loop-unroll' 35# '--eliminate-dead-branches' 36# '--simplify-instructions' 37# '--scalar-replacement=0' 38# '--eliminate-local-single-store' 39# '--if-conversion' 40# '--simplify-instructions' 41# '--eliminate-dead-code-aggressive' 42# '--eliminate-dead-branches' 43# '--merge-blocks' 44# spirv-opt commit hash: dd3d91691f1e1dc4c0f42818756cf5e165c8918c 45 46 47 48SHADER vertex variant_vertex_shader PASSTHROUGH 49 50# variant_fragment_shader is derived from the following GLSL: 51# #version 310 es 52# precision highp float; 53# 54# struct S 55# { 56# int x[1]; 57# }; 58# 59# layout(location = 0) out vec4 _GLF_color; 60# layout(set = 0, binding = 0) uniform buf0 61# { 62# int zero; 63# }; 64# 65# // Function returns 1 or 2. 66# int func(S s, int a) 67# { 68# _GLF_color = vec4(0); 69# 70# if(s.x[0] == a) 71# return 1; 72# 73# return 2; 74# } 75# 76# void main() 77# { 78# S s; 79# s.x[0] = zero; 80# 81# int res = func(s, s.x[0]); 82# 83# // Always true. 84# if (res == 1) 85# _GLF_color = vec4(1, 0, 0, 1); 86# else 87# _GLF_color = vec4(0); 88# } 89SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 90; SPIR-V 91; Version: 1.0 92; Generator: Khronos Glslang Reference Front End; 8 93; Bound: 90 94; Schema: 0 95 OpCapability Shader 96 %1 = OpExtInstImport "GLSL.std.450" 97 OpMemoryModel Logical GLSL450 98 OpEntryPoint Fragment %4 "main" %21 99 OpExecutionMode %4 OriginUpperLeft 100 OpSource ESSL 310 101 OpName %4 "main" 102 OpName %21 "_GLF_color" 103 OpName %38 "buf0" 104 OpMemberName %38 0 "zero" 105 OpName %40 "" 106 OpDecorate %21 Location 0 107 OpMemberDecorate %38 0 RelaxedPrecision 108 OpMemberDecorate %38 0 Offset 0 109 OpDecorate %38 Block 110 OpDecorate %40 DescriptorSet 0 111 OpDecorate %40 Binding 0 112 OpDecorate %43 RelaxedPrecision 113 OpDecorate %50 RelaxedPrecision 114 OpDecorate %74 RelaxedPrecision 115 OpDecorate %81 RelaxedPrecision 116 OpDecorate %86 RelaxedPrecision 117 OpDecorate %89 RelaxedPrecision 118 %2 = OpTypeVoid 119 %3 = OpTypeFunction %2 120 %6 = OpTypeInt 32 1 121 %7 = OpTypeInt 32 0 122 %8 = OpConstant %7 1 123 %9 = OpTypeArray %6 %8 124 %12 = OpTypePointer Function %6 125 %18 = OpTypeFloat 32 126 %19 = OpTypeVector %18 4 127 %20 = OpTypePointer Output %19 128 %21 = OpVariable %20 Output 129 %22 = OpConstant %18 0 130 %23 = OpConstantComposite %19 %22 %22 %22 %22 131 %24 = OpConstant %6 0 132 %28 = OpTypeBool 133 %32 = OpConstant %6 1 134 %34 = OpConstant %6 2 135 %38 = OpTypeStruct %6 136 %39 = OpTypePointer Uniform %38 137 %40 = OpVariable %39 Uniform 138 %41 = OpTypePointer Uniform %6 139 %56 = OpConstant %18 1 140 %57 = OpConstantComposite %19 %56 %22 %22 %56 141 %63 = OpConstant %7 0 142 %80 = OpTypePointer Function %9 143 %4 = OpFunction %2 None %3 144 %5 = OpLabel 145 %86 = OpVariable %80 Function 146 %81 = OpVariable %80 Function 147 %42 = OpAccessChain %41 %40 %24 148 %43 = OpLoad %6 %42 149 %82 = OpAccessChain %12 %81 %24 150 OpStore %82 %43 151 %83 = OpLoad %9 %81 152 OpStore %86 %83 153 %85 = OpAccessChain %12 %81 %24 154 %50 = OpLoad %6 %85 155 OpSelectionMerge %71 None 156 OpSwitch %63 %72 157 %72 = OpLabel 158 OpStore %21 %23 159 %88 = OpAccessChain %12 %86 %24 160 %74 = OpLoad %6 %88 161 %76 = OpIEqual %28 %74 %50 162 OpSelectionMerge %77 None 163 OpBranchConditional %76 %78 %77 164 %78 = OpLabel 165 OpBranch %71 166 %77 = OpLabel 167 OpBranch %71 168 %71 = OpLabel 169 %89 = OpPhi %6 %32 %78 %34 %77 170 %53 = OpIEqual %28 %89 %32 171 OpSelectionMerge %55 None 172 OpBranchConditional %53 %54 %58 173 %54 = OpLabel 174 OpStore %21 %57 175 OpBranch %55 176 %58 = OpLabel 177 OpStore %21 %23 178 OpBranch %55 179 %55 = OpLabel 180 OpReturn 181 OpFunctionEnd 182END 183 184# uniforms for variant 185 186# zero 187BUFFER variant_zero DATA_TYPE int32 DATA 188 0 189END 190 191BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 192 193PIPELINE graphics variant_pipeline 194 ATTACH variant_vertex_shader 195 ATTACH variant_fragment_shader 196 FRAMEBUFFER_SIZE 256 256 197 BIND BUFFER variant_framebuffer AS color LOCATION 0 198 BIND BUFFER variant_zero AS uniform DESCRIPTOR_SET 0 BINDING 0 199END 200CLEAR_COLOR variant_pipeline 0 0 0 255 201 202CLEAR variant_pipeline 203RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 204 205EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 206