Created helper function for Vulkan Buffer creation, KRDevice::createBuffer.
Updated KRMeshManager to use KRDevice::createBuffer for vertex and index data.
This commit is contained in:
@@ -235,6 +235,20 @@ VmaAllocator KRDevice::getAllocator()
|
|||||||
return m_allocator;
|
return m_allocator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KRDevice::createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer* buffer, VmaAllocation* allocation)
|
||||||
|
{
|
||||||
|
VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
|
||||||
|
bufferInfo.size = size;
|
||||||
|
bufferInfo.usage = usage;
|
||||||
|
|
||||||
|
VmaAllocationCreateInfo allocInfo = {};
|
||||||
|
allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
|
||||||
|
allocInfo.requiredFlags = properties;
|
||||||
|
|
||||||
|
VkResult res = vmaCreateBuffer(m_allocator, &bufferInfo, &allocInfo, buffer, allocation, nullptr);
|
||||||
|
// TODO - Error Handling...
|
||||||
|
}
|
||||||
|
|
||||||
KrResult KRDevice::selectSurfaceFormat(VkSurfaceKHR& surface, VkSurfaceFormatKHR& selectedFormat)
|
KrResult KRDevice::selectSurfaceFormat(VkSurfaceKHR& surface, VkSurfaceFormatKHR& selectedFormat)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +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);
|
||||||
|
|
||||||
KrResult selectSurfaceFormat(VkSurfaceKHR& surface, VkSurfaceFormatKHR& surfaceFormat);
|
KrResult selectSurfaceFormat(VkSurfaceKHR& surface, VkSurfaceFormatKHR& surfaceFormat);
|
||||||
KrResult selectDepthFormat(VkFormat& selectedDepthFormat);
|
KrResult selectDepthFormat(VkFormat& selectedDepthFormat);
|
||||||
|
|||||||
@@ -541,24 +541,20 @@ void KRMeshManager::KRVBOData::load()
|
|||||||
for (auto deviceItr = deviceManager->getDevices().begin(); deviceItr != deviceManager->getDevices().end() && iAllocation < KRENGINE_MAX_GPU_COUNT; deviceItr++, iAllocation++) {
|
for (auto deviceItr = deviceManager->getDevices().begin(); deviceItr != deviceManager->getDevices().end() && iAllocation < KRENGINE_MAX_GPU_COUNT; deviceItr++, iAllocation++) {
|
||||||
KRDevice& device = *(*deviceItr).second;
|
KRDevice& device = *(*deviceItr).second;
|
||||||
KrDeviceHandle deviceHandle = (*deviceItr).first;
|
KrDeviceHandle deviceHandle = (*deviceItr).first;
|
||||||
|
VmaAllocator allocator = device.getAllocator();
|
||||||
AllocationInfo& allocation = m_allocations[iAllocation];
|
AllocationInfo& allocation = m_allocations[iAllocation];
|
||||||
|
|
||||||
allocation.device = deviceHandle;
|
allocation.device = deviceHandle;
|
||||||
|
|
||||||
VmaAllocator allocator = device.getAllocator();
|
device.createBuffer(
|
||||||
|
m_data->getSize(),
|
||||||
|
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
|
||||||
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
|
||||||
|
&allocation.vertex_buffer,
|
||||||
|
&allocation.vertex_allocation
|
||||||
|
);
|
||||||
|
|
||||||
// TODO - Use staging buffers
|
// TODO - Use staging buffers
|
||||||
|
|
||||||
VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
|
|
||||||
bufferInfo.size = m_data->getSize();
|
|
||||||
bufferInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
|
||||||
|
|
||||||
VmaAllocationCreateInfo allocInfo = {};
|
|
||||||
allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
|
|
||||||
allocInfo.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
|
|
||||||
|
|
||||||
VkResult res = vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &allocation.vertex_buffer, &allocation.vertex_allocation, nullptr);
|
|
||||||
|
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
char debug_label[KRENGINE_DEBUG_GPU_LABEL_MAX_LEN];
|
char debug_label[KRENGINE_DEBUG_GPU_LABEL_MAX_LEN];
|
||||||
|
|
||||||
@@ -585,7 +581,7 @@ void KRMeshManager::KRVBOData::load()
|
|||||||
debugInfo.objectHandle = (uint64_t)allocation.vertex_buffer;
|
debugInfo.objectHandle = (uint64_t)allocation.vertex_buffer;
|
||||||
debugInfo.objectType = VK_OBJECT_TYPE_BUFFER;
|
debugInfo.objectType = VK_OBJECT_TYPE_BUFFER;
|
||||||
debugInfo.pObjectName = debug_label;
|
debugInfo.pObjectName = debug_label;
|
||||||
res = vkSetDebugUtilsObjectNameEXT(device.m_logicalDevice, &debugInfo);
|
VkResult res = vkSetDebugUtilsObjectNameEXT(device.m_logicalDevice, &debugInfo);
|
||||||
#endif // KRENGINE_DEBUG_GPU_LABELS
|
#endif // KRENGINE_DEBUG_GPU_LABELS
|
||||||
|
|
||||||
void* mappedData = nullptr;
|
void* mappedData = nullptr;
|
||||||
@@ -596,9 +592,14 @@ void KRMeshManager::KRVBOData::load()
|
|||||||
m_data->unlock();
|
m_data->unlock();
|
||||||
|
|
||||||
if (m_index_data->getSize() > 0) {
|
if (m_index_data->getSize() > 0) {
|
||||||
bufferInfo.size = m_index_data->getSize();
|
device.createBuffer(
|
||||||
bufferInfo.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
m_index_data->getSize(),
|
||||||
res = vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &allocation.index_buffer, &allocation.index_allocation, nullptr);
|
VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
|
||||||
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
|
||||||
|
&allocation.index_buffer,
|
||||||
|
&allocation.index_allocation
|
||||||
|
);
|
||||||
|
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
snprintf(debug_label, KRENGINE_DEBUG_GPU_LABEL_MAX_LEN, "%s Indexes: %s", type_label, m_debugLabel);
|
snprintf(debug_label, KRENGINE_DEBUG_GPU_LABEL_MAX_LEN, "%s Indexes: %s", type_label, m_debugLabel);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user