2#ifndef LIBSBX_GRAPHICS_BUFFERS_BUFFER_HPP_
3#define LIBSBX_GRAPHICS_BUFFERS_BUFFER_HPP_
9#include <vk_mem_alloc.h>
11#include <vulkan/vulkan.hpp>
13#include <libsbx/utility/noncopyable.hpp>
15#include <libsbx/memory/observer_ptr.hpp>
17#include <libsbx/graphics/resource_storage.hpp>
19namespace sbx::graphics {
25 using handle_type = VkBuffer;
26 using size_type = VkDeviceSize;
27 using address_type = VkDeviceAddress;
29 inline static constexpr auto null = address_type{0};
35 auto handle()
const noexcept -> handle_type;
37 operator handle_type()
const noexcept;
39 auto address()
const noexcept -> address_type;
41 auto resize(
const size_type new_size) -> void;
43 virtual auto size()
const noexcept -> size_type;
49 virtual auto name()
const noexcept -> std::string {
58 return _mapped_memory;
69 VkBufferUsageFlags _usage;
70 VkMemoryPropertyFlags _properties;
73 VmaAllocation _allocation;
74 address_type _address;
80template<
typename Type, VkBufferUsageFlags Usage, VkMemoryPropertyFlags Properties>
87 using value_type = Type;
88 using size_type = base_type::size_type;
90 typed_buffer(std::span<const Type> elements, VkMemoryPropertyFlags properties = 0, VkBufferUsageFlags usage = 0u)
91 :
base_type{elements.size() *
sizeof(Type), (usage | Usage) , (properties | Properties), elements.data()} { }
93 typed_buffer(size_type size, VkMemoryPropertyFlags properties = 0, VkBufferUsageFlags usage = 0u)
94 :
base_type{size *
sizeof(Type), (usage | Usage) , (properties | Properties),
nullptr} { }
98 auto size()
const noexcept -> VkDeviceSize
override {
99 return size_in_bytes() /
sizeof(Type);
102 auto size_in_bytes()
const noexcept -> VkDeviceSize {
103 return base_type::size();
108using 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:21
Definition: buffer.hpp:81
A non-owning pointer that can be used to observe the value of a pointer.
Definition: observer_ptr.hpp:29
Definition: noncopyable.hpp:7