Hash :
6d3c6370
Author :
Date :
2022-06-18T00:13:56
Vulkan: Fix 180 and 270 degree rotated resolve Bug: angleproject:7197 Bug: b/235877059 Change-Id: I4d4ee622f49bb3218449414a1f0dd91fa4e4f541 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3708997 Auto-Submit: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Amirali Abdolrashidi <abdolrashidi@google.com> Reviewed-by: Ian Elliott <ianelliott@google.com> Commit-Queue: Amirali Abdolrashidi <abdolrashidi@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
//
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// BlitResolve.frag: Blit color or depth/stencil images, or resolve multisampled ones.
#version 450 core
#define MAKE_SRC_RESOURCE(prefix, type) prefix ## type
#if BlitColorFloat
#define IsBlitColor 1
#define COLOR_SRC_RESOURCE(type) type
#define ColorType vec4
#elif BlitColorInt
#define IsBlitColor 1
#define COLOR_SRC_RESOURCE(type) MAKE_SRC_RESOURCE(i, type)
#define ColorType ivec4
#elif BlitColorUint
#define IsBlitColor 1
#define COLOR_SRC_RESOURCE(type) MAKE_SRC_RESOURCE(u, type)
#define ColorType uvec4
#elif BlitDepth
#define IsBlitDepth 1
#elif BlitStencil
#define IsBlitStencil 1
#elif BlitDepthStencil
#define IsBlitDepth 1
#define IsBlitStencil 1
#else
#error "Not all resolve targets are accounted for"
#endif
#if IsBlitColor && (IsBlitDepth || IsBlitStencil)
#error "The shader doesn't blit color and depth/stencil at the same time."
#endif
#if IsResolve
#extension GL_EXT_samplerless_texture_functions : require
#endif
#if IsBlitStencil
#extension GL_ARB_shader_stencil_export : require
#endif
#define MAKE_SRC_RESOURCE(prefix, type) prefix ## type
#define DEPTH_SRC_RESOURCE(type) type
#define STENCIL_SRC_RESOURCE(type) MAKE_SRC_RESOURCE(u, type)
#if IsResolve
#define CoordType ivec2
#if SrcIsArray
#define SRC_RESOURCE_NAME texture2DMSArray
#define TEXEL_FETCH(src, coord, sample) texelFetch(src, ivec3(coord, params.srcLayer), sample)
#else
#define SRC_RESOURCE_NAME texture2DMS
#define TEXEL_FETCH(src, coord, sample) texelFetch(src, coord, sample)
#endif
#define COLOR_TEXEL_FETCH(src, coord, sample) TEXEL_FETCH(src, coord, sample)
#define DEPTH_TEXEL_FETCH(src, coord, sample) TEXEL_FETCH(src, coord, sample)
#define STENCIL_TEXEL_FETCH(src, coord, sample) TEXEL_FETCH(src, coord, sample)
#else
#define CoordType vec2
#if SrcIsArray
#define SRC_RESOURCE_NAME texture2DArray
#define SRC_SAMPLER_NAME sampler2DArray
#define TEXEL_FETCH(src, coord, sample) texture(src, vec3(coord * params.invSrcExtent, params.srcLayer))
#else
#define SRC_RESOURCE_NAME texture2D
#define SRC_SAMPLER_NAME sampler2D
#define TEXEL_FETCH(src, coord, sample) texture(src, coord * params.invSrcExtent)
#endif
#define COLOR_TEXEL_FETCH(src, coord, sample) TEXEL_FETCH(COLOR_SRC_RESOURCE(SRC_SAMPLER_NAME)(src, blitSampler), coord, sample)
#define DEPTH_TEXEL_FETCH(src, coord, sample) TEXEL_FETCH(DEPTH_SRC_RESOURCE(SRC_SAMPLER_NAME)(src, blitSampler), coord, sample)
#define STENCIL_TEXEL_FETCH(src, coord, sample) TEXEL_FETCH(STENCIL_SRC_RESOURCE(SRC_SAMPLER_NAME)(src, blitSampler), coord, sample)
#endif // IsResolve
layout(push_constant) uniform PushConstants {
// Translation from source to destination coordinates.
CoordType offset;
vec2 stretch;
vec2 invSrcExtent;
int srcLayer;
int samples;
float invSamples;
// Mask to output only to color attachments that are actually present.
int outputMask;
// Flip control.
bool flipX;
bool flipY;
bool rotateXY;
} params;
#if IsBlitColor
layout(set = 0, binding = 0) uniform COLOR_SRC_RESOURCE(SRC_RESOURCE_NAME) color;
layout(location = 0) out ColorType colorOut0;
layout(location = 1) out ColorType colorOut1;
layout(location = 2) out ColorType colorOut2;
layout(location = 3) out ColorType colorOut3;
layout(location = 4) out ColorType colorOut4;
layout(location = 5) out ColorType colorOut5;
layout(location = 6) out ColorType colorOut6;
layout(location = 7) out ColorType colorOut7;
#endif
#if IsBlitDepth
layout(set = 0, binding = 0) uniform DEPTH_SRC_RESOURCE(SRC_RESOURCE_NAME) depth;
#endif
#if IsBlitStencil
layout(set = 0, binding = 1) uniform STENCIL_SRC_RESOURCE(SRC_RESOURCE_NAME) stencil;
#endif
#if !IsResolve
layout(set = 0, binding = 2) uniform sampler blitSampler;
#endif
void main()
{
// Assume only one direction; x. We are blitting from source to destination either flipped or
// not, with a stretch factor of T. If resolving, T == 1. Note that T here is:
//
// T = SrcWidth / DstWidth
//
// Assume the blit offset in source is S and in destination D. If flipping, S has the
// coordinates of the opposite size of the rectangle. In this shader, we have the fragment
// coordinates, X, which is a point in the destination buffer. We need to map this to the
// source buffer to know where to sample from.
//
// If there's no flipping:
//
// S Y D X
// +-x----+ -> +----x-----------+
//
// Y = S + (X - D) * T
// => Y = TX - (DT - S)
//
// If there's flipping:
//
// Y S D X
// +----x-+ -> +----x-----------+
//
// Y = S - (X - D) * T
// => Y = -(TX - (DT + S))
//
// The above can be implemented as:
//
// !Flip: Y = TX - O where O = DT-S
// Flip: Y = -(TX - O) where O = DT+S
//
// Note that T is params.stretch and O is params.offset.
CoordType srcImageCoords = CoordType(gl_FragCoord.xy); // X
#if !IsResolve
srcImageCoords *= params.stretch; // TX
#endif
srcImageCoords -= params.offset; // TX - O
// If flipping, negate the coordinates.
if (params.flipX)
srcImageCoords.x = -srcImageCoords.x;
if (params.flipY)
srcImageCoords.y = -srcImageCoords.y;
if (params.rotateXY)
srcImageCoords.xy = srcImageCoords.yx;
#if IsBlitColor
#if IsResolve
ColorType colorValue = ColorType(0, 0, 0, 0);
for (int i = 0; i < params.samples; ++i)
{
colorValue += COLOR_TEXEL_FETCH(color, srcImageCoords, i);
}
#if BlitColorFloat
colorValue *= params.invSamples;
#else
colorValue = ColorType(round(colorValue * params.invSamples));
#endif
#else
ColorType colorValue = COLOR_TEXEL_FETCH(color, srcImageCoords, 0);
#endif
// Note: not exporting to render targets that are not present optimizes the number of export
// instructions, which would have otherwise been a likely bottleneck.
if ((params.outputMask & (1 << 0)) != 0)
{
colorOut0 = colorValue;
}
if ((params.outputMask & (1 << 1)) != 0)
{
colorOut1 = colorValue;
}
if ((params.outputMask & (1 << 2)) != 0)
{
colorOut2 = colorValue;
}
if ((params.outputMask & (1 << 3)) != 0)
{
colorOut3 = colorValue;
}
if ((params.outputMask & (1 << 4)) != 0)
{
colorOut4 = colorValue;
}
if ((params.outputMask & (1 << 5)) != 0)
{
colorOut5 = colorValue;
}
if ((params.outputMask & (1 << 6)) != 0)
{
colorOut6 = colorValue;
}
if ((params.outputMask & (1 << 7)) != 0)
{
colorOut7 = colorValue;
}
#endif // IsBlitColor
// Note: always resolve depth/stencil using sample 0. GLES3 gives us freedom in choosing how
// to resolve depth/stencil images.
#if IsBlitDepth
gl_FragDepth = DEPTH_TEXEL_FETCH(depth, srcImageCoords, 0).x;
#endif // IsBlitDepth
#if IsBlitStencil
gl_FragStencilRefARB = int(STENCIL_TEXEL_FETCH(stencil, srcImageCoords, 0).x);
#endif // IsBlitStencil
}