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

#include <DirectXResource.h>

Inheritance diagram for ne::DirectXResource:
ne::GpuResource

Classes

struct  DescriptorsSameType
 

Public Member Functions

 DirectXResource (const DirectXResource &)=delete
 
DirectXResourceoperator= (const DirectXResource &)=delete
 
std::optional< ErrorbindDescriptor (DirectXDescriptorType descriptorType, ContinuousDirectXDescriptorRange *pRange=nullptr, bool bBindDescriptorsToCubemapFaces=true)
 
std::optional< D3D12_CPU_DESCRIPTOR_HANDLE > getBindedDescriptorCpuHandle (DirectXDescriptorType descriptorType)
 
std::optional< D3D12_CPU_DESCRIPTOR_HANDLE > getBindedCubemapFaceDescriptorCpuHandle (DirectXDescriptorType descriptorType, size_t iCubemapFaceIndex)
 
std::optional< D3D12_GPU_DESCRIPTOR_HANDLE > getBindedDescriptorGpuHandle (DirectXDescriptorType descriptorType)
 
ID3D12Resource * getInternalResource () const
 
DirectXDescriptorgetDescriptor (DirectXDescriptorType descriptorType)
 
- Public Member Functions inherited from ne::GpuResource
 GpuResource (GpuResourceManager *pManager, const std::string &sResourceName, unsigned int iElementSizeInBytes, unsigned int iElementCount)
 
 GpuResource (GpuResource &)=delete
 
GpuResourceoperator= (GpuResource &)=delete
 
std::string getResourceName () const
 
unsigned int getElementSizeInBytes () const
 
unsigned int getElementCount () const
 
GpuResourceManagergetResourceManager () const
 

Private Member Functions

 DirectXResource (DirectXResourceManager *pResourceManager, const std::string &sResourceName, UINT iElementSizeInBytes, UINT iElementCount)
 

Static Private Member Functions

static std::variant< std::unique_ptr< DirectXResource >, Errorcreate (DirectXResourceManager *pResourceManager, const std::string &sResourceName, D3D12MA::Allocator *pMemoryAllocator, const D3D12MA::ALLOCATION_DESC &allocationDesc, const D3D12_RESOURCE_DESC &resourceDesc, const D3D12_RESOURCE_STATES &initialResourceState, std::optional< D3D12_CLEAR_VALUE > resourceClearValue, size_t iElementSizeInBytes=0, size_t iElementCount=0)
 
static std::variant< std::unique_ptr< DirectXResource >, ErrorcreateResourceFromSwapChainBuffer (DirectXResourceManager *pResourceManager, DirectXDescriptorHeap *pRtvHeap, const ComPtr< ID3D12Resource > &pSwapChainBuffer)
 

Private Attributes

std::pair< std::recursive_mutex, std::array< DescriptorsSameType, static_cast< size_t >(DirectXDescriptorType::END)> > mtxHeapDescriptors
 
ComPtr< D3D12MA::Allocation > pAllocatedResource
 
ComPtr< ID3D12Resource > pSwapChainBuffer
 
ID3D12Resource * pInternalResource = nullptr
 

Friends

class DirectXDescriptorHeap
 
class DirectXResourceManager
 

Detailed Description

D3D resource wrapper with automatic descriptor binding.

Constructor & Destructor Documentation

◆ DirectXResource()

ne::DirectXResource::DirectXResource ( DirectXResourceManager pResourceManager,
const std::string &  sResourceName,
UINT  iElementSizeInBytes,
UINT  iElementCount 
)
private

Constructor. Creates an empty resource.

Parameters
pResourceManagerOwner resource manager.
sResourceNameName of this resource.
iElementSizeInBytesResource size information. Size of one array element (if array), otherwise specify size of the whole resource.
iElementCountResource size information. Total number of elements in the array (if array), otherwise specify 1.

Member Function Documentation

◆ bindDescriptor()

std::optional< Error > ne::DirectXResource::bindDescriptor ( DirectXDescriptorType  descriptorType,
ContinuousDirectXDescriptorRange pRange = nullptr,
bool  bBindDescriptorsToCubemapFaces = true 
)

Creates a new descriptor and binds it to this resource.

Remarks
Does nothing if a descriptor of this type is already binded.
Parameters
descriptorTypeType of descriptor to bind.
pRangeSpecify in order to allocate a descriptor from this range.
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.

◆ create()

std::variant< std::unique_ptr< DirectXResource >, Error > ne::DirectXResource::create ( DirectXResourceManager pResourceManager,
const std::string &  sResourceName,
D3D12MA::Allocator *  pMemoryAllocator,
const D3D12MA::ALLOCATION_DESC &  allocationDesc,
const D3D12_RESOURCE_DESC &  resourceDesc,
const D3D12_RESOURCE_STATES &  initialResourceState,
std::optional< D3D12_CLEAR_VALUE >  resourceClearValue,
size_t  iElementSizeInBytes = 0,
size_t  iElementCount = 0 
)
staticprivate

