Created a descriptor pool for Graphics System

This commit is contained in:
Brandon Mak 2022-09-09 14:21:13 +08:00
parent fe954271cb
commit d7954245d6
6 changed files with 61 additions and 29 deletions

View File

@ -7,32 +7,52 @@
namespace SHADE namespace SHADE
{ {
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Constructor/Destructor */ /* Constructor/Destructor */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
SHVkDescriptorPool::SHVkDescriptorPool(Handle<SHVkLogicalDevice> device, const Config& config) SHVkDescriptorPool::SHVkDescriptorPool(Handle<SHVkLogicalDevice> device, const Config& config)
: device { device } : device{ device }
{
// Create the Pool
const vk::DescriptorPoolCreateInfo POOL_CREATE_INFO
{ {
// Create the Pool .flags = config.Flags,
const vk::DescriptorPoolCreateInfo POOL_CREATE_INFO .maxSets = config.MaxSets,
{ .poolSizeCount = static_cast<uint32_t>(config.Limits.size()),
.flags = config.Flags, .pPoolSizes = config.Limits.data()
.maxSets = config.MaxSets, };
.poolSizeCount = static_cast<uint32_t>(config.Limits.size()), pool = device->GetVkLogicalDevice().createDescriptorPool(POOL_CREATE_INFO);
.pPoolSizes = config.Limits.data() }
};
pool = device->GetVkLogicalDevice().createDescriptorPool(POOL_CREATE_INFO);
}
SHVkDescriptorPool::~SHVkDescriptorPool() noexcept SHVkDescriptorPool::SHVkDescriptorPool(SHVkDescriptorPool&& rhs) noexcept
{ : device{ rhs.device }
if (pool) , pool{ rhs.pool }
device->GetVkLogicalDevice().destroyDescriptorPool(pool); {
} rhs.pool = VK_NULL_HANDLE;
}
std::vector<Handle<SHVkDescriptorSetGroup>> SHVkDescriptorPool::Allocate(const std::vector<Handle<SHVkDescriptorSetLayout>>& layouts, std::vector<uint32_t> const& variableDescCounts) SHVkDescriptorPool::~SHVkDescriptorPool() noexcept
{ {
SHVkInstance::GetResourceManager().Create<SHVkDescriptorSetGroup>(device, GetHandle(), layouts, variableDescCounts); if (pool)
return {}; device->GetVkLogicalDevice().destroyDescriptorPool(pool);
} }
SHVkDescriptorPool& SHVkDescriptorPool::operator=(SHVkDescriptorPool&& rhs) noexcept
{
if (&rhs == this)
return *this;
device = rhs.device;
pool = rhs.pool;
rhs.pool = VK_NULL_HANDLE;
return *this;
}
std::vector<Handle<SHVkDescriptorSetGroup>> SHVkDescriptorPool::Allocate(const std::vector<Handle<SHVkDescriptorSetLayout>>& layouts, std::vector<uint32_t> const& variableDescCounts)
{
SHVkInstance::GetResourceManager().Create<SHVkDescriptorSetGroup>(device, GetHandle(), layouts, variableDescCounts);
return {};
}
} }

View File

@ -65,7 +65,7 @@ namespace SHADE
/// </param> /// </param>
SHVkDescriptorPool(Handle<SHVkLogicalDevice> device, const Config& config = {}); SHVkDescriptorPool(Handle<SHVkLogicalDevice> device, const Config& config = {});
SHVkDescriptorPool(const SHVkDescriptorPool&) = delete; SHVkDescriptorPool(const SHVkDescriptorPool&) = delete;
SHVkDescriptorPool(SHVkDescriptorPool&& rhs) noexcept = default; SHVkDescriptorPool(SHVkDescriptorPool&& rhs) noexcept;
/// <summary> /// <summary>
/// Destructor which will unload and deallocate all resources for this Pool. /// Destructor which will unload and deallocate all resources for this Pool.
/// </summary> /// </summary>
@ -75,7 +75,7 @@ namespace SHADE
/* Overloaded Operators */ /* Overloaded Operators */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
SHVkDescriptorPool& operator=(const SHVkDescriptorPool&) = delete; SHVkDescriptorPool& operator=(const SHVkDescriptorPool&) = delete;
SHVkDescriptorPool& operator=(SHVkDescriptorPool&& rhs) noexcept = default; SHVkDescriptorPool& operator=(SHVkDescriptorPool&& rhs) noexcept;
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Getter Functions */ /* Getter Functions */

View File

