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

#include <DirectXResourceManager.h>

Inheritance diagram for ne::DirectXResourceManager:
ne::GpuResourceManager

Public Member Functions

 DirectXResourceManager (const DirectXResourceManager &)=delete
 
DirectXResourceManageroperator= (const DirectXResourceManager &)=delete
 
virtual std::variant< std::unique_ptr< GpuResource >, ErrorloadTextureFromDisk (const std::string &sResourceName, const std::filesystem::path &pathToTextureFile) override
 
virtual std::variant< std::unique_ptr< UploadBuffer >, ErrorcreateResourceWithCpuWriteAccess (const std::string &sResourceName, size_t iElementSizeInBytes, size_t iElementCount, std::optional< bool > isUsedInShadersAsArrayResource) override
 
virtual std::variant< std::unique_ptr< GpuResource >, ErrorcreateResourceWithData (const std::string &sResourceName, const void *pBufferData, size_t iElementSizeInBytes, size_t iElementCount, ResourceUsageType usage, bool bIsShaderReadWriteResource) override
 
virtual std::variant< std::unique_ptr< GpuResource >, ErrorcreateResource (const std::string &sResourceName, size_t iElementSizeInBytes, size_t iElementCount, ResourceUsageType usage, bool bIsShaderReadWriteResource) override
 
virtual std::variant< std::unique_ptr< GpuResource >, ErrorcreateShaderReadWriteTextureResource (const std::string &sResourceName, unsigned int iWidth, unsigned int iHeight, ShaderReadWriteTextureResourceFormat format) override
 
virtual size_t getTotalVideoMemoryInMb () const override
 
virtual size_t getUsedVideoMemoryInMb () const override
 
std::variant< std::unique_ptr< DirectXResource >, ErrorcreateResource (const std::string &sResourceName, const D3D12MA::ALLOCATION_DESC &allocationDesc, const D3D12_RESOURCE_DESC &resourceDesc, const D3D12_RESOURCE_STATES &initialResourceState, const std::optional< D3D12_CLEAR_VALUE > &resourceClearValue)
 
std::variant< std::vector< std::unique_ptr< DirectXResource > >, ErrormakeRtvResourcesFromSwapChainBuffer (IDXGISwapChain3 *pSwapChain, unsigned int iSwapChainBufferCount)
 
DirectXDescriptorHeapgetRtvHeap () const
 
DirectXDescriptorHeapgetDsvHeap () const
 
DirectXDescriptorHeapgetCbvSrvUavHeap () const
 
virtual std::string getCurrentStateInfo () override
 
- Public Member Functions inherited from ne::GpuResourceManager
virtual size_t getTotalVideoMemoryInMb () const =0
 
virtual size_t getUsedVideoMemoryInMb () const =0
 
virtual std::variant< std::unique_ptr< GpuResource >, ErrorloadTextureFromDisk (const std::string &sResourceName, const std::filesystem::path &pathToTextureFile)=0
 
virtual std::variant< std::unique_ptr< UploadBuffer >, ErrorcreateResourceWithCpuWriteAccess (const std::string &sResourceName, size_t iElementSizeInBytes, size_t iElementCount, std::optional< bool > isUsedInShadersAsArrayResource)=0
 
virtual std::variant< std::unique_ptr< GpuResource >, ErrorcreateResourceWithData (const std::string &sResourceName, const void *pBufferData, size_t iElementSizeInBytes, size_t iElementCount, ResourceUsageType usage, bool bIsShaderReadWriteResource)=0
 
virtual std::variant< std::unique_ptr< GpuResource >, ErrorcreateResource (const std::string &sResourceName, size_t iElementSizeInBytes, size_t iElementCount, ResourceUsageType usage, bool bIsShaderReadWriteResource)=0
 
virtual std::variant< std::unique_ptr< GpuResource >, ErrorcreateShaderReadWriteTextureResource (const std::string &sResourceName, unsigned int iWidth, unsigned int iHeight, ShaderReadWriteTextureResourceFormat format)=0
 
virtual std::string getCurrentStateInfo ()=0
 
RenderergetRenderer () const
 
TextureManagergetTextureManager () const
 
ShadowMapManagergetShadowMapManager () const
 
DynamicCpuWriteShaderResourceArrayManagergetDynamicCpuWriteShaderResourceArrayManager () const
 
size_t getTotalAliveResourceCount ()
 

Static Public Member Functions

static DXGI_FORMAT convertTextureResourceFormatToDxFormat (ShaderReadWriteTextureResourceFormat format)
 
static std::variant< std::unique_ptr< DirectXResourceManager >, Errorcreate (DirectXRenderer *pRenderer)
 

