From 915469e0f3467022f7fd3541350b04b8668d20f7 Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Thu, 29 Sep 2022 18:11:53 -0400 Subject: [PATCH] descriptor pool final fix --- engine/xe_engine.cpp | 10 ---------- engine/xe_engine.hpp | 6 +----- engine/xe_render_system.cpp | 14 +++++++++++++- engine/xe_render_system.hpp | 3 ++- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/engine/xe_engine.cpp b/engine/xe_engine.cpp index 5af5ef8..4f64bbf 100644 --- a/engine/xe_engine.cpp +++ b/engine/xe_engine.cpp @@ -13,7 +13,6 @@ Engine::Engine(int width, int height, std::string name, const char *icon) : xeWi xeRenderer{xeWindow, xeDevice}, xeCamera{}, xeInput{xeWindow} { - loadDescriptorPool(); alutInit(0, NULL); std::cout << "Audio device: " << alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER) << "\n"; _instance = this; @@ -25,15 +24,6 @@ Engine::~Engine() { alutExit(); }; -void Engine::loadDescriptorPool() { - xeDescriptorPool = DescriptorPool::Builder(xeDevice) - .setMaxSets(SwapChain::MAX_FRAMES_IN_FLIGHT) - .addPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, SwapChain::MAX_FRAMES_IN_FLIGHT * 4) - .addPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, SwapChain::MAX_FRAMES_IN_FLIGHT * 4) - .addPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, SwapChain::MAX_FRAMES_IN_FLIGHT * 4) - .build(); -} - bool Engine::poll() { glfwPollEvents(); auto newTime = std::chrono::high_resolution_clock::now(); diff --git a/engine/xe_engine.hpp b/engine/xe_engine.hpp index ae75afa..b181688 100644 --- a/engine/xe_engine.hpp +++ b/engine/xe_engine.hpp @@ -40,9 +40,7 @@ class Engine { static Engine* getInstance(); private: - - void loadDescriptorPool(); - + Window xeWindow; Device xeDevice; Renderer xeRenderer; @@ -54,8 +52,6 @@ class Engine { float FOV = 50.f; - std::unique_ptr xeDescriptorPool; - friend class RenderSystem; friend class Image; friend class Model; diff --git a/engine/xe_render_system.cpp b/engine/xe_render_system.cpp index 1ceff78..770bfd5 100644 --- a/engine/xe_render_system.cpp +++ b/engine/xe_render_system.cpp @@ -15,11 +15,11 @@ RenderSystem::RenderSystem( uint32_t vertexSize ) : xeDevice{xeEngine.xeDevice}, xeRenderer{xeEngine.xeRenderer}, - xeDescriptorPool{xeEngine.xeDescriptorPool}, pushCunstantDataSize{pushCunstantDataSize}, uniformBindings{uniformBindings}, imageBindings{imageBindings}, imageArrayBindings{imageArrayBindings} { + createDescriptorPool(); createDescriptorSetLayout(); createUniformBuffers(); createDescriptorSets(); @@ -31,6 +31,18 @@ RenderSystem::~RenderSystem() { vkDestroyPipelineLayout(xeDevice.device(), pipelineLayout, nullptr); }; +void RenderSystem::createDescriptorPool() { + DescriptorPool::Builder builder{xeDevice}; + builder.setMaxSets(SwapChain::MAX_FRAMES_IN_FLIGHT); + builder.addPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, uniformBindings.size() * SwapChain::MAX_FRAMES_IN_FLIGHT); + uint32_t images = imageBindings.size(); + for ( const auto &[binding, size]: imageArrayBindings) { + images += size.size(); + } + builder.addPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, images * SwapChain::MAX_FRAMES_IN_FLIGHT); + xeDescriptorPool = builder.build(); +} + void RenderSystem::createDescriptorSetLayout() { DescriptorSetLayout::Builder builder{xeDevice}; diff --git a/engine/xe_render_system.hpp b/engine/xe_render_system.hpp index e0915dd..bbf96f8 100644 --- a/engine/xe_render_system.hpp +++ b/engine/xe_render_system.hpp @@ -124,6 +124,7 @@ class RenderSystem { private: + void createDescriptorPool(); void createDescriptorSetLayout(); void createUniformBuffers(); void createDescriptorSets(); @@ -148,7 +149,7 @@ class RenderSystem { VkPipelineLayout pipelineLayout; std::unique_ptr xePipeline; - std::unique_ptr &xeDescriptorPool; + std::unique_ptr xeDescriptorPool; std::unique_ptr xeDescriptorSetLayout; };