Lines Matching full:resource

74 void GrResourceCache::insertResource(GrGpuResource* resource) {  in insertResource()  argument
76 SkASSERT(resource); in insertResource()
77 SkASSERT(!this->isInCache(resource)); in insertResource()
78 SkASSERT(!resource->wasDestroyed()); in insertResource()
79 SkASSERT(!resource->resourcePriv().isPurgeable()); in insertResource()
83 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in insertResource()
85 this->addToNonpurgeableArray(resource); in insertResource()
87 size_t size = resource->gpuMemorySize(); in insertResource()
94 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in insertResource()
104 SkASSERT(!resource->cacheAccess().isUsableAsScratch()); in insertResource()
108 void GrResourceCache::removeResource(GrGpuResource* resource) { in removeResource() argument
111 SkASSERT(this->isInCache(resource)); in removeResource()
113 size_t size = resource->gpuMemorySize(); in removeResource()
114 if (resource->resourcePriv().isPurgeable()) { in removeResource()
115 fPurgeableQueue.remove(resource); in removeResource()
118 this->removeFromNonpurgeableArray(resource); in removeResource()
123 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in removeResource()
130 if (resource->cacheAccess().isUsableAsScratch()) { in removeResource()
131 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in removeResource()
133 if (resource->getUniqueKey().isValid()) { in removeResource()
134 fUniqueHash.remove(resource->getUniqueKey()); in removeResource()
202 void GrResourceCache::refResource(GrGpuResource* resource) { in refResource() argument
203 SkASSERT(resource); in refResource()
204 SkASSERT(resource->getContext()->priv().getResourceCache() == this); in refResource()
205 if (resource->cacheAccess().hasRef()) { in refResource()
206 resource->ref(); in refResource()
208 this->refAndMakeResourceMRU(resource); in refResource()
216 GrGpuResource* resource = fScratchMap.find(scratchKey); in findAndRefScratchResource() local
217 if (resource) { in findAndRefScratchResource()
218 fScratchMap.remove(scratchKey, resource); in findAndRefScratchResource()
219 this->refAndMakeResourceMRU(resource); in findAndRefScratchResource()
222 return resource; in findAndRefScratchResource()
225 void GrResourceCache::willRemoveScratchKey(const GrGpuResource* resource) { in willRemoveScratchKey() argument
227 SkASSERT(resource->resourcePriv().getScratchKey().isValid()); in willRemoveScratchKey()
228 if (resource->cacheAccess().isUsableAsScratch()) { in willRemoveScratchKey()
229 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in willRemoveScratchKey()
233 void GrResourceCache::removeUniqueKey(GrGpuResource* resource) { in removeUniqueKey() argument
235 // Someone has a ref to this resource in order to have removed the key. When the ref count in removeUniqueKey()
237 if (resource->getUniqueKey().isValid()) { in removeUniqueKey()
238 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey())); in removeUniqueKey()
239 fUniqueHash.remove(resource->getUniqueKey()); in removeUniqueKey()
241 resource->cacheAccess().removeUniqueKey(); in removeUniqueKey()
242 if (resource->cacheAccess().isUsableAsScratch()) { in removeUniqueKey()
243 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in removeUniqueKey()
246 // Removing a unique key from a kUnbudgetedCacheable resource would make the resource in removeUniqueKey()
247 // require purging. However, the resource must be ref'ed to get here and therefore can't in removeUniqueKey()
249 SkASSERT(!resource->resourcePriv().isPurgeable()); in removeUniqueKey()
253 void GrResourceCache::changeUniqueKey(GrGpuResource* resource, const skgpu::UniqueKey& newKey) { in changeUniqueKey() argument
255 SkASSERT(resource); in changeUniqueKey()
256 SkASSERT(this->isInCache(resource)); in changeUniqueKey()
258 // If another resource has the new key, remove its key then install the key on this resource. in changeUniqueKey()
261 // If the old resource using the key is purgeable and is unreachable, then remove it. in changeUniqueKey()
266 // removeUniqueKey expects an external owner of the resource. in changeUniqueKey()
272 // Remove the entry for this resource if it already has a unique key. in changeUniqueKey()
273 if (resource->getUniqueKey().isValid()) { in changeUniqueKey()
274 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey())); in changeUniqueKey()
275 fUniqueHash.remove(resource->getUniqueKey()); in changeUniqueKey()
276 SkASSERT(nullptr == fUniqueHash.find(resource->getUniqueKey())); in changeUniqueKey()
278 // 'resource' didn't have a valid unique key before so it is switching sides. Remove it in changeUniqueKey()
281 if (resource->cacheAccess().isUsableAsScratch()) { in changeUniqueKey()
282 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in changeUniqueKey()
286 resource->cacheAccess().setUniqueKey(newKey); in changeUniqueKey()
287 fUniqueHash.add(resource); in changeUniqueKey()
289 this->removeUniqueKey(resource); in changeUniqueKey()
295 void GrResourceCache::refAndMakeResourceMRU(GrGpuResource* resource) { in refAndMakeResourceMRU() argument
297 SkASSERT(resource); in refAndMakeResourceMRU()
298 SkASSERT(this->isInCache(resource)); in refAndMakeResourceMRU()
300 if (resource->resourcePriv().isPurgeable()) { in refAndMakeResourceMRU()
302 fPurgeableBytes -= resource->gpuMemorySize(); in refAndMakeResourceMRU()
303 fPurgeableQueue.remove(resource); in refAndMakeResourceMRU()
304 this->addToNonpurgeableArray(resource); in refAndMakeResourceMRU()
305 } else if (!resource->cacheAccess().hasRefOrCommandBufferUsage() && in refAndMakeResourceMRU()
306 resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { in refAndMakeResourceMRU()
310 resource->cacheAccess().ref(); in refAndMakeResourceMRU()
312 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in refAndMakeResourceMRU()
316 void GrResourceCache::notifyARefCntReachedZero(GrGpuResource* resource, in notifyARefCntReachedZero() argument
319 SkASSERT(resource); in notifyARefCntReachedZero()
320 SkASSERT(!resource->wasDestroyed()); in notifyARefCntReachedZero()
321 SkASSERT(this->isInCache(resource)); in notifyARefCntReachedZero()
322 // This resource should always be in the nonpurgeable array when this function is called. It in notifyARefCntReachedZero()
324 SkASSERT(fNonpurgeableResources[*resource->cacheAccess().accessCacheIndex()] == resource); in notifyARefCntReachedZero()
327 if (resource->cacheAccess().isUsableAsScratch()) { in notifyARefCntReachedZero()
328 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in notifyARefCntReachedZero()
332 if (resource->cacheAccess().hasRefOrCommandBufferUsage()) { in notifyARefCntReachedZero()
341 if (resource->resourcePriv().isPurgeable()) { in notifyARefCntReachedZero()
342 fNewlyPurgeableResourceForValidation = resource; in notifyARefCntReachedZero()
345 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in notifyARefCntReachedZero()
348 if (!resource->resourcePriv().isPurgeable() && in notifyARefCntReachedZero()
349 resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { in notifyARefCntReachedZero()
353 if (!resource->resourcePriv().isPurgeable()) { in notifyARefCntReachedZero()
358 this->removeFromNonpurgeableArray(resource); in notifyARefCntReachedZero()
359 fPurgeableQueue.insert(resource); in notifyARefCntReachedZero()
360 resource->cacheAccess().setTimeWhenResourceBecomePurgeable(); in notifyARefCntReachedZero()
361 fPurgeableBytes += resource->gpuMemorySize(); in notifyARefCntReachedZero()
363 bool hasUniqueKey = resource->getUniqueKey().isValid(); in notifyARefCntReachedZero()
365 GrBudgetedType budgetedType = resource->resourcePriv().budgetedType(); in notifyARefCntReachedZero()
368 // Purge the resource immediately if we're over budget in notifyARefCntReachedZero()
369 // Also purge if the resource has neither a valid scratch key nor a unique key. in notifyARefCntReachedZero()
370 bool hasKey = resource->resourcePriv().getScratchKey().isValid() || hasUniqueKey; in notifyARefCntReachedZero()
380 // Check whether this resource could still be used as a scratch resource. in notifyARefCntReachedZero()
381 if (!resource->resourcePriv().refsWrappedObjects() && in notifyARefCntReachedZero()
382 resource->resourcePriv().getScratchKey().isValid()) { in notifyARefCntReachedZero()
383 // We won't purge an existing resource to make room for this one. in notifyARefCntReachedZero()
384 if (this->wouldFit(resource->gpuMemorySize())) { in notifyARefCntReachedZero()
385 resource->resourcePriv().makeBudgeted(); in notifyARefCntReachedZero()
392 resource->cacheAccess().release(); in notifyARefCntReachedZero()
393 // We should at least free this resource, perhaps dependent resources as well. in notifyARefCntReachedZero()
398 void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) { in didChangeBudgetStatus() argument
400 SkASSERT(resource); in didChangeBudgetStatus()
401 SkASSERT(this->isInCache(resource)); in didChangeBudgetStatus()
403 size_t size = resource->gpuMemorySize(); in didChangeBudgetStatus()
405 // resource become purgeable. However, we should never allow that transition. Wrapped in didChangeBudgetStatus()
408 SkDEBUGCODE(bool wasPurgeable = resource->resourcePriv().isPurgeable()); in didChangeBudgetStatus()
409 if (resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { in didChangeBudgetStatus()
416 if (!resource->resourcePriv().isPurgeable() && in didChangeBudgetStatus()
417 !resource->cacheAccess().hasRefOrCommandBufferUsage()) { in didChangeBudgetStatus()
420 if (resource->cacheAccess().isUsableAsScratch()) { in didChangeBudgetStatus()
421 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in didChangeBudgetStatus()
425 SkASSERT(resource->resourcePriv().budgetedType() != GrBudgetedType::kUnbudgetedCacheable); in didChangeBudgetStatus()
428 if (!resource->resourcePriv().isPurgeable() && in didChangeBudgetStatus()
429 !resource->cacheAccess().hasRefOrCommandBufferUsage()) { in didChangeBudgetStatus()
432 if (!resource->cacheAccess().hasRef() && !resource->getUniqueKey().isValid() && in didChangeBudgetStatus()
433 resource->resourcePriv().getScratchKey().isValid()) { in didChangeBudgetStatus()
434 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in didChangeBudgetStatus()
437 SkASSERT(wasPurgeable == resource->resourcePriv().isPurgeable()); in didChangeBudgetStatus()
467 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeAsNeeded() local
468 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeAsNeeded()
469 resource->cacheAccess().release(); in purgeAsNeeded()
478 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeAsNeeded() local
479 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeAsNeeded()
480 resource->cacheAccess().release(); in purgeAsNeeded()
500 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeUnlockedResources() local
503 resource->cacheAccess().timeWhenResourceBecamePurgeable(); in purgeUnlockedResources()
507 // resource is made non-purgeable again. So, at this point all the remaining in purgeUnlockedResources()
513 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
514 resource->cacheAccess().release(); in purgeUnlockedResources()
531 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeUnlockedResources() local
534 resource->cacheAccess().timeWhenResourceBecamePurgeable(); in purgeUnlockedResources()
539 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
540 if (!resource->getUniqueKey().isValid()) { in purgeUnlockedResources()
541 *scratchResources.append() = resource; in purgeUnlockedResources()
568 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeToMakeHeadroom() local
569 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in purgeToMakeHeadroom()
570 projectedBudget -= resource->gpuMemorySize(); in purgeToMakeHeadroom()
588 for (GrGpuResource* resource : resources) { in purgeToMakeHeadroom()
589 resource->cacheAccess().release(); in purgeToMakeHeadroom()
607 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeUnlockedResources() local
608 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
609 if (!resource->getUniqueKey().isValid()) { in purgeUnlockedResources()
610 *scratchResources.append() = resource; in purgeUnlockedResources()
611 scratchByteCount += resource->gpuMemorySize(); in purgeUnlockedResources()
646 void GrResourceCache::addToNonpurgeableArray(GrGpuResource* resource) { in addToNonpurgeableArray() argument
648 *fNonpurgeableResources.append() = resource; in addToNonpurgeableArray()
649 *resource->cacheAccess().accessCacheIndex() = index; in addToNonpurgeableArray()
652 void GrResourceCache::removeFromNonpurgeableArray(GrGpuResource* resource) { in removeFromNonpurgeableArray() argument
653 int* index = resource->cacheAccess().accessCacheIndex(); in removeFromNonpurgeableArray()
657 SkASSERT(fNonpurgeableResources[*index] == resource); in removeFromNonpurgeableArray()
696 // Correct the index in the nonpurgeable array stored on the resource post-sort. in getNextTimestamp()
785 // Reduce the frequency of validations for large resource counts. in validate()
809 void update(GrGpuResource* resource) { in validate()
810 fBytes += resource->gpuMemorySize(); in validate()
812 if (!resource->resourcePriv().isPurgeable()) { in validate()
816 const skgpu::ScratchKey& scratchKey = resource->resourcePriv().getScratchKey(); in validate()
817 const skgpu::UniqueKey& uniqueKey = resource->getUniqueKey(); in validate()
819 if (resource->cacheAccess().isUsableAsScratch()) { in validate()
821 SkASSERT(GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()); in validate()
822 SkASSERT(!resource->cacheAccess().hasRef()); in validate()
825 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); in validate()
827 SkASSERT(GrBudgetedType::kBudgeted != resource->resourcePriv().budgetedType() || in validate()
828 uniqueKey.isValid() || resource->cacheAccess().hasRef()); in validate()
829 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); in validate()
830 SkASSERT(!fScratchMap->has(resource, scratchKey)); in validate()
834 SkASSERT(fUniqueHash->find(uniqueKey) == resource); in validate()
835 SkASSERT(GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType() || in validate()
836 resource->resourcePriv().refsWrappedObjects()); in validate()
839 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in validate()
841 fBudgetedBytes += resource->gpuMemorySize(); in validate()
848 fScratchMap.foreach([&](const GrGpuResource& resource) { in validate() argument
849 SkASSERT(resource.cacheAccess().isUsableAsScratch()); in validate()
905 bool GrResourceCache::isInCache(const GrGpuResource* resource) const { in isInCache()
906 int index = *resource->cacheAccess().accessCacheIndex(); in isInCache()
910 if (index < fPurgeableQueue.count() && fPurgeableQueue.at(index) == resource) { in isInCache()
913 if (index < fNonpurgeableResources.size() && fNonpurgeableResources[index] == resource) { in isInCache()
916 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the cache."); in isInCache()
926 fUniqueHash.foreach([&](const GrGpuResource& resource){ in countUniqueKeysWithTag() argument
927 if (0 == strcmp(tag, resource.getUniqueKey().tag())) { in countUniqueKeysWithTag()