@ -509,6 +509,12 @@ namespace SHADE
} }
Handle<SHVkDescriptorPool> SHVkLogicalDevice::CreateDescriptorPools(const SHVkDescriptorPool::Config& config /*= {}*/) noexcept
{
return SHVkInstance::GetResourceManager().Create <SHVkDescriptorPool>(GetHandle(), config);
}
/***************************************************************************/ /***************************************************************************/
/*! /*!

View File

@ -17,7 +17,7 @@
#include "Graphics/Pipeline/SHPipelineState.h" #include "Graphics/Pipeline/SHPipelineState.h"
#include "Graphics/Pipeline/SHPipelineType.h" #include "Graphics/Pipeline/SHPipelineType.h"
#include "vk_mem_alloc.h" #include "vk_mem_alloc.h"
//#include "Graphics/DescriptorSets/SHDescriptorPool.h" #include "Graphics/Descriptors/SHVkDescriptorPool.h"
#include "Graphics/Descriptors/SHVkDescriptorSetLayout.h" #include "Graphics/Descriptors/SHVkDescriptorSetLayout.h"
namespace SHADE namespace SHADE
@ -165,6 +165,7 @@ namespace SHADE
Handle<SHVkRenderpass> CreateRenderpass (std::span<vk::AttachmentDescription> const vkDescriptions, std::span<vk::SubpassDescription> const spDescs, std::span<vk::SubpassDependency> const spDeps) noexcept; Handle<SHVkRenderpass> CreateRenderpass (std::span<vk::AttachmentDescription> const vkDescriptions, std::span<vk::SubpassDescription> const spDescs, std::span<vk::SubpassDependency> const spDeps) noexcept;
Handle<SHVkFramebuffer> CreateFramebuffer (Handle<SHVkRenderpass> const& renderpassHdl, std::vector<Handle<SHVkImageView>> const& attachments, uint32_t inWidth, uint32_t inHeight) noexcept; Handle<SHVkFramebuffer> CreateFramebuffer (Handle<SHVkRenderpass> const& renderpassHdl, std::vector<Handle<SHVkImageView>> const& attachments, uint32_t inWidth, uint32_t inHeight) noexcept;
Handle<SHVkDescriptorSetLayout> CreateDescriptorSetLayout (std::vector<SHVkDescriptorSetLayout::Binding> const& bindings) noexcept; Handle<SHVkDescriptorSetLayout> CreateDescriptorSetLayout (std::vector<SHVkDescriptorSetLayout::Binding> const& bindings) noexcept;
Handle<SHVkDescriptorPool> CreateDescriptorPools (const SHVkDescriptorPool::Config& config = {}) noexcept;
Handle<SHVkPipelineLayout> CreatePipelineLayout (SHPipelineLayoutParams& pipelineLayoutParams) noexcept; Handle<SHVkPipelineLayout> CreatePipelineLayout (SHPipelineLayoutParams& pipelineLayoutParams) noexcept;
Handle<SHVkFence> CreateFence (void) const noexcept; Handle<SHVkFence> CreateFence (void) const noexcept;
Handle<SHVkSemaphore> CreateSemaphore (void) const noexcept; Handle<SHVkSemaphore> CreateSemaphore (void) const noexcept;

View File

@ -86,6 +86,8 @@ namespace SHADE
descPool = device->CreateDescriptorPools();
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/

View File

@ -22,6 +22,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Graphics/MiddleEnd/PerFrame/SHRenderContext.h" #include "Graphics/MiddleEnd/PerFrame/SHRenderContext.h"
#include "Graphics/RenderGraph/SHRenderGraph.h" #include "Graphics/RenderGraph/SHRenderGraph.h"
#include "Engine/ECS_Base/System/SHSystem.h" #include "Engine/ECS_Base/System/SHSystem.h"
#include "Graphics/Descriptors/SHVkDescriptorPool.h"
namespace SHADE namespace SHADE
{ {
@ -113,7 +114,8 @@ namespace SHADE
Handle<SHVkSwapchain> GetSwapchain() const { return swapchain; } Handle<SHVkSwapchain> GetSwapchain() const { return swapchain; }
Handle<SHVkSurface> GetSurface() const { return surface; } Handle<SHVkSurface> GetSurface() const { return surface; }
Handle<SHVkPhysicalDevice> GetPhysicalDevice() const {return physicalDevice;} Handle<SHVkPhysicalDevice> GetPhysicalDevice() const {return physicalDevice;}
Handle<SHVkQueue> GetQueue () const {return queue;} Handle<SHVkQueue> GetQueue() const { return queue; }
Handle<SHVkDescriptorPool> GetDescriptorPool() const { return descPool; }
//Handle<SHVkRenderpass> GetRenderPass() const { return renderPass; } //Handle<SHVkRenderpass> GetRenderPass() const { return renderPass; }
@ -127,6 +129,7 @@ namespace SHADE
Handle<SHVkSurface> surface; Handle<SHVkSurface> surface;
Handle<SHVkSwapchain> swapchain; Handle<SHVkSwapchain> swapchain;
Handle<SHVkQueue> queue; Handle<SHVkQueue> queue;
Handle<SHVkDescriptorPool> descPool;
//Handle<SHVkRenderpass> renderPass; // Potentially bring out? //Handle<SHVkRenderpass> renderPass; // Potentially bring out?
std::vector<SHScreenSegment> screenSegments; std::vector<SHScreenSegment> screenSegments;
SHRenderContext renderContext; SHRenderContext renderContext;