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;
33 auto handle()
const noexcept -> handle_type;
35 operator handle_type()
const noexcept;
37 auto address()
const noexcept -> address_type;
39 auto resize(
const size_type new_size) -> void;
41 virtual auto size()
const noexcept -> size_type;
47 virtual auto name()
const noexcept -> std::string {
56 return _mapped_memory;
67 VkBufferUsageFlags _usage;
68 VkMemoryPropertyFlags _properties;
71 VmaAllocation _allocation;
72 address_type _address;
78template<
typename Type, VkBufferUsageFlags Usage, VkMemoryPropertyFlags Properties>
85 using value_type = Type;
86 using size_type = base_type::size_type;
88 typed_buffer(std::span<const Type> elements, VkMemoryPropertyFlags properties = 0, VkBufferUsageFlags usage = 0u)
89 :
base_type{elements.size() *
sizeof(Type), (usage | Usage) , (properties | Properties), elements.data()} { }
91 typed_buffer(size_type size, VkMemoryPropertyFlags properties = 0, VkBufferUsageFlags usage = 0u)
92 :
base_type{size *
sizeof(Type), (usage | Usage) , (properties | Properties),
nullptr} { }
96 auto size()
const noexcept -> VkDeviceSize
override {
97 return size_in_bytes() /
sizeof(Type);
100 auto size_in_bytes()
const noexcept -> VkDeviceSize {
101 return base_type::size();
106using 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:79
A non-owning pointer that can be used to observe the value of a pointer.
Definition: observer_ptr.hpp:28
Definition: noncopyable.hpp:7