diff --git a/src/gpu/vk/GrVkAMDMemoryAllocator.cpp b/src/gpu/vk/GrVkAMDMemoryAllocator.cpp index caf73c4a668f8010a3d4769f456d542ec98a710f..ae885c5898e5a8ae1f28a555399c9c753883cbd2 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; // 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))) { diff --git a/src/gpu/vk/GrVkImage.cpp b/src/gpu/vk/GrVkImage.cpp index 5d73895c3b76d11c100e2c4a8582005485bdb4c4..66af12d3bfde10f789d2c70f6856e9fa1f1903c2 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 f33ccbd9b7a148341675e60815f65444499f0295..4aa743982891494488888fcab4c433f8cce18a4c 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 d40c966d12584a90149251dc9b30323318714d27..f81e27bce76de1d32bc534d64cc2f37a35d1d9a1 100644 --- a/src/gpu/vk/GrVkMemoryReclaimer.cpp +++ b/src/gpu/vk/GrVkMemoryReclaimer.cpp @@ -15,18 +15,24 @@ #include "src/gpu/vk/GrVkMemoryReclaimer.h" -#include +#include "include/core/SkLog.h" -#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" +#define VK_CALL(GPU, X) GR_VK_CALL((GPU)->vkInterface(), X) -#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) +SkExecutor& GrVkMemoryReclaimer::getThreadPool() +{ + static std::unique_ptr executor = ({ + auto executor = SkExecutor::MakeFIFOThreadPool(1, false); + executor->add([]() { + int err = pthread_setname_np(pthread_self(), "async-reclaimer"); + if (err) { + SK_LOGE("GrVkMemoryReclaimer::GetThreadPool pthread_setname_np, error = %d", err); + } + }); + std::move(executor); + }); + return *executor; +} bool GrVkMemoryReclaimer::addMemoryToWaitQueue(const GrVkGpu* gpu, const GrVkAlloc& alloc, const VkBuffer& buffer) { @@ -40,7 +46,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 +69,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 +81,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 d3f77ed11477b0160297785cf94dc027572eae2c..d7e014945f84beda1d584641d5aecacaeb95c57a 100644 --- a/src/gpu/vk/GrVkMemoryReclaimer.h +++ b/src/gpu/vk/GrVkMemoryReclaimer.h @@ -16,25 +16,17 @@ #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" +#include "include/core/SkExecutor.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 +35,15 @@ 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); + 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 GrVkImage& image); + bool addMemoryToWaitQueue(const GrVkGpu* gpu, const GrVkAlloc& alloc, const VkImage& image); void flushGpuMemoryInWaitQueue(); private: void invokeParallelReclaiming(); @@ -63,9 +52,6 @@ private: const int fMemoryCountThreshold = 50; std::vector fWaitQueues; - - std::unique_ptr fExecutor; - }; #endif