Hash :
b407e1a0
Author :
Date :
2019-06-03T17:15:51
Vulkan: implement ES3 blit Augment the resolve shaders to be able to stretch and blit too. The UtilsVk resolve function is accordingly expanded to include blit. Bug: angleproject:3200 Change-Id: I30b172a5e388089735ab494f55cbfdc2781a8bf9 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1635753 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
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
//
// 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.
//
// BlitResolveStencilNoExport.comp: Blit stencil images or resolve multisampled ones into a buffer.
// This is used where VK_EXT_shader_stencil_export is not available, to output the resolved stencil
// into a temporary buffer, which is then copied into the stencil aspect of the final image.
#version 450 core
#if IsResolve
#extension GL_EXT_samplerless_texture_functions : require
#endif
#define MAKE_SRC_RESOURCE(prefix, type) prefix ## type
#if IsResolve
#define CoordType ivec2
#if SrcIsArray
#define SRC_RESOURCE utexture2DMSArray
#define TEXEL_FETCH(src, coord, sample) texelFetch(src, ivec3(coord, params.srcLayer), sample)
#else
#define SRC_RESOURCE utexture2DMS
#define TEXEL_FETCH(src, coord, sample) texelFetch(src, coord, sample)
#endif
#else
#define CoordType vec2
#if SrcIsArray
#define SRC_RESOURCE utexture2DArray
#define TEXEL_FETCH(src, coord, sample) texture(usampler2DArray(src, blitSampler), vec3(coord * params.invSrcExtent, params.srcLayer))
#else
#define SRC_RESOURCE utexture2D
#define TEXEL_FETCH(src, coord, sample) texture(usampler2D(src, blitSampler), coord * params.invSrcExtent)
#endif
#endif // IsResolve
layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout(push_constant) uniform PushConstants {
// Translation from source to destination coordinates.
CoordType offset;
vec2 stretch;
vec2 invSrcExtent;
int srcLayer;
int srcWidth;
// Output.
ivec4 blitArea;
int destPitch;
// Flip control.
bool flipX;
bool flipY;
} params;
layout (set = 0, binding = 0) buffer dest
{
// Note: every invocation handles 4 stencil value and output one value here.
uint destData[];
};
layout(set = 0, binding = 1) uniform SRC_RESOURCE stencil;
#if !IsResolve
layout(set = 0, binding = 2) uniform sampler blitSampler;
#endif
void main()
{
ivec2 destSubImageCoords = ivec2(gl_GlobalInvocationID.x * 4, gl_GlobalInvocationID.y);
if (any(lessThanEqual(params.blitArea.zw, destSubImageCoords)))
{
return;
}
// See comment in BlitResolve.frag regarding how the following coordinate transformation is
// derived.
//
// When blitting with the fragment shader, the input coordinates are within the blit area.
// With the compute shader however, the input coordinates start from 0,0. That is, if the
// fragment shader input is Xf and the compute shader's input is Xc, we have:
//
// Xf = Xc + params.blitOffset
//
// So we need to offset the input coordinates here by the blit area offset.
destSubImageCoords += params.blitArea.xy;
CoordType srcImageCoords = CoordType(destSubImageCoords);
#if !IsResolve
srcImageCoords *= params.stretch;
#endif
srcImageCoords -= params.offset;
// If flipping, negate the coordinates.
if (params.flipX)
srcImageCoords.x = -srcImageCoords.x;
if (params.flipY)
srcImageCoords.y = -srcImageCoords.y;
int xDir = params.flipX ? -1 : 1;
uint outStencils = 0;
for (int i = 0; i < 4; ++i)
{
// Bounds check on X:
if (srcImageCoords.x >= 0 && srcImageCoords.x < params.srcWidth)
{
// Note: always resolve using sample 0. GLES3 gives us freedom in choosing how
// to resolve depth/stencil images.
uint stencilValue = TEXEL_FETCH(stencil, srcImageCoords, 0).x;
#if IsBigEndian
outStencils |= (stencilValue & 0xFF) << ((3 - i) * 8);
#else
outStencils |= (stencilValue & 0xFF) << (i * 8);
#endif
}
srcImageCoords.x += xDir;
}
destData[gl_GlobalInvocationID.y * params.destPitch + gl_GlobalInvocationID.x] = outStencils;
}