Files
o3de/Gems/Atom/RHI/Vulkan/Code/Source/RHI/DescriptorPool.h
T
2021-04-23 09:43:40 -07:00

99 lines
3.4 KiB
C++

/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <Atom/RHI/DeviceObject.h>
#include <Atom/RHI/ObjectCollector.h>
#include <AzCore/Memory/PoolAllocator.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/containers/unordered_map.h>
#include <AzCore/std/parallel/mutex.h>
#include <RHI/DescriptorSet.h>
#include <RHI/ReleaseQueue.h>
namespace AZ
{
namespace RHI
{
class ShaderResourceGroupLayout;
}
namespace Vulkan
{
class Device;
class DescriptorSetLayout;
class BufferPool;
namespace Internal
{
class DescriptorPoolFactory;
}
class DescriptorPool final
: public RHI::DeviceObject
{
using Base = RHI::DeviceObject;
using ObjectType = DescriptorSet;
friend class Internal::DescriptorPoolFactory;
public:
AZ_CLASS_ALLOCATOR(DescriptorPool, AZ::ThreadPoolAllocator, 0);
AZ_RTTI(DescriptorPool, "AB200FE2-5783-4BB7-9FDB-A99C3CDC1161", Base);
struct Descriptor
{
Device* m_device = nullptr;
AZStd::vector<VkDescriptorPoolSize> m_descriptorPoolSizes;
uint32_t m_maxSets = 0;
uint32_t m_collectLatency = 0;
BufferPool* m_constantDataPool = nullptr;
};
~DescriptorPool();
using AllocResult = AZStd::pair<VkResult, RHI::Ptr<ObjectType>>;
AllocResult Allocate(const DescriptorSetLayout& descriptorSetLayout);
void DeAllocate(RHI::Ptr<ObjectType> object);
const Descriptor& GetDescriptor() const;
VkDescriptorPool GetNativeDescriptorPool() const;
// Return the total number of objects in the pool. This include the pool objects +
// the ones queued for deletion.
size_t GetTotalObjectCount() const;
void Collect();
private:
DescriptorPool() = default;
static RHI::Ptr<DescriptorPool> Create();
RHI::ResultCode Init(const Descriptor& descriptor);
void Reset();
RHI::ResultCode BuildNativeDescriptorPool();
//////////////////////////////////////////////////////////////////////////
// RHI::Object
void SetNameInternal(const AZStd::string_view& name) override;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// RHI::DeviceObject
void Shutdown() override;
//////////////////////////////////////////////////////////////////////////
Descriptor m_descriptor;
VkDescriptorPool m_nativeDescriptorPool = VK_NULL_HANDLE;
ReleaseQueue m_collector;
AZStd::unordered_set<RHI::Ptr<ObjectType>> m_objects;
};
}
}