summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-06-04 01:25:01 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-06-04 01:25:01 +0000
commit6088509b52673b767b8c883421e68afa9c4da670 (patch)
tree46dbe001e85bb49e6441cb4fc873debc29582dac /Graphics/GraphicsEngineVulkan
parentImplemented Vulkan memory manager (diff)
downloadDiligentCore-6088509b52673b767b8c883421e68afa9c4da670.tar.gz
DiligentCore-6088509b52673b767b8c883421e68afa9c4da670.zip
Implemented reserved memory size in Vk memory manager
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanMemoryManager.h10
-rw-r--r--Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp2
-rw-r--r--Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp14
3 files changed, 19 insertions, 7 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanMemoryManager.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanMemoryManager.h
index e8679ad9..bbe6b91e 100644
--- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanMemoryManager.h
+++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanMemoryManager.h
@@ -138,13 +138,17 @@ public:
const VulkanPhysicalDevice& PhysicalDevice,
Diligent::IMemoryAllocator& Allocator,
VkDeviceSize DeviceLocalPageSize,
- VkDeviceSize HostVisiblePageSize) :
+ VkDeviceSize HostVisiblePageSize,
+ VkDeviceSize DeviceLocalReserveSize,
+ VkDeviceSize HostVisibleReserveSize) :
m_MgrName (std::move(MgrName)),
m_LogicalDevice (LogicalDevice),
m_PhysicalDevice (PhysicalDevice),
m_Allocator (Allocator),
m_DeviceLocalPageSize(DeviceLocalPageSize),
- m_HostVisiblePageSize(HostVisiblePageSize)
+ m_HostVisiblePageSize(HostVisiblePageSize),
+ m_DeviceLocalReserveSize(DeviceLocalReserveSize),
+ m_HostVisibleReserveSize(HostVisibleReserveSize)
{}
~VulkanMemoryManager();
@@ -171,6 +175,8 @@ private:
std::mutex m_Mutex;
const VkDeviceSize m_DeviceLocalPageSize;
const VkDeviceSize m_HostVisiblePageSize;
+ const VkDeviceSize m_DeviceLocalReserveSize;
+ const VkDeviceSize m_HostVisibleReserveSize;
void OnFreeAllocation(VkDeviceSize Size, bool IsHostVisble);
diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp
index 60b3df85..f69b41dc 100644
--- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp
@@ -61,7 +61,7 @@ RenderDeviceVkImpl :: RenderDeviceVkImpl(IReferenceCounters *pRefCounters,
m_UploadHeaps(STD_ALLOCATOR_RAW_MEM(UploadHeapPoolElemType, GetRawAllocator(), "Allocator for vector<unique_ptr<VulkanDynamicHeap>>")),
m_FramebufferCache(*this),
m_TransientCmdPoolMgr(*m_LogicalVkDevice, pCmdQueue->GetQueueFamilyIndex(), VK_COMMAND_POOL_CREATE_TRANSIENT_BIT),
- m_MemoryMgr("Global resource memory manager", *m_LogicalVkDevice, *m_PhysicalDevice, GetRawAllocator(), CreationAttribs.DeviceLocalMemoryPageSize, CreationAttribs.HostVisibleMemoryPageSize )
+ m_MemoryMgr("Global resource memory manager", *m_LogicalVkDevice, *m_PhysicalDevice, GetRawAllocator(), CreationAttribs.DeviceLocalMemoryPageSize, CreationAttribs.HostVisibleMemoryPageSize, CreationAttribs.DeviceLocalMemoryReserveSize, CreationAttribs.HostVisibleMemoryReserveSize)
{
m_DeviceCaps.DevType = DeviceType::Vulkan;
m_DeviceCaps.MajorVersion = 1;
diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp
index 92cf3cea..c440d908 100644
--- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp
@@ -165,16 +165,20 @@ VulkanMemoryAllocation VulkanMemoryManager::Allocate(const VkMemoryRequirements&
void VulkanMemoryManager::ShrinkMemory()
{
std::lock_guard<std::mutex> Lock(m_Mutex);
+ if(m_CurrAllocatedSize[0] <= m_DeviceLocalReserveSize && m_CurrAllocatedSize[1] <= m_HostVisibleReserveSize)
+ return;
+
auto it = m_Pages.begin();
while(it != m_Pages.end())
{
auto curr_it = it;
++it;
auto& Page = curr_it->second;
- if(Page.IsEmpty())
+ bool IsHostVisible = Page.GetCPUMemory() != nullptr;
+ auto ReserveSize = IsHostVisible ? m_HostVisibleReserveSize : m_DeviceLocalReserveSize;
+ if(Page.IsEmpty() && m_CurrAllocatedSize[IsHostVisible ? 1 : 0] > ReserveSize)
{
auto PageSize = Page.GetPageSize();
- bool IsHostVisible = Page.GetCPUMemory() != nullptr;
m_CurrAllocatedSize[IsHostVisible ? 1 : 0] -= PageSize;
LOG_INFO_MESSAGE("VulkanMemoryManager '", m_MgrName, "': destroying ", (IsHostVisible ? "host-visible" : "device-local"), " page. Size: ",
std::fixed, std::setprecision(2), PageSize / double{1 << 20},
@@ -198,8 +202,10 @@ VulkanMemoryManager::~VulkanMemoryManager()
"\n Peak used/peak allocated host-visible memory size: ",
std::fixed, std::setprecision(2), m_PeakUsedSize[1] / double{1 << 20}, "/",
std::fixed, std::setprecision(2), m_PeakAllocatedSize[1] / double{1 << 20}, " MB.");
- VERIFY(m_Pages.empty(), "Not all pages have been released");
- VERIFY_EXPR(m_CurrAllocatedSize[0] == 0 && m_CurrAllocatedSize[1] == 0 && m_CurrUsedSize[0] == 0 && m_CurrUsedSize[1] == 0);
+
+ for(auto it=m_Pages.begin(); it != m_Pages.end(); ++it )
+ VERIFY(it->second.IsEmpty(), "The page contains outstanding allocations");
+ VERIFY(m_CurrUsedSize[0] == 0 && m_CurrUsedSize[1] == 0, "Not all allocations have been released");
}
}