From 85912ce27e3913ceee363e81be3f34513122e374 Mon Sep 17 00:00:00 2001 From: xiaoguandao Date: Sun, 22 Sep 2024 17:52:03 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=BC=82=E6=AD=A5=E7=BA=B9=E7=90=86?= =?UTF-8?q?=E9=87=8A=E6=94=BE=E4=BB=A3=E7=A0=81=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoguandao --- src/gpu/vk/GrVkAMDMemoryAllocator.cpp | 2 +- src/gpu/vk/GrVkImage.cpp | 6 ++--- src/gpu/vk/GrVkImage.h | 2 +- src/gpu/vk/GrVkMemoryReclaimer.cpp | 39 ++++++++++++++++++--------- src/gpu/vk/GrVkMemoryReclaimer.h | 31 +++++---------------- 5 files changed, 38 insertions(+), 42 deletions(-) diff --git a/src/gpu/vk/GrVkAMDMemoryAllocator.cpp b/src/gpu/vk/GrVkAMDMemoryAllocator.cpp index caf73c4a66..e8984fe180 100644 --- a/src/gpu/vk/GrVkAMDMemoryAllocator.cpp +++ b/src/gpu/vk/GrVkAMDMemoryAllocator.cpp @@ -74,7 +74,7 @@ sk_sp GrVkAMDMemoryAllocator::Make(VkInstance instance, GR_COPY_FUNCTION_KHR(GetPhysicalDeviceMemoryProperties2); VmaAllocatorCreateInfo info; - info.flags = VMA_ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT; + info.flags = 0; if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || (extensions->hasExtension(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, 1) && extensions->hasExtension(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, 1))) { diff --git a/src/gpu/vk/GrVkImage.cpp b/src/gpu/vk/GrVkImage.cpp index 5d73895c3b..66af12d3bf 100644 --- a/src/gpu/vk/GrVkImage.cpp +++ b/src/gpu/vk/GrVkImage.cpp @@ -206,7 +206,7 @@ sk_sp GrVkImage::MakeWrapped(GrVkGpu* gpu, } // OH ISSUE: Integrate Destroy and Free -void GrVkImage::DestroyAndFreeImageMemory(const GrVkGpu* gpu, const GrVkAlloc& alloc, const GrVkImage& image) +void GrVkImage::DestroyAndFreeImageMemory(const GrVkGpu* gpu, const GrVkAlloc& alloc, const VkImage& image) { VK_CALL(gpu, DestroyImage(gpu->device(), image, nullptr)); GrVkMemory::FreeImageMemory(gpu, alloc); @@ -553,7 +553,7 @@ bool GrVkImage::InitImageInfo(GrVkGpu* gpu, const ImageDesc& imageDesc, GrVkImag } void GrVkImage::DestroyImageInfo(const GrVkGpu* gpu, GrVkImageInfo* info) { - DestroyAndFreeImageMemory(gpu, info->fAlloc, info->fImage) + DestroyAndFreeImageMemory(gpu, info->fAlloc, info->fImage); } GrVkImage::~GrVkImage() { @@ -612,7 +612,7 @@ void GrVkImage::Resource::freeGPUData() const { this->invokeReleaseProc(); // OH ISSUE: asyn memory reclaimer - auto reclaimer = this->getVkGpu()->memoryReclaimer(); + auto reclaimer = fGpu->memoryReclaimer(); if (reclaimer && reclaimer->addMemoryToWaitQueue(fGpu, fAlloc, fImage)) { return; } diff --git a/src/gpu/vk/GrVkImage.h b/src/gpu/vk/GrVkImage.h index f33ccbd9b7..4aa7439828 100644 --- a/src/gpu/vk/GrVkImage.h +++ b/src/gpu/vk/GrVkImage.h @@ -61,7 +61,7 @@ public: bool forSecondaryCB = false); // OH ISSUE: Integrate Destroy and Free - void DestroyAndFreeImageMemory(const GrVkGpu* gpu, const GrVkAlloc& alloc, const GrVkImage& image); + static void DestroyAndFreeImageMemory(const GrVkGpu* gpu, const GrVkAlloc& alloc, const VkImage& image); ~GrVkImage() override; diff --git a/src/gpu/vk/GrVkMemoryReclaimer.cpp b/src/gpu/vk/GrVkMemoryReclaimer.cpp index d40c966d12..c7003aef73 100644 --- a/src/gpu/vk/GrVkMemoryReclaimer.cpp +++ b/src/gpu/vk/GrVkMemoryReclaimer.cpp @@ -15,18 +15,26 @@ #include "src/gpu/vk/GrVkMemoryReclaimer.h" -#include -#include "GrVkBuffer.h" -#include "GrVkCommandBuffer.h" -#include "src/gpu/vk/GrVkGpu.h" -#include "src/gpu/vk/GrVkImageView.h" -#include "src/gpu/vk/GrVkMemory.h" -#include "src/gpu/vk/GrVkBuffer.h" -#include "src/gpu/vk/GrVkTexture.h" -#include "src/gpu/vk/GrVkUtil.h" +#include "include/core/Sklog.h" +#include "include/core/SkExecutor.h" -#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) +#define VK_CALL(GPU, X) GR_VK_CALL((GPU)->vkInterface(), X) + +static SkExecutor& GetThreadPool() +{ + static std::unique_ptr executor = SkExecutor::MakeFIFOThreadPool(1, false); + static auto call_once = []() ->int { + executor->add([]() { + int err = pthread_setname_np(pthread_Self(), "async_memory_reclaimer"); + if (err) { + SK_LOGE("GrVkMemoryReclaimer::GetThreadPool pthread_setname_np, error = %d", err); + } + return 0; + }); + }(); + return *executor; +} bool GrVkMemoryReclaimer::addMemoryToWaitQueue(const GrVkGpu* gpu, const GrVkAlloc& alloc, const VkBuffer& buffer) { @@ -40,7 +48,7 @@ bool GrVkMemoryReclaimer::addMemoryToWaitQueue(const GrVkGpu* gpu, const GrVkAll return true; } -bool GrVkMemoryReclaimer::addMemoryToWaitQueue(const GrVkGpu* gpu, const GrVkAlloc& alloc, GrVkImage& image) +bool GrVkMemoryReclaimer::addMemoryToWaitQueue(const GrVkGpu* gpu, const GrVkAlloc& alloc, const VkImage& image) { if (!fEnabled) { return false; @@ -63,9 +71,9 @@ void GrVkMemoryReclaimer::flushGpuMemoryInWaitQueue() invokeParallelReclaiming(); } -void GrVkMemoryReclaimer::nvokeParallelReclaiming() +void GrVkMemoryReclaimer::invokeParallelReclaiming() { - fExecutor->add([freeQueues {std::move(fWaitQueues)}] { + GetThreadPool().add([freeQueues {std::move(fWaitQueues)}] { for (auto& item : freeQueues) { if (item.fType == ItemType::BUFFER) { GrVkBuffer::DestroyAndFreeBufferMemory(item.fGpu, item.fAlloc, item.fBuffer); @@ -75,3 +83,8 @@ void GrVkMemoryReclaimer::nvokeParallelReclaiming() } }); } + +void GrVkMemoryReclaimer::setGpuMemoryAsyncReclaimerSwitch(bool enabled) +{ + fEnabled = enabled; +} diff --git a/src/gpu/vk/GrVkMemoryReclaimer.h b/src/gpu/vk/GrVkMemoryReclaimer.h index d3f77ed114..24f0d881cd 100644 --- a/src/gpu/vk/GrVkMemoryReclaimer.h +++ b/src/gpu/vk/GrVkMemoryReclaimer.h @@ -16,25 +16,15 @@ #ifndef GrVkMemoryReclaimer_DEFINED #define GrVkMemoryReclaimer_DEFINED -#include "include/core/SkExecutor.h" -#include "include/gpu/vk/GrVkBackendContext.h" #include "include/gpu/vk/GrVkTypes.h" -#include "src/gpu/GrGpu.h" -#include "src/gpu/GrStagingBufferManager.h" -#include "src/gpu/vk/GrVkCaps.h" -#include "src/gpu/vk/GrVkMSAALoadManager.h" -#include "src/gpu/vk/GrVkMemory.h" -#include "src/gpu/vk/GrVkResourceProvider.h" -#include "src/gpu/vk/GrVkSemaphore.h" -#include "src/gpu/vk/GrVkUtil.h" - -class GrVkGpu; +#include "src/gpu/vk/GrVkImage.h" +#include "src/gpu/vk/GrVkBuffer.h" enum class ItemType { BUFFER, IMAGE -} +}; class GrVkMemoryReclaimer { public: @@ -43,18 +33,14 @@ public: GrVkAlloc fAlloc; ItemType fType; union { - GrVkBuffer fBuffer; - GrVkImage fImage; + VkBuffer fBuffer; + VkImage fImage; }; }; - GrVkMemoryReclaimer(): fExecutor(SkExecutor::MakeFIFOThreadPool(1, false)) {} - ~GrVkMemoryReclaimer() = default; - GrVkMemoryReclaimer(const GrVkMemoryReclaimer&) = delete; - GrVkMemoryReclaimer& operator=(const GrVkMemoryReclaimer&) = delete; - void setGpuCacheSuppressWindowSwitch(bool enabled); + void setGpuMemoryAsyncReclaimerSwitch(bool enabled); bool addMemoryToWaitQueue(const GrVkGpu* gpu, const GrVkAlloc& alloc, const VkBuffer& buffer); - bool addMemoryToWaitQueue(const GrVkGpu* gpu, const GrVkAlloc& alloc, const GrVkImage& image); + bool addMemoryToWaitQueue(const GrVkGpu* gpu, const GrVkAlloc& alloc, const VkImage& image); void flushGpuMemoryInWaitQueue(); private: void invokeParallelReclaiming(); @@ -63,9 +49,6 @@ private: const int fMemoryCountThreshold = 50; std::vector fWaitQueues; - - std::unique_ptr fExecutor; - }; #endif -- Gitee From 9aa0352662093dcda27557d96ddd7cbba1d29c44 Mon Sep 17 00:00:00 2001 From: xiaoguandao Date: Sun, 22 Sep 2024 19:26:13 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=BC=82=E6=AD=A5=E7=BA=B9=E7=90=86?= =?UTF-8?q?=E9=87=8A=E6=94=BE=E4=BB=A3=E7=A0=81=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoguandao --- src/gpu/vk/GrVkMemoryReclaimer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gpu/vk/GrVkMemoryReclaimer.cpp b/src/gpu/vk/GrVkMemoryReclaimer.cpp index c7003aef73..683401f8ef 100644 --- a/src/gpu/vk/GrVkMemoryReclaimer.cpp +++ b/src/gpu/vk/GrVkMemoryReclaimer.cpp @@ -16,7 +16,7 @@ #include "src/gpu/vk/GrVkMemoryReclaimer.h" -#include "include/core/Sklog.h" +#include "include/core/SkLog.h" #include "include/core/SkExecutor.h" #define VK_CALL(GPU, X) GR_VK_CALL((GPU)->vkInterface(), X) @@ -26,7 +26,7 @@ static SkExecutor& GetThreadPool() static std::unique_ptr executor = SkExecutor::MakeFIFOThreadPool(1, false); static auto call_once = []() ->int { executor->add([]() { - int err = pthread_setname_np(pthread_Self(), "async_memory_reclaimer"); + int err = pthread_setname_np(pthread_self(), "async_memory_reclaimer"); if (err) { SK_LOGE("GrVkMemoryReclaimer::GetThreadPool pthread_setname_np, error = %d", err); } -- Gitee From c1d5ff35b5e6e28441eb9af7767f0636f4a5b236 Mon Sep 17 00:00:00 2001 From: xiaoguandao Date: Sun, 22 Sep 2024 22:50:23 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=BC=82=E6=AD=A5=E7=BA=B9=E7=90=86?= =?UTF-8?q?=E9=87=8A=E6=94=BE=E4=BB=A3=E7=A0=81=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoguandao --- src/gpu/vk/GrVkMemoryReclaimer.cpp | 17 +++++++---------- src/gpu/vk/GrVkMemoryReclaimer.h | 3 +++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/gpu/vk/GrVkMemoryReclaimer.cpp b/src/gpu/vk/GrVkMemoryReclaimer.cpp index 683401f8ef..c33c9bfc13 100644 --- a/src/gpu/vk/GrVkMemoryReclaimer.cpp +++ b/src/gpu/vk/GrVkMemoryReclaimer.cpp @@ -15,24 +15,21 @@ #include "src/gpu/vk/GrVkMemoryReclaimer.h" - #include "include/core/SkLog.h" -#include "include/core/SkExecutor.h" #define VK_CALL(GPU, X) GR_VK_CALL((GPU)->vkInterface(), X) -static SkExecutor& GetThreadPool() -{ - static std::unique_ptr executor = SkExecutor::MakeFIFOThreadPool(1, false); - static auto call_once = []() ->int { +SkExecutor& GrVkMemoryReclaimer::getThreadPool() { + static std::unique_ptr executor = ({ + auto executor = SkExecutor::MakeFIFOThreadPool(1, false); executor->add([]() { - int err = pthread_setname_np(pthread_self(), "async_memory_reclaimer"); + int err = pthread_setname_np(pthread_self(), "async-reclaimer"); if (err) { SK_LOGE("GrVkMemoryReclaimer::GetThreadPool pthread_setname_np, error = %d", err); } - return 0; }); - }(); + std::move(executor); + }); return *executor; } @@ -73,7 +70,7 @@ void GrVkMemoryReclaimer::flushGpuMemoryInWaitQueue() void GrVkMemoryReclaimer::invokeParallelReclaiming() { - GetThreadPool().add([freeQueues {std::move(fWaitQueues)}] { + getThreadPool().add([freeQueues {std::move(fWaitQueues)}] { for (auto& item : freeQueues) { if (item.fType == ItemType::BUFFER) { GrVkBuffer::DestroyAndFreeBufferMemory(item.fGpu, item.fAlloc, item.fBuffer); diff --git a/src/gpu/vk/GrVkMemoryReclaimer.h b/src/gpu/vk/GrVkMemoryReclaimer.h index 24f0d881cd..d7e014945f 100644 --- a/src/gpu/vk/GrVkMemoryReclaimer.h +++ b/src/gpu/vk/GrVkMemoryReclaimer.h @@ -18,6 +18,8 @@ #include "include/gpu/vk/GrVkTypes.h" +#include "include/core/SkExecutor.h" + #include "src/gpu/vk/GrVkImage.h" #include "src/gpu/vk/GrVkBuffer.h" @@ -38,6 +40,7 @@ public: }; }; + SkExecutor& getThreadPool(); void setGpuMemoryAsyncReclaimerSwitch(bool enabled); bool addMemoryToWaitQueue(const GrVkGpu* gpu, const GrVkAlloc& alloc, const VkBuffer& buffer); bool addMemoryToWaitQueue(const GrVkGpu* gpu, const GrVkAlloc& alloc, const VkImage& image); -- Gitee From a8adc166d6646c8ed25cd871e2d88ed6a22e9152 Mon Sep 17 00:00:00 2001 From: xiaoguandao Date: Sun, 22 Sep 2024 22:52:34 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=BC=82=E6=AD=A5=E7=BA=B9=E7=90=86?= =?UTF-8?q?=E9=87=8A=E6=94=BE=E4=BB=A3=E7=A0=81=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoguandao --- src/gpu/vk/GrVkMemoryReclaimer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gpu/vk/GrVkMemoryReclaimer.cpp b/src/gpu/vk/GrVkMemoryReclaimer.cpp index c33c9bfc13..f81e27bce7 100644 --- a/src/gpu/vk/GrVkMemoryReclaimer.cpp +++ b/src/gpu/vk/GrVkMemoryReclaimer.cpp @@ -19,7 +19,8 @@ #define VK_CALL(GPU, X) GR_VK_CALL((GPU)->vkInterface(), X) -SkExecutor& GrVkMemoryReclaimer::getThreadPool() { +SkExecutor& GrVkMemoryReclaimer::getThreadPool() +{ static std::unique_ptr executor = ({ auto executor = SkExecutor::MakeFIFOThreadPool(1, false); executor->add([]() { -- Gitee From ebdfe5ceac01ae4df5679f190787089b974032ab Mon Sep 17 00:00:00 2001 From: xiaoguandao Date: Mon, 23 Sep 2024 11:33:15 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=BC=82=E6=AD=A5=E7=BA=B9=E7=90=86?= =?UTF-8?q?=E9=87=8A=E6=94=BE=E4=BB=A3=E7=A0=81=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoguandao --- src/gpu/vk/GrVkAMDMemoryAllocator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gpu/vk/GrVkAMDMemoryAllocator.cpp b/src/gpu/vk/GrVkAMDMemoryAllocator.cpp index e8984fe180..ae885c5898 100644 --- a/src/gpu/vk/GrVkAMDMemoryAllocator.cpp +++ b/src/gpu/vk/GrVkAMDMemoryAllocator.cpp @@ -74,7 +74,7 @@ sk_sp GrVkAMDMemoryAllocator::Make(VkInstance instance, GR_COPY_FUNCTION_KHR(GetPhysicalDeviceMemoryProperties2); VmaAllocatorCreateInfo info; - info.flags = 0; + info.flags = 0; // OH ISSUE: enable vma lock protect if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || (extensions->hasExtension(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, 1) && extensions->hasExtension(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, 1))) { -- Gitee