Implement UploadPool to efficiently update UBOs
This commit is contained in:
@@ -21,7 +21,7 @@ namespace Nz
|
||||
public:
|
||||
Buffer() = default;
|
||||
Buffer(const Buffer&) = delete;
|
||||
Buffer(Buffer&&) = default;
|
||||
Buffer(Buffer&&) noexcept = default;
|
||||
~Buffer() = default;
|
||||
|
||||
bool BindBufferMemory(VkDeviceMemory memory, VkDeviceSize offset = 0);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define NAZARA_VULKANRENDERER_VKDEVICEMEMORY_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
@@ -19,9 +20,9 @@ namespace Nz
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
DeviceMemory();
|
||||
DeviceMemory() = default;
|
||||
DeviceMemory(const DeviceMemory&) = delete;
|
||||
inline DeviceMemory(DeviceMemory&& memory);
|
||||
DeviceMemory(DeviceMemory&& memory) noexcept = default;
|
||||
~DeviceMemory() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
@@ -33,6 +34,7 @@ namespace Nz
|
||||
|
||||
inline void* GetMappedPointer();
|
||||
|
||||
inline bool Map(VkMemoryMapFlags flags = 0);
|
||||
inline bool Map(VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags = 0);
|
||||
|
||||
inline void Unmap();
|
||||
@@ -44,7 +46,7 @@ namespace Nz
|
||||
static inline VkResult CreateHelper(Device& device, const VkMemoryAllocateInfo* allocInfo, const VkAllocationCallbacks* allocator, VkDeviceMemory* handle);
|
||||
static inline void DestroyHelper(Device& device, VkDeviceMemory handle, const VkAllocationCallbacks* allocator);
|
||||
|
||||
void* m_mappedPtr;
|
||||
MovablePtr<void> m_mappedPtr;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,18 +12,6 @@ namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline DeviceMemory::DeviceMemory() :
|
||||
m_mappedPtr(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
inline DeviceMemory::DeviceMemory(DeviceMemory&& memory) :
|
||||
DeviceObject(std::move(memory))
|
||||
{
|
||||
m_mappedPtr = memory.m_mappedPtr;
|
||||
memory.m_mappedPtr = nullptr;
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::Create(Device& device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkMemoryAllocateInfo allocInfo =
|
||||
@@ -87,15 +75,23 @@ namespace Nz
|
||||
return m_mappedPtr;
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::Map(VkMemoryMapFlags flags)
|
||||
{
|
||||
return Map(0, VK_WHOLE_SIZE, flags);
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::Map(VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags)
|
||||
{
|
||||
m_lastErrorCode = m_device->vkMapMemory(*m_device, m_handle, offset, size, flags, &m_mappedPtr);
|
||||
void* mappedPtr;
|
||||
m_lastErrorCode = m_device->vkMapMemory(*m_device, m_handle, offset, size, flags, &mappedPtr);
|
||||
if (m_lastErrorCode != VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to map device memory: " + TranslateVulkanError(m_lastErrorCode));
|
||||
return false;
|
||||
}
|
||||
|
||||
m_mappedPtr = mappedPtr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user