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