sandbox
Loading...
Searching...
No Matches
storage_buffer.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_GRAPHICS_BUFFERS_STORAGE_BUFFER_HPP_
3#define LIBSBX_GRAPHICS_BUFFERS_STORAGE_BUFFER_HPP_
4
5#include <libsbx/units/bytes.hpp>
6
7#include <libsbx/memory/observer_ptr.hpp>
8
9#include <libsbx/graphics/descriptor/descriptor.hpp>
10
11#include <libsbx/graphics/buffers/buffer.hpp>
12
13#include <libsbx/graphics/resource_storage.hpp>
14
15namespace sbx::graphics {
16
17class storage_buffer : public buffer, public descriptor {
18
19public:
20
21 inline static constexpr auto max_size = units::quantity_cast<units::byte>(units::kibibyte{512});
22 inline static constexpr auto min_size = units::quantity_cast<units::byte>(units::kibibyte{16});
23
24 storage_buffer(VkDeviceSize size, memory::observer_ptr<const void> data = nullptr);
25
26 storage_buffer(VkDeviceSize size, VkBufferUsageFlags additional_usage, memory::observer_ptr<const void> data = nullptr);
27
28 ~storage_buffer() override;
29
30 auto update(memory::observer_ptr<const void> data, VkDeviceSize size, std::size_t offset = 0u) -> void;
31
32 template<typename Type>
33 auto read(const std::size_t index) const -> const Type& {
34 return *(static_cast<const Type*>(_mapped_memory.get()) + index * sizeof(Type));
35 }
36
37 auto name() const noexcept -> std::string override {
38 return "Storage Buffer";
39 }
40
41 auto write_descriptor_set(std::uint32_t binding, VkDescriptorType descriptor_type) const noexcept -> graphics::write_descriptor_set override;
42
43 static auto create_descriptor_set_layout_binding(std::uint32_t binding, VkDescriptorType descriptor_type, VkShaderStageFlags stage_flags) noexcept -> VkDescriptorSetLayoutBinding;
44
45}; // class storage_buffer
46
48
49} // namespace sbx::graphics
50
51#endif // LIBSBX_GRAPHICS_BUFFERS_STORAGE_BUFFER_HPP_
52
Definition: buffer.hpp:21
Definition: descriptor.hpp:38
Definition: resource_storage.hpp:18
Definition: storage_buffer.hpp:17
Definition: descriptor.hpp:13
A non-owning pointer that can be used to observe the value of a pointer.
Definition: observer_ptr.hpp:28
Definition: quantity.hpp:66