Creates a new resource (without binding a descriptor to it).

Parameters
pResourceManagerOwner resource manager.
sResourceNameResource name, used for logging.
pMemoryAllocatorAllocator to create resource.
allocationDescAllocation description.
resourceDescResource description.
initialResourceStateInitial state of this resource.
resourceClearValueOptimized clear value. Pass empty if creating CBV/SRV/UAV resource.
iElementSizeInBytesOptional parameter. Specify if this resource represents an array. Used for SRV creation.
iElementCountOptional parameter. Specify if this resource represents an array. Used for SRV creation.
Returns
Error if something went wrong, otherwise created resource.

◆ createResourceFromSwapChainBuffer()

std::variant< std::unique_ptr< DirectXResource >, Error > ne::DirectXResource::createResourceFromSwapChainBuffer ( DirectXResourceManager pResourceManager,
DirectXDescriptorHeap pRtvHeap,
const ComPtr< ID3D12Resource > &  pSwapChainBuffer 
)
staticprivate

Creates a new resource instance by wrapping existing swap chain buffer, also binds RTV to the specified resource.

Parameters
pResourceManagerOwner resource manager.
pRtvHeapRender target view heap manager.
pSwapChainBufferSwap chain buffer to wrap.
Returns
Error if something went wrong, otherwise created resource.

◆ getBindedCubemapFaceDescriptorCpuHandle()

std::optional< D3D12_CPU_DESCRIPTOR_HANDLE > ne::DirectXResource::getBindedCubemapFaceDescriptorCpuHandle ( DirectXDescriptorType  descriptorType,
size_t  iCubemapFaceIndex 
)

Returns descriptor handle to a cubemap face that was previously binded using bindDescriptor.

Parameters
descriptorTypeType of descriptor to get.
iCubemapFaceIndexIndex of the cubemap face to get descriptor handle to.
Returns
Empty this is not a cubemap resource or descriptor was not binded previously, otherwise descriptor handle.

◆ getBindedDescriptorCpuHandle()

std::optional< D3D12_CPU_DESCRIPTOR_HANDLE > ne::DirectXResource::getBindedDescriptorCpuHandle ( DirectXDescriptorType  descriptorType)

Returns descriptor handle to the descriptor that was previously binded using bindDescriptor.

Parameters
descriptorTypeType of descriptor to get.
Returns
Empty if descriptor if this type was not binded to this resource, otherwise descriptor handle.

◆ getBindedDescriptorGpuHandle()

std::optional< D3D12_GPU_DESCRIPTOR_HANDLE > ne::DirectXResource::getBindedDescriptorGpuHandle ( DirectXDescriptorType  descriptorType)

Returns descriptor handle to the descriptor that was previously binded using bindDescriptor.

Parameters
descriptorTypeType of descriptor to get.
Returns
Empty if descriptor if this type was not binded to this resource, otherwise descriptor handle.

◆ getDescriptor()

DirectXDescriptor * ne::DirectXResource::getDescriptor ( DirectXDescriptorType  descriptorType)

Returns a raw (non-owning) pointer to a binded descriptor.

Remarks
Do not delete (free) returned pointer.
Parameters
descriptorTypeType of descriptor to query.
Returns
nullptr if a descriptor of this type was not binded to this resource, otherwise valid pointer.

◆ getInternalResource()

ID3D12Resource * ne::DirectXResource::getInternalResource ( ) const
inline

Returns internal resource.

Remarks
Do not delete (free) this pointer.
Returned pointer is only valid while this object is valid.
Returns
Internal resource.

Member Data Documentation

◆ mtxHeapDescriptors

std::pair< std::recursive_mutex, std::array<DescriptorsSameType, static_cast<size_t>(DirectXDescriptorType::END)> > ne::DirectXResource::mtxHeapDescriptors
private

Array of descriptors used by this resource.

Remarks
Access elements like this: "vHeapDescriptors[DirectXDescriptorType::SRV]".
Some descriptors are nullptr. nullptr descriptor means that it's not set (not used).
There might be 6 descriptors of the same type if this resource is a cubemap, then each descriptor will reference a specific cubemap face.

◆ pAllocatedResource

ComPtr<D3D12MA::Allocation> ne::DirectXResource::pAllocatedResource
private

Created resource (can be empty if pSwapChainBuffer is used).

◆ pInternalResource

ID3D12Resource* ne::DirectXResource::pInternalResource = nullptr
private

Pointer to pSwapChainBuffer or pAllocatedResource used for fast access to internal resource.

◆ pSwapChainBuffer

ComPtr<ID3D12Resource> ne::DirectXResource::pSwapChainBuffer
private

Used when resource was created from swap chain buffer (can be empty if pAllocatedResource is used).


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