Lines Matching full:resource
198 auto resource = fPurgeableQueue.at(i); in cacheInfoPurgeableQueue() local
199 auto resourceTag = resource->getResourceTag(); in cacheInfoPurgeableQueue()
201 …updatePurgeableWidMap(resource, purgNameInfoWid, purgSizeInfoWid, purgPidInfoWid, purgCountInfoWid… in cacheInfoPurgeableQueue()
203 updatePurgeableFidMap(resource, purgNameInfoFid, purgSizeInfoFid, purgCountInfoFid); in cacheInfoPurgeableQueue()
205 updatePurgeablePidMap(resource, purgNameInfoPid, purgSizeInfoPid, purgCountInfoPid); in cacheInfoPurgeableQueue()
209 purgSizeUnknown += resource->gpuMemorySize(); in cacheInfoPurgeableQueue()
249 auto resource = fNonpurgeableResources[i]; in cacheInfoNoPurgeableQueue() local
250 if (resource == nullptr) { in cacheInfoNoPurgeableQueue()
253 auto resourceTag = resource->getResourceTag(); in cacheInfoNoPurgeableQueue()
255 …updatePurgeableWidMap(resource, noPurgNameInfoWid, noPurgSizeInfoWid, noPurgPidInfoWid, noPurgCoun… in cacheInfoNoPurgeableQueue()
257 … updatePurgeableFidMap(resource, noPurgNameInfoFid, noPurgSizeInfoFid, noPurgCountInfoFid); in cacheInfoNoPurgeableQueue()
259 … updatePurgeablePidMap(resource, noPurgNameInfoPid, noPurgSizeInfoPid, noPurgCountInfoPid); in cacheInfoNoPurgeableQueue()
263 noPurgSizeUnknown += resource->gpuMemorySize(); in cacheInfoNoPurgeableQueue()
284 void GrResourceCache::updatePurgeableWidMap(GrGpuResource* resource, in updatePurgeableWidMap() argument
290 auto resourceTag = resource->getResourceTag(); in updatePurgeableWidMap()
293 sizeInfoWid[resourceTag.fWid] = it->second + resource->gpuMemorySize(); in updatePurgeableWidMap()
296 sizeInfoWid[resourceTag.fWid] = resource->gpuMemorySize(); in updatePurgeableWidMap()
303 void GrResourceCache::updatePurgeablePidMap(GrGpuResource* resource, in updatePurgeablePidMap() argument
308 auto resourceTag = resource->getResourceTag(); in updatePurgeablePidMap()
311 sizeInfoPid[resourceTag.fPid] = it->second + resource->gpuMemorySize(); in updatePurgeablePidMap()
314 sizeInfoPid[resourceTag.fPid] = resource->gpuMemorySize(); in updatePurgeablePidMap()
320 void GrResourceCache::updatePurgeableFidMap(GrGpuResource* resource, in updatePurgeableFidMap() argument
325 auto resourceTag = resource->getResourceTag(); in updatePurgeableFidMap()
328 sizeInfoFid[resourceTag.fFid] = it->second + resource->gpuMemorySize(); in updatePurgeableFidMap()
331 sizeInfoFid[resourceTag.fFid] = resource->gpuMemorySize(); in updatePurgeableFidMap()
396 void GrResourceCache::insertResource(GrGpuResource* resource) in insertResource() argument
399 SkASSERT(resource); in insertResource()
400 SkASSERT(!this->isInCache(resource)); in insertResource()
401 SkASSERT(!resource->wasDestroyed()); in insertResource()
402 SkASSERT(!resource->resourcePriv().isPurgeable()); in insertResource()
406 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in insertResource()
408 this->addToNonpurgeableArray(resource); in insertResource()
410 size_t size = resource->gpuMemorySize(); in insertResource()
415 auto pid = resource->getResourceTag().fPid; in insertResource()
416 if (pid && resource->isRealAlloc()) { in insertResource()
423 SkDebugf("OHOS resource overflow! pid[%{public}d], size[%{public}zu]", pid, pidSize); in insertResource()
425 … HITRACE_OHOS_NAME_FMT_ALWAYS("OHOS gpu resource overflow: pid(%u), size:(%u)", pid, pidSize); in insertResource()
434 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in insertResource()
444 SkASSERT(!resource->cacheAccess().isUsableAsScratch()); in insertResource()
465 void GrResourceCache::removeResource(GrGpuResource* resource) { in removeResource() argument
468 SkASSERT(this->isInCache(resource)); in removeResource()
470 size_t size = resource->gpuMemorySize(); in removeResource()
471 if (resource->resourcePriv().isPurgeable()) { in removeResource()
472 fPurgeableQueue.remove(resource); in removeResource()
475 this->removeFromNonpurgeableArray(resource); in removeResource()
482 auto pid = resource->getResourceTag().fPid; in removeResource()
483 if (pid && resource->isRealAlloc()) { in removeResource()
492 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in removeResource()
499 if (resource->cacheAccess().isUsableAsScratch()) { in removeResource()
500 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in removeResource()
502 if (resource->getUniqueKey().isValid()) { in removeResource()
503 fUniqueHash.remove(resource->getUniqueKey()); in removeResource()
577 GrGpuResource* resource = fNonpurgeableResources[i]; in releaseByTag() local
578 if (tag.filter(resource->getResourceTag())) { in releaseByTag()
579 recycleVector.emplace_back(resource); in releaseByTag()
580 if (resource->getUniqueKey().isValid()) { in releaseByTag()
581 fProxyProvider->processInvalidUniqueKey(resource->getUniqueKey(), nullptr, in releaseByTag()
588 GrGpuResource* resource = fPurgeableQueue.at(i); in releaseByTag() local
589 if (tag.filter(resource->getResourceTag())) { in releaseByTag()
590 recycleVector.emplace_back(resource); in releaseByTag()
591 if (resource->getUniqueKey().isValid()) { in releaseByTag()
592 fProxyProvider->processInvalidUniqueKey(resource->getUniqueKey(), nullptr, in releaseByTag()
598 for (auto resource : recycleVector) { in releaseByTag() local
599 SkASSERT(!resource->wasDestroyed()); in releaseByTag()
600 resource->cacheAccess().release(); in releaseByTag()
658 // OH ISSUE: change the fbyte when the resource tag changes.
677 void GrResourceCache::refResource(GrGpuResource* resource) { in refResource() argument
678 SkASSERT(resource); in refResource()
679 SkASSERT(resource->getContext()->priv().getResourceCache() == this); in refResource()
680 if (resource->cacheAccess().hasRef()) { in refResource()
681 resource->ref(); in refResource()
683 this->refAndMakeResourceMRU(resource); in refResource()
691 GrGpuResource* resource = fScratchMap.find(scratchKey); in findAndRefScratchResource() local
692 if (resource) { in findAndRefScratchResource()
693 fScratchMap.remove(scratchKey, resource); in findAndRefScratchResource()
694 this->refAndMakeResourceMRU(resource); in findAndRefScratchResource()
697 return resource; in findAndRefScratchResource()
700 void GrResourceCache::willRemoveScratchKey(const GrGpuResource* resource) { in willRemoveScratchKey() argument
702 SkASSERT(resource->resourcePriv().getScratchKey().isValid()); in willRemoveScratchKey()
703 if (resource->cacheAccess().isUsableAsScratch()) { in willRemoveScratchKey()
704 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in willRemoveScratchKey()
708 void GrResourceCache::removeUniqueKey(GrGpuResource* resource) { in removeUniqueKey() argument
710 // Someone has a ref to this resource in order to have removed the key. When the ref count in removeUniqueKey()
712 if (resource->getUniqueKey().isValid()) { in removeUniqueKey()
713 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey())); in removeUniqueKey()
714 fUniqueHash.remove(resource->getUniqueKey()); in removeUniqueKey()
716 resource->cacheAccess().removeUniqueKey(); in removeUniqueKey()
717 if (resource->cacheAccess().isUsableAsScratch()) { in removeUniqueKey()
718 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in removeUniqueKey()
721 // Removing a unique key from a kUnbudgetedCacheable resource would make the resource in removeUniqueKey()
722 // require purging. However, the resource must be ref'ed to get here and therefore can't in removeUniqueKey()
724 SkASSERT(!resource->resourcePriv().isPurgeable()); in removeUniqueKey()
728 void GrResourceCache::changeUniqueKey(GrGpuResource* resource, const skgpu::UniqueKey& newKey) { in changeUniqueKey() argument
730 SkASSERT(resource); in changeUniqueKey()
731 SkASSERT(this->isInCache(resource)); in changeUniqueKey()
733 // If another resource has the new key, remove its key then install the key on this resource. in changeUniqueKey()
736 // If the old resource using the key is purgeable and is unreachable, then remove it. in changeUniqueKey()
741 // removeUniqueKey expects an external owner of the resource. in changeUniqueKey()
747 // Remove the entry for this resource if it already has a unique key. in changeUniqueKey()
748 if (resource->getUniqueKey().isValid()) { in changeUniqueKey()
749 SkASSERT(resource == fUniqueHash.find(resource->getUniqueKey())); in changeUniqueKey()
750 fUniqueHash.remove(resource->getUniqueKey()); in changeUniqueKey()
751 SkASSERT(nullptr == fUniqueHash.find(resource->getUniqueKey())); in changeUniqueKey()
753 // 'resource' didn't have a valid unique key before so it is switching sides. Remove it in changeUniqueKey()
756 if (resource->cacheAccess().isUsableAsScratch()) { in changeUniqueKey()
757 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in changeUniqueKey()
761 resource->cacheAccess().setUniqueKey(newKey); in changeUniqueKey()
762 fUniqueHash.add(resource); in changeUniqueKey()
764 this->removeUniqueKey(resource); in changeUniqueKey()
770 void GrResourceCache::refAndMakeResourceMRU(GrGpuResource* resource) { in refAndMakeResourceMRU() argument
772 SkASSERT(resource); in refAndMakeResourceMRU()
773 SkASSERT(this->isInCache(resource)); in refAndMakeResourceMRU()
775 if (resource->resourcePriv().isPurgeable()) { in refAndMakeResourceMRU()
777 fPurgeableBytes -= resource->gpuMemorySize(); in refAndMakeResourceMRU()
778 fPurgeableQueue.remove(resource); in refAndMakeResourceMRU()
779 this->addToNonpurgeableArray(resource); in refAndMakeResourceMRU()
780 } else if (!resource->cacheAccess().hasRefOrCommandBufferUsage() && in refAndMakeResourceMRU()
781 resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { in refAndMakeResourceMRU()
785 resource->cacheAccess().ref(); in refAndMakeResourceMRU()
787 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in refAndMakeResourceMRU()
791 void GrResourceCache::notifyARefCntReachedZero(GrGpuResource* resource, in notifyARefCntReachedZero() argument
794 SkASSERT(resource); in notifyARefCntReachedZero()
795 SkASSERT(!resource->wasDestroyed()); in notifyARefCntReachedZero()
796 SkASSERT(this->isInCache(resource)); in notifyARefCntReachedZero()
797 // This resource should always be in the nonpurgeable array when this function is called. It in notifyARefCntReachedZero()
799 SkASSERT(fNonpurgeableResources[*resource->cacheAccess().accessCacheIndex()] == resource); in notifyARefCntReachedZero()
802 if (resource->cacheAccess().isUsableAsScratch()) { in notifyARefCntReachedZero()
803 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in notifyARefCntReachedZero()
807 if (resource->cacheAccess().hasRefOrCommandBufferUsage()) { in notifyARefCntReachedZero()
816 if (resource->resourcePriv().isPurgeable()) { in notifyARefCntReachedZero()
817 fNewlyPurgeableResourceForValidation = resource; in notifyARefCntReachedZero()
820 resource->cacheAccess().setTimestamp(this->getNextTimestamp()); in notifyARefCntReachedZero()
823 if (!resource->resourcePriv().isPurgeable() && in notifyARefCntReachedZero()
824 resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { in notifyARefCntReachedZero()
828 if (!resource->resourcePriv().isPurgeable()) { in notifyARefCntReachedZero()
833 this->removeFromNonpurgeableArray(resource); in notifyARefCntReachedZero()
834 fPurgeableQueue.insert(resource); in notifyARefCntReachedZero()
835 resource->cacheAccess().setTimeWhenResourceBecomePurgeable(); in notifyARefCntReachedZero()
836 fPurgeableBytes += resource->gpuMemorySize(); in notifyARefCntReachedZero()
838 bool hasUniqueKey = resource->getUniqueKey().isValid(); in notifyARefCntReachedZero()
840 GrBudgetedType budgetedType = resource->resourcePriv().budgetedType(); in notifyARefCntReachedZero()
843 // Purge the resource immediately if we're over budget in notifyARefCntReachedZero()
844 // Also purge if the resource has neither a valid scratch key nor a unique key. in notifyARefCntReachedZero()
845 bool hasKey = resource->resourcePriv().getScratchKey().isValid() || hasUniqueKey; in notifyARefCntReachedZero()
855 // Check whether this resource could still be used as a scratch resource. in notifyARefCntReachedZero()
856 if (!resource->resourcePriv().refsWrappedObjects() && in notifyARefCntReachedZero()
857 resource->resourcePriv().getScratchKey().isValid()) { in notifyARefCntReachedZero()
858 // We won't purge an existing resource to make room for this one. in notifyARefCntReachedZero()
859 if (this->wouldFit(resource->gpuMemorySize())) { in notifyARefCntReachedZero()
860 resource->resourcePriv().makeBudgeted(); in notifyARefCntReachedZero()
867 resource->cacheAccess().release(); in notifyARefCntReachedZero()
868 // We should at least free this resource, perhaps dependent resources as well. in notifyARefCntReachedZero()
873 void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) { in didChangeBudgetStatus() argument
875 SkASSERT(resource); in didChangeBudgetStatus()
876 SkASSERT(this->isInCache(resource)); in didChangeBudgetStatus()
878 size_t size = resource->gpuMemorySize(); in didChangeBudgetStatus()
880 // resource become purgeable. However, we should never allow that transition. Wrapped in didChangeBudgetStatus()
883 SkDEBUGCODE(bool wasPurgeable = resource->resourcePriv().isPurgeable()); in didChangeBudgetStatus()
884 if (resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { in didChangeBudgetStatus()
891 if (!resource->resourcePriv().isPurgeable() && in didChangeBudgetStatus()
892 !resource->cacheAccess().hasRefOrCommandBufferUsage()) { in didChangeBudgetStatus()
895 if (resource->cacheAccess().isUsableAsScratch()) { in didChangeBudgetStatus()
896 fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); in didChangeBudgetStatus()
900 SkASSERT(resource->resourcePriv().budgetedType() != GrBudgetedType::kUnbudgetedCacheable); in didChangeBudgetStatus()
902 GrPerfMonitorReporter::GetInstance().recordTextureCache(resource->getResourceTag().fName); in didChangeBudgetStatus()
906 if (!resource->resourcePriv().isPurgeable() && in didChangeBudgetStatus()
907 !resource->cacheAccess().hasRefOrCommandBufferUsage()) { in didChangeBudgetStatus()
910 if (!resource->cacheAccess().hasRef() && !resource->getUniqueKey().isValid() && in didChangeBudgetStatus()
911 resource->resourcePriv().getScratchKey().isValid()) { in didChangeBudgetStatus()
912 fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); in didChangeBudgetStatus()
915 SkASSERT(wasPurgeable == resource->resourcePriv().isPurgeable()); in didChangeBudgetStatus()
945 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeAsNeeded() local
946 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeAsNeeded()
947 resource->cacheAccess().release(); in purgeAsNeeded()
956 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeAsNeeded() local
957 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeAsNeeded()
958 resource->cacheAccess().release(); in purgeAsNeeded()
982 GrGpuResource* resource = fPurgeableQueue.peek(); in purgeUnlockedResources() local
985 resource->cacheAccess().timeWhenResourceBecamePurgeable(); in purgeUnlockedResources()
989 // resource is made non-purgeable again. So, at this point all the remaining in purgeUnlockedResources()
995 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
996 resource->cacheAccess().release(); in purgeUnlockedResources()
1016 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeUnlockedResources() local
1019 resource->cacheAccess().timeWhenResourceBecamePurgeable(); in purgeUnlockedResources()
1024 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
1025 if (!resource->getUniqueKey().isValid()) { in purgeUnlockedResources()
1026 *scratchResources.append() = resource; in purgeUnlockedResources()
1056 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeUnlockedResourcesByPid() local
1057 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResourcesByPid()
1058 if (exitedPidSet.count(resource->getResourceTag().fPid)) { in purgeUnlockedResourcesByPid()
1059 *exitPidResources.append() = resource; in purgeUnlockedResourcesByPid()
1060 } else if (!resource->getUniqueKey().isValid()) { in purgeUnlockedResourcesByPid()
1061 *scratchResources.append() = resource; in purgeUnlockedResourcesByPid()
1065 //Delete the exited pid and scatch resource. This must be done as a separate pass in purgeUnlockedResourcesByPid()
1091 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeUnlockedResourcesByTag() local
1092 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResourcesByTag()
1093 …if (tag.filter(resource->getResourceTag()) && (!scratchResourcesOnly || !resource->getUniqueKey().… in purgeUnlockedResourcesByTag()
1094 *scratchResources.append() = resource; in purgeUnlockedResourcesByTag()
1098 //Delete the scatch resource. This must be done as a separate pass in purgeUnlockedResourcesByTag()
1120 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeToMakeHeadroom() local
1121 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in purgeToMakeHeadroom()
1122 projectedBudget -= resource->gpuMemorySize(); in purgeToMakeHeadroom()
1140 for (GrGpuResource* resource : resources) { in purgeToMakeHeadroom()
1141 resource->cacheAccess().release(); in purgeToMakeHeadroom()
1159 GrGpuResource* resource = fPurgeableQueue.at(i); in purgeUnlockedResources() local
1160 SkASSERT(resource->resourcePriv().isPurgeable()); in purgeUnlockedResources()
1161 if (!resource->getUniqueKey().isValid()) { in purgeUnlockedResources()
1162 *scratchResources.append() = resource; in purgeUnlockedResources()
1163 scratchByteCount += resource->gpuMemorySize(); in purgeUnlockedResources()
1198 void GrResourceCache::addToNonpurgeableArray(GrGpuResource* resource) { in addToNonpurgeableArray() argument
1200 *fNonpurgeableResources.append() = resource; in addToNonpurgeableArray()
1201 *resource->cacheAccess().accessCacheIndex() = index; in addToNonpurgeableArray()
1204 void GrResourceCache::removeFromNonpurgeableArray(GrGpuResource* resource) { in removeFromNonpurgeableArray() argument
1205 int* index = resource->cacheAccess().accessCacheIndex(); in removeFromNonpurgeableArray()
1209 SkASSERT(fNonpurgeableResources[*index] == resource); in removeFromNonpurgeableArray()
1248 // Correct the index in the nonpurgeable array stored on the resource post-sort. in getNextTimestamp()
1285 GrGpuResource* resource = fPurgeableQueue.at(i); in dumpAllResource() local
1286 if (resource == nullptr) { in dumpAllResource()
1289 if (strcmp(resource->getResourceType(), "VkImage") != 0) { in dumpAllResource()
1292 resource->dumpVkImageInfo(dump); in dumpAllResource()
1296 GrGpuResource* resource = fNonpurgeableResources[i]; in dumpAllResource() local
1297 if (resource == nullptr) { in dumpAllResource()
1300 if (strcmp(resource->getResourceType(), "VkImage") != 0) { in dumpAllResource()
1303 resource->dumpVkImageInfo(dump); in dumpAllResource()
1384 // Reduce the frequency of validations for large resource counts. in validate()
1408 void update(GrGpuResource* resource) { in validate()
1409 fBytes += resource->gpuMemorySize(); in validate()
1411 if (!resource->resourcePriv().isPurgeable()) { in validate()
1415 const skgpu::ScratchKey& scratchKey = resource->resourcePriv().getScratchKey(); in validate()
1416 const skgpu::UniqueKey& uniqueKey = resource->getUniqueKey(); in validate()
1418 if (resource->cacheAccess().isUsableAsScratch()) { in validate()
1420 SkASSERT(GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()); in validate()
1421 SkASSERT(!resource->cacheAccess().hasRef()); in validate()
1424 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); in validate()
1426 SkASSERT(GrBudgetedType::kBudgeted != resource->resourcePriv().budgetedType() || in validate()
1427 uniqueKey.isValid() || resource->cacheAccess().hasRef()); in validate()
1428 SkASSERT(!resource->resourcePriv().refsWrappedObjects()); in validate()
1429 SkASSERT(!fScratchMap->has(resource, scratchKey)); in validate()
1433 SkASSERT(fUniqueHash->find(uniqueKey) == resource); in validate()
1434 SkASSERT(GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType() || in validate()
1435 resource->resourcePriv().refsWrappedObjects()); in validate()
1438 if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { in validate()
1440 fBudgetedBytes += resource->gpuMemorySize(); in validate()
1447 fScratchMap.foreach([&](const GrGpuResource& resource) { in validate() argument
1448 SkASSERT(resource.cacheAccess().isUsableAsScratch()); in validate()
1504 bool GrResourceCache::isInCache(const GrGpuResource* resource) const { in isInCache()
1505 int index = *resource->cacheAccess().accessCacheIndex(); in isInCache()
1509 if (index < fPurgeableQueue.count() && fPurgeableQueue.at(index) == resource) { in isInCache()
1512 if (index < fNonpurgeableResources.size() && fNonpurgeableResources[index] == resource) { in isInCache()
1515 SkDEBUGFAIL("Resource index should be -1 or the resource should be in the cache."); in isInCache()
1525 fUniqueHash.foreach([&](const GrGpuResource& resource){ in countUniqueKeysWithTag() argument
1526 if (0 == strcmp(tag, resource.getUniqueKey().tag())) { in countUniqueKeysWithTag()