From fb28c6fb7fe3f069eb5dca7a5ef2bbd8c87a7cd3 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Fri, 10 Jan 2020 13:04:45 -0500 Subject: [PATCH] Enable transfer from texture to buffer on ANGLE. This is necessary to support the async readback API on Windows Chrome. Transfer from buffer to texture is still disabled as the unit test still fails. Bug: chromium:1040643 Change-Id: I0e16437c066fadfdd8dbbbcaf376c6901a538063 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/263528 Commit-Queue: Brian Salomon Reviewed-by: Robert Phillips --- src/gpu/GrCaps.cpp | 8 ++++++-- src/gpu/GrCaps.h | 7 ++++--- src/gpu/GrSurfaceContext.cpp | 2 +- src/gpu/gl/GrGLCaps.cpp | 17 ++++++++++------- src/gpu/mtl/GrMtlCaps.mm | 3 ++- src/gpu/vk/GrVkCaps.cpp | 5 +++-- tests/ReadPixelsTest.cpp | 5 +++-- tests/TransferPixelsTest.cpp | 8 ++++---- 8 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp index 85342e57d4..077ba1cffa 100644 --- a/src/gpu/GrCaps.cpp +++ b/src/gpu/GrCaps.cpp @@ -45,7 +45,8 @@ GrCaps::GrCaps(const GrContextOptions& options) { fAvoidLargeIndexBufferDraws = false; fPerformStencilClearsAsDraws = false; fAllowCoverageCounting = false; - fTransferBufferSupport = false; + fTransferFromBufferToTextureSupport = false; + fTransferFromSurfaceToBufferSupport = false; fWritePixelsRowBytesSupport = false; fReadPixelsRowBytesSupport = false; fDriverBlacklistCCPR = false; @@ -212,7 +213,10 @@ void GrCaps::dumpJSON(SkJSONWriter* writer) const { writer->appendBool("Avoid Large IndexBuffer Draws", fAvoidLargeIndexBufferDraws); writer->appendBool("Use draws for stencil clip clears", fPerformStencilClearsAsDraws); writer->appendBool("Allow coverage counting shortcuts", fAllowCoverageCounting); - writer->appendBool("Supports transfer buffers", fTransferBufferSupport); + writer->appendBool("Supports transfers from buffers to textures", + fTransferFromBufferToTextureSupport); + writer->appendBool("Supports transfers from textures to buffers", + fTransferFromSurfaceToBufferSupport); writer->appendBool("Write pixels row bytes support", fWritePixelsRowBytesSupport); writer->appendBool("Read pixels row bytes support", fReadPixelsRowBytesSupport); writer->appendBool("Blacklist CCPR on current driver [workaround]", fDriverBlacklistCCPR); diff --git a/src/gpu/GrCaps.h b/src/gpu/GrCaps.h index e8444912dc..447bbb77f3 100644 --- a/src/gpu/GrCaps.h +++ b/src/gpu/GrCaps.h @@ -290,8 +290,8 @@ public: */ bool readPixelsRowBytesSupport() const { return fReadPixelsRowBytesSupport; } - /** Are transfer buffers (to textures and from surfaces) supported? */ - bool transferBufferSupport() const { return fTransferBufferSupport; } + bool transferFromSurfaceToBufferSupport() const { return fTransferFromSurfaceToBufferSupport; } + bool transferFromBufferToTextureSupport() const { return fTransferFromBufferToTextureSupport; } bool suppressPrints() const { return fSuppressPrints; } @@ -511,7 +511,8 @@ protected: bool fAvoidLargeIndexBufferDraws : 1; bool fPerformStencilClearsAsDraws : 1; bool fAllowCoverageCounting : 1; - bool fTransferBufferSupport : 1; + bool fTransferFromBufferToTextureSupport : 1; + bool fTransferFromSurfaceToBufferSupport : 1; bool fWritePixelsRowBytesSupport : 1; bool fReadPixelsRowBytesSupport : 1; diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp index cca4865a73..ca840baceb 100644 --- a/src/gpu/GrSurfaceContext.cpp +++ b/src/gpu/GrSurfaceContext.cpp @@ -694,7 +694,7 @@ GrSurfaceContext::PixelTransferResult GrSurfaceContext::transferPixels(GrColorTy return {}; } - if (!this->caps()->transferBufferSupport() || + if (!this->caps()->transferFromSurfaceToBufferSupport() || !supportedRead.fOffsetAlignmentForTransferBuffer) { return {}; } diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index a1d7fe30f2..fa9adc59dd 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -493,7 +493,8 @@ void GrGLCaps::init(const GrContextOptions& contextOptions, if (GR_IS_GR_GL(standard)) { if (version >= GR_GL_VER(2, 1) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object") || ctxInfo.hasExtension("GL_EXT_pixel_buffer_object")) { - fTransferBufferSupport = true; + fTransferFromBufferToTextureSupport = true; + fTransferFromSurfaceToBufferSupport = true; fTransferBufferType = kPBO_TransferBufferType; } } else if (GR_IS_GR_GL_ES(standard)) { @@ -501,11 +502,13 @@ void GrGLCaps::init(const GrContextOptions& contextOptions, (ctxInfo.hasExtension("GL_NV_pixel_buffer_object") && // GL_EXT_unpack_subimage needed to support subtexture rectangles ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) { - fTransferBufferSupport = true; + fTransferFromBufferToTextureSupport = true; + fTransferFromSurfaceToBufferSupport = true; fTransferBufferType = kPBO_TransferBufferType; // TODO: get transfer buffers working in Chrome // } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) { -// fTransferBufferSupport = true; +// fTransferFromBufferToTextureSupport = false; +// fTransferFromSurfaceToBufferSupport = false; // fTransferBufferType = kChromium_TransferBufferType; } } // no WebGL support @@ -3328,14 +3331,14 @@ void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo, ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) { fMapBufferType = kNone_MapBufferType; fMapBufferFlags = kNone_MapFlags; - fTransferBufferSupport = false; + fTransferFromBufferToTextureSupport = false; + fTransferFromSurfaceToBufferSupport = false; fTransferBufferType = kNone_TransferBufferType; } - // TODO: re-enable for ANGLE + // The TransferPixelsToTexture test fails on ANGLE. if (kANGLE_GrGLDriver == ctxInfo.driver()) { - fTransferBufferSupport = false; - fTransferBufferType = kNone_TransferBufferType; + fTransferFromBufferToTextureSupport = false; } // Using MIPs on this GPU seems to be a source of trouble. diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm index 7c72e8027d..31a54709f1 100644 --- a/src/gpu/mtl/GrMtlCaps.mm +++ b/src/gpu/mtl/GrMtlCaps.mm @@ -268,7 +268,8 @@ void GrMtlCaps::initGrCaps(const id device) { fReuseScratchTextures = true; // Assuming this okay - fTransferBufferSupport = true; + fTransferFromBufferToTextureSupport = true; + fTransferFromSurfaceToBufferSupport = true; fTextureBarrierSupport = false; // Need to figure out if we can do this diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp index e3b82ffcb5..ded002da86 100644 --- a/src/gpu/vk/GrVkCaps.cpp +++ b/src/gpu/vk/GrVkCaps.cpp @@ -51,7 +51,8 @@ GrVkCaps::GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* fReadPixelsRowBytesSupport = true; fWritePixelsRowBytesSupport = true; - fTransferBufferSupport = true; + fTransferFromBufferToTextureSupport = true; + fTransferFromSurfaceToBufferSupport = true; fMaxRenderTargetSize = 4096; // minimum required by spec fMaxTextureSize = 4096; // minimum required by spec @@ -403,7 +404,7 @@ void GrVkCaps::applyDriverCorrectnessWorkarounds(const VkPhysicalDevicePropertie if (kQualcomm_VkVendor == properties.vendorID) { fMustDoCopiesFromOrigin = true; // Transfer doesn't support this workaround. - fTransferBufferSupport = false; + fTransferFromSurfaceToBufferSupport = false; } #if defined(SK_BUILD_FOR_WIN) diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp index e87d9af925..453f6e6366 100644 --- a/tests/ReadPixelsTest.cpp +++ b/tests/ReadPixelsTest.cpp @@ -1035,8 +1035,9 @@ DEF_GPUTEST(AsyncReadPixelsContextShutdown, reporter, options) { if (!context) { continue; } - // This test is only meaningful for contexts that support transfer buffers. - if (!context->priv().caps()->transferBufferSupport()) { + // This test is only meaningful for contexts that support transfer buffers for + // reads. + if (!context->priv().caps()->transferFromSurfaceToBufferSupport()) { continue; } auto surf = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, ii, 1, nullptr); diff --git a/tests/TransferPixelsTest.cpp b/tests/TransferPixelsTest.cpp index 228edd3acd..d385ff4357 100644 --- a/tests/TransferPixelsTest.cpp +++ b/tests/TransferPixelsTest.cpp @@ -417,8 +417,8 @@ void basic_transfer_from_test(skiatest::Reporter* reporter, const sk_gpu_test::C #endif } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TransferPixelsToTest, reporter, ctxInfo) { - if (!ctxInfo.grContext()->priv().caps()->transferBufferSupport()) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TransferPixelsToTextureTest, reporter, ctxInfo) { + if (!ctxInfo.grContext()->priv().caps()->transferFromBufferToTextureSupport()) { return; } for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) { @@ -448,8 +448,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TransferPixelsToTest, reporter, ctxInfo) { } // TODO(bsalomon): Metal -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TransferPixelsFromTest, reporter, ctxInfo) { - if (!ctxInfo.grContext()->priv().caps()->transferBufferSupport()) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TransferPixelsFromTextureTest, reporter, ctxInfo) { + if (!ctxInfo.grContext()->priv().caps()->transferFromSurfaceToBufferSupport()) { return; } for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {