sandbox
Loading...
Searching...
No Matches
command_buffer.hpp
1#ifndef LIBSBX_GRAPHICS_COMMANDS_COMMAND_BUFFER_HPP_
2#define LIBSBX_GRAPHICS_COMMANDS_COMMAND_BUFFER_HPP_
3
4#include <memory>
5
6#include <vulkan/vulkan.hpp>
7
8#include <libsbx/graphics/devices/logical_device.hpp>
9
10#include <libsbx/graphics/commands/command_pool.hpp>
11
12namespace sbx::graphics {
13
15
16public:
17
18 struct wait_data {
19 VkSemaphore semaphore;
20 VkPipelineStageFlags stage;
21 }; // struct wait_data
22
24 std::vector<VkBuffer> buffers;
25 VkPipelineStageFlags src_stage_mask;
26 VkPipelineStageFlags dst_stage_mask;
27 VkAccessFlags src_access_mask;
28 VkAccessFlags dst_access_mask;
29 std::uint32_t src_queue_family;
30 std::uint32_t dst_queue_family;
31 }; // struct buffer_barrier
32
34 VkPipelineStageFlags2 src_stage_mask;
35 VkAccessFlags2 src_access_mask;
36 std::uint32_t src_queue_family;
37 std::uint32_t dst_queue_family;
38 VkBuffer buffer;
39 VkDeviceSize size{VK_WHOLE_SIZE};
40 VkDeviceSize offset{0};
41 }; // struct release_ownership_data
42
44 VkPipelineStageFlags2 dst_stage_mask;
45 VkAccessFlags2 dst_access_mask;
46 std::uint32_t src_queue_family;
47 std::uint32_t dst_queue_family;
48 VkBuffer buffer;
49 VkDeviceSize size{VK_WHOLE_SIZE};
50 VkDeviceSize offset{0};
51 }; // struct acquire_ownership_data
52
53 command_buffer(bool should_begin = true, VkQueueFlagBits queue_type = VK_QUEUE_GRAPHICS_BIT, VkCommandBufferLevel buffer_level = VK_COMMAND_BUFFER_LEVEL_PRIMARY);
54
55 command_buffer(const command_buffer&) = delete;
56
58
60
61 auto operator=(const command_buffer&) -> command_buffer& = delete;
62
63 auto operator=(command_buffer&&) noexcept -> command_buffer&;
64
65 auto handle() const noexcept -> VkCommandBuffer;
66
67 operator VkCommandBuffer() const noexcept;
68
69 auto is_running() const noexcept -> bool;
70
71 auto begin(VkCommandBufferUsageFlags usage = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) -> void;
72
73 auto end() -> void;
74
75 auto submit_idle() -> void;
76
77 auto submit(const std::vector<wait_data>& wait_data = {}, const VkSemaphore &signal_semaphore = nullptr, const VkFence& fence = nullptr) -> void;
78
79 auto copy_buffer(const VkBuffer& source, const VkBuffer& destination, const VkBufferCopy& region) -> void;
80
81 auto buffer_barrier(const buffer_barrier_data& buffer_barrier_data) -> void;
82
83 auto memory_dependency(const VkMemoryBarrier2& memory_barrier) -> void;
84
85 auto release_ownership(const std::vector<release_ownership_data>& releases) -> void;
86
87 auto acquire_ownership(const std::vector<acquire_ownership_data>& acquires) -> void;
88
89 auto set_viewport(const VkViewport& viewport) -> void;
90
91 auto set_scissor(const VkRect2D& scissor) -> void;
92
93 auto bind_vertex_buffer(std::uint32_t first_binding, const VkBuffer& buffer) -> void;
94
95 auto bind_index_buffer(const VkBuffer& buffer, VkDeviceSize offset, VkIndexType index_type) -> void;
96
97 auto draw(std::uint32_t vertex_count, std::uint32_t instance_count, std::uint32_t first_vertex, std::uint32_t first_instance) -> void;
98
99 auto draw_indexed(std::uint32_t index_count, std::uint32_t instance_count, std::uint32_t first_index, std::int32_t vertex_offset, std::uint32_t first_instance) -> void;
100
101 auto draw_indirect(VkBuffer buffer, std::uint32_t offset, std::uint32_t count) -> void;
102
103 auto draw_indexed_indirect(VkBuffer buffer, std::uint32_t offset, std::uint32_t count) -> void;
104
105 auto begin_render_pass(const VkRenderPassBeginInfo& renderpass_begin_info, VkSubpassContents subpass_contents) -> void;
106
107 auto end_render_pass() -> void;
108
109 auto fill_buffer(const VkBuffer& buffer, VkDeviceSize offset, VkDeviceSize size, std::uint32_t data) -> void;
110
111private:
112
113 auto _queue() const -> const graphics::queue&;
114
115 std::shared_ptr<command_pool> _command_pool{};
116
117 VkCommandBuffer _handle{};
118 VkQueueFlagBits _queue_type{};
119 bool _is_running{};
120
121}; // class command_buffer
122
123} // namespace sbx::graphics
124
125#endif // LIBSBX_GRAPHICS_COMMANDS_COMMAND_BUFFER_HPP_
Definition: buffer.hpp:20
Definition: command_buffer.hpp:14
Definition: command_pool.hpp:12
Definition: logical_device.hpp:18
Definition: render_stage.hpp:123
Definition: command_buffer.hpp:18