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 that writes to color in a loop 20 21# Checks that the top-left pixel is red. 22# Passes because main ends by writing red to _GLF_color. 23 24# Optimized using spirv-opt with the following arguments: 25# '-O' 26# spirv-opt commit hash: a2ef7be242bcacaa9127a3ce011602ec54b2c9ed 27 28# Derived from the following GLSL. 29 30# Fragment shader GLSL: 31# #version 310 es 32# 33# precision highp float; 34# 35# struct S { 36# int f0; 37# mat4x3 f1; 38# }; 39# 40# layout(location = 0) out vec4 _GLF_color; 41# 42# void g() 43# { 44# S s = S(0, mat4x3(1.0)); 45# for( 46# int l = 0; 47# l < (gl_FragCoord.x == 0.0 ? 1 : 2); 48# l ++ 49# ) 50# { 51# _GLF_color = vec4(1.0); 52# s.f0++; 53# } 54# if(s.f0 < 1000) 55# { 56# return; 57# } 58# } 59# void main() 60# { 61# g(); 62# for( 63# int i = 0; 64# i < (gl_FragCoord.x == 0.0 ? 1 : 2); 65# i++ 66# ) 67# { 68# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); 69# } 70# } 71 72SHADER vertex variant_vertex_shader PASSTHROUGH 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; 7 78; Bound: 120 79; Schema: 0 80 OpCapability Shader 81 %1 = OpExtInstImport "GLSL.std.450" 82 OpMemoryModel Logical GLSL450 83 OpEntryPoint Fragment %4 "main" %34 %47 84 OpExecutionMode %4 OriginUpperLeft 85 OpSource ESSL 310 86 OpName %4 "main" 87 OpName %12 "S" 88 OpMemberName %12 0 "f0" 89 OpMemberName %12 1 "f1" 90 OpName %34 "gl_FragCoord" 91 OpName %47 "_GLF_color" 92 OpMemberDecorate %12 0 RelaxedPrecision 93 OpDecorate %34 BuiltIn FragCoord 94 OpDecorate %47 Location 0 95 OpDecorate %76 RelaxedPrecision 96 OpDecorate %104 RelaxedPrecision 97 OpDecorate %105 RelaxedPrecision 98 OpDecorate %107 RelaxedPrecision 99 OpDecorate %109 RelaxedPrecision 100 OpDecorate %117 RelaxedPrecision 101 OpDecorate %119 RelaxedPrecision 102 %2 = OpTypeVoid 103 %3 = OpTypeFunction %2 104 %8 = OpTypeInt 32 1 105 %9 = OpTypeFloat 32 106 %10 = OpTypeVector %9 3 107 %11 = OpTypeMatrix %10 4 108 %12 = OpTypeStruct %8 %11 109 %15 = OpConstant %8 0 110 %16 = OpConstant %9 1 111 %17 = OpConstant %9 0 112 %18 = OpConstantComposite %10 %16 %17 %17 113 %19 = OpConstantComposite %10 %17 %16 %17 114 %20 = OpConstantComposite %10 %17 %17 %16 115 %21 = OpConstantComposite %10 %17 %17 %17 116 %22 = OpConstantComposite %11 %18 %19 %20 %21 117 %23 = OpConstantComposite %12 %15 %22 118 %32 = OpTypeVector %9 4 119 %33 = OpTypePointer Input %32 120 %34 = OpVariable %33 Input 121 %35 = OpTypeInt 32 0 122 %36 = OpConstant %35 0 123 %37 = OpTypePointer Input %9 124 %40 = OpTypeBool 125 %42 = OpConstant %8 1 126 %43 = OpConstant %8 2 127 %46 = OpTypePointer Output %32 128 %47 = OpVariable %46 Output 129 %48 = OpConstantComposite %32 %16 %16 %16 %16 130 %56 = OpConstant %8 1000 131 %74 = OpConstantComposite %32 %16 %17 %17 %16 132 %4 = OpFunction %2 None %3 133 %5 = OpLabel 134 OpBranch %88 135 %88 = OpLabel 136 OpLoopMerge %89 %90 None 137 OpBranch %92 138 %92 = OpLabel 139 %118 = OpPhi %12 %23 %88 %115 %102 140 %117 = OpPhi %8 %15 %88 %107 %102 141 %97 = OpAccessChain %37 %34 %36 142 %98 = OpLoad %9 %97 143 %99 = OpFOrdEqual %40 %98 %17 144 %100 = OpSelect %8 %99 %42 %43 145 %101 = OpSLessThan %40 %117 %100 146 OpLoopMerge %93 %102 None 147 OpBranchConditional %101 %102 %93 148 %102 = OpLabel 149 OpStore %47 %48 150 %104 = OpCompositeExtract %8 %118 0 151 %105 = OpIAdd %8 %104 %42 152 %115 = OpCompositeInsert %12 %105 %118 0 153 %107 = OpIAdd %8 %117 %42 154 OpBranch %92 155 %93 = OpLabel 156 %109 = OpCompositeExtract %8 %118 0 157 %110 = OpSLessThan %40 %109 %56 158 OpSelectionMerge %111 None 159 OpBranchConditional %110 %112 %111 160 %112 = OpLabel 161 OpBranch %89 162 %111 = OpLabel 163 OpBranch %89 164 %90 = OpLabel 165 OpBranch %88 166 %89 = OpLabel 167 OpBranch %63 168 %63 = OpLabel 169 %119 = OpPhi %8 %15 %89 %76 %64 170 %73 = OpSLessThan %40 %119 %100 171 OpLoopMerge %65 %64 None 172 OpBranchConditional %73 %64 %65 173 %64 = OpLabel 174 OpStore %47 %74 175 %76 = OpIAdd %8 %119 %42 176 OpBranch %63 177 %65 = OpLabel 178 OpReturn 179 OpFunctionEnd 180END 181 182BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 183 184PIPELINE graphics variant_pipeline 185 ATTACH variant_vertex_shader 186 ATTACH variant_fragment_shader 187 FRAMEBUFFER_SIZE 256 256 188 BIND BUFFER variant_framebuffer AS color LOCATION 0 189END 190CLEAR_COLOR variant_pipeline 0 0 0 255 191 192CLEAR variant_pipeline 193RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 194 195EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 196