Nameless Engine
Loading...
Searching...
No Matches
ne::DirectXDescriptorHeap Class Reference

#include <DirectXDescriptorHeap.h>

Classes

struct  InternalData
 

Public Member Functions

 DirectXDescriptorHeap (const DirectXDescriptorHeap &)=delete
 
DirectXDescriptorHeapoperator= (const DirectXDescriptorHeap &)=delete
 
 ~DirectXDescriptorHeap ()
 
std::variant< std::shared_ptr< ContinuousDirectXDescriptorRange >, ErrorallocateContinuousDescriptorRange (const std::string &sRangeName, const std::function< void()> &onRangeIndicesChanged)
 
INT getHeapCapacity ()
 
INT getHeapSize ()
 
size_t getNoLongerUsedDescriptorCount ()
 
UINT getDescriptorSize () const
 
ID3D12DescriptorHeap * getInternalHeap () const
 
std::pair< std::recursive_mutex, InternalData > * getInternalData ()
 

Static Public Member Functions

static constexpr INT getHeapGrowSize ()
 
static std::variant< std::unique_ptr< DirectXDescriptorHeap >, Errorcreate (DirectXRenderer *pRenderer, DescriptorHeapType heapType)
 

Protected Member Functions

 DirectXDescriptorHeap (DirectXRenderer *pRenderer, DescriptorHeapType heapType)
 
void onDescriptorBeingDestroyed (DirectXDescriptor *pDescriptor, ContinuousDirectXDescriptorRange *pRange=nullptr)
 
void onDescriptorRangeBeingDestroyed (ContinuousDirectXDescriptorRange *pRange)
 
void createView (CD3DX12_CPU_DESCRIPTOR_HANDLE heapHandle, const DirectXResource *pResource, DirectXDescriptorType descriptorType, std::optional< size_t > cubemapFaceIndex) const
 
std::optional< ErrorexpandHeap (ContinuousDirectXDescriptorRange *pChangedRange)
 
std::variant< bool, ErrorshrinkHeapIfPossible (ContinuousDirectXDescriptorRange *pChangedRange)
 
std::optional< ErrorcreateHeap (INT iCapacity, ContinuousDirectXDescriptorRange *pChangedRange)
 
std::vector< DirectXDescriptorType > getDescriptorTypesHandledByThisHeap () const
 
std::optional< ErrorrebindViewsUpdateIndices ()
 

Static Protected Member Functions

static std::string convertHeapTypeToString (DescriptorHeapType heapType)
 

Private Member Functions

std::optional< ErrorassignDescriptor (DirectXResource *pResource, DirectXDescriptorType descriptorType, const std::shared_ptr< ContinuousDirectXDescriptorRange > &pRange=nullptr, bool bBindDescriptorsToCubemapFaces=true)
 
std::optional< ErrorexpandRange (ContinuousDirectXDescriptorRange *pRange)
 

Static Private Member Functions

static bool isShrinkingPossible (INT iSize, INT iCapacity, INT iGrowSize)
 

Private Attributes

DirectXRendererpRenderer
 
std::pair< std::recursive_mutex, InternalDatamtxInternalData
 
UINT iDescriptorSize = 0
 
DescriptorHeapType heapType
 
std::string sHeapType
 
D3D12_DESCRIPTOR_HEAP_TYPE d3dHeapType
 

Static Private Attributes

static constexpr INT iHeapGrowSize = 300
 

Friends

class DirectXDescriptor
 
class ContinuousDirectXDescriptorRange
 
class DirectXResource
 

Detailed Description

Represents a descriptor heap.

Constructor & Destructor Documentation

◆ ~DirectXDescriptorHeap()

ne::DirectXDescriptorHeap::~DirectXDescriptorHeap ( )

Makes sure no descriptor or range exists.

◆ DirectXDescriptorHeap()

ne::DirectXDescriptorHeap::DirectXDescriptorHeap ( DirectXRenderer pRenderer,
DescriptorHeapType  heapType 
)
protected

Constructor.

Parameters
pRendererDirectX renderer that owns this manager.
heapTypeType of the heap.

Member Function Documentation

◆ allocateContinuousDescriptorRange()

std::variant< std::shared_ptr< ContinuousDirectXDescriptorRange >, Error > ne::DirectXDescriptorHeap::allocateContinuousDescriptorRange ( const std::string &  sRangeName,
const std::function< void()> &  onRangeIndicesChanged 
)

Allocates a continuous range of descriptors that can be used for bindless bindings of descriptor arrays.

Parameters
sRangeNameName of the range (used for logging).
onRangeIndicesChangedCallback that will be called after the range was moved in the heap due to things like heap expand/shrink.
Returns
Error if something went wrong, otherwise allocated descriptor range.

