1#!amber 2 3# Copyright 2021 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 BRW 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 320 es 28# #define _int_1 _GLF_uniform_int_values[0] 29# #define _int_0 _GLF_uniform_int_values[1] 30# 31# precision highp int; 32# precision highp float; 33# 34# // Contents of _GLF_uniform_int_values: [1, 0] 35# layout(set = 0, binding = 0) uniform buf0 36# { 37# int _GLF_uniform_int_values[2]; 38# }; 39# 40# layout(location = 0) out vec4 _GLF_color; 41# 42# void main() 43# { 44# // Always selects ~0. 45# int a = int(gl_FragCoord.x) < _int_0 ? 0 : ~0; 46# 47# for (int i = 0; i < 5; i ++) 48# { 49# a /= 2; 50# } 51# 52# // Always true. 53# if (a == ~0 / 32) 54# { 55# _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1); 56# } 57# else 58# { 59# _GLF_color = vec4(_int_0); 60# } 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; 10 66; Bound: 71 67; Schema: 0 68 OpCapability Shader 69 %1 = OpExtInstImport "GLSL.std.450" 70 OpMemoryModel Logical GLSL450 71 OpEntryPoint Fragment %4 "main" %12 %52 72 OpExecutionMode %4 OriginUpperLeft 73 OpSource ESSL 320 74 OpName %4 "main" 75 OpName %8 "a" 76 OpName %12 "gl_FragCoord" 77 OpName %21 "buf0" 78 OpMemberName %21 0 "_GLF_uniform_int_values" 79 OpName %23 "" 80 OpName %33 "i" 81 OpName %52 "_GLF_color" 82 OpDecorate %12 BuiltIn FragCoord 83 OpDecorate %20 ArrayStride 16 84 OpMemberDecorate %21 0 Offset 0 85 OpDecorate %21 Block 86 OpDecorate %23 DescriptorSet 0 87 OpDecorate %23 Binding 0 88 OpDecorate %52 Location 0 89 %2 = OpTypeVoid 90 %3 = OpTypeFunction %2 91 %6 = OpTypeInt 32 1 92 %7 = OpTypePointer Function %6 93 %9 = OpTypeFloat 32 94 %10 = OpTypeVector %9 4 95 %11 = OpTypePointer Input %10 96 %12 = OpVariable %11 Input 97 %13 = OpTypeInt 32 0 98 %14 = OpConstant %13 0 99 %15 = OpTypePointer Input %9 100 %19 = OpConstant %13 2 101 %20 = OpTypeArray %6 %19 102 %21 = OpTypeStruct %20 103 %22 = OpTypePointer Uniform %21 104 %23 = OpVariable %22 Uniform 105 %24 = OpConstant %6 0 106 %25 = OpConstant %6 1 107 %26 = OpTypePointer Uniform %6 108 %29 = OpTypeBool 109 %31 = OpConstant %6 -1 110 %40 = OpConstant %6 5 111 %42 = OpConstant %6 2 112 %51 = OpTypePointer Output %10 113 %52 = OpVariable %51 Output 114 %4 = OpFunction %2 None %3 115 %5 = OpLabel 116 %8 = OpVariable %7 Function 117 %33 = OpVariable %7 Function 118 %16 = OpAccessChain %15 %12 %14 119 %17 = OpLoad %9 %16 120 %18 = OpConvertFToS %6 %17 121 %27 = OpAccessChain %26 %23 %24 %25 122 %28 = OpLoad %6 %27 123 %30 = OpSLessThan %29 %18 %28 124 %32 = OpSelect %6 %30 %24 %31 125 OpStore %8 %32 126 OpStore %33 %24 127 OpBranch %34 128 %34 = OpLabel 129 OpLoopMerge %36 %37 None 130 OpBranch %38 131 %38 = OpLabel 132 %39 = OpLoad %6 %33 133 %41 = OpSLessThan %29 %39 %40 134 OpBranchConditional %41 %35 %36 135 %35 = OpLabel 136 %43 = OpLoad %6 %8 137 %44 = OpSDiv %6 %43 %42 138 OpStore %8 %44 139 OpBranch %37 140 %37 = OpLabel 141 %45 = OpLoad %6 %33 142 %46 = OpIAdd %6 %45 %25 143 OpStore %33 %46 144 OpBranch %34 145 %36 = OpLabel 146 %47 = OpLoad %6 %8 147 %48 = OpIEqual %29 %47 %24 148 OpSelectionMerge %50 None 149 OpBranchConditional %48 %49 %66 150 %49 = OpLabel 151 %53 = OpAccessChain %26 %23 %24 %24 152 %54 = OpLoad %6 %53 153 %55 = OpConvertSToF %9 %54 154 %56 = OpAccessChain %26 %23 %24 %25 155 %57 = OpLoad %6 %56 156 %58 = OpConvertSToF %9 %57 157 %59 = OpAccessChain %26 %23 %24 %25 158 %60 = OpLoad %6 %59 159 %61 = OpConvertSToF %9 %60 160 %62 = OpAccessChain %26 %23 %24 %24 161 %63 = OpLoad %6 %62 162 %64 = OpConvertSToF %9 %63 163 %65 = OpCompositeConstruct %10 %55 %58 %61 %64 164 OpStore %52 %65 165 OpBranch %50 166 %66 = OpLabel 167 %67 = OpAccessChain %26 %23 %24 %25 168 %68 = OpLoad %6 %67 169 %69 = OpConvertSToF %9 %68 170 %70 = OpCompositeConstruct %10 %69 %69 %69 %69 171 OpStore %52 %70 172 OpBranch %50 173 %50 = OpLabel 174 OpReturn 175 OpFunctionEnd 176END 177 178# uniforms for variant 179 180# _GLF_uniform_int_values 181BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 182 1 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__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0 193END 194CLEAR_COLOR variant_pipeline 0 0 0 255 195 196CLEAR variant_pipeline 197RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 198 199EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 200