commands.hpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#pragma once


#include <planet/vk/forward.hpp>
#include <planet/vk/owned_handle.hpp>
#include <planet/vk/view.hpp>

#include <vector>


namespace planet::vk {

Command buffer

15
16
    class command_buffer final {
        friend class command_buffers;

These instances are owned by the command_buffers type

18
        VkCommandBuffer handle;

The command buffer can be either a one-off used for a particular purpose, or it can be owned by the command_buffers structure. This flags tells the destructor which is which.

25
        bool self_owned = false;

Used when the command_buffers instance owns the handles

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
        command_buffer(vk::command_pool &, VkCommandBuffer);


      public:
        command_buffer() {}
        explicit command_buffer(
                vk::command_pool &,
                VkCommandBufferLevel = VK_COMMAND_BUFFER_LEVEL_PRIMARY);
        command_buffer(command_buffer const &) = delete;
        command_buffer(command_buffer &&);
        ~command_buffer() { reset(); }

        command_buffer &operator=(command_buffer const &) = delete;
        command_buffer &operator=(command_buffer &&);

        device_view device;
        view<vk::command_pool> command_pool;
        auto get() const noexcept { return handle; }

Single use graphics command buffer

Start a single use command buffer

50
        static command_buffer single_use(vk::command_pool &);

End and submit on the graphics queue

As well as combining the end with a submit to the device's graphics queue, it also waits for the queue to become idle again.

56
        void end_and_submit();

API wrappers

vkBeginCommandBuffer

62
        void begin(VkCommandBufferUsageFlags = {});

vkEndCommandBuffer

64
        void end();

vkQueueSubmit

66
67
68
69
70
71
        void submit(VkQueue);


      private:
        void reset();
    };

Command buffers

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
    class command_buffers final {
        std::vector<VkCommandBuffer> handles;
        std::vector<command_buffer> buffers;


      public:
        command_buffers(
                vk::command_pool &,
                std::size_t number_of_buffers,
                VkCommandBufferLevel = VK_COMMAND_BUFFER_LEVEL_PRIMARY);
        command_buffers(command_buffers const &) = delete;
        command_buffers(command_buffers &&) = delete;
        ~command_buffers();

        command_buffers &operator=(command_buffers const &) = delete;
        command_buffers &operator=(command_buffers &&) = delete;

        device_view device;
        view<vk::command_pool> command_pool;

        std::size_t size() const noexcept { return buffers.size(); }
        command_buffer &operator[](std::size_t const i) {
            return buffers.at(i);
        }
    };

Command pool

103
104
105
106
107
108
109
110
111
112
113
114
115
    class command_pool final {
        using handle_type = device_handle<VkCommandPool, vkDestroyCommandPool>;
        handle_type handle;

      public:
        command_pool(vk::device &, vk::surface const &);

        device_view device;
        VkCommandPool get() const noexcept { return handle.get(); }
    };


}