From 57d2beabc714e1ca0d01125e456c81297f9eb4eb Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Mon, 10 Sep 2018 09:35:41 -0400 Subject: [PATCH] Simplify GrResourceCache/GrDrawingManager flush interaction. Change-Id: I2442da32a364ec77ccbefc58ceaa62de8e991caf Reviewed-on: https://skia-review.googlesource.com/152669 Commit-Queue: Brian Salomon Reviewed-by: Greg Daniel --- src/gpu/GrDrawingManager.cpp | 18 +++++++++--------- src/gpu/GrDrawingManager.h | 9 +-------- src/gpu/GrResourceCache.cpp | 19 ------------------- src/gpu/GrResourceCache.h | 10 +--------- 4 files changed, 11 insertions(+), 45 deletions(-) diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp index 3dbab2cabc..73495bccc6 100644 --- a/src/gpu/GrDrawingManager.cpp +++ b/src/gpu/GrDrawingManager.cpp @@ -195,11 +195,10 @@ void GrDrawingManager::freeGpuResources() { } // MDB TODO: make use of the 'proxy' parameter. -GrSemaphoresSubmitted GrDrawingManager::internalFlush(GrSurfaceProxy*, - GrResourceCache::FlushType type, - int numSemaphores, - GrBackendSemaphore backendSemaphores[]) { - GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "internalFlush", fContext); +GrSemaphoresSubmitted GrDrawingManager::flush(GrSurfaceProxy*, + int numSemaphores, + GrBackendSemaphore backendSemaphores[]) { + GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "flush", fContext); if (fFlushing || this->wasAbandoned()) { return GrSemaphoresSubmitted::kNo; @@ -321,9 +320,9 @@ GrSemaphoresSubmitted GrDrawingManager::internalFlush(GrSurfaceProxy*, flushState.uninstantiateProxyTracker()->uninstantiateAllProxies(); - // We always have to notify the cache when it requested a flush so it can reset its state. - if (flushed || type == GrResourceCache::FlushType::kCacheRequested) { - fContext->contextPriv().getResourceCache()->notifyFlushOccurred(type); + // Give the cache a chance to purge resources that become purgeable due to flushing. + if (flushed) { + fContext->contextPriv().getResourceCache()->purgeAsNeeded(); } for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) { onFlushCBObject->postFlush(fTokenTracker.nextTokenToFlush(), fFlushingOpListIDs.begin(), @@ -633,7 +632,8 @@ GrCoverageCountingPathRenderer* GrDrawingManager::getCoverageCountingPathRendere void GrDrawingManager::flushIfNecessary() { GrResourceCache* resourceCache = fContext->contextPriv().getResourceCache(); if (resourceCache && resourceCache->requestsFlush()) { - this->internalFlush(nullptr, GrResourceCache::kCacheRequested, 0, nullptr); + this->flush(nullptr, 0, nullptr); + resourceCache->purgeAsNeeded(); } } diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h index 6bfc726e51..9d6ce28a9e 100644 --- a/src/gpu/GrDrawingManager.h +++ b/src/gpu/GrDrawingManager.h @@ -139,14 +139,7 @@ private: GrSemaphoresSubmitted flush(GrSurfaceProxy* proxy, int numSemaphores = 0, - GrBackendSemaphore backendSemaphores[] = nullptr) { - return this->internalFlush(proxy, GrResourceCache::FlushType::kExternal, - numSemaphores, backendSemaphores); - } - GrSemaphoresSubmitted internalFlush(GrSurfaceProxy*, - GrResourceCache::FlushType, - int numSemaphores, - GrBackendSemaphore backendSemaphores[]); + GrBackendSemaphore backendSemaphores[] = nullptr); SkDEBUGCODE(void validate() const); diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index 6a21e72673..2cceedfe54 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -78,7 +78,6 @@ GrResourceCache::GrResourceCache(const GrCaps* caps, uint32_t contextUniqueID) , fBudgetedCount(0) , fBudgetedBytes(0) , fPurgeableBytes(0) - , fRequestFlush(false) , fInvalidUniqueKeyInbox(contextUniqueID) , fFreedGpuResourceInbox(contextUniqueID) , fContextUniqueID(contextUniqueID) @@ -459,12 +458,6 @@ void GrResourceCache::purgeAsNeeded() { } this->validate(); - - if (stillOverbudget) { - // Set this so that GrDrawingManager will issue a flush to free up resources with pending - // IO that we were unable to purge in this pass. - fRequestFlush = true; - } } void GrResourceCache::purgeUnlockedResources(bool scratchResourcesOnly) { @@ -672,18 +665,6 @@ uint32_t GrResourceCache::getNextTimestamp() { return fTimestamp++; } -void GrResourceCache::notifyFlushOccurred(FlushType type) { - switch (type) { - case FlushType::kCacheRequested: - SkASSERT(fRequestFlush); - fRequestFlush = false; - break; - case FlushType::kExternal: - break; - } - this->purgeAsNeeded(); -} - void GrResourceCache::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { for (int i = 0; i < fNonpurgeableResources.count(); ++i) { fNonpurgeableResources[i]->dumpMemoryStatistics(traceMemoryDump); diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h index a7084683c7..3cc6665590 100644 --- a/src/gpu/GrResourceCache.h +++ b/src/gpu/GrResourceCache.h @@ -189,13 +189,7 @@ public: /** Returns true if the cache would like a flush to occur in order to make more resources purgeable. */ - bool requestsFlush() const { return fRequestFlush; } - - enum FlushType { - kExternal, - kCacheRequested, - }; - void notifyFlushOccurred(FlushType); + bool requestsFlush() const { return this->overBudget() && !fPurgeableQueue.count(); } /** Maintain a ref to this resource until we receive a GrGpuResourceFreedMessage. */ void insertCrossContextGpuResource(GrGpuResource* resource); @@ -352,8 +346,6 @@ private: size_t fBudgetedBytes; size_t fPurgeableBytes; - bool fRequestFlush; - InvalidUniqueKeyInbox fInvalidUniqueKeyInbox; FreedGpuResourceInbox fFreedGpuResourceInbox;