1#!amber 2 3# Copyright 2020 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 coverage-gap found by GraphicsFuzz. 19 20# Short description: A fragment shader that covers a specific code simplification path. 21 22# The test passes because shader always writes red. 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# precision highp int; 30# 31# layout(location = 0) out vec4 _GLF_color; 32# layout(set = 0, binding = 0) uniform buf0 33# { 34# int one; 35# }; 36# layout(set = 0, binding = 1) uniform buf1 37# { 38# int zero; 39# }; 40# 41# void main() 42# { 43# _GLF_color = vec4(0); 44# 45# for(int i = 0; i < one; i++) 46# { 47# do 48# { 49# // Always true. 50# if(one == 1) 51# _GLF_color = vec4(1, 0, 0, 1); 52# } 53# while(false); 54# } 55# 56# vec4 v; 57# v.y = float(zero); 58# _GLF_color.y = v.y; 59# } 60SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 61; SPIR-V 62; Version: 1.0 63; Generator: Khronos Glslang Reference Front End; 8 64; Bound: 61 65; Schema: 0 66 OpCapability Shader 67 %1 = OpExtInstImport "GLSL.std.450" 68 OpMemoryModel Logical GLSL450 69 OpEntryPoint Fragment %4 "main" %9 70 OpExecutionMode %4 OriginUpperLeft 71 OpSource ESSL 310 72 OpName %4 "main" 73 OpName %9 "_GLF_color" 74 OpName %14 "i" 75 OpName %22 "buf0" 76 OpMemberName %22 0 "one" 77 OpName %24 "" 78 OpName %46 "v" 79 OpName %47 "buf1" 80 OpMemberName %47 0 "zero" 81 OpName %49 "" 82 OpDecorate %9 Location 0 83 OpMemberDecorate %22 0 Offset 0 84 OpDecorate %22 Block 85 OpDecorate %24 DescriptorSet 0 86 OpDecorate %24 Binding 0 87 OpMemberDecorate %47 0 Offset 0 88 OpDecorate %47 Block 89 OpDecorate %49 DescriptorSet 0 90 OpDecorate %49 Binding 1 91 %2 = OpTypeVoid 92 %3 = OpTypeFunction %2 93 %6 = OpTypeFloat 32 94 %7 = OpTypeVector %6 4 95 %8 = OpTypePointer Output %7 96 %9 = OpVariable %8 Output 97 %10 = OpConstant %6 0 98 %11 = OpConstantComposite %7 %10 %10 %10 %10 99 %12 = OpTypeInt 32 1 100 %13 = OpTypePointer Function %12 101 %15 = OpConstant %12 0 102 %22 = OpTypeStruct %12 103 %23 = OpTypePointer Uniform %22 104 %24 = OpVariable %23 Uniform 105 %25 = OpTypePointer Uniform %12 106 %28 = OpTypeBool 107 %36 = OpConstant %12 1 108 %40 = OpConstant %6 1 109 %41 = OpConstantComposite %7 %40 %10 %10 %40 110 %42 = OpConstantFalse %28 111 %45 = OpTypePointer Function %7 112 %47 = OpTypeStruct %12 113 %48 = OpTypePointer Uniform %47 114 %49 = OpVariable %48 Uniform 115 %53 = OpTypeInt 32 0 116 %54 = OpConstant %53 1 117 %55 = OpTypePointer Function %6 118 %59 = OpTypePointer Output %6 119 %4 = OpFunction %2 None %3 120 %5 = OpLabel 121 %14 = OpVariable %13 Function 122 %46 = OpVariable %45 Function 123 OpStore %9 %11 124 OpStore %14 %15 125 OpBranch %16 126 %16 = OpLabel 127 OpLoopMerge %18 %19 None 128 OpBranch %20 129 %20 = OpLabel 130 %21 = OpLoad %12 %14 131 %26 = OpAccessChain %25 %24 %15 132 %27 = OpLoad %12 %26 133 %29 = OpSLessThan %28 %21 %27 134 OpBranchConditional %29 %17 %18 135 %17 = OpLabel 136 OpBranch %30 137 %30 = OpLabel 138 OpLoopMerge %32 %33 None 139 OpBranch %31 140 %31 = OpLabel 141 %34 = OpAccessChain %25 %24 %15 142 %35 = OpLoad %12 %34 143 %37 = OpIEqual %28 %35 %36 144 OpSelectionMerge %39 None 145 OpBranchConditional %37 %38 %39 146 %38 = OpLabel 147 OpStore %9 %41 148 OpBranch %39 149 %39 = OpLabel 150 OpBranch %33 151 %33 = OpLabel 152 OpBranchConditional %42 %30 %32 153 %32 = OpLabel 154 OpBranch %19 155 %19 = OpLabel 156 %43 = OpLoad %12 %14 157 %44 = OpIAdd %12 %43 %36 158 OpStore %14 %44 159 OpBranch %16 160 %18 = OpLabel 161 %50 = OpAccessChain %25 %49 %15 162 %51 = OpLoad %12 %50 163 %52 = OpConvertSToF %6 %51 164 %56 = OpAccessChain %55 %46 %54 165 OpStore %56 %52 166 %57 = OpAccessChain %55 %46 %54 167 %58 = OpLoad %6 %57 168 %60 = OpAccessChain %59 %9 %54 169 OpStore %60 %58 170 OpReturn 171 OpFunctionEnd 172END 173 174# uniforms for variant 175 176# one 177BUFFER variant_one DATA_TYPE int32 DATA 178 1 179END 180# zero 181BUFFER variant_zero DATA_TYPE int32 DATA 182 0 183END 184 185BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 186 187PIPELINE graphics variant_pipeline 188 ATTACH variant_vertex_shader 189 ATTACH variant_fragment_shader 190 FRAMEBUFFER_SIZE 256 256 191 BIND BUFFER variant_framebuffer AS color LOCATION 0 192 BIND BUFFER variant_one AS uniform DESCRIPTOR_SET 0 BINDING 0 193 BIND BUFFER variant_zero AS uniform DESCRIPTOR_SET 0 BINDING 1 194END 195CLEAR_COLOR variant_pipeline 0 0 0 255 196 197CLEAR variant_pipeline 198RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 199 200EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 201