Private Member Functions

 DirectXResourceManager (DirectXRenderer *pRenderer, ComPtr< D3D12MA::Allocator > &&pMemoryAllocator, std::unique_ptr< DirectXDescriptorHeap > &&pRtvHeap, std::unique_ptr< DirectXDescriptorHeap > &&pDsvHeap, std::unique_ptr< DirectXDescriptorHeap > &&pCbvSrvUavHeap)
 
virtual std::variant< std::unique_ptr< GpuResource >, ErrorcreateShadowMapTexture (const std::string &sResourceName, unsigned int iTextureSize, bool bPointLightColorCubemap) override
 
std::variant< std::unique_ptr< GpuResource >, ErrorcreateResourceWithData (const std::string &sResourceName, const D3D12_RESOURCE_DESC &finalResourceDescription, const std::vector< D3D12_SUBRESOURCE_DATA > &vSubresourcesToCopy, const D3D12_RESOURCE_DESC &uploadResourceDescription, bool bIsTextureResource, size_t iElementSizeInBytes=0, size_t iElementCount=0)
 

Static Private Member Functions

static size_t makeMultipleOf256 (size_t iNumber)
 

Private Attributes

ComPtr< D3D12MA::Allocator > pMemoryAllocator
 
std::unique_ptr< DirectXDescriptorHeappRtvHeap
 
std::unique_ptr< DirectXDescriptorHeappDsvHeap
 
std::unique_ptr< DirectXDescriptorHeappCbvSrvUavHeap
 

Additional Inherited Members

- Protected Member Functions inherited from ne::GpuResourceManager
virtual std::variant< std::unique_ptr< GpuResource >, ErrorcreateShadowMapTexture (const std::string &sResourceName, unsigned int iTextureSize, bool bPointLightColorCubemap)=0
 
 GpuResourceManager (Renderer *pRenderer)
 
void resetManagers ()
 
- Static Protected Member Functions inherited from ne::GpuResourceManager
static std::variant< std::unique_ptr< GpuResourceManager >, Errorcreate (Renderer *pRenderer)
 
static std::variant< std::unique_ptr< GpuResourceManager >, ErrorcreateRendererSpecificManager (Renderer *pRenderer)
 

Detailed Description

Controls resource creation and descriptors heaps.

Constructor & Destructor Documentation

◆ DirectXResourceManager()

ne::DirectXResourceManager::DirectXResourceManager ( DirectXRenderer pRenderer,
ComPtr< D3D12MA::Allocator > &&  pMemoryAllocator,
std::unique_ptr< DirectXDescriptorHeap > &&  pRtvHeap,
std::unique_ptr< DirectXDescriptorHeap > &&  pDsvHeap,
std::unique_ptr< DirectXDescriptorHeap > &&  pCbvSrvUavHeap 
)
private

Constructor.

Parameters
pRendererDirectX renderer.
pMemoryAllocatorCreated memory allocator to use.
pRtvHeapCreated RTV heap manager.
pDsvHeapCreated DSV heap manager.
pCbvSrvUavHeapCreated CBV/SRV/UAV heap.

Member Function Documentation

◆ convertTextureResourceFormatToDxFormat()

DXGI_FORMAT ne::DirectXResourceManager::convertTextureResourceFormatToDxFormat ( ShaderReadWriteTextureResourceFormat  format)
static

Converts texture resource format to DirectX format.

Parameters
formatFormat to convert.
Returns
DirectX format.

◆ create()

std::variant< std::unique_ptr< DirectXResourceManager >, Error > ne::DirectXResourceManager::create ( DirectXRenderer pRenderer)
static

Creates a new resource manager.

Parameters
pRendererDirectX renderer.
Returns
Error if something went wrong, otherwise created resource manager.

◆ createResource() [1/2]

std::variant< std::unique_ptr< DirectXResource >, Error > ne::DirectXResourceManager::createResource ( const std::string &  sResourceName,
const D3D12MA::ALLOCATION_DESC &  allocationDesc,
const D3D12_RESOURCE_DESC &  resourceDesc,
const D3D12_RESOURCE_STATES &  initialResourceState,
const std::optional< D3D12_CLEAR_VALUE > &  resourceClearValue 
)

Creates a new GPU resource.

Parameters
sResourceNameResource name, used for logging.
allocationDescAllocation description.
resourceDescResource description.
initialResourceStateInitial resource state.
resourceClearValueClear value for render target or depth/stencil resources.
Returns
Error if something went wrong, otherwise created resource.

◆ createResource() [2/2]

std::variant< std::unique_ptr< GpuResource >, Error > ne::DirectXResourceManager::createResource ( const std::string &  sResourceName,
size_t  iElementSizeInBytes,
size_t  iElementCount,
ResourceUsageType  usage,
bool  bIsShaderReadWriteResource 
)
overridevirtual

Creates a new GPU resource (buffer, not a texture) without any initial data.