◆ assignDescriptor()

std::optional< Error > ne::DirectXDescriptorHeap::assignDescriptor ( DirectXResource pResource,
DirectXDescriptorType  descriptorType,
const std::shared_ptr< ContinuousDirectXDescriptorRange > &  pRange = nullptr,
bool  bBindDescriptorsToCubemapFaces = true 
)
private

Creates a new descriptor that points to the given resource, the descriptor is saved in the resource.

Remarks
You can use this function to assign a different descriptor to already created resource. For example: create SRV resource using resource manager and use RTV heap to assign a RTV descriptor to this resource so it will have 2 different descriptors.
Parameters
pResourceResource to point new descriptor to.
descriptorTypeType of the new descriptor.
pRangeSpecify in order to allocate a descriptor from this range. The specified shared pointer will be copied and saved in the resource so that the range will not be destroyed while this resource references a descriptor from it.
bBindDescriptorsToCubemapFacesIf this resource is a cubemap, specify true to also bind descriptors that reference specific cubemap faces, specify false to only bind 1 descriptor that references the entire resource.
Returns
Error if something went wrong.

◆ convertHeapTypeToString()

std::string ne::DirectXDescriptorHeap::convertHeapTypeToString ( DescriptorHeapType  heapType)
staticprotected

Converts heap type to string.

Parameters
heapTypeHeap type to convert to text.
Returns
Heap type text.

◆ create()

std::variant< std::unique_ptr< DirectXDescriptorHeap >, Error > ne::DirectXDescriptorHeap::create ( DirectXRenderer pRenderer,
DescriptorHeapType  heapType 
)
static

Creates a new manager that controls a specific heap.

Parameters
pRendererDirectX renderer that owns this manager.
heapTypeHeap type that this manager will control.
Returns
Error if something went wrong, otherwise pointer to the manager.

◆ createHeap()

std::optional< Error > ne::DirectXDescriptorHeap::createHeap ( INT  iCapacity,
ContinuousDirectXDescriptorRange pChangedRange 
)
protected

(Re)creates the heap with the specified capacity.

Remarks
Only updates the heap resource, internal capacity and updates old descriptors (if any), other internal values are not changed and should be corrected afterwards.
Parameters
iCapacitySize of the heap (in descriptors).
pChangedRangeIf this event was caused by changes in descriptor range, specify one for logging purposes.
Returns
Error if something went wrong.

◆ createView()

void ne::DirectXDescriptorHeap::createView ( CD3DX12_CPU_DESCRIPTOR_HANDLE  heapHandle,
const DirectXResource pResource,
DirectXDescriptorType  descriptorType,
std::optional< size_t >  cubemapFaceIndex 
) const
protected

Creates a new view using the specified descriptor handle that will point to the specified resource.

Parameters
heapHandleA place in the heap to create view.
pResourceResource to bind to the new view.
descriptorTypeDescriptor type.
cubemapFaceIndexSpecify empty if creating a view for the entire resource, otherwise specify index of the cubemap face to bind the descriptor to.

◆ expandHeap()

std::optional< Error > ne::DirectXDescriptorHeap::expandHeap ( ContinuousDirectXDescriptorRange pChangedRange)
protected

Re-creates the heap to expand its capacity to support iHeapGrowSize more descriptors.

Remarks
All internal values and old descriptors will be updated.
Parameters
pChangedRangeIf this event was caused by changes in descriptor range, specify one for logging purposes.
Returns
Error if something went wrong.

◆ expandRange()

std::optional< Error > ne::DirectXDescriptorHeap::expandRange ( ContinuousDirectXDescriptorRange pRange)
private

Expands the specified descriptor range and expands or re-creates the heap to support updated range.

Parameters
pRangeRange to expand.
Returns
Error if something went wrong.

◆ getDescriptorSize()

UINT ne::DirectXDescriptorHeap::getDescriptorSize ( ) const
inline

Returns size of one descriptor in this heap.

Returns
Descriptor size.

◆ getDescriptorTypesHandledByThisHeap()

std::vector< DirectXDescriptorType > ne::DirectXDescriptorHeap::getDescriptorTypesHandledByThisHeap ( ) const
protected

Returns an array of descriptor types that this heap handles. For example: for RTV heap it will only be RTV descriptor type, for DSV - DSV, for CBV/UAV/SRV heap it will be CBV, UAV and SRV (3 types).

Returns
Descriptor types that this heap handles.

◆ getHeapCapacity()

INT ne::DirectXDescriptorHeap::getHeapCapacity ( )

Returns current heap capacity (allocated heap size).

This function is used for engine testing and generally should not be used outside of testing.

