nngn
Loading...
Searching...
No Matches
cmd_pool.h
Go to the documentation of this file.
1#ifndef NNGN_GRAPHICS_VULKAN_CMD_POOL_H
2#define NNGN_GRAPHICS_VULKAN_CMD_POOL_H
3
4#include <cstddef>
5#include <cstdint>
6#include <span>
7#include <utility>
8#include <vector>
9
10#include "vulkan.h"
11
12namespace nngn {
13
14class CommandPool {
15public:
16 CommandPool() = default;
18 CommandPool(const CommandPool &rhs) = delete;
19 CommandPool &operator=(const CommandPool &rhs) = delete;
20 CommandPool(CommandPool &&rhs) noexcept { *this = std::move(rhs); }
22 VkCommandPool id() const { return this->h; }
23 std::span<const VkCommandBuffer> buffers() const { return this->m_buffers; }
24 bool init(
25 VkDevice dev, std::uint32_t queue_family,
26 VkCommandPoolCreateFlagBits flags = {});
28 bool alloc(std::size_t n);
30 bool realloc(std::size_t n);
31 void reset();
33 void free();
34private:
35 bool alloc(std::size_t n, VkCommandBuffer *p);
36 void free(std::size_t n, VkCommandBuffer *p);
37 VkDevice dev = {};
38 VkCommandPool h = {};
39 std::vector<VkCommandBuffer> m_buffers = {};
40};
41
42inline CommandPool &CommandPool::operator=(CommandPool &&rhs) noexcept {
43 this->dev = std::exchange(rhs.dev, {});
44 this->h = std::exchange(rhs.h, {});
45 this->m_buffers = std::exchange(rhs.m_buffers, {});
46 return *this;
47}
48
49}
50
51#endif
Definition: cmd_pool.h:14
bool alloc(std::size_t n)
Allocates n command buffers, which are appended to buffers.
VkCommandPool h
Definition: cmd_pool.h:38
std::span< const VkCommandBuffer > buffers() const
Definition: cmd_pool.h:23
void free(std::size_t n, VkCommandBuffer *p)
VkDevice dev
Definition: cmd_pool.h:37
VkCommandPool id() const
Definition: cmd_pool.h:22
bool alloc(std::size_t n, VkCommandBuffer *p)
CommandPool(CommandPool &&rhs) noexcept
Definition: cmd_pool.h:20
CommandPool(const CommandPool &rhs)=delete
CommandPool & operator=(const CommandPool &rhs)=delete
CommandPool & operator=(CommandPool &&rhs) noexcept
bool realloc(std::size_t n)
Resets the pool and allocates n command buffers.
void free()
Deallocates and frees all commands allocated from the pool.
std::vector< VkCommandBuffer > m_buffers
Definition: cmd_pool.h:39
CommandPool()=default
bool init(VkDevice dev, std::uint32_t queue_family, VkCommandPoolCreateFlagBits flags={})
n
Definition: dump_lights.lua:5
p
Definition: input.lua:29
Definition: audio.cpp:7
COMMAND_BUFFER DESCRIPTOR_POOL DESCRIPTOR_SET_LAYOUT FENCE IMAGE PIPELINE PIPELINE_CACHE RENDER_PASS SEMAPHORE BUFFER VkCommandPool
Definition: types.h:77
VkCommandBuffer
Definition: types.h:71