Nameless Engine
|
#include <DirectXResourceManager.h>
Public Member Functions | |
DirectXResourceManager (const DirectXResourceManager &)=delete | |
DirectXResourceManager & | operator= (const DirectXResourceManager &)=delete |
virtual std::variant< std::unique_ptr< GpuResource >, Error > | loadTextureFromDisk (const std::string &sResourceName, const std::filesystem::path &pathToTextureFile) override |
virtual std::variant< std::unique_ptr< UploadBuffer >, Error > | createResourceWithCpuWriteAccess (const std::string &sResourceName, size_t iElementSizeInBytes, size_t iElementCount, std::optional< bool > isUsedInShadersAsArrayResource) override |
virtual std::variant< std::unique_ptr< GpuResource >, Error > | createResourceWithData (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 >, Error > | createResource (const std::string &sResourceName, size_t iElementSizeInBytes, size_t iElementCount, ResourceUsageType usage, bool bIsShaderReadWriteResource) override |
virtual std::variant< std::unique_ptr< GpuResource >, Error > | createShaderReadWriteTextureResource (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 >, Error > | 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) |
std::variant< std::vector< std::unique_ptr< DirectXResource > >, Error > | makeRtvResourcesFromSwapChainBuffer (IDXGISwapChain3 *pSwapChain, unsigned int iSwapChainBufferCount) |
DirectXDescriptorHeap * | getRtvHeap () const |
DirectXDescriptorHeap * | getDsvHeap () const |
DirectXDescriptorHeap * | getCbvSrvUavHeap () 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 >, Error > | loadTextureFromDisk (const std::string &sResourceName, const std::filesystem::path &pathToTextureFile)=0 |
virtual std::variant< std::unique_ptr< UploadBuffer >, Error > | createResourceWithCpuWriteAccess (const std::string &sResourceName, size_t iElementSizeInBytes, size_t iElementCount, std::optional< bool > isUsedInShadersAsArrayResource)=0 |
virtual std::variant< std::unique_ptr< GpuResource >, Error > | createResourceWithData (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 >, Error > | createResource (const std::string &sResourceName, size_t iElementSizeInBytes, size_t iElementCount, ResourceUsageType usage, bool bIsShaderReadWriteResource)=0 |
virtual std::variant< std::unique_ptr< GpuResource >, Error > | createShaderReadWriteTextureResource (const std::string &sResourceName, unsigned int iWidth, unsigned int iHeight, ShaderReadWriteTextureResourceFormat format)=0 |
virtual std::string | getCurrentStateInfo ()=0 |
Renderer * | getRenderer () const |
TextureManager * | getTextureManager () const |
ShadowMapManager * | getShadowMapManager () const |
DynamicCpuWriteShaderResourceArrayManager * | getDynamicCpuWriteShaderResourceArrayManager () const |
size_t | getTotalAliveResourceCount () |
Static Public Member Functions | |
static DXGI_FORMAT | convertTextureResourceFormatToDxFormat (ShaderReadWriteTextureResourceFormat format) |
static std::variant< std::unique_ptr< DirectXResourceManager >, Error > | create (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 >, Error > | createShadowMapTexture (const std::string &sResourceName, unsigned int iTextureSize, bool bPointLightColorCubemap) override |
std::variant< std::unique_ptr< GpuResource >, Error > | 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) |
Static Private Member Functions | |
static size_t | makeMultipleOf256 (size_t iNumber) |
Private Attributes | |
ComPtr< D3D12MA::Allocator > | pMemoryAllocator |
std::unique_ptr< DirectXDescriptorHeap > | pRtvHeap |
std::unique_ptr< DirectXDescriptorHeap > | pDsvHeap |
std::unique_ptr< DirectXDescriptorHeap > | pCbvSrvUavHeap |
Additional Inherited Members | |
Protected Member Functions inherited from ne::GpuResourceManager | |
virtual std::variant< std::unique_ptr< GpuResource >, Error > | createShadowMapTexture (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 >, Error > | create (Renderer *pRenderer) |
static std::variant< std::unique_ptr< GpuResourceManager >, Error > | createRendererSpecificManager (Renderer *pRenderer) |
Controls resource creation and descriptors heaps.
|
private |
Constructor.
pRenderer | DirectX renderer. |
pMemoryAllocator | Created memory allocator to use. |
pRtvHeap | Created RTV heap manager. |
pDsvHeap | Created DSV heap manager. |
pCbvSrvUavHeap | Created CBV/SRV/UAV heap. |
|
static |
Converts texture resource format to DirectX format.
format | Format to convert. |
|
static |
Creates a new resource manager.
pRenderer | DirectX renderer. |
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.
sResourceName | Resource name, used for logging. |
allocationDesc | Allocation description. |
resourceDesc | Resource description. |
initialResourceState | Initial resource state. |
resourceClearValue | Clear value for render target or depth/stencil resources. |
|
overridevirtual |
Creates a new GPU resource (buffer, not a texture) without any initial data.
sResourceName | Resource name, used for logging. |
iElementSizeInBytes | Size of one buffer element in bytes. |
iElementCount | Number of elements in the resulting buffer. |
usage | Describes how you plan to use this resource. |
bIsShaderReadWriteResource | Specify true if you plan to modify the resource from shaders, otherwise false . |
Implements ne::GpuResourceManager.
|
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:
cbuffer
in shaders if bIsUsedInShadersAsReadOnlyData
is true
.sResourceName | Resource name, used for logging. |
iElementSizeInBytes | Size of one buffer element in bytes. |
iElementCount | Number of elements in the resulting buffer. |
isUsedInShadersAsArrayResource | Specify 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). |
Implements ne::GpuResourceManager.
|
private |
Creates a new GPU resource and fills it with the specified data.
sResourceName | Resource name, used for logging. |
finalResourceDescription | Description of the final resource to create. |
vSubresourcesToCopy | Describes the data that the resulting resource should have. |
uploadResourceDescription | Description of the upload/staging resource. |
bIsTextureResource | true if the final resource will be used as a read-only texture in pixel shader, false if the final resource is not a texture. |
iElementSizeInBytes | Optional size of one buffer element in bytes. |
iElementCount | Optional number of elements in the resulting buffer. |
|
overridevirtual |
Creates a new GPU resource (buffer, not a texture) and fills it with the specified data.
Example:
sResourceName | Resource name, used for logging. |
pBufferData | Pointer to the data that the new resource will contain. |
iElementSizeInBytes | Size of one buffer element in bytes. |
iElementCount | Number of elements in the resulting buffer. |
usage | Describes how you plan to use this resource. |
bIsShaderReadWriteResource | Specify true if you plan to modify the resource from shaders, otherwise false . |
Implements ne::GpuResourceManager.
|
overridevirtual |
Creates a texture resource that is available as a read/write resource in shaders.
sResourceName | Resource name, used for logging. |
iWidth | Width of the texture in pixels. |
iHeight | Height of the texture in pixels. |
format | Format of the texture. |
Implements ne::GpuResourceManager.
|
overrideprivatevirtual |
Creates a GPU resource to be used as a shadow map.
sResourceName | Resource name, used for logging. |
iTextureSize | Size of one dimension of the texture in pixels. Must be power of 2 (128, 256, 512, 1024, 2048, etc.). |
bPointLightColorCubemap | false is you need a single 2D texture resource or true to have 6 2D textures arranged as a cube map specifically for point lights. |
Implements ne::GpuResourceManager.
DirectXDescriptorHeap * ne::DirectXResourceManager::getCbvSrvUavHeap | ( | ) | const |
Returns CBV/SRV/UAV heap.
|
overridevirtual |
Dumps internal state of the resource manager in JSON format.
Implements ne::GpuResourceManager.
DirectXDescriptorHeap * ne::DirectXResourceManager::getDsvHeap | ( | ) | const |
Returns DSV heap.
DirectXDescriptorHeap * ne::DirectXResourceManager::getRtvHeap | ( | ) | const |
Returns RTV heap.
|
overridevirtual |
Returns total video memory size (VRAM) in megabytes.
Implements ne::GpuResourceManager.
|
overridevirtual |
Returns the amount of video memory (VRAM) occupied by all currently allocated resources.
Implements ne::GpuResourceManager.
|
overridevirtual |
Loads a texture from a DDS file in the GPU memory.
sResourceName | Resource name, used for logging. |
pathToTextureFile | Path to the image file that stores texture data. |
Implements ne::GpuResourceManager.
|
inlinestaticprivate |
Modifies the value to be a multiple of 256.
Example:
iNumber | Value to make a multiple of 256. |
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.
pSwapChain | Swap chain. |
iSwapChainBufferCount | Number of buffers swap chain has. |
|
private |
CBV/SRV/UAV heap manager.
|
private |
DSV heap manager.
|
private |
Allocator for GPU resources.
|
private |
RTV heap manager.