summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-10-06 23:03:25 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-10-06 23:03:25 +0000
commit41c249a537f8f793ec7193c0d70c5e58599d63d7 (patch)
treeb7711fa09412ad2fbdb9914132eba02646b11965 /Graphics/GraphicsEngineVulkan
parentSome mostly cosmetic code changes + better reporting of dynamic descriptor al... (diff)
downloadDiligentCore-41c249a537f8f793ec7193c0d70c5e58599d63d7.tar.gz
DiligentCore-41c249a537f8f793ec7193c0d70c5e58599d63d7.zip
Added VariableSizeAllocationsManager::Allocation::IsValid() method for clearer implementation
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/VulkanDynamicHeap.h5
-rw-r--r--Graphics/GraphicsEngineVulkan/src/VulkanDynamicHeap.cpp16
-rw-r--r--Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp2
3 files changed, 11 insertions, 12 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanDynamicHeap.h b/Graphics/GraphicsEngineVulkan/include/VulkanDynamicHeap.h
index 9182c599..4c162aea 100644
--- a/Graphics/GraphicsEngineVulkan/include/VulkanDynamicHeap.h
+++ b/Graphics/GraphicsEngineVulkan/include/VulkanDynamicHeap.h
@@ -112,8 +112,7 @@ class VulkanDynamicMemoryManager : public DynamicHeap::MasterBlockListBasedManag
{
public:
using TBase = DynamicHeap::MasterBlockListBasedManager;
- using OffsetType = TBase::OffsetType;
- using TBase::InvalidOffset;
+ using OffsetType = TBase::OffsetType;
using MasterBlock = TBase::MasterBlock;
VulkanDynamicMemoryManager(IMemoryAllocator& Allocator,
@@ -200,7 +199,7 @@ public:
using OffsetType = VulkanDynamicMemoryManager::OffsetType;
using MasterBlock = VulkanDynamicMemoryManager::MasterBlock;
- static constexpr OffsetType InvalidOffset = VulkanDynamicMemoryManager::InvalidOffset;
+ static constexpr OffsetType InvalidOffset = static_cast<OffsetType>(-1);
size_t GetAllocatedMasterBlockCount()const {return m_MasterBlocks.size();}
diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanDynamicHeap.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanDynamicHeap.cpp
index 83a36b34..0e5f4957 100644
--- a/Graphics/GraphicsEngineVulkan/src/VulkanDynamicHeap.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/VulkanDynamicHeap.cpp
@@ -136,7 +136,7 @@ VulkanDynamicMemoryManager::MasterBlock VulkanDynamicMemoryManager::AllocateMast
}
auto Block = TBase::AllocateMasterBlock(SizeInBytes, Alignment);
- if (Block.UnalignedOffset == InvalidOffset)
+ if (!Block.IsValid())
{
// Allocation failed. Try to wait for GPU to finish pending frames to release some space
auto StartIdleTime = std::chrono::high_resolution_clock::now();
@@ -144,11 +144,11 @@ VulkanDynamicMemoryManager::MasterBlock VulkanDynamicMemoryManager::AllocateMast
static constexpr const auto MaxIdleDuration = std::chrono::duration<double>{60.0 / 1000.0}; // 60 ms
std::chrono::duration<double> IdleDuration;
Uint32 SleepIterations = 0;
- while (Block.UnalignedOffset == InvalidOffset && IdleDuration < MaxIdleDuration)
+ while (!Block.IsValid() && IdleDuration < MaxIdleDuration)
{
m_DeviceVk.PurgeReleaseQueues();
Block = TBase::AllocateMasterBlock(SizeInBytes, Alignment);
- if (Block.UnalignedOffset == InvalidOffset)
+ if (!Block.IsValid())
{
std::this_thread::sleep_for(SleepPeriod);
++SleepIterations;
@@ -158,14 +158,14 @@ VulkanDynamicMemoryManager::MasterBlock VulkanDynamicMemoryManager::AllocateMast
IdleDuration = std::chrono::duration_cast<std::chrono::duration<double>>(CurrTime - StartIdleTime);
}
- if (Block.UnalignedOffset == InvalidOffset)
+ if (!Block.IsValid())
{
// Last resort - idle GPU (there seems to be a driver bug: vkQueueWaitIdle() deadlocks and never returns)
//m_DeviceVk.IdleGPU(true);
//auto LastCompletedFenceValue = m_DeviceVk.GetCompletedFenceValue();
//m_AllocationStrategy.ReleaseStaleAllocations(LastCompletedFenceValue);
//Offset = m_AllocationStrategy.Allocate(SizeInBytes);
- if (Block.UnalignedOffset == InvalidOffset)
+ if (!Block.IsValid())
{
LOG_ERROR_MESSAGE("Space in dynamic heap is exausted! After idling for ", std::fixed, std::setprecision(1), IdleDuration.count()*1000.0, " ms still no space is available. Increase the size of the heap by setting EngineVkAttribs::DynamicHeapSize to a greater value or optimize dynamic resource usage");
}
@@ -187,7 +187,7 @@ VulkanDynamicMemoryManager::MasterBlock VulkanDynamicMemoryManager::AllocateMast
}
}
- if (Block.UnalignedOffset != InvalidOffset)
+ if (Block.IsValid())
{
m_TotalPeakSize = std::max(m_TotalPeakSize, GetUsedSize());
}
@@ -207,7 +207,7 @@ VulkanDynamicAllocation VulkanDynamicHeap::Allocate(Uint32 SizeInBytes, Uint32 A
{
// Allocate directly from the memory manager
auto MasterBlock = m_GlobalDynamicMemMgr.AllocateMasterBlock(SizeInBytes, Alignment);
- if (MasterBlock.UnalignedOffset != InvalidOffset)
+ if (MasterBlock.IsValid())
{
AlignedOffset = Align(MasterBlock.UnalignedOffset, size_t{Alignment});
AlignedSize = MasterBlock.Size;
@@ -220,7 +220,7 @@ VulkanDynamicAllocation VulkanDynamicHeap::Allocate(Uint32 SizeInBytes, Uint32 A
if (m_CurrOffset == InvalidOffset || SizeInBytes + (Align(m_CurrOffset, size_t{Alignment}) - m_CurrOffset) > m_AvailableSize)
{
auto MasterBlock = m_GlobalDynamicMemMgr.AllocateMasterBlock(m_MasterBlockSize, 0);
- if (MasterBlock.UnalignedOffset != InvalidOffset)
+ if (MasterBlock.IsValid())
{
m_CurrOffset = MasterBlock.UnalignedOffset;
m_MasterBlocks.emplace_back(MasterBlock);
diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp
index 65e138b6..5f531c9a 100644
--- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp
@@ -78,7 +78,7 @@ VulkanMemoryAllocation VulkanMemoryPage::Allocate(VkDeviceSize size, VkDeviceSiz
{
std::lock_guard<std::mutex> Lock(m_Mutex);
auto Allocation = m_AllocationMgr.Allocate(size, alignment);
- if (Allocation.UnalignedOffset != Diligent::VariableSizeAllocationsManager::InvalidOffset)
+ if (Allocation.IsValid())
{
// Offset may not necessarily be aligned, but the allocation is guaranteed to be large enough
// to accomodate requested alignment