From ef396c82756864a0834a391e28a822b20cc7b019 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 30 Nov 2019 08:57:13 -0800 Subject: Fixed some 32-bit compilation warnings --- .../include/VulkanUploadHeap.h | 22 +++++++++++----------- .../include/VulkanUtilities/VulkanMemoryManager.h | 2 ++ .../GraphicsEngineVulkan/src/VulkanUploadHeap.cpp | 2 +- .../src/VulkanUtilities/VulkanMemoryManager.cpp | 15 ++++++++++++--- 4 files changed, 26 insertions(+), 15 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUploadHeap.h b/Graphics/GraphicsEngineVulkan/include/VulkanUploadHeap.h index f544dd1f..dce3a711 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanUploadHeap.h +++ b/Graphics/GraphicsEngineVulkan/include/VulkanUploadHeap.h @@ -96,7 +96,7 @@ public: ~VulkanUploadHeap(); - VulkanUploadAllocation Allocate(size_t SizeInBytes, size_t Alignment); + VulkanUploadAllocation Allocate(VkDeviceSize SizeInBytes, VkDeviceSize Alignment); // Releases all allocated pages that are later returned to the global memory manager by the release queues. // As global memory manager is hosted by the render device, the upload heap can be destroyed before the @@ -134,12 +134,12 @@ private: struct CurrPageInfo { - VkBuffer vkBuffer = VK_NULL_HANDLE; - Uint8* CurrCPUAddress = nullptr; - size_t CurrOffset = 0; - size_t AvailableSize = 0; + VkBuffer vkBuffer = VK_NULL_HANDLE; + Uint8* CurrCPUAddress = nullptr; + VkDeviceSize CurrOffset = 0; + VkDeviceSize AvailableSize = 0; - void Reset(UploadPageInfo& NewPage, size_t PageSize) + void Reset(UploadPageInfo& NewPage, VkDeviceSize PageSize) { vkBuffer = NewPage.Buffer; CurrCPUAddress = NewPage.CPUAddress; @@ -147,7 +147,7 @@ private: AvailableSize = PageSize; } - void Advance(size_t SizeInBytes) + void Advance(VkDeviceSize SizeInBytes) { CurrCPUAddress += SizeInBytes; CurrOffset += SizeInBytes; @@ -155,10 +155,10 @@ private: } } m_CurrPage; - size_t m_CurrFrameSize = 0; - size_t m_PeakFrameSize = 0; - size_t m_CurrAllocatedSize = 0; - size_t m_PeakAllocatedSize = 0; + VkDeviceSize m_CurrFrameSize = 0; + VkDeviceSize m_PeakFrameSize = 0; + VkDeviceSize m_CurrAllocatedSize = 0; + VkDeviceSize m_PeakAllocatedSize = 0; UploadPageInfo CreateNewPage(VkDeviceSize SizeInBytes) const; }; diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanMemoryManager.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanMemoryManager.h index b736c5ad..f1aaf139 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanMemoryManager.h +++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanMemoryManager.h @@ -124,6 +124,8 @@ public: void* GetCPUMemory() const { return m_CPUMemory; } private: + using AllocationsMgrOffsetType = Diligent::VariableSizeAllocationsManager::OffsetType; + friend struct VulkanMemoryAllocation; // Memory is reclaimed immediately. The application is responsible to ensure it is not in use by the GPU diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUploadHeap.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUploadHeap.cpp index 0316ec05..c693905d 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanUploadHeap.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanUploadHeap.cpp @@ -86,7 +86,7 @@ VulkanUploadHeap::UploadPageInfo VulkanUploadHeap::CreateNewPage(VkDeviceSize Si return UploadPageInfo{std::move(MemAllocation), std::move(NewBuffer), CPUAddress}; } -VulkanUploadAllocation VulkanUploadHeap::Allocate(size_t SizeInBytes, size_t Alignment) +VulkanUploadAllocation VulkanUploadHeap::Allocate(VkDeviceSize SizeInBytes, VkDeviceSize Alignment) { VERIFY(IsPowerOfTwo(Alignment), "Alignment (", Alignment, ") must be power of two"); diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp index cc36ed99..94e8e10c 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp @@ -42,9 +42,13 @@ VulkanMemoryPage::VulkanMemoryPage(VulkanMemoryManager& ParentMemoryMgr, bool IsHostVisible) noexcept : // clang-format off m_ParentMemoryMgr{ParentMemoryMgr}, - m_AllocationMgr {PageSize, ParentMemoryMgr.m_Allocator} + m_AllocationMgr {static_cast(PageSize), ParentMemoryMgr.m_Allocator} // clang-format on { + VERIFY(PageSize <= std::numeric_limits::max(), + "PageSize (", PageSize, ") exceeds maximum allowed value ", + std::numeric_limits::max()); + VkMemoryAllocateInfo MemAlloc = {}; MemAlloc.pNext = nullptr; @@ -81,7 +85,10 @@ VulkanMemoryPage::~VulkanMemoryPage() VulkanMemoryAllocation VulkanMemoryPage::Allocate(VkDeviceSize size, VkDeviceSize alignment) { std::lock_guard Lock{m_Mutex}; - auto Allocation = m_AllocationMgr.Allocate(size, alignment); + VERIFY(size <= std::numeric_limits::max(), + "Allocation size (", size, ") exceeds maximum allowed value ", + std::numeric_limits::max()); + auto Allocation = m_AllocationMgr.Allocate(static_cast(size), static_cast(alignment)); if (Allocation.IsValid()) { // Offset may not necessarily be aligned, but the allocation is guaranteed to be large enough @@ -99,7 +106,9 @@ void VulkanMemoryPage::Free(VulkanMemoryAllocation&& Allocation) { m_ParentMemoryMgr.OnFreeAllocation(Allocation.Size, m_CPUMemory != nullptr); std::lock_guard Lock{m_Mutex}; - m_AllocationMgr.Free(Allocation.UnalignedOffset, Allocation.Size); + VERIFY_EXPR(Allocation.UnalignedOffset <= std::numeric_limits::max()); + VERIFY_EXPR(Allocation.Size <= std::numeric_limits::max()); + m_AllocationMgr.Free(static_cast(Allocation.UnalignedOffset), static_cast(Allocation.Size)); Allocation = VulkanMemoryAllocation{}; } -- cgit v1.2.3