From e6c4f617cce02224c33d9a358d5fc2adb33fdaa0 Mon Sep 17 00:00:00 2001 From: BearOso Date: Sat, 26 Oct 2024 20:26:47 -0500 Subject: [PATCH] Vulkan: Move descriptor pool out of context. --- common/video/vulkan/vulkan_context.cpp | 18 ------------------ common/video/vulkan/vulkan_context.hpp | 2 -- common/video/vulkan/vulkan_simple_output.cpp | 13 ++++++++++--- common/video/vulkan/vulkan_simple_output.hpp | 1 + 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/common/video/vulkan/vulkan_context.cpp b/common/video/vulkan/vulkan_context.cpp index 12beddb5..195cbfbe 100644 --- a/common/video/vulkan/vulkan_context.cpp +++ b/common/video/vulkan/vulkan_context.cpp @@ -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); diff --git a/common/video/vulkan/vulkan_context.hpp b/common/video/vulkan/vulkan_context.hpp index 0e05c7d7..8e9d1787 100644 --- a/common/video/vulkan/vulkan_context.hpp +++ b/common/video/vulkan/vulkan_context.hpp @@ -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; 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 diff --git a/common/video/vulkan/vulkan_simple_output.cpp b/common/video/vulkan/vulkan_simple_output.cpp index d8a61802..97e3f814 100644 --- a/common/video/vulkan/vulkan_simple_output.cpp +++ b/common/video/vulkan/vulkan_simple_output.cpp @@ -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; diff --git a/common/video/vulkan/vulkan_simple_output.hpp b/common/video/vulkan/vulkan_simple_output.hpp index a4a4f137..ac791cb1 100644 --- a/common/video/vulkan/vulkan_simple_output.hpp +++ b/common/video/vulkan/vulkan_simple_output.hpp @@ -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;