aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-03-22 10:04:27 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-22 14:42:11 +0000
commitfbb56ce83fc717b7c6722324bbccd1ae73c350a4 (patch)
tree0025d8cca6e55eb2fd25b370f7c1bded5e5e910c /src/gpu
parentb667fe2f67a072da74d7a7da32cae4f06a2f0ee4 (diff)
Add a new GrResourceCache purging mechanism for purging unused resources.
The client may call GrContext::purgeResourceNotUsedSince() with a stead_clock::time_point and all resources that have been purgeable since before that time point are purged. This is intended to replace the "max unused flushes" purging mechanism once Chrome adopts it. Change-Id: I28881dd2959cc01c0acca81b2d6001ee5626439d Reviewed-on: https://skia-review.googlesource.com/8920 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com> Reviewed-by: Eric Karl <ericrk@google.com>
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrContext.cpp5
-rw-r--r--src/gpu/GrGpuResourceCacheAccess.h12
-rw-r--r--src/gpu/GrResourceCache.cpp19
-rw-r--r--src/gpu/GrResourceCache.h8
4 files changed, 42 insertions, 2 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index bcb93b30be..efce0b205c 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -193,6 +193,11 @@ void GrContext::freeGpuResources() {
fResourceCache->purgeAllUnlocked();
}
+void GrContext::purgeResourcesNotUsedSince(std::chrono::steady_clock::time_point purgeTime) {
+ ASSERT_SINGLE_OWNER
+ fResourceCache->purgeResourcesNotUsedSince(purgeTime);
+}
+
void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
ASSERT_SINGLE_OWNER
diff --git a/src/gpu/GrGpuResourceCacheAccess.h b/src/gpu/GrGpuResourceCacheAccess.h
index e91f899cf2..e679aff696 100644
--- a/src/gpu/GrGpuResourceCacheAccess.h
+++ b/src/gpu/GrGpuResourceCacheAccess.h
@@ -63,6 +63,10 @@ private:
SkASSERT(fResource->isPurgeable());
fResource->fExternalFlushCntWhenBecamePurgeable = cnt;
}
+ void setTimeWhenResourceBecomePurgeable() {
+ SkASSERT(fResource->isPurgeable());
+ fResource->fTimeWhenBecamePurgeable = std::chrono::steady_clock::now();
+ }
/**
* Called by the cache to determine whether this resource has been puregable for more than
* a threshold number of external flushes.
@@ -71,6 +75,14 @@ private:
SkASSERT(fResource->isPurgeable());
return fResource->fExternalFlushCntWhenBecamePurgeable;
}
+ /**
+ * Called by the cache to determine whether this resource should be purged based on the length
+ * of time it has been available for purging.
+ */
+ std::chrono::steady_clock::time_point timeWhenResourceBecamePurgeable() {
+ SkASSERT(fResource->isPurgeable());
+ return fResource->fTimeWhenBecamePurgeable;
+ }
int* accessCacheIndex() const { return &fResource->fCacheArrayIndex; }
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index 9462a7384d..97d3b96808 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -365,6 +365,7 @@ void GrResourceCache::notifyCntReachedZero(GrGpuResource* resource, uint32_t fla
this->removeFromNonpurgeableArray(resource);
fPurgeableQueue.insert(resource);
resource->cacheAccess().setFlushCntWhenResourceBecamePurgeable(fExternalFlushCnt);
+ resource->cacheAccess().setTimeWhenResourceBecomePurgeable();
if (SkBudgeted::kNo == resource->resourcePriv().isBudgeted()) {
// Check whether this resource could still be used as a scratch resource.
@@ -504,6 +505,24 @@ void GrResourceCache::purgeAllUnlocked() {
this->validate();
}
+void GrResourceCache::purgeResourcesNotUsedSince(std::chrono::steady_clock::time_point purgeTime) {
+ while (fPurgeableQueue.count()) {
+ const std::chrono::steady_clock::time_point resourceTime =
+ fPurgeableQueue.peek()->cacheAccess().timeWhenResourceBecamePurgeable();
+ if (resourceTime >= purgeTime) {
+ // Resources were given both LRU timestamps and tagged with a frame number when
+ // they first became purgeable. The LRU timestamp won't change again until the
+ // resource is made non-purgeable again. So, at this point all the remaining
+ // resources in the timestamp-sorted queue will have a frame number >= to this
+ // one.
+ break;
+ }
+ GrGpuResource* resource = fPurgeableQueue.peek();
+ SkASSERT(resource->isPurgeable());
+ resource->cacheAccess().release();
+ }
+}
+
void GrResourceCache::processInvalidUniqueKeys(
const SkTArray<GrUniqueKeyInvalidatedMessage>& msgs) {
for (int i = 0; i < msgs.count(); ++i) {
diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h
index 5f08a51aa0..aef9a5c8df 100644
--- a/src/gpu/GrResourceCache.h
+++ b/src/gpu/GrResourceCache.h
@@ -50,8 +50,9 @@ public:
static const int kDefaultMaxCount = 2 * (1 << 12);
// Default maximum number of bytes of gpu memory of budgeted resources in the cache.
static const size_t kDefaultMaxSize = 96 * (1 << 20);
- // Default number of external flushes a budgeted resources can go unused in the cache before it
- // is purged. Using a value <= 0 disables this feature.
+ // Default number of external flushes a budgeted resources can go unused in the cache before it
+ // is purged. Using a value <= 0 disables this feature. This will be removed once Chrome
+ // starts using time-based purging.
static const int kDefaultMaxUnusedFlushes =
1 * /* flushes per frame */
60 * /* fps */
@@ -159,6 +160,9 @@ public:
/** Purges all resources that don't have external owners. */
void purgeAllUnlocked();
+ /** Purge all resources not used since the passed in time. */
+ void purgeResourcesNotUsedSince(std::chrono::steady_clock::time_point);
+
/** Returns true if the cache would like a flush to occur in order to make more resources
purgeable. */
bool requestsFlush() const { return fRequestFlush; }