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();
swapchain.reset();
command_pool.reset();
descriptor_pool.reset();
allocator.destroy();
surface.reset();
wait_idle();
@ -179,28 +178,11 @@ bool Context::init()
init_device();
init_vma();
init_command_pool();
init_descriptor_pool();
wait_idle();
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()
{
vk::CommandPoolCreateInfo cpci({}, graphics_queue_family_index);

View File

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

View File

@ -48,6 +48,7 @@ SimpleOutput::~SimpleOutput()
context->wait_idle();
textures.clear();
descriptors.clear();
descriptor_pool.reset();
device.destroySampler(linear_sampler);
device.destroySampler(nearest_sampler);
}
@ -55,11 +56,17 @@ SimpleOutput::~SimpleOutput()
void SimpleOutput::create_objects()
{
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++)
{
vk::DescriptorSetAllocateInfo dsai{};
dsai
.setDescriptorPool(context->descriptor_pool.get())
auto dsai = vk::DescriptorSetAllocateInfo{}
.setDescriptorPool(descriptor_pool.get())
.setDescriptorSetCount(1)
.setSetLayouts(descriptor_set_layout.get());
auto descriptor = device.allocateDescriptorSetsUnique(dsai).value;

View File

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