Vulkan: Move descriptor pool out of context.

This commit is contained in:
BearOso 2024-10-26 20:26:47 -05:00
parent 20768ed8b2
commit e6c4f617cc
4 changed files with 11 additions and 23 deletions

View File

@ -22,7 +22,6 @@ Context::~Context()
wait_idle(); wait_idle();
swapchain.reset(); swapchain.reset();
command_pool.reset(); command_pool.reset();
descriptor_pool.reset();
allocator.destroy(); allocator.destroy();
surface.reset(); surface.reset();
wait_idle(); wait_idle();
@ -179,28 +178,11 @@ bool Context::init()
init_device(); init_device();
init_vma(); init_vma();
init_command_pool(); init_command_pool();
init_descriptor_pool();
wait_idle(); wait_idle();
return true; return true;
} }
bool Context::init_descriptor_pool()
{
auto descriptor_pool_size = vk::DescriptorPoolSize{}
.setDescriptorCount(9)
.setType(vk::DescriptorType::eCombinedImageSampler);
auto descriptor_pool_create_info = vk::DescriptorPoolCreateInfo{}
.setPoolSizes(descriptor_pool_size)
.setMaxSets(20)
.setFlags(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet);
auto retval = device.createDescriptorPoolUnique(descriptor_pool_create_info);
descriptor_pool = std::move(retval.value);
return true;
}
bool Context::init_command_pool() bool Context::init_command_pool()
{ {
vk::CommandPoolCreateInfo cpci({}, graphics_queue_family_index); vk::CommandPoolCreateInfo cpci({}, graphics_queue_family_index);

View File

@ -50,7 +50,6 @@ class Context
uint32_t graphics_queue_family_index; uint32_t graphics_queue_family_index;
vk::Queue queue; vk::Queue queue;
vk::UniqueCommandPool command_pool; vk::UniqueCommandPool command_pool;
vk::UniqueDescriptorPool descriptor_pool;
std::unique_ptr<Swapchain> swapchain; std::unique_ptr<Swapchain> swapchain;
vk::UniqueInstance instance; vk::UniqueInstance instance;
vk::PhysicalDevice physical_device; vk::PhysicalDevice physical_device;
@ -61,7 +60,6 @@ class Context
bool init_vma(); bool init_vma();
bool init_device(); bool init_device();
bool init_command_pool(); bool init_command_pool();
bool init_descriptor_pool();
int preferred_device; int preferred_device;
#ifdef VK_USE_PLATFORM_XLIB_KHR #ifdef VK_USE_PLATFORM_XLIB_KHR

View File

@ -48,6 +48,7 @@ SimpleOutput::~SimpleOutput()
context->wait_idle(); context->wait_idle();
textures.clear(); textures.clear();
descriptors.clear(); descriptors.clear();
descriptor_pool.reset();
device.destroySampler(linear_sampler); device.destroySampler(linear_sampler);
device.destroySampler(nearest_sampler); device.destroySampler(nearest_sampler);
} }
@ -55,11 +56,17 @@ SimpleOutput::~SimpleOutput()
void SimpleOutput::create_objects() void SimpleOutput::create_objects()
{ {
descriptors.clear(); descriptors.clear();
descriptor_pool.reset();
vk::DescriptorPoolSize descriptor_pool_size(vk::DescriptorType::eCombinedImageSampler, 20);
vk::DescriptorPoolCreateInfo dpci(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 20,
descriptor_pool_size);
descriptor_pool = device.createDescriptorPoolUnique(dpci).value;
for (int i = 0; i < queue_size; i++) for (int i = 0; i < queue_size; i++)
{ {
vk::DescriptorSetAllocateInfo dsai{}; auto dsai = vk::DescriptorSetAllocateInfo{}
dsai .setDescriptorPool(descriptor_pool.get())
.setDescriptorPool(context->descriptor_pool.get())
.setDescriptorSetCount(1) .setDescriptorSetCount(1)
.setSetLayouts(descriptor_set_layout.get()); .setSetLayouts(descriptor_set_layout.get());
auto descriptor = device.allocateDescriptorSetsUnique(dsai).value; auto descriptor = device.allocateDescriptorSetsUnique(dsai).value;

View File

@ -25,6 +25,7 @@ class SimpleOutput
vk::Device device; vk::Device device;
Vulkan::Swapchain *swapchain; Vulkan::Swapchain *swapchain;
vk::UniqueDescriptorPool descriptor_pool;
vk::UniqueDescriptorSetLayout descriptor_set_layout; vk::UniqueDescriptorSetLayout descriptor_set_layout;
vk::UniquePipelineLayout pipeline_layout; vk::UniquePipelineLayout pipeline_layout;
vk::UniquePipeline pipeline; vk::UniquePipeline pipeline;