Skip to content
Snippets Groups Projects
Commit c6efc0db authored by Lava Block's avatar Lava Block
Browse files

add vma_flags to device::create_param

parent b35c7883
No related branches found
No related tags found
No related merge requests found
...@@ -150,7 +150,10 @@ namespace lava { ...@@ -150,7 +150,10 @@ namespace lava {
transfer_queue_list.clear(); transfer_queue_list.clear();
queue_list.clear(); queue_list.clear();
if (mem_allocator) {
mem_allocator->destroy();
mem_allocator = nullptr; mem_allocator = nullptr;
}
call().vkDestroyDevice(vk_device, memory::alloc()); call().vkDestroyDevice(vk_device, memory::alloc());
vk_device = nullptr; vk_device = nullptr;
...@@ -206,7 +209,7 @@ namespace lava { ...@@ -206,7 +209,7 @@ namespace lava {
if (!result->create(param)) if (!result->create(param))
return nullptr; return nullptr;
auto allocator = make_allocator(result->get_vk_physical_device(), result->get()); auto allocator = create_allocator(result.get(), param.vma_flags);
if (!allocator) if (!allocator)
return nullptr; return nullptr;
......
...@@ -22,6 +22,7 @@ namespace lava { ...@@ -22,6 +22,7 @@ namespace lava {
using ref = create_param const&; using ref = create_param const&;
physical_device_cptr physical_device = nullptr; physical_device_cptr physical_device = nullptr;
VmaAllocatorCreateFlags vma_flags = 0;
names extensions; names extensions;
VkPhysicalDeviceFeatures features{}; VkPhysicalDeviceFeatures features{};
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// copyright : Copyright (c) 2018-present, Lava Block OÜ and contributors // copyright : Copyright (c) 2018-present, Lava Block OÜ and contributors
// license : MIT; see accompanying LICENSE file // license : MIT; see accompanying LICENSE file
#include <liblava/base/device.hpp>
#include <liblava/base/instance.hpp> #include <liblava/base/instance.hpp>
#include <liblava/base/memory.hpp> #include <liblava/base/memory.hpp>
...@@ -83,54 +84,51 @@ namespace lava { ...@@ -83,54 +84,51 @@ namespace lava {
return no_type; return no_type;
} }
allocator::allocator(VkPhysicalDevice physical_device, VkDevice device) { bool allocator::create(device_cptr device, VmaAllocatorCreateFlags flags) {
VmaVulkanFunctions vulkan_function { VmaVulkanFunctions const vulkan_function {
.vkGetPhysicalDeviceProperties = vkGetPhysicalDeviceProperties, .vkGetPhysicalDeviceProperties = vkGetPhysicalDeviceProperties,
.vkGetPhysicalDeviceMemoryProperties = vkGetPhysicalDeviceMemoryProperties, .vkGetPhysicalDeviceMemoryProperties = vkGetPhysicalDeviceMemoryProperties,
.vkAllocateMemory = vkAllocateMemory, .vkAllocateMemory = device->call().vkAllocateMemory,
.vkFreeMemory = vkFreeMemory, .vkFreeMemory = device->call().vkFreeMemory,
.vkMapMemory = vkMapMemory, .vkMapMemory = device->call().vkMapMemory,
.vkUnmapMemory = vkUnmapMemory, .vkUnmapMemory = device->call().vkUnmapMemory,
.vkFlushMappedMemoryRanges = vkFlushMappedMemoryRanges, .vkFlushMappedMemoryRanges = device->call().vkFlushMappedMemoryRanges,
.vkInvalidateMappedMemoryRanges = vkInvalidateMappedMemoryRanges, .vkInvalidateMappedMemoryRanges = device->call().vkInvalidateMappedMemoryRanges,
.vkBindBufferMemory = vkBindBufferMemory, .vkBindBufferMemory = device->call().vkBindBufferMemory,
.vkBindImageMemory = vkBindImageMemory, .vkBindImageMemory = device->call().vkBindImageMemory,
.vkGetBufferMemoryRequirements = vkGetBufferMemoryRequirements, .vkGetBufferMemoryRequirements = device->call().vkGetBufferMemoryRequirements,
.vkGetImageMemoryRequirements = vkGetImageMemoryRequirements, .vkGetImageMemoryRequirements = device->call().vkGetImageMemoryRequirements,
.vkCreateBuffer = vkCreateBuffer, .vkCreateBuffer = device->call().vkCreateBuffer,
.vkDestroyBuffer = vkDestroyBuffer, .vkDestroyBuffer = device->call().vkDestroyBuffer,
.vkCreateImage = vkCreateImage, .vkCreateImage = device->call().vkCreateImage,
.vkDestroyImage = vkDestroyImage, .vkDestroyImage = device->call().vkDestroyImage,
.vkCmdCopyBuffer = vkCmdCopyBuffer, .vkCmdCopyBuffer = device->call().vkCmdCopyBuffer,
#if VMA_DEDICATED_ALLOCATION #if VMA_DEDICATED_ALLOCATION
.vkGetBufferMemoryRequirements2KHR = vkGetBufferMemoryRequirements2KHR, .vkGetBufferMemoryRequirements2KHR = device->call().vkGetBufferMemoryRequirements2KHR,
.vkGetImageMemoryRequirements2KHR = vkGetImageMemoryRequirements2KHR, .vkGetImageMemoryRequirements2KHR = device->call().vkGetImageMemoryRequirements2KHR,
#endif #endif
#if VMA_BIND_MEMORY2 #if VMA_BIND_MEMORY2
.vkBindBufferMemory2KHR = vkBindBufferMemory2KHR, .vkBindBufferMemory2KHR = device->call().vkBindBufferMemory2KHR,
.vkBindImageMemory2KHR = vkBindImageMemory2KHR, .vkBindImageMemory2KHR = device->call().vkBindImageMemory2KHR,
#endif #endif
#if VMA_MEMORY_BUDGET #if VMA_MEMORY_BUDGET
.vkGetPhysicalDeviceMemoryProperties2KHR = vkGetPhysicalDeviceMemoryProperties2KHR .vkGetPhysicalDeviceMemoryProperties2KHR = vkGetPhysicalDeviceMemoryProperties2KHR
#endif #endif
}; };
VmaAllocatorCreateInfo allocator_info{ VmaAllocatorCreateInfo const allocator_info{
.physicalDevice = physical_device, .flags = flags,
.device = device, .physicalDevice = device->get_vk_physical_device(),
.device = device->get(),
.pAllocationCallbacks = memory::alloc(), .pAllocationCallbacks = memory::alloc(),
.pVulkanFunctions = &vulkan_function, .pVulkanFunctions = &vulkan_function,
.instance = instance::get(), .instance = instance::get(),
}; };
check(vmaCreateAllocator(&allocator_info, &vma_allocator)); return check(vmaCreateAllocator(&allocator_info, &vma_allocator));
} }
allocator::allocator(VmaAllocator allocator) { void allocator::destroy() {
vma_allocator = allocator;
}
allocator::~allocator() {
if (!vma_allocator) if (!vma_allocator)
return; return;
......
...@@ -13,13 +13,20 @@ ...@@ -13,13 +13,20 @@
namespace lava { namespace lava {
struct allocator { // fwd
explicit allocator(VkPhysicalDevice physical_device, VkDevice device); struct device;
explicit allocator(VmaAllocator allocator); using device_cptr = device const*;
~allocator();
struct allocator {
using ptr = std::shared_ptr<allocator>; using ptr = std::shared_ptr<allocator>;
allocator() = default;
explicit allocator(VmaAllocator allocator)
: vma_allocator(allocator) {}
bool create(device_cptr device, VmaAllocatorCreateFlags flags = 0);
void destroy();
bool valid() const { bool valid() const {
return vma_allocator != nullptr; return vma_allocator != nullptr;
} }
...@@ -32,8 +39,16 @@ namespace lava { ...@@ -32,8 +39,16 @@ namespace lava {
VmaAllocator vma_allocator = nullptr; VmaAllocator vma_allocator = nullptr;
}; };
inline allocator::ptr make_allocator(VkPhysicalDevice physical_device, VkDevice device) { inline allocator::ptr make_allocator() {
return std::make_shared<allocator>(physical_device, device); return std::make_shared<allocator>();
}
inline allocator::ptr create_allocator(device_cptr device, VmaAllocatorCreateFlags flags = 0) {
auto result = make_allocator();
if (!result->create(device, flags))
return nullptr;
return result;
} }
struct memory : no_copy_no_move { struct memory : no_copy_no_move {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment