Open 3D Engine Atom Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::RHI::ResourcePool Class Referenceabstract

#include <ResourcePool.h>

Inherits AZ::RHI::DeviceObject, MemoryStatisticsEventBus::Handler, and FrameEventBus::Handler.

Inherited by AZ::RHI::AliasedHeap, AZ::RHI::BufferPoolBase, AZ::RHI::ImagePoolBase, AZ::RHI::QueryPool, and AZ::RHI::ShaderResourceGroupPool.

Public Member Functions

 AZ_RTTI (ResourcePool, "{757EB674-25DC-4D00-9808-D3DAF33A4EFE}", DeviceObject)
 
void Shutdown () override final
 Shuts down the pool. This method will shutdown all resources associated with the pool.
 
template<typename ResourceType >
void ForEach (AZStd::function< void(ResourceType &)> callback)
 
template<typename ResourceType >
void ForEach (AZStd::function< void(const ResourceType &)> callback) const
 
uint32_t GetResourceCount () const
 Returns the number of resources in the pool.
 
ResourcePoolResolverGetResolver ()
 Returns the resolver for this pool.
 
const ResourcePoolResolverGetResolver () const
 
virtual const ResourcePoolDescriptorGetDescriptor () const =0
 Returns the resource pool descriptor.
 
const HeapMemoryUsageGetHeapMemoryUsage (HeapMemoryLevel heapMemoryLevel) const
 Returns the memory used by this pool for a specific heap type.
 
const PoolMemoryUsageGetMemoryUsage () const
 Returns the memory used by this pool.
 
- Public Member Functions inherited from AZ::RHI::DeviceObject
 AZ_RTTI (DeviceObject, "{17D34F71-944C-4AF5-9823-627474C4C0A6}", Object)
 
bool IsInitialized () const
 Returns whether the device object is initialized.
 
DeviceGetDevice () const
 
- Public Member Functions inherited from AZ::RHI::Object
 AZ_RTTI (Object, "{E43378F1-2331-4173-94B8-990ED20E6003}")
 
void SetName (const Name &name)
 Sets the name of the object.
 
const Name & GetName () const
 Returns the name set on the object by SetName.
 
uint32_t use_count ()
 Returns the current use count of the object.
 

Protected Types

using PlatformMethod = AZStd::function< RHI::ResultCode()>
 A simple functor that returns a result code.
 

Protected Member Functions

void OnFrameBegin () override
 
void OnFrameCompile () override
 
void OnFrameEnd () override
 
void SetResolver (AZStd::unique_ptr< ResourcePoolResolver > &&resolvePolicy)
 
virtual void ComputeFragmentation () const =0
 
ResultCode Init (Device &device, const ResourcePoolDescriptor &descriptor, const PlatformMethod &initMethod)
 
ResultCode InitResource (Resource *resource, const PlatformMethod &initResourceMethod)
 
bool ValidateIsRegistered (const Resource *resource) const
 
bool ValidateIsUnregistered (const Resource *resource) const
 
bool ValidateIsInitialized () const
 Validates that the resource pool is initialized and ready to service requests.
 
bool ValidateNotProcessingFrame () const
 Validates that we are not in the frame processing phase.
 
- Protected Member Functions inherited from AZ::RHI::DeviceObject
void Init (Device &device)
 The derived class should call this method to assign the device.
 
void Shutdown () override
 Clears the current bound device to null.
 
- Protected Member Functions inherited from AZ::RHI::Object
void add_ref () const
 
void release () const
 

Protected Attributes

PoolMemoryUsage m_memoryUsage
 
- Protected Attributes inherited from AZ::RHI::Object
AZStd::atomic_int m_useCount = 0
 

Friends

class Resource
 

Detailed Description

A base class for resource pools. This class facilitates registration of resources into the pool, and allows iterating child resource instances.

Member Function Documentation

◆ ComputeFragmentation()

virtual void AZ::RHI::ResourcePool::ComputeFragmentation ( ) const
protectedpure virtual

Compute the memory fragmentation for each constituent heap and store the results in m_memoryUsage. This method is invoked when memory statistics gathering is active.

Implemented in AZ::RHI::AliasedHeap, AZ::RHI::ImagePool, AZ::RHI::QueryPool, AZ::RHI::ShaderResourceGroupPool, and AZ::RHI::SwapChain.

◆ ForEach()

template<typename ResourceType >
void AZ::RHI::ResourcePool::ForEach ( AZStd::function< void(ResourceType &)>  callback)

Loops through every resource matching the provided resource type (RTTI casting is used) and calls the provided callback method. Both methods are thread-safe with respect to other Init calls. A shared_mutex is used to guard the internal registry. This means that multiple iterations can be done without blocking each other, but a resource Init / Shutdown will serialize with this method.

◆ GetDescriptor()

virtual const ResourcePoolDescriptor & AZ::RHI::ResourcePool::GetDescriptor ( ) const
pure virtual

◆ Init()

ResultCode AZ::RHI::ResourcePool::Init ( Device device,
const ResourcePoolDescriptor descriptor,
const PlatformMethod initMethod 
)
protected

Validates the pool for initialization, calls the provided init method (which wraps the platform-specific resource init call). If the platform init fails, the resource pool is shutdown and an error code is returned.

◆ InitResource()

ResultCode AZ::RHI::ResourcePool::InitResource ( Resource resource,
const PlatformMethod initResourceMethod 
)
protected

Validates the state of resource, calls the provided init method, and registers the resource with the pool. If validation or the internal platform init method fail, the resource is not registered and an error code is returned.

◆ SetResolver()

void AZ::RHI::ResourcePool::SetResolver ( AZStd::unique_ptr< ResourcePoolResolver > &&  resolvePolicy)
protected

Each platform implementation has the option to supply a resolver object. It's a platform defined class charged with performing resource data uploads on a scope in the FrameScheduler. Leaving this empty means the platform pool does not require a resolve operation.

◆ Shutdown()

void AZ::RHI::ResourcePool::Shutdown ( )
finaloverridevirtual

Shuts down the pool. This method will shutdown all resources associated with the pool.

Reimplemented from AZ::RHI::DeviceObject.

◆ ValidateIsRegistered()

bool AZ::RHI::ResourcePool::ValidateIsRegistered ( const Resource resource) const
protected

Validates the resource is registered / unregistered with the pool, and that it not null. In non-release builds this will issue a warning. Non-release builds will branch and fail the call if validation fails, but this should be treated as a bug, because release will disable validation.

Member Data Documentation

◆ m_memoryUsage

PoolMemoryUsage AZ::RHI::ResourcePool::m_memoryUsage
protected

Pool memory usage is held by the base class. It is exposed for public const access and protected mutable access. The budget components are assigned by this class (those should not be touched as they are passed from the user), but the usage components are managed by the platform pool implementation. The platform components are atomic, which enables for lock-free memory tracking.


The documentation for this class was generated from the following file: