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 24# Optimized using spirv-opt with the following arguments: 25# '-O' 26# spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af 27 28 29 30SHADER vertex variant_vertex_shader PASSTHROUGH 31 32# variant_fragment_shader is derived from the following GLSL: 33# #version 320 es 34# #define _int_0 _GLF_uniform_int_values[0] 35# #define _int_1 _GLF_uniform_int_values[1] 36# 37# precision highp float; 38# precision highp int; 39# 40# // Contents of _GLF_uniform_int_values: [0, 1] 41# layout(set = 0, binding = 0) uniform buf0 42# { 43# int _GLF_uniform_int_values[2]; 44# }; 45# 46# const int _GLF_global_loop_bound = 100; 47# int _GLF_global_loop_count = 0; 48# 49# layout(location = 0) out vec4 _GLF_color; 50# 51# void main() 52# { 53# int a = 1; 54# 55# while (_GLF_global_loop_count < _GLF_global_loop_bound - _int_1) 56# { 57# _GLF_global_loop_count++; 58# } 59# 60# // Always true. 61# if (_int_0 == 0) 62# { 63# // Iterated once. 64# while (_GLF_global_loop_count < _GLF_global_loop_bound) 65# { 66# _GLF_global_loop_count++; 67# // a becomes 0. 68# a *= 1 - a; 69# } 70# } 71# 72# // Always true. 73# if (a == _int_0) 74# { 75# _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1); 76# } 77# else 78# { 79# _GLF_color = vec4(_int_0); 80# } 81# } 82SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 83; SPIR-V 84; Version: 1.0 85; Generator: Khronos Glslang Reference Front End; 10 86; Bound: 85 87; Schema: 0 88 OpCapability Shader 89 %1 = OpExtInstImport "GLSL.std.450" 90 OpMemoryModel Logical GLSL450 91 OpEntryPoint Fragment %4 "main" %61 92 OpExecutionMode %4 OriginUpperLeft 93 OpSource ESSL 320 94 OpName %4 "main" 95 OpName %23 "buf0" 96 OpMemberName %23 0 "_GLF_uniform_int_values" 97 OpName %25 "" 98 OpName %61 "_GLF_color" 99 OpDecorate %22 ArrayStride 16 100 OpMemberDecorate %23 0 Offset 0 101 OpDecorate %23 Block 102 OpDecorate %25 DescriptorSet 0 103 OpDecorate %25 Binding 0 104 OpDecorate %61 Location 0 105 %2 = OpTypeVoid 106 %3 = OpTypeFunction %2 107 %6 = OpTypeInt 32 1 108 %9 = OpConstant %6 0 109 %12 = OpConstant %6 1 110 %19 = OpConstant %6 100 111 %20 = OpTypeInt 32 0 112 %21 = OpConstant %20 2 113 %22 = OpTypeArray %6 %21 114 %23 = OpTypeStruct %22 115 %24 = OpTypePointer Uniform %23 116 %25 = OpVariable %24 Uniform 117 %26 = OpTypePointer Uniform %6 118 %30 = OpTypeBool 119 %58 = OpTypeFloat 32 120 %59 = OpTypeVector %58 4 121 %60 = OpTypePointer Output %59 122 %61 = OpVariable %60 Output 123 %4 = OpFunction %2 None %3 124 %5 = OpLabel 125 OpBranch %13 126 %13 = OpLabel 127 %80 = OpPhi %6 %9 %5 %33 %14 128 %27 = OpAccessChain %26 %25 %9 %12 129 %28 = OpLoad %6 %27 130 %29 = OpISub %6 %19 %28 131 %31 = OpSLessThan %30 %80 %29 132 OpLoopMerge %15 %14 None 133 OpBranchConditional %31 %14 %15 134 %14 = OpLabel 135 %33 = OpIAdd %6 %80 %12 136 OpBranch %13 137 %15 = OpLabel 138 %34 = OpAccessChain %26 %25 %9 %9 139 %35 = OpLoad %6 %34 140 %36 = OpIEqual %30 %35 %9 141 OpSelectionMerge %38 None 142 OpBranchConditional %36 %37 %38 143 %37 = OpLabel 144 OpBranch %39 145 %39 = OpLabel 146 %84 = OpPhi %6 %12 %37 %51 %40 147 %81 = OpPhi %6 %80 %37 %47 %40 148 %45 = OpSLessThan %30 %81 %19 149 OpLoopMerge %41 %40 None 150 OpBranchConditional %45 %40 %41 151 %40 = OpLabel 152 %47 = OpIAdd %6 %81 %12 153 %49 = OpISub %6 %12 %84 154 %51 = OpIMul %6 %84 %49 155 OpBranch %39 156 %41 = OpLabel 157 OpBranch %38 158 %38 = OpLabel 159 %82 = OpPhi %6 %12 %15 %84 %41 160 %55 = OpIEqual %30 %82 %35 161 OpSelectionMerge %57 None 162 OpBranchConditional %55 %56 %75 163 %56 = OpLabel 164 %64 = OpConvertSToF %58 %28 165 %67 = OpConvertSToF %58 %35 166 %74 = OpCompositeConstruct %59 %64 %67 %67 %64 167 OpStore %61 %74 168 OpBranch %57 169 %75 = OpLabel 170 %78 = OpConvertSToF %58 %35 171 %79 = OpCompositeConstruct %59 %78 %78 %78 %78 172 OpStore %61 %79 173 OpBranch %57 174 %57 = OpLabel 175 OpReturn 176 OpFunctionEnd 177END 178 179# uniforms for variant 180 181# _GLF_uniform_int_values 182BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 183 0 1 184END 185 186BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 187 188PIPELINE graphics variant_pipeline 189 ATTACH variant_vertex_shader 190 ATTACH variant_fragment_shader 191 FRAMEBUFFER_SIZE 256 256 192 BIND BUFFER variant_framebuffer AS color LOCATION 0 193 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0 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