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# A test for a bug found by GraphicsFuzz. 18 19# Short description: A fragment shader with unreachable loops in a switch 20 21# The test passes because the fragment shader writes a red pixel, and then 22# terminates without further output manipulation. 23 24# Derived from the following GLSL. 25 26# Fragment shader GLSL: 27# #version 310 es 28# 29# precision highp float; 30# 31# layout(location = 0) out vec4 _GLF_color; 32# 33# void main() 34# { 35# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); 36# float data[1]; 37# for(int i = 0; i < 1; i++) { 38# if(data[i] < data[0]) { 39# if(false) { 40# if(float(i) >= 1.0) { } 41# } 42# switch(0) { 43# case 1: 44# for(; 1 > 0;) { } 45# for(;;) { } 46# case 0: 47# data[0] = 2.0; 48# break; 49# } 50# } 51# } 52# } 53 54SHADER vertex variant_vertex_shader PASSTHROUGH 55 56SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 57; SPIR-V 58; Version: 1.0 59; Generator: Khronos Glslang Reference Front End; 7 60; Bound: 67 61; Schema: 0 62 OpCapability Shader 63 %1 = OpExtInstImport "GLSL.std.450" 64 OpMemoryModel Logical GLSL450 65 OpEntryPoint Fragment %4 "main" %9 66 OpExecutionMode %4 OriginUpperLeft 67 OpSource ESSL 310 68 OpName %4 "main" 69 OpName %9 "_GLF_color" 70 OpName %15 "i" 71 OpName %30 "data" 72 OpDecorate %9 Location 0 73 OpDecorate %15 RelaxedPrecision 74 OpDecorate %22 RelaxedPrecision 75 OpDecorate %31 RelaxedPrecision 76 OpDecorate %43 RelaxedPrecision 77 OpDecorate %65 RelaxedPrecision 78 OpDecorate %66 RelaxedPrecision 79 %2 = OpTypeVoid 80 %3 = OpTypeFunction %2 81 %6 = OpTypeFloat 32 82 %7 = OpTypeVector %6 4 83 %8 = OpTypePointer Output %7 84 %9 = OpVariable %8 Output 85 %10 = OpConstant %6 1 86 %11 = OpConstant %6 0 87 %12 = OpConstantComposite %7 %10 %11 %11 %10 88 %13 = OpTypeInt 32 1 89 %14 = OpTypePointer Function %13 90 %16 = OpConstant %13 0 91 %23 = OpConstant %13 1 92 %24 = OpTypeBool 93 %26 = OpTypeInt 32 0 94 %27 = OpConstant %26 1 95 %28 = OpTypeArray %6 %27 96 %29 = OpTypePointer Function %28 97 %32 = OpTypePointer Function %6 98 %40 = OpConstantFalse %24 99 %56 = OpConstantTrue %24 100 %61 = OpConstant %6 2 101 %4 = OpFunction %2 None %3 102 %5 = OpLabel 103 %15 = OpVariable %14 Function 104 %30 = OpVariable %29 Function 105 OpStore %9 %12 106 OpStore %15 %16 107 OpBranch %17 108 %17 = OpLabel 109 OpLoopMerge %19 %20 None 110 OpBranch %21 111 %21 = OpLabel 112 %22 = OpLoad %13 %15 113 %25 = OpSLessThan %24 %22 %23 114 OpBranchConditional %25 %18 %19 115 %18 = OpLabel 116 %31 = OpLoad %13 %15 117 %33 = OpAccessChain %32 %30 %31 118 %34 = OpLoad %6 %33 119 %35 = OpAccessChain %32 %30 %16 120 %36 = OpLoad %6 %35 121 %37 = OpFOrdLessThan %24 %34 %36 122 OpSelectionMerge %39 None 123 OpBranchConditional %37 %38 %39 124 %38 = OpLabel 125 OpSelectionMerge %42 None 126 OpBranchConditional %40 %41 %42 127 %41 = OpLabel 128 %43 = OpLoad %13 %15 129 %44 = OpConvertSToF %6 %43 130 %45 = OpFOrdGreaterThanEqual %24 %44 %10 131 OpSelectionMerge %47 None 132 OpBranchConditional %45 %46 %47 133 %46 = OpLabel 134 OpBranch %47 135 %47 = OpLabel 136 OpBranch %42 137 %42 = OpLabel 138 OpSelectionMerge %50 None 139 OpSwitch %16 %50 1 %48 0 %49 140 %48 = OpLabel 141 OpBranch %51 142 %51 = OpLabel 143 OpLoopMerge %53 %54 None 144 OpBranch %55 145 %55 = OpLabel 146 OpBranchConditional %56 %52 %53 147 %52 = OpLabel 148 OpBranch %54 149 %54 = OpLabel 150 OpBranch %51 151 %53 = OpLabel 152 OpBranch %57 153 %57 = OpLabel 154 OpLoopMerge %59 %60 None 155 OpBranch %58 156 %58 = OpLabel 157 OpBranch %60 158 %60 = OpLabel 159 OpBranch %57 160 %59 = OpLabel 161 OpBranch %49 162 %49 = OpLabel 163 %62 = OpAccessChain %32 %30 %16 164 OpStore %62 %61 165 OpBranch %50 166 %50 = OpLabel 167 OpBranch %39 168 %39 = OpLabel 169 OpBranch %20 170 %20 = OpLabel 171 %65 = OpLoad %13 %15 172 %66 = OpIAdd %13 %65 %23 173 OpStore %15 %66 174 OpBranch %17 175 %19 = OpLabel 176 OpReturn 177 OpFunctionEnd 178END 179 180BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 181 182PIPELINE graphics variant_pipeline 183 ATTACH variant_vertex_shader 184 ATTACH variant_fragment_shader 185 FRAMEBUFFER_SIZE 256 256 186 BIND BUFFER variant_framebuffer AS color LOCATION 0 187END 188CLEAR_COLOR variant_pipeline 0 0 0 255 189 190CLEAR variant_pipeline 191RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 192 193EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 194