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