Remarks
This function can be useful if you plan to create a resource to be filled from a (compute) shader and then use this data in some other shader.
Parameters
sResourceNameResource name, used for logging.
iElementSizeInBytesSize of one buffer element in bytes.
iElementCountNumber of elements in the resulting buffer.
usageDescribes how you plan to use this resource.
bIsShaderReadWriteResourceSpecify true if you plan to modify the resource from shaders, otherwise false.
Returns
Error if something went wrong, otherwise created resource with filled data.

Implements ne::GpuResourceManager.

◆ createResourceWithCpuWriteAccess()

std::variant< std::unique_ptr< UploadBuffer >, Error > ne::DirectXResourceManager::createResourceWithCpuWriteAccess ( const std::string &  sResourceName,
size_t  iElementSizeInBytes,
size_t  iElementCount,
std::optional< bool >  isUsedInShadersAsArrayResource 
)
overridevirtual

Creates a new GPU resource with available CPU write access (only CPU write not read), typically used for resources that needs to be frequently updated from the CPU side.

Example:

struct ObjectData{
glm::mat4x4 world;
};
auto result = pResourceManager->createResourceWithCpuWriteAccess(
"object constant data",
sizeof(ObjectData),
1,
false);
Remarks
This resource can be used as a cbuffer in shaders if bIsUsedInShadersAsReadOnlyData is true.
Parameters
sResourceNameResource name, used for logging.
iElementSizeInBytesSize of one buffer element in bytes.
iElementCountNumber of elements in the resulting buffer.
isUsedInShadersAsArrayResourceSpecify empty if this resource is not going to be used in shaders, false if this resource will be used in shaders as a single (non-array) resource (cbuffer, uniform, might cause padding to 256 bytes and size limitation up to 64 KB) and true if this resource will be used in shaders as an array resource (StructuredBuffer, storage buffer).
Returns
Error if something went wrong, otherwise created resource.

Implements ne::GpuResourceManager.

◆ createResourceWithData() [1/2]

std::variant< std::unique_ptr< GpuResource >, Error > ne::DirectXResourceManager::createResourceWithData ( const std::string &  sResourceName,
const D3D12_RESOURCE_DESC &  finalResourceDescription,
const std::vector< D3D12_SUBRESOURCE_DATA > &  vSubresourcesToCopy,
const D3D12_RESOURCE_DESC &  uploadResourceDescription,
bool  bIsTextureResource,
size_t  iElementSizeInBytes = 0,
size_t  iElementCount = 0 
)
private

Creates a new GPU resource and fills it with the specified data.

Parameters
sResourceNameResource name, used for logging.
finalResourceDescriptionDescription of the final resource to create.
vSubresourcesToCopyDescribes the data that the resulting resource should have.
uploadResourceDescriptionDescription of the upload/staging resource.
bIsTextureResourcetrue if the final resource will be used as a read-only texture in pixel shader, false if the final resource is not a texture.
iElementSizeInBytesOptional size of one buffer element in bytes.
iElementCountOptional number of elements in the resulting buffer.
Returns
Error if something went wrong, otherwise created resource with filled data.

◆ createResourceWithData() [2/2]

std::variant< std::unique_ptr< GpuResource >, Error > ne::DirectXResourceManager::createResourceWithData ( const std::string &  sResourceName,
const void *  pBufferData,
size_t  iElementSizeInBytes,
size_t  iElementCount,
ResourceUsageType  usage,
bool  bIsShaderReadWriteResource 
)
overridevirtual

Creates a new GPU resource (buffer, not a texture) and fills it with the specified data.

Example:

std::vector<glm::vec3> vVertices;
auto result = pResourceManager->createResourceWithData(
"mesh vertex buffer",
vVertices.data(),
sizeof(glm::vec3),
vVertices.size(),
true);
Parameters
sResourceNameResource name, used for logging.
pBufferDataPointer to the data that the new resource will contain.
iElementSizeInBytesSize of one buffer element in bytes.
iElementCountNumber of elements in the resulting buffer.
usageDescribes how you plan to use this resource.
bIsShaderReadWriteResourceSpecify true if you plan to modify the resource from shaders, otherwise false.
Returns
Error if something went wrong, otherwise created resource with filled data.

Implements ne::GpuResourceManager.

◆ createShaderReadWriteTextureResource()

std::variant< std::unique_ptr< GpuResource >, Error > ne::DirectXResourceManager::createShaderReadWriteTextureResource ( const std::string &  sResourceName,
unsigned int  iWidth,
unsigned int  iHeight,
ShaderReadWriteTextureResourceFormat  format 
)
overridevirtual

Creates a texture resource that is available as a read/write resource in shaders.

Parameters
sResourceNameResource name, used for logging.
iWidthWidth of the texture in pixels.
iHeightHeight of the texture in pixels.
formatFormat of the texture.
Returns
Error if something went wrong, otherwise created texture resource.