Returns
Heap capacity.

◆ getHeapGrowSize()

static constexpr INT ne::DirectXDescriptorHeap::getHeapGrowSize ( )
inlinestaticconstexpr

Returns grow/shrink size for the heap.

Returns
Grow/shrink size.

◆ getHeapSize()

INT ne::DirectXDescriptorHeap::getHeapSize ( )

Returns current heap size (actually used heap size).

This function is used for engine testing and generally should not be used outside of testing.

Returns
Heap size.

◆ getInternalData()

std::pair< std::recursive_mutex, InternalData > * ne::DirectXDescriptorHeap::getInternalData ( )
inline

Returns internal data of the object.

Warning
Only used for read-only purposes of automated-tests.
Returns
Internal data.

◆ getInternalHeap()

ID3D12DescriptorHeap * ne::DirectXDescriptorHeap::getInternalHeap ( ) const
inline

Returns internal DirectX heap.

Returns
DirectX heap.

◆ getNoLongerUsedDescriptorCount()

size_t ne::DirectXDescriptorHeap::getNoLongerUsedDescriptorCount ( )

Returns amount of descriptors that were created but no longer being used.

Returns
Descriptor count.

◆ isShrinkingPossible()

bool ne::DirectXDescriptorHeap::isShrinkingPossible ( INT  iSize,
INT  iCapacity,
INT  iGrowSize 
)
staticprivate

Checks shrink condition: if capacity can be decremented by grow size with the current size.

Parameters
iSizeCurrent size.
iCapacityCurrent capacity.
iGrowSizeGrow/shrink size. Expected to be even.
Returns
true if capacity can be decremented by one grow size, false if not yet.

◆ onDescriptorBeingDestroyed()

void ne::DirectXDescriptorHeap::onDescriptorBeingDestroyed ( DirectXDescriptor pDescriptor,
ContinuousDirectXDescriptorRange pRange = nullptr 
)
protected

Marks resource descriptor as no longer being used so the descriptor's index can be reused by some other descriptor.

Remarks
Called from DirectXDescriptor destructor.
Parameters
pDescriptorDescriptor that is being destroyed.
pRangeRange that allocated the descriptor (if the descriptor was allocated from a range).

◆ onDescriptorRangeBeingDestroyed()

void ne::DirectXDescriptorHeap::onDescriptorRangeBeingDestroyed ( ContinuousDirectXDescriptorRange pRange)
protected

Notifies the heap about some range being destroyed.

Remarks
Called from range destructor.
Parameters
pRangeRange that is being destroyed.

◆ rebindViewsUpdateIndices()

std::optional< Error > ne::DirectXDescriptorHeap::rebindViewsUpdateIndices ( )
protected

Recreates views for previously created descriptors so that they will reference the new re-created heap and reference the correct index inside of the heap.

Remarks
Also updates next free descriptor index and queue of unused indices.
Returns
Error if something went wrong.

◆ shrinkHeapIfPossible()

std::variant< bool, Error > ne::DirectXDescriptorHeap::shrinkHeapIfPossible ( ContinuousDirectXDescriptorRange pChangedRange)
protected

Checks if the heap can be shrinked (based on the current internal state mtxInternalData) and if possible re-creates the heap to shrink its capacity to support iHeapGrowSize less descriptors.

Remarks
All internal values and old descriptors will be updated.
Parameters
pChangedRangeIf this event was caused by changes in descriptor range, specify one for logging purposes.
Returns
Error if something went wrong, otherwise true if heap was shrinked, false if no shrinking is needed yet.

Member Data Documentation

◆ d3dHeapType

D3D12_DESCRIPTOR_HEAP_TYPE ne::DirectXDescriptorHeap::d3dHeapType
private

Direct3D type of this heap.

◆ heapType

DescriptorHeapType ne::DirectXDescriptorHeap::heapType
private

Type of the heap.

◆ iDescriptorSize

UINT ne::DirectXDescriptorHeap::iDescriptorSize = 0
private

Size of one descriptor.

◆ iHeapGrowSize

constexpr INT ne::DirectXDescriptorHeap::iHeapGrowSize = 300
staticconstexprprivate

Number of descriptors to add to the heap when there is no more free space left.

◆ mtxInternalData

std::pair<std::recursive_mutex, InternalData> ne::DirectXDescriptorHeap::mtxInternalData
private

Descriptor heap internal resources.

◆ pRenderer

DirectXRenderer* ne::DirectXDescriptorHeap::pRenderer
private

Do not delete. Owner renderer.

◆ sHeapType

std::string ne::DirectXDescriptorHeap::sHeapType
private

String version of heap type (used for logging).


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