diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2021-01-27 22:28:53 +0100 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2021-01-27 22:28:53 +0100 |
| commit | e4180902265c36744a770e932bb0a3f204d58b28 (patch) | |
| tree | f695fba6fc88277bf999c5dcdf47b3a79e13bbf4 /src/vk-api.cpp | |
| parent | 1314f696a7861f3b1509c7f5c27d6b06bc22d5f1 (diff) | |
Convert buffer creation function to an api one
Diffstat (limited to 'src/vk-api.cpp')
| -rw-r--r-- | src/vk-api.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/vk-api.cpp b/src/vk-api.cpp new file mode 100644 index 0000000..a8897dd --- /dev/null +++ b/src/vk-api.cpp @@ -0,0 +1,30 @@ +#include <cassert> +#include <memory> + +#include "vk-api.hpp" + +#define VKRESULT(result) assert(result == VK_SUCCESS); + + +Buffer vkapi::create_buffer(size_t data_size, VkBufferUsageFlags buffer_usage, VmaMemoryUsage mem_usage) { + Buffer buffer = {}; + + VkBufferCreateInfo buffer_info = { }; + buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info.size = data_size; + buffer_info.usage = buffer_usage; + + VmaAllocationCreateInfo alloc_create_info = {}; + alloc_create_info.usage = mem_usage; + + vmaCreateBuffer(context.allocator, &buffer_info, &alloc_create_info, &buffer.vkbuffer, &buffer.alloc, nullptr); + + vmaMapMemory(context.allocator, buffer.alloc, (void**) &buffer.mapped_ptr); + + return std::move(buffer); +} + +void vkapi::destroy_buffer(Buffer& buffer) { + vmaUnmapMemory(context.allocator, buffer.alloc); + vmaDestroyBuffer(context.allocator, buffer.vkbuffer, buffer.alloc); +} |