Implements ne::GpuResourceManager.

◆ createShadowMapTexture()

std::variant< std::unique_ptr< GpuResource >, Error > ne::DirectXResourceManager::createShadowMapTexture ( const std::string &  sResourceName,
unsigned int  iTextureSize,
bool  bPointLightColorCubemap 
)
overrideprivatevirtual

Creates a GPU resource to be used as a shadow map.

Parameters
sResourceNameResource name, used for logging.
iTextureSizeSize of one dimension of the texture in pixels. Must be power of 2 (128, 256, 512, 1024, 2048, etc.).
bPointLightColorCubemapfalse is you need a single 2D texture resource or true to have 6 2D textures arranged as a cube map specifically for point lights.
Returns
Error if something went wrong, otherwise created texture resource.

Implements ne::GpuResourceManager.

◆ getCbvSrvUavHeap()

DirectXDescriptorHeap * ne::DirectXResourceManager::getCbvSrvUavHeap ( ) const

Returns CBV/SRV/UAV heap.

Returns
CBV/SRV/UAV heap. Do not delete returned pointer.

◆ getCurrentStateInfo()

std::string ne::DirectXResourceManager::getCurrentStateInfo ( )
overridevirtual

Dumps internal state of the resource manager in JSON format.

Returns
JSON string.

Implements ne::GpuResourceManager.

◆ getDsvHeap()

DirectXDescriptorHeap * ne::DirectXResourceManager::getDsvHeap ( ) const

Returns DSV heap.

Returns
DSV heap. Do not delete returned pointer.

◆ getRtvHeap()

DirectXDescriptorHeap * ne::DirectXResourceManager::getRtvHeap ( ) const

Returns RTV heap.

Returns
RTV heap. Do not delete returned pointer.

◆ getTotalVideoMemoryInMb()

size_t ne::DirectXResourceManager::getTotalVideoMemoryInMb ( ) const
overridevirtual

Returns total video memory size (VRAM) in megabytes.

Returns
Total video memory size in megabytes.

Implements ne::GpuResourceManager.

◆ getUsedVideoMemoryInMb()

size_t ne::DirectXResourceManager::getUsedVideoMemoryInMb ( ) const
overridevirtual

Returns the amount of video memory (VRAM) occupied by all currently allocated resources.

Returns
Size of the video memory used by allocated resources.

Implements ne::GpuResourceManager.

◆ loadTextureFromDisk()

std::variant< std::unique_ptr< GpuResource >, Error > ne::DirectXResourceManager::loadTextureFromDisk ( const std::string &  sResourceName,
const std::filesystem::path &  pathToTextureFile 
)
overridevirtual

Loads a texture from a DDS file in the GPU memory.

Parameters
sResourceNameResource name, used for logging.
pathToTextureFilePath to the image file that stores texture data.
Returns
Error if something went wrong, otherwise created GPU resource that stores texture data.

Implements ne::GpuResourceManager.

◆ makeMultipleOf256()

static size_t ne::DirectXResourceManager::makeMultipleOf256 ( size_t  iNumber)
inlinestaticprivate

Modifies the value to be a multiple of 256.

Example:

const auto iResult = makeMultipleOf256(300);
assert(iResult == 512);
static size_t makeMultipleOf256(size_t iNumber)
Definition: DirectXResourceManager.h:276
Parameters
iNumberValue to make a multiple of 256.
Returns
Resulting value.

◆ makeRtvResourcesFromSwapChainBuffer()

std::variant< std::vector< std::unique_ptr< DirectXResource > >, Error > ne::DirectXResourceManager::makeRtvResourcesFromSwapChainBuffer ( IDXGISwapChain3 *  pSwapChain,
unsigned int  iSwapChainBufferCount 
)

Creates new resources by wrapping swap chain buffers and binding a RTV descriptor to each buffer.

Parameters
pSwapChainSwap chain.
iSwapChainBufferCountNumber of buffers swap chain has.
Returns
Error if something went wrong, otherwise created resources.

Member Data Documentation

◆ pCbvSrvUavHeap

std::unique_ptr<DirectXDescriptorHeap> ne::DirectXResourceManager::pCbvSrvUavHeap
private

CBV/SRV/UAV heap manager.

◆ pDsvHeap

std::unique_ptr<DirectXDescriptorHeap> ne::DirectXResourceManager::pDsvHeap
private

DSV heap manager.

◆ pMemoryAllocator

ComPtr<D3D12MA::Allocator> ne::DirectXResourceManager::pMemoryAllocator
private

Allocator for GPU resources.

◆ pRtvHeap

std::unique_ptr<DirectXDescriptorHeap> ne::DirectXResourceManager::pRtvHeap
private

RTV heap manager.


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