summaryrefslogtreecommitdiffstats
path: root/tools/gfx/vulkan/vk-descriptor-allocator.h
blob: 5be1cfae26c6138b1964438847613110bae73c0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// vk-descriptor-allocator.h

#pragma once

#include "core/slang-list.h"
#include "vk-api.h"

namespace gfx
{
struct VulkanDescriptorSet
{
    VkDescriptorSet handle;
    VkDescriptorPool pool;
};
class DescriptorSetAllocator
{
public:
    Slang::List<VkDescriptorPool> pools;
    const VulkanApi* m_api;
    VkDescriptorPool newPool();
    VkDescriptorPool getPool()
    {
        if (pools.getCount())
            return pools.getLast();
        return newPool();
    }
    VulkanDescriptorSet allocate(VkDescriptorSetLayout layout);
    void free(VulkanDescriptorSet set)
    {
        m_api->vkFreeDescriptorSets(m_api->m_device, set.pool, 1, &set.handle);
    }
    void reset()
    {
        for (auto pool : pools)
            m_api->vkResetDescriptorPool(m_api->m_device, pool, 0);
    }
    void close()
    {
        for (auto pool : pools)
            m_api->vkDestroyDescriptorPool(m_api->m_device, pool, nullptr);
    }
};
} // namespace gfx