1#ifndef LIBSBX_GRAPHICS_BUFFERS_BUFFER_HPP_
2#define LIBSBX_GRAPHICS_BUFFERS_BUFFER_HPP_
8#include <vk_mem_alloc.h>
10#include <vulkan/vulkan.hpp>
12#include <libsbx/utility/noncopyable.hpp>
14#include <libsbx/memory/observer_ptr.hpp>
16#include <libsbx/graphics/resource_storage.hpp>
18namespace sbx::graphics {
24 using handle_type = VkBuffer;
25 using size_type = VkDeviceSize;
31 auto handle()
const noexcept -> handle_type;
33 operator handle_type()
const noexcept;
35 auto address()
const noexcept -> std::uint64_t;
37 auto resize(
const size_type new_size) -> void;
39 virtual auto size()
const noexcept -> size_type;
57 VkBufferUsageFlags _usage;
58 VkMemoryPropertyFlags _properties;
61 VmaAllocation _allocation;
62 std::uint64_t _address;
68template<
typename Type, VkBufferUsageFlags Usage, VkMemoryPropertyFlags Properties>
75 using value_type = Type;
76 using size_type = base_type::size_type;
78 typed_buffer(std::span<const Type> elements, VkMemoryPropertyFlags properties = 0, VkBufferUsageFlags usage = 0u)
79 :
base_type{elements.size() *
sizeof(Type), (usage | Usage) , (properties | Properties), elements.data()} { }
81 typed_buffer(size_type size, VkMemoryPropertyFlags properties = 0, VkBufferUsageFlags usage = 0u)
82 :
base_type{size *
sizeof(Type), (usage | Usage) , (properties | Properties),
nullptr} { }
86 auto size()
const noexcept -> VkDeviceSize
override {
87 return size_in_bytes() /
sizeof(Type);
90 auto size_in_bytes()
const noexcept -> VkDeviceSize {
91 return base_type::size();
96using staging_buffer =
typed_buffer<std::uint8_t, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)>;
Definition: buffer.hpp:20
Definition: buffer.hpp:69
A non-owning pointer that can be used to observe the value of a pointer.
Definition: observer_ptr.hpp:27
Definition: noncopyable.hpp:6