Make vk_allocator a singleton

This commit is contained in:
Patrick Nicolas
2024-02-07 18:25:54 +01:00
parent 595d27f8dc
commit df394ec079
15 changed files with 163 additions and 96 deletions
+2
View File
@@ -22,6 +22,7 @@
#include <vulkan/vulkan.hpp>
#include <fastgltf/types.hpp>
#include <fastgltf/tools.hpp>
#include "application.h"
#include "vk/allocation.h"
#include "utils/alignment.h"
@@ -117,6 +118,7 @@ public:
buffer_allocation copy_to_gpu()
{
buffer_allocation gpu_buffer{
application::get_device(),
vk::BufferCreateInfo{
.size = bytes.size(),
.usage = usage},
+4 -1
View File
@@ -154,19 +154,22 @@ void image_loader::do_load(vk::raii::Device & device, vk::raii::CommandBuffer &
// Copy to staging buffer
staging_buffer = buffer_allocation{
device,
vk::BufferCreateInfo{
.size = byte_size,
.usage = vk::BufferUsageFlagBits::eTransferSrc},
VmaAllocationCreateInfo{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
}, "image_loader::do_load (staging)"};
},
"image_loader::do_load (staging)"};
memcpy(staging_buffer.map(), pixels, byte_size);
staging_buffer.unmap();
// Allocate image
image = image_allocation{
device,
vk::ImageCreateInfo{
.imageType = vk::ImageType::e2D,
.format = format,
+12 -10
View File
@@ -139,6 +139,7 @@ std::shared_ptr<scene_data::material> scene_renderer::create_default_material(vk
device.waitForFences(*fence, true, 1'000'000'000); // TODO check for timeout
default_material->buffer = std::make_shared<buffer_allocation>(
device,
vk::BufferCreateInfo{
.size = sizeof(default_material->staging),
.usage = vk::BufferUsageFlagBits::eUniformBuffer
@@ -371,7 +372,8 @@ scene_renderer::output_image scene_renderer::create_output_image_data(vk::Image
.subresourceRange = {.aspectMask = vk::ImageAspectFlagBits::eColor, .baseMipLevel = 0, .levelCount = 1, .baseArrayLayer = 0, .layerCount = 1},
});
out.depth_buffer = image_allocation{vk::ImageCreateInfo{
out.depth_buffer = image_allocation{device,
vk::ImageCreateInfo{
.imageType = vk::ImageType::e2D,
.format = depth_format,
.extent = {
@@ -388,7 +390,7 @@ scene_renderer::output_image scene_renderer::create_output_image_data(vk::Image
},
VmaAllocationCreateInfo{
.flags = VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
.usage = VMA_MEMORY_USAGE_AUTO,
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, // TODO: check
}};
@@ -579,14 +581,14 @@ void scene_renderer::start_frame()
f.staging_buffer_offset = 0;
if (!f.staging_buffer)
{
f.staging_buffer = buffer_allocation{vk::BufferCreateInfo{
.size = 1048576,
.usage = vk::BufferUsageFlagBits::eUniformBuffer},
VmaAllocationCreateInfo{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE},
"scene_renderer::render (UBO staging)"
};
f.staging_buffer = buffer_allocation{device,
vk::BufferCreateInfo{
.size = 1048576,
.usage = vk::BufferUsageFlagBits::eUniformBuffer},
VmaAllocationCreateInfo{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE},
"scene_renderer::render (UBO staging)"};
}
}
+4 -2
View File
@@ -140,7 +140,8 @@ text_rasterizer::text_rasterizer(vk::raii::Device & device, vk::raii::PhysicalDe
image_allocation text_rasterizer::create_image(vk::Extent2D size)
{
image_allocation alloc{vk::ImageCreateInfo{
image_allocation alloc{device,
vk::ImageCreateInfo{
.imageType = vk::ImageType::e2D,
.format = text::format,
.extent = {
@@ -167,7 +168,8 @@ image_allocation text_rasterizer::create_image(vk::Extent2D size)
buffer_allocation text_rasterizer::create_buffer(size_t size)
{
buffer_allocation alloc{vk::BufferCreateInfo{
buffer_allocation alloc{device,
vk::BufferCreateInfo{
.size = size,
.usage = vk::BufferUsageFlagBits::eTransferSrc,
},