Diligent Engine
 
Loading...
Searching...
No Matches
Diligent::ResourceReleaseQueue< ResourceWrapperType > Class Template Reference

Facilitates safe resource destruction in D3D12 and Vulkan. More...

#include <ResourceReleaseQueue.hpp>

Public Member Functions

template<typename ResourceType, typename = typename std::enable_if<std::is_object<ResourceType>::value>::type>
void SafeReleaseResource (ResourceType &&Resource, Uint64 NextCommandListNumber)
 Moves a resource to the stale resources queue.
 
void SafeReleaseResource (ResourceWrapperType &&Wrapper, Uint64 NextCommandListNumber)
 Moves a resource wrapper to the stale resources queue.
 
void SafeReleaseResource (const ResourceWrapperType &Wrapper, Uint64 NextCommandListNumber)
 Moves a copy of the resource wrapper to the stale resources queue.
 
template<typename ResourceType, typename = typename std::enable_if<std::is_object<ResourceType>::value>::type>
void DiscardResource (ResourceType &&Resource, Uint64 FenceValue)
 Adds a resource directly to the release queue.
 
void DiscardResource (ResourceWrapperType &&Wrapper, Uint64 FenceValue)
 Adds a resource wrapper directly to the release queue.
 
void DiscardResource (const ResourceWrapperType &Wrapper, Uint64 FenceValue)
 Adds a copy of the resource wrapper directly to the release queue.
 
template<typename ResourceType, typename IteratorType>
void DiscardResources (Uint64 FenceValue, IteratorType Iterator)
 Adds multiple resources directly to the release queue.
 
void DiscardStaleResources (Uint64 SubmittedCmdBuffNumber, Uint64 FenceValue)
 Moves stale objects to the release queue.
 
void Purge (Uint64 CompletedFenceValue)
 
size_t GetStaleResourceCount () const
 Returns the number of stale resources.
 
size_t GetPendingReleaseResourceCount () const
 Returns the number of resources pending release.
 

Static Public Member Functions

template<typename ResourceType, typename = typename std::enable_if<std::is_object<ResourceType>::value>::type>
static ResourceWrapperType CreateWrapper (ResourceType &&Resource, typename ResourceWrapperType::RefCounterType NumReferences)
 Creates a resource wrapper for the specific resource type.
 

Detailed Description

template<typename ResourceWrapperType>
class Diligent::ResourceReleaseQueue< ResourceWrapperType >

Facilitates safe resource destruction in D3D12 and Vulkan.

Resource destruction is a two-stage process:

  • When resource is released, it is moved into the stale objects queue along with the next command list number
  • When command list is submitted to the command queue, all stale objects associated with this and earlier command lists are moved to the release queue, along with the fence value associated with the command list
  • Resources are removed and actually destroyed from the queue when fence is signaled and the queue is purged
Template Parameters
ResourceWrapperType- Type of the resource wrapper used by the release queue.

Member Function Documentation

◆ CreateWrapper()

template<typename ResourceWrapperType>
template<typename ResourceType, typename = typename std::enable_if<std::is_object<ResourceType>::value>::type>
static ResourceWrapperType Diligent::ResourceReleaseQueue< ResourceWrapperType >::CreateWrapper ( ResourceType && Resource,
typename ResourceWrapperType::RefCounterType NumReferences )
inlinestatic

Creates a resource wrapper for the specific resource type.

Parameters
[in]Resource- Resource to be released
[in]NumReferences- Number of references to the resource

◆ DiscardResource() [1/3]

template<typename ResourceWrapperType>
void Diligent::ResourceReleaseQueue< ResourceWrapperType >::DiscardResource ( const ResourceWrapperType & Wrapper,
Uint64 FenceValue )
inline

Adds a copy of the resource wrapper directly to the release queue.

Parameters
[in]Wrapper- Resource wrapper containing the resource to be released.
[in]FenceValue- Fence value indicating when the resource was used last time.

