KRDevice::createBuffer is now fallible.
Staging buffer flags corrected.
This commit is contained in:
@@ -359,16 +359,20 @@ bool KRDevice::initialize(const std::vector<const char*>& deviceExtensions)
|
|||||||
// TODO - Dynamically size staging buffer using heuristics
|
// TODO - Dynamically size staging buffer using heuristics
|
||||||
m_streamingStagingBufferSize = size_t(256) * 1024 * 1024;
|
m_streamingStagingBufferSize = size_t(256) * 1024 * 1024;
|
||||||
|
|
||||||
createBuffer(
|
if (!createBuffer(
|
||||||
m_streamingStagingBufferSize,
|
m_streamingStagingBufferSize,
|
||||||
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
|
VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||||
&m_streamingStagingBuffer,
|
&m_streamingStagingBuffer,
|
||||||
&m_streamingStagingBufferAllocation
|
&m_streamingStagingBufferAllocation
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
, "Streaming Staging Buffer"
|
, "Streaming Staging Buffer"
|
||||||
#endif // KRENGINE_DEBUG_GPU_LABELS
|
#endif // KRENGINE_DEBUG_GPU_LABELS
|
||||||
);
|
)) {
|
||||||
|
destroy();
|
||||||
|
// TODO - Log a warning
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Create Staging Buffer for the graphics queue.
|
// Create Staging Buffer for the graphics queue.
|
||||||
// This will be used for uploading assets procedurally generated while recording the graphics command buffer.
|
// This will be used for uploading assets procedurally generated while recording the graphics command buffer.
|
||||||
@@ -376,16 +380,20 @@ bool KRDevice::initialize(const std::vector<const char*>& deviceExtensions)
|
|||||||
// TODO - Dynamically size staging buffer using heuristics
|
// TODO - Dynamically size staging buffer using heuristics
|
||||||
m_graphicsStagingBufferSize = size_t(256) * 1024 * 1024;
|
m_graphicsStagingBufferSize = size_t(256) * 1024 * 1024;
|
||||||
|
|
||||||
createBuffer(
|
if (!createBuffer(
|
||||||
m_graphicsStagingBufferSize,
|
m_graphicsStagingBufferSize,
|
||||||
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
|
VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||||
&m_graphicsStagingBuffer,
|
&m_graphicsStagingBuffer,
|
||||||
&m_graphicsStagingBufferAllocation
|
&m_graphicsStagingBufferAllocation
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
, "Streaming Staging Buffer"
|
, "Streaming Staging Buffer"
|
||||||
#endif // KRENGINE_DEBUG_GPU_LABELS
|
#endif // KRENGINE_DEBUG_GPU_LABELS
|
||||||
);
|
)) {
|
||||||
|
destroy();
|
||||||
|
// TODO - Log a warning
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -397,23 +405,35 @@ VmaAllocator KRDevice::getAllocator()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KRDevice::createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer* buffer, VmaAllocation* allocation
|
bool KRDevice::createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer* buffer, VmaAllocation* allocation
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
, const char* debug_label
|
, const char* debug_label
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
int familyCount = 1;
|
||||||
|
uint32_t queueFamilyIndices[2] = {};
|
||||||
|
queueFamilyIndices[0] = m_graphicsFamilyQueueIndex;
|
||||||
|
if (m_graphicsFamilyQueueIndex != m_transferFamilyQueueIndex) {
|
||||||
|
queueFamilyIndices[1] = m_transferFamilyQueueIndex;
|
||||||
|
familyCount++;
|
||||||
|
}
|
||||||
|
|
||||||
VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
|
VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
|
||||||
bufferInfo.size = size;
|
bufferInfo.size = size;
|
||||||
bufferInfo.usage = usage;
|
bufferInfo.usage = usage;
|
||||||
bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
bufferInfo.sharingMode = VK_SHARING_MODE_CONCURRENT;
|
||||||
|
bufferInfo.queueFamilyIndexCount = familyCount;
|
||||||
|
bufferInfo.pQueueFamilyIndices = queueFamilyIndices;
|
||||||
|
|
||||||
VmaAllocationCreateInfo allocInfo = {};
|
VmaAllocationCreateInfo allocInfo = {};
|
||||||
allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
|
allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
|
||||||
allocInfo.requiredFlags = properties;
|
allocInfo.requiredFlags = properties;
|
||||||
|
|
||||||
VkResult res = vmaCreateBuffer(m_allocator, &bufferInfo, &allocInfo, buffer, allocation, nullptr);
|
VkResult res = vmaCreateBuffer(m_allocator, &bufferInfo, &allocInfo, buffer, allocation, nullptr);
|
||||||
// TODO - Error Handling...
|
if (res != VK_SUCCESS) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
VkDebugUtilsObjectNameInfoEXT debugInfo{};
|
VkDebugUtilsObjectNameInfoEXT debugInfo{};
|
||||||
@@ -423,6 +443,8 @@ void KRDevice::createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemor
|
|||||||
debugInfo.pObjectName = debug_label;
|
debugInfo.pObjectName = debug_label;
|
||||||
res = vkSetDebugUtilsObjectNameEXT(m_logicalDevice, &debugInfo);
|
res = vkSetDebugUtilsObjectNameEXT(m_logicalDevice, &debugInfo);
|
||||||
#endif // KRENGINE_DEBUG_GPU_LABELS
|
#endif // KRENGINE_DEBUG_GPU_LABELS
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
KrResult KRDevice::selectSurfaceFormat(VkSurfaceKHR& surface, VkSurfaceFormatKHR& selectedFormat)
|
KrResult KRDevice::selectSurfaceFormat(VkSurfaceKHR& surface, VkSurfaceFormatKHR& selectedFormat)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
bool initialize(const std::vector<const char*>& deviceExtensions);
|
bool initialize(const std::vector<const char*>& deviceExtensions);
|
||||||
|
|
||||||
VmaAllocator getAllocator();
|
VmaAllocator getAllocator();
|
||||||
void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer* buffer, VmaAllocation* allocation
|
bool createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer* buffer, VmaAllocation* allocation
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
, const char* debug_label
|
, const char* debug_label
|
||||||
#endif
|
#endif
|
||||||
@@ -77,12 +77,14 @@ public:
|
|||||||
|
|
||||||
// Staging buffer for uploading with the transfer queue
|
// Staging buffer for uploading with the transfer queue
|
||||||
// This will be used for asynchronous asset streaming in the streamer thread.
|
// This will be used for asynchronous asset streaming in the streamer thread.
|
||||||
|
// TODO - We should allocate at least two of these and double-buffer for increased CPU-GPU concurrency
|
||||||
VkBuffer m_streamingStagingBuffer;
|
VkBuffer m_streamingStagingBuffer;
|
||||||
VmaAllocation m_streamingStagingBufferAllocation;
|
VmaAllocation m_streamingStagingBufferAllocation;
|
||||||
size_t m_streamingStagingBufferSize;
|
size_t m_streamingStagingBufferSize;
|
||||||
|
|
||||||
// Staging buffer for uploading with the graphics queue
|
// Staging buffer for uploading with the graphics queue
|
||||||
// This will be used for uploading assets procedurally generated while recording the graphics command buffer.
|
// This will be used for uploading assets procedurally generated while recording the graphics command buffer.
|
||||||
|
// TODO - We should allocate at least two of these and double-buffer for increased CPU-GPU concurrency
|
||||||
VkBuffer m_graphicsStagingBuffer;
|
VkBuffer m_graphicsStagingBuffer;
|
||||||
VmaAllocation m_graphicsStagingBufferAllocation;
|
VmaAllocation m_graphicsStagingBufferAllocation;
|
||||||
size_t m_graphicsStagingBufferSize;
|
size_t m_graphicsStagingBufferSize;
|
||||||
|
|||||||
Reference in New Issue
Block a user