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: Fragment shader that writes red despite unreachable loops 21 22# The test passes because red is written, and the loops inside the if (one of 23# which would be infinite) are dynamically unreachable due to the runtime content 24# of 'injected'. 25 26SHADER vertex variant_vertex_shader PASSTHROUGH 27 28# variant_fragment_shader is derived from the following GLSL: 29# #version 310 es 30# precision highp float; 31# 32# layout(location = 0) out vec4 _GLF_color; 33# 34# layout(set = 0, binding = 0) uniform buf0 { 35# vec2 injected; 36# }; 37# 38# void main() 39# { 40# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); 41# if (injected.x > injected.y) { 42# do 43# { 44# } 45# while(false); 46# { 47# for( 48# int m = 1; 49# true; 50# 1 51# ) 52# { 53# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); 54# } 55# } 56# } 57# } 58SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 59; SPIR-V 60; Version: 1.0 61; Generator: Khronos Glslang Reference Front End; 7 62; Bound: 45 63; Schema: 0 64 OpCapability Shader 65 %1 = OpExtInstImport "GLSL.std.450" 66 OpMemoryModel Logical GLSL450 67 OpEntryPoint Fragment %4 "main" %9 68 OpExecutionMode %4 OriginUpperLeft 69 OpSource ESSL 310 70 OpName %4 "main" 71 OpName %9 "_GLF_color" 72 OpName %14 "buf0" 73 OpMemberName %14 0 "injected" 74 OpName %16 "" 75 OpName %37 "m" 76 OpDecorate %9 Location 0 77 OpMemberDecorate %14 0 Offset 0 78 OpDecorate %14 Block 79 OpDecorate %16 DescriptorSet 0 80 OpDecorate %16 Binding 0 81 OpDecorate %37 RelaxedPrecision 82 %2 = OpTypeVoid 83 %3 = OpTypeFunction %2 84 %6 = OpTypeFloat 32 85 %7 = OpTypeVector %6 4 86 %8 = OpTypePointer Output %7 87 %9 = OpVariable %8 Output 88 %10 = OpConstant %6 1 89 %11 = OpConstant %6 0 90 %12 = OpConstantComposite %7 %10 %11 %11 %10 91 %13 = OpTypeVector %6 2 92 %14 = OpTypeStruct %13 93 %15 = OpTypePointer Uniform %14 94 %16 = OpVariable %15 Uniform 95 %17 = OpTypeInt 32 1 96 %18 = OpConstant %17 0 97 %19 = OpTypeInt 32 0 98 %20 = OpConstant %19 0 99 %21 = OpTypePointer Uniform %6 100 %24 = OpConstant %19 1 101 %27 = OpTypeBool 102 %35 = OpConstantFalse %27 103 %36 = OpTypePointer Function %17 104 %38 = OpConstant %17 1 105 %44 = OpConstantTrue %27 106 %4 = OpFunction %2 None %3 107 %5 = OpLabel 108 %37 = OpVariable %36 Function 109 OpStore %9 %12 110 %22 = OpAccessChain %21 %16 %18 %20 111 %23 = OpLoad %6 %22 112 %25 = OpAccessChain %21 %16 %18 %24 113 %26 = OpLoad %6 %25 114 %28 = OpFOrdGreaterThan %27 %23 %26 115 OpSelectionMerge %30 None 116 OpBranchConditional %28 %29 %30 117 %29 = OpLabel 118 OpBranch %31 119 %31 = OpLabel 120 OpLoopMerge %33 %34 None 121 OpBranch %32 122 %32 = OpLabel 123 OpBranch %34 124 %34 = OpLabel 125 OpBranchConditional %35 %31 %33 126 %33 = OpLabel 127 OpStore %37 %38 128 OpBranch %39 129 %39 = OpLabel 130 OpLoopMerge %41 %42 None 131 OpBranch %43 132 %43 = OpLabel 133 OpBranchConditional %44 %40 %41 134 %40 = OpLabel 135 OpStore %9 %12 136 OpBranch %42 137 %42 = OpLabel 138 OpBranch %39 139 %41 = OpLabel 140 OpBranch %30 141 %30 = OpLabel 142 OpReturn 143 OpFunctionEnd 144END 145 146# uniforms for variant 147 148# resolution 149BUFFER variant_resolution DATA_TYPE vec2<float> DATA 150 0.0 1.0 151END 152 153BUFFER framebuffer FORMAT B8G8R8A8_UNORM 154 155PIPELINE graphics gfz_pipeline 156 ATTACH variant_vertex_shader 157 ATTACH variant_fragment_shader 158 FRAMEBUFFER_SIZE 256 256 159 BIND BUFFER framebuffer AS color LOCATION 0 160 BIND BUFFER variant_resolution AS uniform DESCRIPTOR_SET 0 BINDING 0 161END 162CLEAR_COLOR gfz_pipeline 0 0 0 255 163 164CLEAR gfz_pipeline 165RUN gfz_pipeline DRAW_RECT POS 0 0 SIZE 256 256 166EXPECT framebuffer IDX 0 0 SIZE 256 256 EQ_RGB 255 0 0