◆ DiscardResource() [2/3]

template<typename ResourceWrapperType>
template<typename ResourceType, typename = typename std::enable_if<std::is_object<ResourceType>::value>::type>
void Diligent::ResourceReleaseQueue< ResourceWrapperType >::DiscardResource ( ResourceType && Resource,
Uint64 FenceValue )
inline

Adds a resource directly to the release queue.

Parameters
[in]Resource- Resource to be released.
[in]FenceValue- Fence value indicating when the resource was used last time.

◆ DiscardResource() [3/3]

template<typename ResourceWrapperType>
void Diligent::ResourceReleaseQueue< ResourceWrapperType >::DiscardResource ( ResourceWrapperType && Wrapper,
Uint64 FenceValue )
inline

Adds a resource wrapper directly to the release queue.

Parameters
[in]Wrapper- Resource wrapper containing the resource to be released.
[in]FenceValue- Fence value indicating when the resource was used last time.

◆ DiscardResources()

template<typename ResourceWrapperType>
template<typename ResourceType, typename IteratorType>
void Diligent::ResourceReleaseQueue< ResourceWrapperType >::DiscardResources ( Uint64 FenceValue,
IteratorType Iterator )
inline

Adds multiple resources directly to the release queue.

Parameters
[in]FenceValue- Fence value indicating when the resource was used last time.
[in]Iterator- Iterator that returns resources to be released.

◆ DiscardStaleResources()

template<typename ResourceWrapperType>
void Diligent::ResourceReleaseQueue< ResourceWrapperType >::DiscardStaleResources ( Uint64 SubmittedCmdBuffNumber,
Uint64 FenceValue )
inline

Moves stale objects to the release queue.

Parameters
[in]SubmittedCmdBuffNumber- number of the last submitted command list. All resources in the stale object list whose command list number is less than or equal to this value are moved to the release queue.
[in]FenceValue- Fence value associated with the resources moved to the release queue. A resource will be destroyed by Purge() method when completed fence value is greater or equal to the fence value associated with the resource

◆ Purge()

template<typename ResourceWrapperType>
void Diligent::ResourceReleaseQueue< ResourceWrapperType >::Purge ( Uint64 CompletedFenceValue)
inline

Removes all objects from the release queue whose fence value is less than or equal to CompletedFenceValue

Parameters
[in]CompletedFenceValue- Value of the fence that has been completed by the GPU

◆ SafeReleaseResource() [1/3]

template<typename ResourceWrapperType>
void Diligent::ResourceReleaseQueue< ResourceWrapperType >::SafeReleaseResource ( const ResourceWrapperType & Wrapper,
Uint64 NextCommandListNumber )
inline

Moves a copy of the resource wrapper to the stale resources queue.

Parameters
[in]Wrapper- Resource wrapper containing the resource to be released
[in]NextCommandListNumber- Number of the command list that will be submitted to the queue next

◆ SafeReleaseResource() [2/3]

template<typename ResourceWrapperType>
template<typename ResourceType, typename = typename std::enable_if<std::is_object<ResourceType>::value>::type>
void Diligent::ResourceReleaseQueue< ResourceWrapperType >::SafeReleaseResource ( ResourceType && Resource,
Uint64 NextCommandListNumber )
inline

Moves a resource to the stale resources queue.

Parameters
[in]Resource- Resource to be released
[in]NextCommandListNumber- Number of the command list that will be submitted to the queue next

◆ SafeReleaseResource() [3/3]

template<typename ResourceWrapperType>
void Diligent::ResourceReleaseQueue< ResourceWrapperType >::SafeReleaseResource ( ResourceWrapperType && Wrapper,
Uint64 NextCommandListNumber )
inline

Moves a resource wrapper to the stale resources queue.

Parameters
[in]Wrapper- Resource wrapper containing the resource to be released
[in]NextCommandListNumber- Number of the command list that will be submitted to the queue next