Panda3DS/include/renderer_vk/vk_descriptor_heap.hpp
Wunkolo 72c77e41b4 Draft Vulkan DescriptorHeap
A utility class from a personal project for managing a heap of
descriptors of a particular layout.

Allows the display graphics pipeline to be successfully created,
satisfying its descriptor layout issues.
2023-08-20 23:01:43 -07:00

49 lines
No EOL
1.6 KiB
C++

#pragma once
#include <optional>
#include <span>
#include "helpers.hpp"
#include "vk_api.hpp"
namespace Vulkan {
// Implements a basic heap of descriptor sets given a layout of particular
// bindings. Create a descriptor set by providing a list of bindings and it will
// automatically create both the pool, layout, and maintail a heap of descriptor
// sets. Descriptor sets will be reused and recycled. Assume that newly
// allocated descriptor sets are in an undefined state.
class DescriptorHeap {
private:
const vk::Device device;
vk::UniqueDescriptorPool descriptorPool;
vk::UniqueDescriptorSetLayout descriptorSetLayout;
std::vector<vk::UniqueDescriptorSet> descriptorSets;
std::vector<vk::DescriptorSetLayoutBinding> bindings;
std::vector<bool> allocationMap;
explicit DescriptorHeap(vk::Device device);
public:
~DescriptorHeap() = default;
DescriptorHeap(DescriptorHeap&&) = default;
const vk::DescriptorPool& getDescriptorPool() const { return descriptorPool.get(); };
const vk::DescriptorSetLayout& getDescriptorSetLayout() const { return descriptorSetLayout.get(); };
const std::span<const vk::UniqueDescriptorSet> getDescriptorSets() const { return descriptorSets; };
std::span<const vk::DescriptorSetLayoutBinding> getBindings() const { return bindings; };
std::optional<vk::DescriptorSet> allocateDescriptorSet();
bool freeDescriptorSet(vk::DescriptorSet set);
static std::optional<DescriptorHeap> create(
vk::Device device, std::span<const vk::DescriptorSetLayoutBinding> bindings, u16 descriptorHeapCount = 1024
);
};
} // namespace Vulkan