Lines Matching full:resource
71 void GrResourceCache::insertResource(GrGpuResource* resource) { in insertResource() argument
73 SkASSERT(resource); in insertResource()
74 SkASSERT(!this->isInCache(resource)); in insertResource()
75 SkASSERT(!resource->wasDestroyed()); in insertResource()
76 SkASSERT(!resource->resourcePriv().isPurgeable()); in insertResource()
80 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in insertResource()
82 this->addToNonpurgeableArray(resource); in insertResource()
84 size_t size = resource->gpuMemorySize(); in insertResource()
91 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in insertResource()
101 SkASSERT(!resource->cacheAccess().isUsableAsScratch()); in insertResource()
105 void GrResourceCache::removeResource(GrGpuResource* resource) { in removeResource() argument
108 SkASSERT(this->isInCache(resource)); in removeResource()
110 size_t size = resource->gpuMemorySize(); in removeResource()
111 if (resource->resourcePriv().isPurgeable()) { in removeResource()
112 fPurgeableQueue.remove(resource); in removeResource()
115 this->removeFromNonpurgeableArray(resource); in removeResource()
120 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in removeResource()
127 if (resource->cacheAccess().isUsableAsScratch()) { in removeResource()
128 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in removeResource()
130 if (resource->getUniqueKey().isValid()) { in removeResource()
131 fUniqueHash.remove(resource->getUniqueKey()); in removeResource()
199 void GrResourceCache::refResource(GrGpuResource* resource) { in refResource() argument
200 SkASSERT(resource); in refResource()
201 SkASSERT(resource->getContext()->priv().getResourceCache() == this); in refResource()
202 if (resource->cacheAccess().hasRef()) { in refResource()
203 resource->ref(); in refResource()
205 this->refAndMakeResourceMRU(resource); in refResource()
213 GrGpuResource* resource = fScratchMap.find(scratchKey); in findAndRefScratchResource() local
214 if (resource) { in findAndRefScratchResource()
215 fScratchMap.remove(scratchKey, resource); in findAndRefScratchResource()
216 this->refAndMakeResourceMRU(resource); in findAndRefScratchResource()
219 return resource; in findAndRefScratchResource()
222 void GrResourceCache::willRemoveScratchKey(const GrGpuResource* resource) { in willRemoveScratchKey() argument
224 SkASSERT(resource->resourcePriv().getScratchKey().isValid()); in willRemoveScratchKey()
225 if (resource->cacheAccess().isUsableAsScratch()) { in willRemoveScratchKey()
226 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in willRemoveScratchKey()
230 void GrResourceCache::removeUniqueKey(GrGpuResource* resource) { in removeUniqueKey() argument
232 // Someone has a ref to this resource in order to have removed the key. When the ref count in removeUniqueKey()
234 if (resource->getUniqueKey().isValid()) { in removeUniqueKey()
235 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey())); in removeUniqueKey()
236 fUniqueHash.remove(resource->getUniqueKey()); in removeUniqueKey()
238 resource->cacheAccess().removeUniqueKey(); in removeUniqueKey()
239 if (resource->cacheAccess().isUsableAsScratch()) { in removeUniqueKey()
240 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in removeUniqueKey()
243 // Removing a unique key from a kUnbudgetedCacheable resource would make the resource in removeUniqueKey()
244 // require purging. However, the resource must be ref'ed to get here and therefore can't in removeUniqueKey()
246 SkASSERT(!resource->resourcePriv().isPurgeable()); in removeUniqueKey()
250 void GrResourceCache::changeUniqueKey(GrGpuResource* resource, const skgpu::UniqueKey& newKey) { in changeUniqueKey() argument
252 SkASSERT(resource); in changeUniqueKey()
253 SkASSERT(this->isInCache(resource)); in changeUniqueKey()
255 // If another resource has the new key, remove its key then install the key on this resource. in changeUniqueKey()
258 // If the old resource using the key is purgeable and is unreachable, then remove it. in changeUniqueKey()
263 // removeUniqueKey expects an external owner of the resource. in changeUniqueKey()
269 // Remove the entry for this resource if it already has a unique key. in changeUniqueKey()
270 if (resource->getUniqueKey().isValid()) { in changeUniqueKey()
271 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey())); in changeUniqueKey()
272 fUniqueHash.remove(resource->getUniqueKey()); in changeUniqueKey()
273 SkASSERT(nullptr == fUniqueHash.find(resource->getUniqueKey())); in changeUniqueKey()
275 // 'resource' didn't have a valid unique key before so it is switching sides. Remove it in changeUniqueKey()
278 if (resource->cacheAccess().isUsableAsScratch()) { in changeUniqueKey()
279 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in changeUniqueKey()
283 resource->cacheAccess().setUniqueKey(newKey); in changeUniqueKey()
284 fUniqueHash.add(resource); in changeUniqueKey()
286 this->removeUniqueKey(resource); in changeUniqueKey()
292 void GrResourceCache::refAndMakeResourceMRU(GrGpuResource* resource) { in refAndMakeResourceMRU() argument
294 SkASSERT(resource); in refAndMakeResourceMRU()
295 SkASSERT(this->isInCache(resource)); in refAndMakeResourceMRU()
297 if (resource->resourcePriv().isPurgeable()) { in refAndMakeResourceMRU()
299 fPurgeableBytes -= resource->gpuMemorySize(); in refAndMakeResourceMRU()
300 fPurgeableQueue.remove(resource); in refAndMakeResourceMRU()
301 this->addToNonpurgeableArray(resource); in refAndMakeResourceMRU()
302 } else if (!resource->cacheAccess().hasRefOrCommandBufferUsage() && in refAndMakeResourceMRU()
303 resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { in refAndMakeResourceMRU()
307 resource->cacheAccess().ref(); in refAndMakeResourceMRU()
309 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in refAndMakeResourceMRU()
313 void GrResourceCache::notifyARefCntReachedZero(GrGpuResource* resource, in notifyARefCntReachedZero() argument
316 SkASSERT(resource); in notifyARefCntReachedZero()
317 SkASSERT(!resource->wasDestroyed()); in notifyARefCntReachedZero()
318 SkASSERT(this->isInCache(resource)); in notifyARefCntReachedZero()
319 // This resource should always be in the nonpurgeable array when this function is called. It in notifyARefCntReachedZero()
321 SkASSERT(fNonpurgeableResources[*resource->cacheAccess().accessCacheIndex()] == resource); in notifyARefCntReachedZero()
324 if (resource->cacheAccess().isUsableAsScratch()) { in notifyARefCntReachedZero()
325 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in notifyARefCntReachedZero()
329 if (resource->cacheAccess().hasRefOrCommandBufferUsage()) { in notifyARefCntReachedZero()
338 if (resource->resourcePriv().isPurgeable()) { in notifyARefCntReachedZero()
339 fNewlyPurgeableResourceForValidation = resource; in notifyARefCntReachedZero()
342 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in notifyARefCntReachedZero()
345 if (!resource->resourcePriv().isPurgeable() && in notifyARefCntReachedZero()
346 resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { in notifyARefCntReachedZero()
350 if (!resource->resourcePriv().isPurgeable()) { in notifyARefCntReachedZero()
355 this->removeFromNonpurgeableArray(resource); in notifyARefCntReachedZero()
356 fPurgeableQueue.insert(resource); in notifyARefCntReachedZero()
357 resource->cacheAccess().setTimeWhenResourceBecomePurgeable(); in notifyARefCntReachedZero()
358 fPurgeableBytes += resource->gpuMemorySize(); in notifyARefCntReachedZero()
360 bool hasUniqueKey = resource->getUniqueKey().isValid(); in notifyARefCntReachedZero()
362 GrBudgetedType budgetedType = resource->resourcePriv().budgetedType(); in notifyARefCntReachedZero()
365 // Purge the resource immediately if we're over budget in notifyARefCntReachedZero()
366 // Also purge if the resource has neither a valid scratch key nor a unique key. in notifyARefCntReachedZero()
367 bool hasKey = resource->resourcePriv().getScratchKey().isValid() || hasUniqueKey; in notifyARefCntReachedZero()
377 // Check whether this resource could still be used as a scratch resource. in notifyARefCntReachedZero()
378 if (!resource->resourcePriv().refsWrappedObjects() && in notifyARefCntReachedZero()
379 resource->resourcePriv().getScratchKey().isValid()) { in notifyARefCntReachedZero()
380 // We won't purge an existing resource to make room for this one. in notifyARefCntReachedZero()
381 if (this->wouldFit(resource->gpuMemorySize())) { in notifyARefCntReachedZero()
382 resource->resourcePriv().makeBudgeted(); in notifyARefCntReachedZero()
389 resource->cacheAccess().release(); in notifyARefCntReachedZero()
390 // We should at least free this resource, perhaps dependent resources as well. in notifyARefCntReachedZero()
395 void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) { in didChangeBudgetStatus() argument
397 SkASSERT(resource); in didChangeBudgetStatus()
398 SkASSERT(this->isInCache(resource)); in didChangeBudgetStatus()
400 size_t size = resource->gpuMemorySize(); in didChangeBudgetStatus()
402 // resource become purgeable. However, we should never allow that transition. Wrapped in didChangeBudgetStatus()
405 SkDEBUGCODE(bool wasPurgeable = resource->resourcePriv().isPurgeable()); in didChangeBudgetStatus()
406 if (resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { in didChangeBudgetStatus()
413 if (!resource->resourcePriv().isPurgeable() && in didChangeBudgetStatus()
414 !resource->cacheAccess().hasRefOrCommandBufferUsage()) { in didChangeBudgetStatus()
417 if (resource->cacheAccess().isUsableAsScratch()) { in didChangeBudgetStatus()
418 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in didChangeBudgetStatus()
422 SkASSERT(resource->resourcePriv().budgetedType() != GrBudgetedType::kUnbudgetedCacheable); in didChangeBudgetStatus()
425 if (!resource->resourcePriv().isPurgeable() && in didChangeBudgetStatus()
426 !resource->cacheAccess().hasRefOrCommandBufferUsage()) { in didChangeBudgetStatus()
429 if (!resource->cacheAccess().hasRef() && !resource->getUniqueKey().isValid() && in didChangeBudgetStatus()
430 resource->resourcePriv().getScratchKey().isValid()) { in didChangeBudgetStatus()
431 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in didChangeBudgetStatus()
434 SkASSERT(wasPurgeable == resource->resourcePriv().isPurgeable()); in didChangeBudgetStatus()
464 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeAsNeeded() local
465 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeAsNeeded()
466 resource->cacheAccess().release(); in purgeAsNeeded()
475 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeAsNeeded() local
476 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeAsNeeded()
477 resource->cacheAccess().release(); in purgeAsNeeded()
497 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeUnlockedResources() local
500 resource->cacheAccess().timeWhenResourceBecamePurgeable(); in purgeUnlockedResources()
504 // resource is made non-purgeable again. So, at this point all the remaining in purgeUnlockedResources()
510 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
511 resource->cacheAccess().release(); in purgeUnlockedResources()
528 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeUnlockedResources() local
531 resource->cacheAccess().timeWhenResourceBecamePurgeable(); in purgeUnlockedResources()
536 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
537 if (!resource->getUniqueKey().isValid()) { in purgeUnlockedResources()
538 *scratchResources.append() = resource; in purgeUnlockedResources()
565 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeToMakeHeadroom() local
566 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in purgeToMakeHeadroom()
567 projectedBudget -= resource->gpuMemorySize(); in purgeToMakeHeadroom()
585 for (GrGpuResource* resource : resources) { in purgeToMakeHeadroom()
586 resource->cacheAccess().release(); in purgeToMakeHeadroom()
604 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeUnlockedResources() local
605 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
606 if (!resource->getUniqueKey().isValid()) { in purgeUnlockedResources()
607 *scratchResources.append() = resource; in purgeUnlockedResources()
608 scratchByteCount += resource->gpuMemorySize(); in purgeUnlockedResources()
643 void GrResourceCache::addToNonpurgeableArray(GrGpuResource* resource) { in addToNonpurgeableArray() argument
645 *fNonpurgeableResources.append() = resource; in addToNonpurgeableArray()
646 *resource->cacheAccess().accessCacheIndex() = index; in addToNonpurgeableArray()
649 void GrResourceCache::removeFromNonpurgeableArray(GrGpuResource* resource) { in removeFromNonpurgeableArray() argument
650 int* index = resource->cacheAccess().accessCacheIndex(); in removeFromNonpurgeableArray()
654 SkASSERT(fNonpurgeableResources[*index] == resource); in removeFromNonpurgeableArray()
693 // Correct the index in the nonpurgeable array stored on the resource post-sort. in getNextTimestamp()
782 // Reduce the frequency of validations for large resource counts. in validate()
806 void update(GrGpuResource* resource) { in validate()
807 fBytes += resource->gpuMemorySize(); in validate()
809 if (!resource->resourcePriv().isPurgeable()) { in validate()
813 const skgpu::ScratchKey& scratchKey = resource->resourcePriv().getScratchKey(); in validate()
814 const skgpu::UniqueKey& uniqueKey = resource->getUniqueKey(); in validate()
816 if (resource->cacheAccess().isUsableAsScratch()) { in validate()
818 SkASSERT(GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()); in validate()
819 SkASSERT(!resource->cacheAccess().hasRef()); in validate()
822 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); in validate()
824 SkASSERT(GrBudgetedType::kBudgeted != resource->resourcePriv().budgetedType() || in validate()
825 uniqueKey.isValid() || resource->cacheAccess().hasRef()); in validate()
826 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); in validate()
827 SkASSERT(!fScratchMap->has(resource, scratchKey)); in validate()
831 SkASSERT(fUniqueHash->find(uniqueKey) == resource); in validate()
832 SkASSERT(GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType() || in validate()
833 resource->resourcePriv().refsWrappedObjects()); in validate()
836 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in validate()
838 fBudgetedBytes += resource->gpuMemorySize(); in validate()
845 fScratchMap.foreach([&](const GrGpuResource& resource) { in validate() argument
846 SkASSERT(resource.cacheAccess().isUsableAsScratch()); in validate()
902 bool GrResourceCache::isInCache(const GrGpuResource* resource) const { in isInCache()
903 int index = *resource->cacheAccess().accessCacheIndex(); in isInCache()
907 if (index < fPurgeableQueue.count() && fPurgeableQueue.at(index) == resource) { in isInCache()
910 if (index < fNonpurgeableResources.size() && fNonpurgeableResources[index] == resource) { in isInCache()
913 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the cache."); in isInCache()
923 fUniqueHash.foreach([&](const GrGpuResource& resource){ in countUniqueKeysWithTag() argument
924 if (0 == strcmp(tag, resource.getUniqueKey().tag())) { in countUniqueKeysWithTag()