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 the GraphicsFuzz project. 19 20# Short description: A fragment shader that covers specific constant fold and selection dag code paths 21 22# The test passes because the 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# #define _float_1_0 _GLF_uniform_float_values[0] 29# #define _float_0_0 _GLF_uniform_float_values[1] 30# 31# precision highp float; 32# 33# // Contents of _GLF_uniform_float_values: [1.0, 0.0] 34# layout(set = 0, binding = 0) uniform buf0 35# { 36# float _GLF_uniform_float_values[2]; 37# }; 38# 39# layout(location = 0) out vec4 _GLF_color; 40# 41# void main() 42# { 43# float a = -1.0; 44# float b = 1.7; 45# 46# // c becomes undefined since a < 0. This results in an undefined value, but not in undefined behavior. 47# float c = pow(a, b); 48# 49# _GLF_color = vec4(c); 50# 51# if (a == -1.0 && b == 1.7) 52# { 53# _GLF_color = vec4(_float_1_0, _float_0_0, _float_0_0, _float_1_0); 54# } 55# else 56# { 57# _GLF_color = vec4(_float_1_0); 58# } 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; 10 64; Bound: 52 65; Schema: 0 66 OpCapability Shader 67 %1 = OpExtInstImport "GLSL.std.450" 68 OpMemoryModel Logical GLSL450 69 OpEntryPoint Fragment %4 "main" %18 70 OpExecutionMode %4 OriginUpperLeft 71 OpSource ESSL 310 72 OpName %4 "main" 73 OpName %8 "a" 74 OpName %10 "b" 75 OpName %12 "c" 76 OpName %18 "_GLF_color" 77 OpName %32 "buf0" 78 OpMemberName %32 0 "_GLF_uniform_float_values" 79 OpName %34 "" 80 OpDecorate %18 Location 0 81 OpDecorate %31 ArrayStride 16 82 OpMemberDecorate %32 0 Offset 0 83 OpDecorate %32 Block 84 OpDecorate %34 DescriptorSet 0 85 OpDecorate %34 Binding 0 86 %2 = OpTypeVoid 87 %3 = OpTypeFunction %2 88 %6 = OpTypeFloat 32 89 %7 = OpTypePointer Function %6 90 %9 = OpConstant %6 -1 91 %11 = OpConstant %6 1.70000005 92 %16 = OpTypeVector %6 4 93 %17 = OpTypePointer Output %16 94 %18 = OpVariable %17 Output 95 %22 = OpTypeBool 96 %29 = OpTypeInt 32 0 97 %30 = OpConstant %29 2 98 %31 = OpTypeArray %6 %30 99 %32 = OpTypeStruct %31 100 %33 = OpTypePointer Uniform %32 101 %34 = OpVariable %33 Uniform 102 %35 = OpTypeInt 32 1 103 %36 = OpConstant %35 0 104 %37 = OpTypePointer Uniform %6 105 %40 = OpConstant %35 1 106 %4 = OpFunction %2 None %3 107 %5 = OpLabel 108 %8 = OpVariable %7 Function 109 %10 = OpVariable %7 Function 110 %12 = OpVariable %7 Function 111 OpStore %8 %9 112 OpStore %10 %11 113 %13 = OpLoad %6 %8 114 %14 = OpLoad %6 %10 115 %15 = OpExtInst %6 %1 Pow %13 %14 116 OpStore %12 %15 117 %19 = OpLoad %6 %12 118 %20 = OpCompositeConstruct %16 %19 %19 %19 %19 119 OpStore %18 %20 120 %21 = OpLoad %6 %8 121 %23 = OpFOrdEqual %22 %21 %9 122 %24 = OpLoad %6 %10 123 %25 = OpFOrdEqual %22 %24 %11 124 %26 = OpLogicalAnd %22 %23 %25 125 OpSelectionMerge %28 None 126 OpBranchConditional %26 %27 %48 127 %27 = OpLabel 128 %38 = OpAccessChain %37 %34 %36 %36 129 %39 = OpLoad %6 %38 130 %41 = OpAccessChain %37 %34 %36 %40 131 %42 = OpLoad %6 %41 132 %43 = OpAccessChain %37 %34 %36 %40 133 %44 = OpLoad %6 %43 134 %45 = OpAccessChain %37 %34 %36 %36 135 %46 = OpLoad %6 %45 136 %47 = OpCompositeConstruct %16 %39 %42 %44 %46 137 OpStore %18 %47 138 OpBranch %28 139 %48 = OpLabel 140 %49 = OpAccessChain %37 %34 %36 %36 141 %50 = OpLoad %6 %49 142 %51 = OpCompositeConstruct %16 %50 %50 %50 %50 143 OpStore %18 %51 144 OpBranch %28 145 %28 = OpLabel 146 OpReturn 147 OpFunctionEnd 148END 149 150# uniforms for variant 151 152# _GLF_uniform_float_values 153BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA 154 1.0 0.0 155END 156 157BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 158 159PIPELINE graphics variant_pipeline 160 ATTACH variant_vertex_shader 161 ATTACH variant_fragment_shader 162 FRAMEBUFFER_SIZE 256 256 163 BIND BUFFER variant_framebuffer AS color LOCATION 0 164 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0 165END 166CLEAR_COLOR variant_pipeline 0 0 0 255 167 168CLEAR variant_pipeline 169RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 170 171EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 172