WIP Index and Vertex buffer allocation
This commit is contained in:
@@ -228,3 +228,9 @@ bool KRDevice::initialize(const std::vector<const char*>& deviceExtensions)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VmaAllocator KRDevice::getAllocator()
|
||||||
|
{
|
||||||
|
assert(m_allocator != VK_NULL_HANDLE);
|
||||||
|
return m_allocator;
|
||||||
|
}
|
||||||
@@ -47,6 +47,8 @@ public:
|
|||||||
void destroy();
|
void destroy();
|
||||||
bool initialize(const std::vector<const char*>& deviceExtensions);
|
bool initialize(const std::vector<const char*>& deviceExtensions);
|
||||||
|
|
||||||
|
VmaAllocator getAllocator();
|
||||||
|
|
||||||
VkPhysicalDevice m_device;
|
VkPhysicalDevice m_device;
|
||||||
VkDevice m_logicalDevice;
|
VkDevice m_logicalDevice;
|
||||||
VkPhysicalDeviceProperties m_deviceProperties;
|
VkPhysicalDeviceProperties m_deviceProperties;
|
||||||
|
|||||||
@@ -213,3 +213,8 @@ KrSurfaceHandle KRDeviceManager::getBestDeviceForSurface(const VkSurfaceKHR& sur
|
|||||||
}
|
}
|
||||||
return deviceHandle;
|
return deviceHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unordered_map<KrDeviceHandle, std::unique_ptr<KRDevice>>& KRDeviceManager::getDevices()
|
||||||
|
{
|
||||||
|
return m_devices;
|
||||||
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public:
|
|||||||
KRDevice& getDeviceInfo(KrDeviceHandle handle);
|
KRDevice& getDeviceInfo(KrDeviceHandle handle);
|
||||||
VkInstance& getVulkanInstance();
|
VkInstance& getVulkanInstance();
|
||||||
KrSurfaceHandle getBestDeviceForSurface(const VkSurfaceKHR& surface);
|
KrSurfaceHandle getBestDeviceForSurface(const VkSurfaceKHR& surface);
|
||||||
|
unordered_map<KrDeviceHandle, std::unique_ptr<KRDevice>>& getDevices();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unordered_map<KrDeviceHandle, std::unique_ptr<KRDevice>> m_devices;
|
unordered_map<KrDeviceHandle, std::unique_ptr<KRDevice>> m_devices;
|
||||||
|
|||||||
@@ -33,6 +33,8 @@
|
|||||||
#ifndef KRENGINE_COMMON_H
|
#ifndef KRENGINE_COMMON_H
|
||||||
#define KRENGINE_COMMON_H
|
#define KRENGINE_COMMON_H
|
||||||
|
|
||||||
|
#define KRENGINE_MAX_GPU_COUNT 4
|
||||||
|
|
||||||
#include "public/kraken.h"
|
#include "public/kraken.h"
|
||||||
#include "KRHelpers.h"
|
#include "KRHelpers.h"
|
||||||
using namespace kraken;
|
using namespace kraken;
|
||||||
|
|||||||
@@ -534,10 +534,13 @@ KRMeshManager::KRVBOData::KRVBOData()
|
|||||||
|
|
||||||
m_last_frame_used = 0;
|
m_last_frame_used = 0;
|
||||||
m_last_frame_max_lod_coverage = 0.0f;
|
m_last_frame_max_lod_coverage = 0.0f;
|
||||||
|
|
||||||
|
memset(m_allocations, 0, sizeof(AllocationInfo) * KRENGINE_MAX_GPU_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRMeshManager::KRVBOData::KRVBOData(KRMeshManager *manager, KRDataBlock &data, KRDataBlock &index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t)
|
KRMeshManager::KRVBOData::KRVBOData(KRMeshManager *manager, KRDataBlock &data, KRDataBlock &index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t)
|
||||||
{
|
{
|
||||||
|
memset(m_allocations, 0, sizeof(AllocationInfo) * KRENGINE_MAX_GPU_COUNT);
|
||||||
m_is_vbo_loaded = false;
|
m_is_vbo_loaded = false;
|
||||||
m_is_vbo_ready = false;
|
m_is_vbo_ready = false;
|
||||||
init(manager, data,index_data,vertex_attrib_flags, static_vbo, t);
|
init(manager, data,index_data,vertex_attrib_flags, static_vbo, t);
|
||||||
@@ -573,11 +576,38 @@ KRMeshManager::KRVBOData::~KRVBOData()
|
|||||||
|
|
||||||
void KRMeshManager::KRVBOData::load()
|
void KRMeshManager::KRVBOData::load()
|
||||||
{
|
{
|
||||||
|
// TODO - We should load on each GPU only if there is a surface using the mesh
|
||||||
if(isVBOLoaded()) {
|
if(isVBOLoaded()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KRDeviceManager* deviceManager = m_manager->getContext().getDeviceManager();
|
||||||
|
int iAllocation = 0;
|
||||||
|
|
||||||
|
for (auto deviceItr = deviceManager->getDevices().begin(); deviceItr != deviceManager->getDevices().end() && iAllocation < KRENGINE_MAX_GPU_COUNT; deviceItr++, iAllocation++) {
|
||||||
|
KRDevice& device = *(*deviceItr).second;
|
||||||
|
KrDeviceHandle deviceHandle = (*deviceItr).first;
|
||||||
|
AllocationInfo& allocation = m_allocations[iAllocation];
|
||||||
|
|
||||||
|
allocation.device = deviceHandle;
|
||||||
|
|
||||||
|
VmaAllocator allocator = device.getAllocator();
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
VkResult res = vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &allocation.vertex_buffer, &allocation.vertex_allocation, nullptr);
|
||||||
|
|
||||||
|
if (m_index_data->getSize() > 0) {
|
||||||
|
bufferInfo.size = m_index_data->getSize();
|
||||||
|
bufferInfo.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||||
|
res = vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &allocation.index_buffer, &allocation.index_allocation, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO - Replace OpenGL code below...
|
// TODO - Replace OpenGL code below...
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -118,6 +118,16 @@ public:
|
|||||||
bool m_static_vbo;
|
bool m_static_vbo;
|
||||||
bool m_is_vbo_loaded;
|
bool m_is_vbo_loaded;
|
||||||
bool m_is_vbo_ready;
|
bool m_is_vbo_ready;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
KrDeviceHandle device;
|
||||||
|
VkBuffer vertex_buffer;
|
||||||
|
VmaAllocation vertex_allocation;
|
||||||
|
VkBuffer index_buffer;
|
||||||
|
VmaAllocation index_allocation;
|
||||||
|
} AllocationInfo;
|
||||||
|
|
||||||
|
AllocationInfo m_allocations[KRENGINE_MAX_GPU_COUNT];
|
||||||
};
|
};
|
||||||
|
|
||||||
void bindVBO(KRVBOData *vbo_data, float lodCoverage);
|
void bindVBO(KRVBOData *vbo_data, float lodCoverage);
|
||||||
|
|||||||
Reference in New Issue
Block a user