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