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 do-while loop in conditional nest 20 21# The test passes because the fragment shader writes red, and the 22# do-while loop is not dynamically reachable. 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# if(true) 37# { 38# if(gl_FragCoord.x < 0.0) 39# { 40# do 41# { 42# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); 43# } 44# while(gl_FragCoord.x < 0.0); 45# } 46# } 47# } 48 49SHADER vertex variant_vertex_shader PASSTHROUGH 50 51SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 52; SPIR-V 53; Version: 1.0 54; Generator: Khronos Glslang Reference Front End; 7 55; Bound: 34 56; Schema: 0 57 OpCapability Shader 58 %1 = OpExtInstImport "GLSL.std.450" 59 OpMemoryModel Logical GLSL450 60 OpEntryPoint Fragment %4 "main" %9 %18 61 OpExecutionMode %4 OriginUpperLeft 62 OpSource ESSL 310 63 OpName %4 "main" 64 OpName %9 "_GLF_color" 65 OpName %18 "gl_FragCoord" 66 OpDecorate %9 Location 0 67 OpDecorate %18 BuiltIn FragCoord 68 %2 = OpTypeVoid 69 %3 = OpTypeFunction %2 70 %6 = OpTypeFloat 32 71 %7 = OpTypeVector %6 4 72 %8 = OpTypePointer Output %7 73 %9 = OpVariable %8 Output 74 %10 = OpConstant %6 1 75 %11 = OpConstant %6 0 76 %12 = OpConstantComposite %7 %10 %11 %11 %10 77 %13 = OpTypeBool 78 %14 = OpConstantTrue %13 79 %17 = OpTypePointer Input %7 80 %18 = OpVariable %17 Input 81 %19 = OpTypeInt 32 0 82 %20 = OpConstant %19 0 83 %21 = OpTypePointer Input %6 84 %4 = OpFunction %2 None %3 85 %5 = OpLabel 86 OpStore %9 %12 87 OpSelectionMerge %16 None 88 OpBranchConditional %14 %15 %16 89 %15 = OpLabel 90 %22 = OpAccessChain %21 %18 %20 91 %23 = OpLoad %6 %22 92 %24 = OpFOrdLessThan %13 %23 %11 93 OpSelectionMerge %26 None 94 OpBranchConditional %24 %25 %26 95 %25 = OpLabel 96 OpBranch %27 97 %27 = OpLabel 98 OpLoopMerge %29 %30 None 99 OpBranch %28 100 %28 = OpLabel 101 OpStore %9 %12 102 OpBranch %30 103 %30 = OpLabel 104 %31 = OpAccessChain %21 %18 %20 105 %32 = OpLoad %6 %31 106 %33 = OpFOrdLessThan %13 %32 %11 107 OpBranchConditional %33 %27 %29 108 %29 = OpLabel 109 OpBranch %26 110 %26 = OpLabel 111 OpBranch %16 112 %16 = OpLabel 113 OpReturn 114 OpFunctionEnd 115END 116 117BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 118 119PIPELINE graphics variant_pipeline 120 ATTACH variant_vertex_shader 121 ATTACH variant_fragment_shader 122 FRAMEBUFFER_SIZE 256 256 123 BIND BUFFER variant_framebuffer AS color LOCATION 0 124END 125CLEAR_COLOR variant_pipeline 0 0 0 255 126 127CLEAR variant_pipeline 128RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 129 130EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 131