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 uninitialized element cast in loop 21 22# The test passes because main always writes the color red. 23 24# Optimized using spirv-opt with the following arguments: 25# '--inline-entry-points-exhaustive' 26# '--eliminate-local-single-block' 27# '--ccp' 28# '--eliminate-local-multi-store' 29# '--inline-entry-points-exhaustive' 30# '--combine-access-chains' 31# '--combine-access-chains' 32# '--reduce-load-size' 33# '--copy-propagate-arrays' 34# '--reduce-load-size' 35# '--eliminate-local-multi-store' 36# '--scalar-replacement=100' 37# '--convert-local-access-chains' 38# '--scalar-replacement=100' 39# '--vector-dce' 40# '--eliminate-dead-inserts' 41# '--scalar-replacement=100' 42# '--eliminate-dead-inserts' 43# '--simplify-instructions' 44# '--eliminate-dead-branches' 45# '--merge-blocks' 46# '--ccp' 47# '--copy-propagate-arrays' 48# '--combine-access-chains' 49# '--eliminate-local-multi-store' 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# layout(location = 0) out vec4 _GLF_color; 61# layout(set = 0, binding = 0) uniform buf0 { vec2 injectionSwitch; }; 62# 63# void main() 64# { 65# while(true) 66# { 67# while(false) 68# break; 69# 70# float uninit[1]; 71# float(uninit[0]); 72# 73# if (injectionSwitch.x < injectionSwitch.y) // always true 74# { 75# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); 76# return; 77# } 78# } 79# } 80SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 81; SPIR-V 82; Version: 1.0 83; Generator: Khronos Glslang Reference Front End; 7 84; Bound: 56 85; Schema: 0 86 OpCapability Shader 87 %1 = OpExtInstImport "GLSL.std.450" 88 OpMemoryModel Logical GLSL450 89 OpEntryPoint Fragment %4 "main" %46 90 OpExecutionMode %4 OriginUpperLeft 91 OpSource ESSL 310 92 OpName %4 "main" 93 OpName %32 "buf0" 94 OpMemberName %32 0 "injectionSwitch" 95 OpName %34 "" 96 OpName %46 "_GLF_color" 97 OpMemberDecorate %32 0 Offset 0 98 OpDecorate %32 Block 99 OpDecorate %34 DescriptorSet 0 100 OpDecorate %34 Binding 0 101 OpDecorate %46 Location 0 102 %2 = OpTypeVoid 103 %3 = OpTypeFunction %2 104 %11 = OpTypeBool 105 %12 = OpConstantTrue %11 106 %18 = OpConstantFalse %11 107 %20 = OpTypeFloat 32 108 %21 = OpTypeInt 32 0 109 %22 = OpConstant %21 1 110 %23 = OpTypeArray %20 %22 111 %24 = OpTypePointer Function %23 112 %26 = OpTypeInt 32 1 113 %27 = OpConstant %26 0 114 %28 = OpTypePointer Function %20 115 %31 = OpTypeVector %20 2 116 %32 = OpTypeStruct %31 117 %33 = OpTypePointer Uniform %32 118 %34 = OpVariable %33 Uniform 119 %35 = OpConstant %21 0 120 %36 = OpTypePointer Uniform %20 121 %44 = OpTypeVector %20 4 122 %45 = OpTypePointer Output %44 123 %46 = OpVariable %45 Output 124 %47 = OpConstant %20 1 125 %48 = OpConstant %20 0 126 %49 = OpConstantComposite %44 %47 %48 %48 %47 127 %54 = OpUndef %20 128 %4 = OpFunction %2 None %3 129 %5 = OpLabel 130 %51 = OpVariable %28 Function 131 OpBranch %6 132 %6 = OpLabel 133 %53 = OpPhi %20 %54 %5 %52 %43 134 OpLoopMerge %8 %43 None 135 OpBranch %13 136 %13 = OpLabel 137 %52 = OpPhi %20 %53 %6 %54 %16 138 %37 = OpAccessChain %36 %34 %27 %35 139 %38 = OpLoad %20 %37 140 %39 = OpAccessChain %36 %34 %27 %22 141 %40 = OpLoad %20 %39 142 %41 = OpFOrdLessThan %11 %38 %40 143 OpSelectionMerge %55 None 144 OpBranchConditional %41 %42 %43 145 %16 = OpLabel 146 OpBranch %13 147 %42 = OpLabel 148 OpStore %46 %49 149 OpReturn 150 %55 = OpLabel 151 OpBranch %43 152 %43 = OpLabel 153 OpBranch %6 154 %8 = OpLabel 155 OpUnreachable 156 OpFunctionEnd 157END 158 159# uniforms for variant 160 161# injectionSwitch 162BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA 163 0.0 1.0 164END 165 166BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 167 168PIPELINE graphics variant_pipeline 169 ATTACH variant_vertex_shader 170 ATTACH variant_fragment_shader 171 FRAMEBUFFER_SIZE 256 256 172 BIND BUFFER variant_framebuffer AS color LOCATION 0 173 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0 174END 175CLEAR_COLOR variant_pipeline 0 0 0 255 176 177CLEAR variant_pipeline 178RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 179 180EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 181