From 2be3fefb6a75298b7175fe53e9707d974ca6acf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=80=9D=E8=BF=9C?= Date: Mon, 18 Aug 2025 14:43:11 +0800 Subject: [PATCH] =?UTF-8?q?vkimage=E7=BB=B4=E6=B5=8Bbugfix=20&&=20?= =?UTF-8?q?=E6=B6=88=E9=99=A4=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周思远 --- include/gpu/vk/GrVulkanTrackerInterface.h | 2 +- .../include/gpu/vk/GrVulkanTrackerInterface.h | 2 +- m133/src/gpu/ganesh/GrDirectContext.cpp | 2 +- m133/src/gpu/ganesh/GrResourceCache.cpp | 6 ++-- m133/src/gpu/ganesh/GrSurfaceProxy.cpp | 2 +- m133/src/gpu/ganesh/vk/GrVkImage.cpp | 27 ++++++++++++---- m133/src/gpu/ganesh/vk/GrVkImage.h | 6 ++-- m133/src/gpu/ganesh/vk/GrVulkanTracker.cpp | 19 +++++++----- src/gpu/GrDirectContext.cpp | 2 +- src/gpu/GrResourceCache.cpp | 8 ++--- src/gpu/GrSurfaceProxy.cpp | 2 +- src/gpu/vk/GrVkImage.cpp | 31 ++++++++++++++----- src/gpu/vk/GrVkImage.h | 6 ++-- src/gpu/vk/GrVulkanTracker.cpp | 19 +++++++----- 14 files changed, 84 insertions(+), 50 deletions(-) diff --git a/include/gpu/vk/GrVulkanTrackerInterface.h b/include/gpu/vk/GrVulkanTrackerInterface.h index 9b123afd7a..c1415add6a 100644 --- a/include/gpu/vk/GrVulkanTrackerInterface.h +++ b/include/gpu/vk/GrVulkanTrackerInterface.h @@ -13,7 +13,7 @@ * limitations under the License. */ -#ifndef GrVulkanTrackerInterface_DEFINED +#ifndef GrVulkanTrackerInterface_DEFINED #define GrVulkanTrackerInterface_DEFINED #include diff --git a/m133/include/gpu/vk/GrVulkanTrackerInterface.h b/m133/include/gpu/vk/GrVulkanTrackerInterface.h index 0fb102cab5..3d7912a283 100644 --- a/m133/include/gpu/vk/GrVulkanTrackerInterface.h +++ b/m133/include/gpu/vk/GrVulkanTrackerInterface.h @@ -13,7 +13,7 @@ * limitations under the License. */ - #ifndef GrVulkanTrackerInterface_DEFINED + #ifndef GrVulkanTrackerInterface_DEFINED #define GrVulkanTrackerInterface_DEFINED #include diff --git a/m133/src/gpu/ganesh/GrDirectContext.cpp b/m133/src/gpu/ganesh/GrDirectContext.cpp index 4417504f78..685ec42097 100644 --- a/m133/src/gpu/ganesh/GrDirectContext.cpp +++ b/m133/src/gpu/ganesh/GrDirectContext.cpp @@ -593,7 +593,7 @@ bool GrDirectContext::supportsDistanceFieldText() const { ////////////////////////////////////////////////////////////////////////////// -void GrDirectContext::dumpAllResource(std::stringstream &dump) const { +void GrDirectContext::dumpAllResource(std::stringstream& dump) const { #ifdef SKIA_DFX_FOR_RECORD_VKIMAGE if (fResourceCache) { fResourceCache->dumpAllResource(dump); diff --git a/m133/src/gpu/ganesh/GrResourceCache.cpp b/m133/src/gpu/ganesh/GrResourceCache.cpp index 0ead5dc7a2..c7c1f25596 100644 --- a/m133/src/gpu/ganesh/GrResourceCache.cpp +++ b/m133/src/gpu/ganesh/GrResourceCache.cpp @@ -1276,12 +1276,12 @@ uint32_t GrResourceCache::getNextTimestamp() { } #ifdef SKIA_DFX_FOR_RECORD_VKIMAGE -void GrResourceCache::dumpAllResource(std::stringstream &dump) const { +void GrResourceCache::dumpAllResource(std::stringstream& dump) const { if (getResourceCount() == 0) { return; } dump << "Purgeable: " << fPurgeableQueue.count() << std::endl; - for (int i = 0; i < fPurgeableQueue.count(); ++i) { + for (size_t i = 0; i < fPurgeableQueue.count(); ++i) { GrGpuResource* resource = fPurgeableQueue.at(i); if (resource == nullptr) { continue; @@ -1292,7 +1292,7 @@ void GrResourceCache::dumpAllResource(std::stringstream &dump) const { resource->dumpVkImageInfo(dump); } dump << "Non-Purgeable: " << fNonpurgeableResources.size() << std::endl; - for (int i = 0; i < fNonpurgeableResources.size(); ++i) { + for (size_t i = 0; i < fNonpurgeableResources.size(); ++i) { GrGpuResource* resource = fNonpurgeableResources[i]; if (resource == nullptr) { continue; diff --git a/m133/src/gpu/ganesh/GrSurfaceProxy.cpp b/m133/src/gpu/ganesh/GrSurfaceProxy.cpp index a98ab0df41..4014eb17ac 100644 --- a/m133/src/gpu/ganesh/GrSurfaceProxy.cpp +++ b/m133/src/gpu/ganesh/GrSurfaceProxy.cpp @@ -151,7 +151,7 @@ GrSurfaceProxy::~GrSurfaceProxy() { #ifdef SKIA_DFX_FOR_RECORD_VKIMAGE struct NodeIdHelper { - explicit inline NodeIdHelper(uint64_t nodeId): initNodeId_(ParallelDebug::GetNodeId()) + explicit inline NodeIdHelper(uint64_t nodeId) : initNodeId_(ParallelDebug::GetNodeId()) { ParallelDebug::RecordNodeId(nodeId); } diff --git a/m133/src/gpu/ganesh/vk/GrVkImage.cpp b/m133/src/gpu/ganesh/vk/GrVkImage.cpp index 35bf14d608..a4a0abe793 100644 --- a/m133/src/gpu/ganesh/vk/GrVkImage.cpp +++ b/m133/src/gpu/ganesh/vk/GrVkImage.cpp @@ -253,6 +253,11 @@ GrVkImage::GrVkImage(GrVkGpu* gpu, #endif , fIsBorrowed(false) { this->init(gpu, false); +#ifdef SKIA_DFX_FOR_RECORD_VKIMAGE + if (ParallelDebug::IsVkImageDfxEnabled() && fResource) { + fResource->fCaller = ParallelDebug::GenerateVkImageInvokeRecord(); + } +#endif this->setRealAlloc(true); // OH ISSUE: set real alloc flag this->registerWithCache(budgeted); } @@ -282,6 +287,11 @@ GrVkImage::GrVkImage(GrVkGpu* gpu, , fTextureView(std::move(textureView)) , fIsBorrowed(GrBackendObjectOwnership::kBorrowed == ownership) { this->init(gpu, forSecondaryCB); +#ifdef SKIA_DFX_FOR_RECORD_VKIMAGE + if (ParallelDebug::IsVkImageDfxEnabled() && fResource) { + fResource->fCaller = ParallelDebug::GenerateVkImageInvokeRecord(); + } +#endif this->registerWithCacheWrapped(cacheable); } @@ -676,7 +686,7 @@ void GrVkImage::dumpVkImageInfo(std::stringstream& dump) const { return; } fResource->dumpVkImageResource(dump); - dump << "Borrowed: " << isBorrowed() << ", " << "ImageSize: " << imageSize << ", "; + dump << "Borrowed: " << isBorrowed() << ", " << "ImageSize: " << imageSize; if (fResource->fCaller == nullptr) { SK_LOGE("GrVkImage::dumpVkImageInfo fCaller nullptr"); } else { @@ -687,12 +697,15 @@ void GrVkImage::dumpVkImageInfo(std::stringstream& dump) const { void GrVkImage::Resource::dumpVkImageResource(std::stringstream& dump) { dump << "VkImage: " << fImage << ", " - << "Memory: " << fAlloc.fMemory << ", " - << "Offset: " << fAlloc.fOffset << ", " - << "Size: " << fAlloc.fSize << ", "; + << "Memory: " << fAlloc.fMemory << ", " + << "Offset: " << fAlloc.fOffset << ", " + << "Size: " << fAlloc.fSize << ", "; } void GrVkImage::Resource::RecordFreeVkImage(bool isBorrowed) const { + if (!ParallelDebug::IsVkImageDfxEnabled()) { + return; + } static const bool isInRenderSevice = IsRenderService(); if (isInRenderSevice) { ParallelDebug::VkImageDestroyRecord::Record(fImage, isBorrowed, fCaller, fAlloc.fMemory); @@ -708,13 +721,15 @@ void GrVkImage::updateNodeId(uint64_t nodeId) { GrVkImage::Resource::~Resource() { #ifdef SKIA_DFX_FOR_RECORD_VKIMAGE - ParallelDebug::DestroyVkImageInvokeRecord(fCaller); + if (ParallelDebug::IsVkImageDfxEnabled()) { + ParallelDebug::DestroyVkImageInvokeRecord(fCaller); + } #endif } void GrVkImage::Resource::freeGPUData() const { #ifdef SKIA_DFX_FOR_RECORD_VKIMAGE - RecordFreeVkImage(true); + RecordFreeVkImage(false); #endif this->invokeReleaseProc(); VK_CALL(fGpu, DestroyImage(fGpu->device(), fImage, nullptr)); diff --git a/m133/src/gpu/ganesh/vk/GrVkImage.h b/m133/src/gpu/ganesh/vk/GrVkImage.h index 59c153e0f6..a3297a60d0 100644 --- a/m133/src/gpu/ganesh/vk/GrVkImage.h +++ b/m133/src/gpu/ganesh/vk/GrVkImage.h @@ -327,9 +327,9 @@ private: #endif #ifdef SKIA_DFX_FOR_RECORD_VKIMAGE - ParallelDebug::VkImageInvokeRecord* fCaller = ParallelDebug::GenerateVkImageInvokeRecord(); - void dumpVkImageResource(std::stringstream& dump); - void RecordFreeVkImage(bool isBorrowed) const; + ParallelDebug::VkImageInvokeRecord* fCaller = nullptr; + void dumpVkImageResource(std::stringstream& dump); + void RecordFreeVkImage(bool isBorrowed) const; #endif #ifdef SK_DEBUG diff --git a/m133/src/gpu/ganesh/vk/GrVulkanTracker.cpp b/m133/src/gpu/ganesh/vk/GrVulkanTracker.cpp index 1ea4a6d1ff..c7a6315dfe 100644 --- a/m133/src/gpu/ganesh/vk/GrVulkanTracker.cpp +++ b/m133/src/gpu/ganesh/vk/GrVulkanTracker.cpp @@ -22,9 +22,9 @@ static thread_local ParallelDebug::VkImageInvokeRecord g_caller; static thread_local std::deque g_delete; -static constexpr size_t DESTROY_RECORD_CAPACITY = 100; +static constexpr size_t DESTROY_RECORD_CAPACITY = 1000; -static inline int64_t GetNanoSecords() +static inline int64_t GetNanoSeconds() { struct timespec ts {}; clock_gettime(CLOCK_REALTIME, &ts); @@ -57,6 +57,9 @@ ParallelDebug::VkImageInvokeRecord* ParallelDebug::GenerateVkImageInvokeRecord() void ParallelDebug::DestroyVkImageInvokeRecord(ParallelDebug::VkImageInvokeRecord* vkImageInvokeRecord) { + if (vkImageInvokeRecord == nullptr) { + return; + } delete vkImageInvokeRecord; } @@ -66,20 +69,20 @@ void ParallelDebug::VkImageInvokeRecord::Dump(std::stringstream& ss) } void ParallelDebug::VkImageDestroyRecord::Record(VkImage image, - bool borrow, - const ParallelDebug::VkImageInvokeRecord* call, - VkDeviceMemory memory) + bool borrow, + const ParallelDebug::VkImageInvokeRecord* call, + VkDeviceMemory memory) { if (call == nullptr) { return; } - g_delete.push_back({image, borrow, *call, memory, GetNanoSecords()}); + g_delete.push_back({image, borrow, *call, memory, GetNanoSeconds()}); if (g_delete.size() > DESTROY_RECORD_CAPACITY) { g_delete.pop_front(); } } -void ParallelDebug::DumpAllDestroyVkImage(std::stringstream &ss) +void ParallelDebug::DumpAllDestroyVkImage(std::stringstream& ss) { for (auto& del : g_delete) { del.Dump(ss); @@ -94,6 +97,6 @@ void ParallelDebug::VkImageDestroyRecord::Dump(std::stringstream& ss) time_t seconds = timeStamp_ / 1000000000LL; localtime_r(&seconds, &timeInfo); std::strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", &timeInfo); - ss << timeStr << "VkImage: " << image_ << ", " << borrowed_ << ", " << memory_ << " "; + ss << timeStr << "VkImage: " << image_ << ", " << "borrowed: " << borrowed_ << ", " << "memory: " << memory_; caller_.Dump(ss); } diff --git a/src/gpu/GrDirectContext.cpp b/src/gpu/GrDirectContext.cpp index e4f9c5ae2b..e89bee956d 100644 --- a/src/gpu/GrDirectContext.cpp +++ b/src/gpu/GrDirectContext.cpp @@ -527,7 +527,7 @@ bool GrDirectContext::supportsDistanceFieldText() const { } ////////////////////////////////////////////////////////////////////////////// -void GrDirectContext::dumpAllResource(std::stringstream &dump) const { +void GrDirectContext::dumpAllResource(std::stringstream& dump) const { #ifdef SKIA_DFX_FOR_RECORD_VKIMAGE if (fResourceCache) { fResourceCache->dumpAllResource(dump); diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index 4f87202f69..b23189ec1e 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -1529,12 +1529,12 @@ uint32_t GrResourceCache::getNextTimestamp() { } #ifdef SKIA_DFX_FOR_RECORD_VKIMAGE -void GrResourceCache::dumpAllResource(std::stringstream &dump) const { +void GrResourceCache::dumpAllResource(std::stringstream& dump) const { if (getResourceCount() == 0) { return; } dump << "Purgeable: " << fPurgeableQueue.count() << std::endl; - for (int i = 0; i < fPurgeableQueue.count(); ++i) { + for (size_t i = 0; i < fPurgeableQueue.count(); ++i) { GrGpuResource* resource = fPurgeableQueue.at(i); if (resource == nullptr) { continue; @@ -1542,11 +1542,10 @@ void GrResourceCache::dumpAllResource(std::stringstream &dump) const { if (strcmp(resource->getResourceType(), "VkImage") != 0) { continue; } - dump << i << " " << resource->getResourceType() << " "; resource->dumpVkImageInfo(dump); } dump << "Non-Purgeable: " << fNonpurgeableResources.count() << std::endl; - for (int i = 0; i < fNonpurgeableResources.count(); ++i) { + for (size_t i = 0; i < fNonpurgeableResources.count(); ++i) { GrGpuResource* resource = fNonpurgeableResources[i]; if (resource == nullptr) { continue; @@ -1554,7 +1553,6 @@ void GrResourceCache::dumpAllResource(std::stringstream &dump) const { if (strcmp(resource->getResourceType(), "VkImage") != 0) { continue; } - dump << i << " " << resource->getResourceType() << " "; resource->dumpVkImageInfo(dump); } #ifdef SK_VULKAN diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp index 04472e2680..d559e0d11a 100644 --- a/src/gpu/GrSurfaceProxy.cpp +++ b/src/gpu/GrSurfaceProxy.cpp @@ -149,7 +149,7 @@ GrSurfaceProxy::~GrSurfaceProxy() { #ifdef SKIA_DFX_FOR_RECORD_VKIMAGE struct NodeIdHelper { - explicit inline NodeIdHelper(uint64_t nodeId): initNodeId_(ParallelDebug::GetNodeId()) + explicit inline NodeIdHelper(uint64_t nodeId) : initNodeId_(ParallelDebug::GetNodeId()) { ParallelDebug::RecordNodeId(nodeId); } diff --git a/src/gpu/vk/GrVkImage.cpp b/src/gpu/vk/GrVkImage.cpp index 2b079f9b8c..96f7da5904 100644 --- a/src/gpu/vk/GrVkImage.cpp +++ b/src/gpu/vk/GrVkImage.cpp @@ -242,6 +242,11 @@ GrVkImage::GrVkImage(GrVkGpu* gpu, #endif , fIsBorrowed(false) { this->init(gpu, false); +#ifdef SKIA_DFX_FOR_RECORD_VKIMAGE + if (ParallelDebug::IsVkImageDfxEnabled() && fResource) { + fResource->fCaller = ParallelDebug::GenerateVkImageInvokeRecord(); + } +#endif this->setRealAlloc(true); // OH ISSUE: set real alloc flag this->registerWithCache(budgeted); } @@ -269,6 +274,11 @@ GrVkImage::GrVkImage(GrVkGpu* gpu, , fTextureView(std::move(textureView)) , fIsBorrowed(GrBackendObjectOwnership::kBorrowed == ownership) { this->init(gpu, forSecondaryCB); +#ifdef SKIA_DFX_FOR_RECORD_VKIMAGE + if (ParallelDebug::IsVkImageDfxEnabled() && fResource) { + fResource->fCaller = ParallelDebug::GenerateVkImageInvokeRecord(); + } +#endif #ifdef SKIA_DFX_FOR_OHOS if (RealAllocConfig::GetRealAllocStatus()) { // OH ISSUE: set real alloc flag @@ -633,7 +643,7 @@ void GrVkImage::dumpVkImageInfo(std::stringstream& dump) const { return; } fResource->dumpVkImageResource(dump); - dump << "Borrowed: " << isBorrowed() << ", " << "ImageSize: " << imageSize << ", "; + dump << "Borrowed: " << isBorrowed() << ", " << "ImageSize: " << imageSize; if (fResource->fCaller == nullptr) { SK_LOGE("GrVkImage::dumpVkImageInfo fCaller nullptr"); } else { @@ -643,13 +653,16 @@ void GrVkImage::dumpVkImageInfo(std::stringstream& dump) const { } void GrVkImage::Resource::dumpVkImageResource(std::stringstream& dump) { - dump << "VkImage: " << fResource->fImage << ", " - << "Memory: " << fResource->fAlloc.fMemory << ", " - << "Offset: " << fResource->fAlloc.fOffset << ", " - << "Size: " << fResource->fAlloc.fSize << ", "; + dump << "VkImage: " << fImage << ", " + << "Memory: " << fAlloc.fMemory << ", " + << "Offset: " << fAlloc.fOffset << ", " + << "Size: " << fAlloc.fSize << ", "; } void GrVkImage::Resource::RecordFreeVkImage(bool isBorrowed) const { + if (!ParallelDebug::IsVkImageDfxEnabled()) { + return; + } static const bool isInRenderSevice = IsRenderService(); if (isInRenderSevice) { ParallelDebug::VkImageDestroyRecord::Record(fImage, isBorrowed, fCaller, fAlloc.fMemory); @@ -665,13 +678,15 @@ void GrVkImage::updateNodeId(uint64_t nodeId) { GrVkImage::Resource::~Resource() { #ifdef SKIA_DFX_FOR_RECORD_VKIMAGE - ParallelDebug::DestroyVkImageInvokeRecord(fCaller); + if (ParallelDebug::IsVkImageDfxEnabled()) { + ParallelDebug::DestroyVkImageInvokeRecord(fCaller); + } #endif } void GrVkImage::Resource::freeGPUData() const { #ifdef SKIA_DFX_FOR_RECORD_VKIMAGE - RecordFreeVkImage(true); + RecordFreeVkImage(false); #endif this->invokeReleaseProc(); @@ -686,7 +701,7 @@ void GrVkImage::Resource::freeGPUData() const { void GrVkImage::BorrowedResource::freeGPUData() const { #ifdef SKIA_DFX_FOR_RECORD_VKIMAGE - RecordFreeVkImage(false); + RecordFreeVkImage(true); #endif this->invokeReleaseProc(); } diff --git a/src/gpu/vk/GrVkImage.h b/src/gpu/vk/GrVkImage.h index c850c23d4f..add105531f 100644 --- a/src/gpu/vk/GrVkImage.h +++ b/src/gpu/vk/GrVkImage.h @@ -310,9 +310,9 @@ private: #endif #ifdef SKIA_DFX_FOR_RECORD_VKIMAGE - ParallelDebug::VkImageInvokeRecord* fCaller = ParallelDebug::GenerateVkImageInvokeRecord(); - void dumpVkImageResource(std::stringstream& dump); - void RecordFreeVkImage(bool isBorrowed) const; + ParallelDebug::VkImageInvokeRecord* fCaller = nullptr; + void dumpVkImageResource(std::stringstream& dump); + void RecordFreeVkImage(bool isBorrowed) const; #endif #ifdef SK_DEBUG const GrManagedResource* asVkImageResource() const override { return this; } diff --git a/src/gpu/vk/GrVulkanTracker.cpp b/src/gpu/vk/GrVulkanTracker.cpp index e13793cf19..ebaed459cb 100644 --- a/src/gpu/vk/GrVulkanTracker.cpp +++ b/src/gpu/vk/GrVulkanTracker.cpp @@ -21,10 +21,10 @@ static thread_local ParallelDebug::VkImageInvokeRecord CALLER_; static thread_local std::deque DELETE_; -static constexpr size_t DESTROY_RECORD_CAPACITY = 100; +static constexpr size_t DESTROY_RECORD_CAPACITY = 1000; static std::atomic count; -static inline int64_t GetNanoSecords() +static inline int64_t GetNanoSeconds() { struct timespec ts {}; clock_gettime(CLOCK_REALTIME, &ts); @@ -57,6 +57,9 @@ ParallelDebug::VkImageInvokeRecord* ParallelDebug::GenerateVkImageInvokeRecord() void ParallelDebug::DestroyVkImageInvokeRecord(ParallelDebug::VkImageInvokeRecord* vkImageInvokeRecord) { + if (vkImageInvokeRecord == nullptr) { + return; + } delete vkImageInvokeRecord; } @@ -66,20 +69,20 @@ void ParallelDebug::VkImageInvokeRecord::Dump(std::stringstream& ss) } void ParallelDebug::VkImageDestroyRecord::Record(VkImage image, - bool borrow, - const ParallelDebug::VkImageInvokeRecord* call, - VkDeviceMemory fMemory) + bool borrow, + const ParallelDebug::VkImageInvokeRecord* call, + VkDeviceMemory fMemory) { if (call == nullptr) { return; } - DELETE_.push_back({image, borrow, *call, fMemory, GetNanoSecords()}); + DELETE_.push_back({image, borrow, *call, fMemory, GetNanoSeconds()}); if (DELETE_.size() > DESTROY_RECORD_CAPACITY) { DELETE_.pop_front(); } } -void ParallelDebug::DumpAllDestroyVkImage(std::stringstream &ss) +void ParallelDebug::DumpAllDestroyVkImage(std::stringstream& ss) { for (auto& del : DELETE_) { del.Dump(ss); @@ -94,7 +97,7 @@ void ParallelDebug::VkImageDestroyRecord::Dump(std::stringstream& ss) time_t seconds = timeStamp / 1000000000LL; localtime_r(&seconds, &timeInfo); std::strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", &timeInfo); - ss << timeStr << "VkImage: " << image_ << ", " << borrowed_ << ", " << memory_ << " "; + ss << timeStr << "VkImage: " << image_ << ", " << "borrowed: " << borrowed_ << ", " << "memory: " << memory_; caller_.Dump(ss); } -- Gitee