Disallow direct readback of compressed textures in Metal

Bug: skia:12592
Change-Id: Ic07b68c7101850a5d2b7aa921f592a93dbfff196
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/470836
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2021-11-12 11:30:38 -05:00 committed by SkCQ
parent 152299ee42
commit e96b25c622
2 changed files with 10 additions and 2 deletions

View File

@ -129,8 +129,8 @@ bool SurfaceContext::readPixels(GrDirectContext* dContext, GrPixmap dst, SkIPoin
dContext->priv().validPMUPMConversionExists();
// Since the validPMUPMConversionExists function actually submits work to the gpu to do its
// tests, it is possible that during that call we have abanoned the context. Thus we do
// another abanoned check here to make sure we are still valid.
// tests, it is possible that during that call we have abandoned the context. Thus, we do
// another abandoned check here to make sure we are still valid.
RETURN_FALSE_IF_ABANDONED
auto readFlag = caps->surfaceSupportsReadPixels(srcSurface);

View File

@ -20,6 +20,7 @@
#include "src/gpu/GrShaderCaps.h"
#include "src/gpu/GrSurfaceProxy.h"
#include "src/gpu/mtl/GrMtlRenderTarget.h"
#include "src/gpu/mtl/GrMtlTexture.h"
#include "src/gpu/mtl/GrMtlUtil.h"
#if !__has_feature(objc_arc)
@ -968,6 +969,13 @@ bool GrMtlCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const {
GrCaps::SurfaceReadPixelsSupport GrMtlCaps::surfaceSupportsReadPixels(
const GrSurface* surface) const {
if (auto tex = static_cast<const GrMtlTexture*>(surface->asTexture())) {
// We disallow reading back directly from compressed textures.
if (GrMtlFormatIsCompressed(tex->attachment()->mtlFormat())) {
return SurfaceReadPixelsSupport::kCopyToTexture2D;
}
}
if (auto mtlRT = static_cast<const GrMtlRenderTarget*>(surface->asRenderTarget())) {
if (mtlRT->numSamples() > 1 && !mtlRT->resolveAttachment()) {
return SurfaceReadPixelsSupport::kCopyToTexture2D;