Use SkSpan to cut out some noise when flushing surfaces

Once I noticed this, I had to go for it.

Change-Id: Ibd720e8b731298ab716eab8409c6fe05417c12b5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/332721
Commit-Queue: Adlai Holler <adlai@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Adlai Holler 2020-11-06 15:39:36 -05:00 committed by Skia Commit-Bot
parent 86d4cfdf8e
commit c2bfcff072
14 changed files with 60 additions and 79 deletions

View File

@ -366,7 +366,7 @@ GrSemaphoresSubmitted GrDirectContext::flush(const GrFlushInfo& info) {
}
bool flushed = this->drawingManager()->flush(
nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, info, nullptr);
{}, SkSurface::BackendSurfaceAccess::kNoAccess, info, nullptr);
if (!flushed || (!this->priv().caps()->semaphoreSupport() && info.fNumSemaphores)) {
return GrSemaphoresSubmitted::kNo;

View File

@ -39,23 +39,24 @@ void GrDirectContextPriv::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFl
fContext->addOnFlushCallbackObject(onFlushCBObject);
}
GrSemaphoresSubmitted GrDirectContextPriv::flushSurfaces(GrSurfaceProxy* proxies[], int numProxies,
GrSemaphoresSubmitted GrDirectContextPriv::flushSurfaces(SkSpan<GrSurfaceProxy*> proxies,
const GrFlushInfo& info) {
ASSERT_SINGLE_OWNER
RETURN_VALUE_IF_ABANDONED(GrSemaphoresSubmitted::kNo)
GR_CREATE_TRACE_MARKER_CONTEXT("GrDirectContextPriv", "flushSurfaces", fContext);
SkASSERT(numProxies >= 0);
SkASSERT(!numProxies || proxies);
for (int i = 0; i < numProxies; ++i) {
SkASSERT(proxies[i]);
ASSERT_OWNED_PROXY(proxies[i]);
#ifdef SK_DEBUG
for (GrSurfaceProxy* proxy : proxies) {
SkASSERT(proxy);
ASSERT_OWNED_PROXY(proxy);
}
#endif
return fContext->drawingManager()->flushSurfaces(
proxies, numProxies, SkSurface::BackendSurfaceAccess::kNoAccess, info, nullptr);
proxies, SkSurface::BackendSurfaceAccess::kNoAccess, info, nullptr);
}
void GrDirectContextPriv::flushSurface(GrSurfaceProxy* proxy) {
this->flushSurfaces(proxy ? &proxy : nullptr, proxy ? 1 : 0, {});
size_t size = proxy ? 1 : 0;
this->flushSurfaces({&proxy, size}, {});
}
void GrDirectContextPriv::copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList> ddl,

View File

@ -9,6 +9,7 @@
#define GrDirectContextPriv_DEFINED
#include "include/gpu/GrDirectContext.h"
#include "src/core/SkSpan.h"
class GrAtlasManager;
class GrBackendFormat;
@ -80,7 +81,7 @@ public:
* GrContext will detect when it must perform a resolve before reading pixels back from the
* surface or using it as a texture.
*/
GrSemaphoresSubmitted flushSurfaces(GrSurfaceProxy*[], int numProxies, const GrFlushInfo&);
GrSemaphoresSubmitted flushSurfaces(SkSpan<GrSurfaceProxy*>, const GrFlushInfo&);
/** Version of above that flushes for a single proxy and uses a default GrFlushInfo. Null is
* allowed. */

View File

@ -7,6 +7,7 @@
#include "src/gpu/GrDrawingManager.h"
#include <algorithm>
#include <memory>
#include "include/core/SkDeferredDisplayList.h"
@ -170,15 +171,12 @@ void GrDrawingManager::freeGpuResources() {
fSoftwarePathRenderer = nullptr;
}
// MDB TODO: make use of the 'proxy' parameter.
// MDB TODO: make use of the 'proxies' parameter.
bool GrDrawingManager::flush(
GrSurfaceProxy* proxies[],
int numProxies,
SkSpan<GrSurfaceProxy*> proxies,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info,
const GrBackendSurfaceMutableState* newState) {
SkASSERT(numProxies >= 0);
SkASSERT(!numProxies || proxies);
GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "flush", fContext);
if (fFlushing || this->wasAbandoned()) {
@ -193,13 +191,13 @@ bool GrDrawingManager::flush(
SkDEBUGCODE(this->validate());
if (!info.fNumSemaphores && !info.fFinishedProc &&
// As of now we only short-circuit if we got an explicit list of surfaces to flush.
if (!proxies.empty() && !info.fNumSemaphores && !info.fFinishedProc &&
access == SkSurface::BackendSurfaceAccess::kNoAccess && !newState) {
bool canSkip = numProxies > 0;
for (int i = 0; i < numProxies && canSkip; ++i) {
canSkip = !fDAG.isUsed(proxies[i]) && !this->isDDLTarget(proxies[i]);
}
if (canSkip) {
bool allUnused = std::all_of(proxies.begin(), proxies.end(), [&](GrSurfaceProxy* proxy) {
return !fDAG.isUsed(proxy) && !this->isDDLTarget(proxy);
});
if (allUnused) {
if (info.fSubmittedProc) {
info.fSubmittedProc(info.fSubmittedContext, true);
}
@ -343,7 +341,7 @@ bool GrDrawingManager::flush(
opMemoryPool->isEmpty();
#endif
gpu->executeFlushInfo(proxies, numProxies, access, info, newState);
gpu->executeFlushInfo(proxies, access, info, newState);
// Give the cache a chance to purge resources that become purgeable due to flushing.
if (flushed) {
@ -507,8 +505,7 @@ static void resolve_and_mipmap(GrGpu* gpu, GrSurfaceProxy* proxy) {
}
GrSemaphoresSubmitted GrDrawingManager::flushSurfaces(
GrSurfaceProxy* proxies[],
int numProxies,
SkSpan<GrSurfaceProxy*> proxies,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info,
const GrBackendSurfaceMutableState* newState) {
@ -522,8 +519,6 @@ GrSemaphoresSubmitted GrDrawingManager::flushSurfaces(
return GrSemaphoresSubmitted::kNo;
}
SkDEBUGCODE(this->validate());
SkASSERT(numProxies >= 0);
SkASSERT(!numProxies || proxies);
auto direct = fContext->asDirectContext();
SkASSERT(direct);
@ -534,9 +529,9 @@ GrSemaphoresSubmitted GrDrawingManager::flushSurfaces(
// TODO: It is important to upgrade the drawingmanager to just flushing the
// portion of the DAG required by 'proxies' in order to restore some of the
// semantics of this method.
bool didFlush = this->flush(proxies, numProxies, access, info, newState);
for (int i = 0; i < numProxies; ++i) {
resolve_and_mipmap(gpu, proxies[i]);
bool didFlush = this->flush(proxies, access, info, newState);
for (GrSurfaceProxy* proxy : proxies) {
resolve_and_mipmap(gpu, proxy);
}
SkDEBUGCODE(this->validate());
@ -924,7 +919,8 @@ GrPathRenderer* GrDrawingManager::getSoftwarePathRenderer() {
GrCoverageCountingPathRenderer* GrDrawingManager::getCoverageCountingPathRenderer() {
if (!fPathRendererChain) {
fPathRendererChain = std::make_unique<GrPathRendererChain>(fContext, fOptionsForPathRendererChain);
fPathRendererChain = std::make_unique<GrPathRendererChain>(fContext,
fOptionsForPathRendererChain);
}
return fPathRendererChain->getCoverageCountingPathRenderer();
}
@ -937,8 +933,7 @@ void GrDrawingManager::flushIfNecessary() {
auto resourceCache = direct->priv().getResourceCache();
if (resourceCache && resourceCache->requestsFlush()) {
if (this->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(),
nullptr)) {
if (this->flush({}, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(), nullptr)) {
this->submitToGpu(false);
}
resourceCache->purgeAsNeeded();

View File

@ -11,6 +11,7 @@
#include "include/core/SkSurface.h"
#include "include/private/SkTArray.h"
#include "include/private/SkTHash.h"
#include "src/core/SkSpan.h"
#include "src/gpu/GrBufferAllocPool.h"
#include "src/gpu/GrDeferredUpload.h"
#include "src/gpu/GrHashMapWithCache.h"
@ -97,17 +98,10 @@ public:
static bool ProgramUnitTest(GrDirectContext*, int maxStages, int maxLevels);
GrSemaphoresSubmitted flushSurfaces(GrSurfaceProxy* proxies[],
int cnt,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info,
GrSemaphoresSubmitted flushSurfaces(SkSpan<GrSurfaceProxy*>,
SkSurface::BackendSurfaceAccess,
const GrFlushInfo&,
const GrBackendSurfaceMutableState* newState);
GrSemaphoresSubmitted flushSurface(GrSurfaceProxy* proxy,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info,
const GrBackendSurfaceMutableState* newState) {
return this->flushSurfaces(&proxy, 1, access, info, newState);
}
void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
@ -183,8 +177,7 @@ private:
void removeRenderTasks(int startIndex, int stopIndex);
bool flush(GrSurfaceProxy* proxies[],
int numProxies,
bool flush(SkSpan<GrSurfaceProxy*> proxies,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo&,
const GrBackendSurfaceMutableState* newState);

View File

@ -582,8 +582,7 @@ int GrGpu::findOrAssignSamplePatternKey(GrRenderTarget* renderTarget) {
return fSamplePatternDictionary.findOrAssignSamplePatternKey(sampleLocations);
}
void GrGpu::executeFlushInfo(GrSurfaceProxy* proxies[],
int numProxies,
void GrGpu::executeFlushInfo(SkSpan<GrSurfaceProxy*> proxies,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info,
const GrBackendSurfaceMutableState* newState) {
@ -626,9 +625,9 @@ void GrGpu::executeFlushInfo(GrSurfaceProxy* proxies[],
// We currently don't support passing in new surface state for multiple proxies here. The only
// time we have multiple proxies is if we are flushing a yuv SkImage which won't have state
// updates anyways.
SkASSERT(!newState || numProxies == 1);
SkASSERT(!newState || proxies.count() == 1);
SkASSERT(!newState || access == SkSurface::BackendSurfaceAccess::kNoAccess);
this->prepareSurfacesForBackendAccessAndStateUpdates(proxies, numProxies, access, newState);
this->prepareSurfacesForBackendAccessAndStateUpdates(proxies, access, newState);
}
GrOpsRenderPass* GrGpu::getOpsRenderPass(

View File

@ -12,6 +12,7 @@
#include "include/core/SkSurface.h"
#include "include/gpu/GrTypes.h"
#include "include/private/SkTArray.h"
#include "src/core/SkSpan.h"
#include "src/core/SkTInternalLList.h"
#include "src/gpu/GrAttachment.h"
#include "src/gpu/GrCaps.h"
@ -361,7 +362,7 @@ public:
// Provides a hook for post-flush actions (e.g. Vulkan command buffer submits). This will also
// insert any numSemaphore semaphores on the gpu and set the backendSemaphores to match the
// inserted semaphores.
void executeFlushInfo(GrSurfaceProxy*[], int numProxies,
void executeFlushInfo(SkSpan<GrSurfaceProxy*>,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo&,
const GrBackendSurfaceMutableState* newState);
@ -868,8 +869,7 @@ private:
GrXferBarrierFlags renderPassXferBarriers) = 0;
virtual void prepareSurfacesForBackendAccessAndStateUpdates(
GrSurfaceProxy* proxies[],
int numProxies,
SkSpan<GrSurfaceProxy*> proxies,
SkSurface::BackendSurfaceAccess access,
const GrBackendSurfaceMutableState* newState) {}

View File

@ -1229,7 +1229,8 @@ GrSemaphoresSubmitted GrSurfaceContext::flush(SkSurface::BackendSurfaceAccess ac
SkDEBUGCODE(this->validate();)
GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "flush", fContext);
return this->drawingManager()->flushSurface(this->asSurfaceProxy(), access, info, newState);
GrSurfaceProxy* proxies[1] = {this->asSurfaceProxy()};
return this->drawingManager()->flushSurfaces(proxies, access, info, newState);
}
GrSurfaceContext::PixelTransferResult GrSurfaceContext::transferPixels(GrColorType dstCT,

View File

@ -1291,22 +1291,18 @@ void GrD3DGpu::addBufferResourceBarriers(GrD3DBuffer* buffer,
void GrD3DGpu::prepareSurfacesForBackendAccessAndStateUpdates(
GrSurfaceProxy* proxies[],
int numProxies,
SkSpan<GrSurfaceProxy*> proxies,
SkSurface::BackendSurfaceAccess access,
const GrBackendSurfaceMutableState* newState) {
SkASSERT(numProxies >= 0);
SkASSERT(!numProxies || proxies);
// prepare proxies by transitioning to PRESENT renderState
if (numProxies && access == SkSurface::BackendSurfaceAccess::kPresent) {
if (!proxies.empty() && access == SkSurface::BackendSurfaceAccess::kPresent) {
GrD3DTextureResource* resource;
for (int i = 0; i < numProxies; ++i) {
SkASSERT(proxies[i]->isInstantiated());
if (GrTexture* tex = proxies[i]->peekTexture()) {
for (GrSurfaceProxy* proxy : proxies) {
SkASSERT(proxy->isInstantiated());
if (GrTexture* tex = proxy->peekTexture()) {
resource = static_cast<GrD3DTexture*>(tex);
} else {
GrRenderTarget* rt = proxies[i]->peekRenderTarget();
GrRenderTarget* rt = proxy->peekRenderTarget();
SkASSERT(rt);
resource = static_cast<GrD3DRenderTarget*>(rt);
}

View File

@ -214,8 +214,7 @@ private:
GrXferBarrierFlags renderPassXferBarriers) override;
void prepareSurfacesForBackendAccessAndStateUpdates(
GrSurfaceProxy* proxies[],
int numProxies,
SkSpan<GrSurfaceProxy*> proxies,
SkSurface::BackendSurfaceAccess access,
const GrBackendSurfaceMutableState* newState) override;

View File

@ -2080,22 +2080,19 @@ void GrVkGpu::addImageMemoryBarrier(const GrManagedResource* resource,
}
void GrVkGpu::prepareSurfacesForBackendAccessAndStateUpdates(
GrSurfaceProxy* proxies[],
int numProxies,
SkSpan<GrSurfaceProxy*> proxies,
SkSurface::BackendSurfaceAccess access,
const GrBackendSurfaceMutableState* newState) {
SkASSERT(numProxies >= 0);
SkASSERT(!numProxies || proxies);
// Submit the current command buffer to the Queue. Whether we inserted semaphores or not does
// not effect what we do here.
if (numProxies && (access == SkSurface::BackendSurfaceAccess::kPresent || newState)) {
if (!proxies.empty() && (access == SkSurface::BackendSurfaceAccess::kPresent || newState)) {
GrVkImage* image;
for (int i = 0; i < numProxies; ++i) {
SkASSERT(proxies[i]->isInstantiated());
if (GrTexture* tex = proxies[i]->peekTexture()) {
for (GrSurfaceProxy* proxy : proxies) {
SkASSERT(proxy->isInstantiated());
if (GrTexture* tex = proxy->peekTexture()) {
image = static_cast<GrVkTexture*>(tex);
} else {
GrRenderTarget* rt = proxies[i]->peekRenderTarget();
GrRenderTarget* rt = proxy->peekRenderTarget();
SkASSERT(rt);
image = static_cast<GrVkRenderTarget*>(rt);
}

View File

@ -293,8 +293,7 @@ private:
GrXferBarrierFlags renderPassXferBarriers) override;
void prepareSurfacesForBackendAccessAndStateUpdates(
GrSurfaceProxy* proxies[],
int numProxies,
SkSpan<GrSurfaceProxy*> proxies,
SkSurface::BackendSurfaceAccess access,
const GrBackendSurfaceMutableState* newState) override;

View File

@ -78,7 +78,7 @@ GrSemaphoresSubmitted SkImage_Gpu::onFlush(GrDirectContext* dContext, const GrFl
}
GrSurfaceProxy* p[1] = {fView.proxy()};
return dContext->priv().flushSurfaces(p, 1, info);
return dContext->priv().flushSurfaces(p, info);
}
sk_sp<SkImage> SkImage_Gpu::onMakeColorTypeAndColorSpace(SkColorType targetCT,
@ -749,7 +749,7 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrDirectContext* dContex
surfaceContext.writePixels(dContext, srcInfo, pixmap.addr(0, 0), pixmap.rowBytes(), {0, 0});
GrSurfaceProxy* p[1] = {surfaceContext.asSurfaceProxy()};
drawingManager->flush(p, 1, SkSurface::BackendSurfaceAccess::kNoAccess, {}, nullptr);
drawingManager->flush(p, SkSurface::BackendSurfaceAccess::kNoAccess, {}, nullptr);
return image;
}

View File

@ -134,7 +134,7 @@ GrSemaphoresSubmitted SkImage_GpuYUVA::onFlush(GrDirectContext* dContext, const
GrSurfaceProxy* proxies[4] = {fViews[0].proxy(), fViews[1].proxy(), fViews[2].proxy(),
fViews[3].proxy()};
int numProxies = fNumViews;
size_t numProxies = fNumViews;
if (fRGBView.proxy()) {
// Either we've already flushed the flattening draw or the flattening is unflushed. In the
// latter case it should still be ok to just pass fRGBView proxy because it in turn depends
@ -142,7 +142,7 @@ GrSemaphoresSubmitted SkImage_GpuYUVA::onFlush(GrDirectContext* dContext, const
proxies[0] = fRGBView.proxy();
numProxies = 1;
}
return dContext->priv().flushSurfaces(proxies, numProxies, info);
return dContext->priv().flushSurfaces({proxies, numProxies}, info);
}
GrTextureProxy* SkImage_GpuYUVA::peekProxy() const { return fRGBView.asTextureProxy(); }