descriptors.hpp

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


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

#include <span>


namespace planet::vk {


    class device;

Descriptor pool

17
18
19
20
21
22
    class descriptor_pool final {
        using handle_type =
                device_handle<VkDescriptorPool, vkDestroyDescriptorPool>;
        handle_type handle;

      public:

General purpose creation of a pool for the described sizes

24
25
26
27
        descriptor_pool(
                vk::device &,
                std::span<VkDescriptorPoolSize const>,
                std::uint32_t max_sets);

Create a pool for a single type with the requested size

29
30
31
32
33
        descriptor_pool(vk::device &, VkDescriptorType, std::uint32_t count);

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

Descriptor set layout

37
38
39
40
41
42
    class descriptor_set_layout final {
        using handle_type =
                device_handle<VkDescriptorSetLayout, vkDestroyDescriptorSetLayout>;
        handle_type handle;

      public:

General purpose set layout creation

44
45
        descriptor_set_layout(
                vk::device &, VkDescriptorSetLayoutCreateInfo const &);

Create a set layout for only a single binding

47
48
        descriptor_set_layout(
                vk::device &, VkDescriptorSetLayoutBinding const &);

For a uniform buffer object

50
51
52
53
54
55
56
57
        static descriptor_set_layout for_uniform_buffer_object(vk::device &);

        device_view device;
        VkDescriptorSetLayout get() const noexcept { return handle.get(); }
        VkDescriptorSetLayout const *address() const noexcept {
            return handle.address();
        }
    };

Descriptor sets

61
62
63
64
    class descriptor_sets final {
        std::vector<VkDescriptorSet> sets;

      public:

Create sets for a single layout, but multiple frames

66
67
68
69
70
71
        descriptor_sets(
                descriptor_pool const &,
                descriptor_set_layout const &,
                std::uint32_t count = 1,
                felspar::source_location const & =
                        felspar::source_location::current());

Access to individual sets

74
75
76
77
78
79
80
81
82
83
84
        auto &operator[](std::uint32_t const index) { return sets.at(index); }
        auto const &operator[](std::uint32_t const index) const {
            return sets.at(index);
        }
        std::size_t size() const noexcept { return sets.size(); }
        VkDescriptorSet *data() noexcept { return sets.data(); }
        VkDescriptorSet const *data() const noexcept { return sets.data(); }
    };


}