Allocated staging buffers for asset upload. For each GPU, two buffers. One for asynchronous asset streaming with the transfer queue and another for immediate asset streaming with the graphics queue.
This commit is contained in:
@@ -45,6 +45,12 @@ KRDevice::KRDevice(KRContext& context, const VkPhysicalDevice& device)
|
|||||||
, m_graphicsCommandPool(VK_NULL_HANDLE)
|
, m_graphicsCommandPool(VK_NULL_HANDLE)
|
||||||
, m_computeCommandPool(VK_NULL_HANDLE)
|
, m_computeCommandPool(VK_NULL_HANDLE)
|
||||||
, m_allocator(VK_NULL_HANDLE)
|
, m_allocator(VK_NULL_HANDLE)
|
||||||
|
, m_streamingStagingBuffer(VK_NULL_HANDLE)
|
||||||
|
, m_streamingStagingBufferAllocation(VK_NULL_HANDLE)
|
||||||
|
, m_streamingStagingBufferSize(0)
|
||||||
|
, m_graphicsStagingBuffer(VK_NULL_HANDLE)
|
||||||
|
, m_graphicsStagingBufferAllocation(VK_NULL_HANDLE)
|
||||||
|
, m_graphicsStagingBufferSize(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -56,6 +62,20 @@ KRDevice::~KRDevice()
|
|||||||
|
|
||||||
void KRDevice::destroy()
|
void KRDevice::destroy()
|
||||||
{
|
{
|
||||||
|
if (m_streamingStagingBuffer) {
|
||||||
|
vmaDestroyBuffer(m_allocator, m_streamingStagingBuffer, m_streamingStagingBufferAllocation);
|
||||||
|
m_streamingStagingBufferSize = 0;
|
||||||
|
m_streamingStagingBuffer = VK_NULL_HANDLE;
|
||||||
|
m_streamingStagingBufferAllocation = VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_graphicsStagingBuffer) {
|
||||||
|
vmaDestroyBuffer(m_allocator, m_graphicsStagingBuffer, m_graphicsStagingBufferAllocation);
|
||||||
|
m_graphicsStagingBufferSize = 0;
|
||||||
|
m_graphicsStagingBuffer = VK_NULL_HANDLE;
|
||||||
|
m_graphicsStagingBufferAllocation = VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_logicalDevice != VK_NULL_HANDLE) {
|
if (m_logicalDevice != VK_NULL_HANDLE) {
|
||||||
vkDestroyCommandPool(m_logicalDevice, m_graphicsCommandPool, nullptr);
|
vkDestroyCommandPool(m_logicalDevice, m_graphicsCommandPool, nullptr);
|
||||||
m_graphicsCommandPool = VK_NULL_HANDLE;
|
m_graphicsCommandPool = VK_NULL_HANDLE;
|
||||||
@@ -226,6 +246,41 @@ bool KRDevice::initialize(const std::vector<const char*>& deviceExtensions)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Create Staging Buffer for the transfer queue.
|
||||||
|
// This will be used for asynchronous asset streaming in the streamer thread.
|
||||||
|
// Start with a 256MB staging buffer.
|
||||||
|
// TODO - Dynamically size staging buffer using heuristics
|
||||||
|
m_streamingStagingBufferSize = size_t(256) * 1024 * 1024;
|
||||||
|
|
||||||
|
createBuffer(
|
||||||
|
m_streamingStagingBufferSize,
|
||||||
|
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
|
||||||
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||||
|
&m_streamingStagingBuffer,
|
||||||
|
&m_streamingStagingBufferAllocation
|
||||||
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
|
, "Streaming Staging Buffer"
|
||||||
|
#endif // KRENGINE_DEBUG_GPU_LABELS
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create Staging Buffer for the graphics queue.
|
||||||
|
// This will be used for uploading assets procedurally generated while recording the graphics command buffer.
|
||||||
|
// Start with a 256MB staging buffer.
|
||||||
|
// TODO - Dynamically size staging buffer using heuristics
|
||||||
|
m_graphicsStagingBufferSize = size_t(256) * 1024 * 1024;
|
||||||
|
|
||||||
|
createBuffer(
|
||||||
|
m_graphicsStagingBufferSize,
|
||||||
|
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
|
||||||
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||||
|
&m_graphicsStagingBuffer,
|
||||||
|
&m_graphicsStagingBufferAllocation
|
||||||
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
|
, "Streaming Staging Buffer"
|
||||||
|
#endif // KRENGINE_DEBUG_GPU_LABELS
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,5 +70,17 @@ public:
|
|||||||
std::vector<VkCommandBuffer> m_graphicsCommandBuffers;
|
std::vector<VkCommandBuffer> m_graphicsCommandBuffers;
|
||||||
std::vector<VkCommandBuffer> m_computeCommandBuffers;
|
std::vector<VkCommandBuffer> m_computeCommandBuffers;
|
||||||
VmaAllocator m_allocator;
|
VmaAllocator m_allocator;
|
||||||
|
|
||||||
|
// Staging buffer for uploading with the transfer queue
|
||||||
|
// This will be used for asynchronous asset streaming in the streamer thread.
|
||||||
|
VkBuffer m_streamingStagingBuffer;
|
||||||
|
VmaAllocation m_streamingStagingBufferAllocation;
|
||||||
|
size_t m_streamingStagingBufferSize;
|
||||||
|
|
||||||
|
// Staging buffer for uploading with the graphics queue
|
||||||
|
// This will be used for uploading assets procedurally generated while recording the graphics command buffer.
|
||||||
|
VkBuffer m_graphicsStagingBuffer;
|
||||||
|
VmaAllocation m_graphicsStagingBufferAllocation;
|
||||||
|
size_t m_graphicsStagingBufferSize;
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user