Nameless Engine
Loading...
Searching...
No Matches
ne::GpuResourceManager Class Referenceabstract

#include <GpuResourceManager.h>

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

Public Member Functions

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 ()
 

Protected Member Functions

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

static std::variant< std::unique_ptr< GpuResourceManager >, Errorcreate (Renderer *pRenderer)
 
static std::variant< std::unique_ptr< GpuResourceManager >, ErrorcreateRendererSpecificManager (Renderer *pRenderer)
 

Private Attributes

std::unique_ptr< TextureManagerpTextureManager
 
std::unique_ptr< ShadowMapManagerpShadowMapManager
 
std::unique_ptr< DynamicCpuWriteShaderResourceArrayManagerpDynamicCpuWriteShaderResourceArrayManager
 
std::atomic< size_t > iAliveResourceCount {0}
 
Renderer *const pRenderer = nullptr
 

Friends

class Renderer
 
class ShadowMapManager
 
class GpuResource
 

Detailed Description

Allows creating GPU resources.

Constructor & Destructor Documentation

◆ GpuResourceManager()

ne::GpuResourceManager::GpuResourceManager ( Renderer pRenderer)
protected

Creates partially initialized manager, used internally.

Remarks
Prefer to use create.
Parameters
pRendererRenderer that owns this manager.

Member Function Documentation

◆ create()

std::variant< std::unique_ptr< GpuResourceManager >, Error > ne::GpuResourceManager::create ( Renderer pRenderer)
staticprotected

Creates a new platform-specific resource manager.

Parameters
pRendererRenderer.
Returns
Error if something went wrong, otherwise fully initialized resource manager.

◆ createRendererSpecificManager()

std::variant< std::unique_ptr< GpuResourceManager >, Error > ne::GpuResourceManager::createRendererSpecificManager ( Renderer pRenderer)
staticprotected

Used internally to create initial (base) manager object.

Remarks
Prefer to use create.
Parameters
pRendererRenderer
Returns
Error if something went wrong, otherwise partially initialized manager.

◆ createResource()

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

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.

Implemented in ne::DirectXResourceManager, and ne::VulkanResourceManager.

◆ createResourceWithCpuWriteAccess()

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

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);
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 constant (cbuffer in HLSL, uniform in GLSL), might cause padding to 256 bytes and size limitation up to 64 KB, specify true if this resource will be used in shaders as an array resource (StructuredBuffer in HLSL, storage buffer in GLSL - not an array but it will be a storage buffer).
Returns
Error if something went wrong, otherwise created resource.

Implemented in ne::DirectXResourceManager, and ne::VulkanResourceManager.

◆ createResourceWithData()

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

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.

Implemented in ne::DirectXResourceManager, and ne::VulkanResourceManager.

◆ createShaderReadWriteTextureResource()

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

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.

Implemented in ne::DirectXResourceManager, and ne::VulkanResourceManager.

◆ createShadowMapTexture()

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

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.

Implemented in ne::DirectXResourceManager, and ne::VulkanResourceManager.

◆ getCurrentStateInfo()

virtual std::string ne::GpuResourceManager::getCurrentStateInfo ( )
pure virtual

Dumps internal state of the resource manager in JSON format.

Returns
JSON string.

Implemented in ne::DirectXResourceManager, and ne::VulkanResourceManager.

◆ getDynamicCpuWriteShaderResourceArrayManager()

DynamicCpuWriteShaderResourceArrayManager * ne::GpuResourceManager::getDynamicCpuWriteShaderResourceArrayManager ( ) const

Returns CPU-write shader resource array manager.

Remarks
Do not delete (free) returned pointer.
Returns
CPU-write array manager.

◆ getRenderer()

Renderer * ne::GpuResourceManager::getRenderer ( ) const

Returns renderer that owns this resource manager.

Remarks
Do not delete (free) returned pointer.
Returns
Renderer that owns this manager.

◆ getShadowMapManager()

ShadowMapManager * ne::GpuResourceManager::getShadowMapManager ( ) const

Returns shadow map manager.

Remarks
Do not delete (free) returned pointer.
Returns
Shadow map manager.

◆ getTextureManager()

TextureManager * ne::GpuResourceManager::getTextureManager ( ) const

Returns texture manager.

Remarks
Do not delete (free) returned pointer.
Returns
Texture manager.

◆ getTotalAliveResourceCount()

size_t ne::GpuResourceManager::getTotalAliveResourceCount ( )

Returns the total number of GPU resources currently alive.

Returns
GPU resource count.

◆ getTotalVideoMemoryInMb()

virtual size_t ne::GpuResourceManager::getTotalVideoMemoryInMb ( ) const
pure virtual

Returns total video memory size (VRAM) in megabytes.

Returns
Total video memory size in megabytes.

Implemented in ne::DirectXResourceManager, and ne::VulkanResourceManager.

◆ getUsedVideoMemoryInMb()

virtual size_t ne::GpuResourceManager::getUsedVideoMemoryInMb ( ) const
pure virtual

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

Returns
Size of the video memory used by allocated resources.

Implemented in ne::DirectXResourceManager, and ne::VulkanResourceManager.

◆ loadTextureFromDisk()

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

Loads a texture from the specified path 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.

Implemented in ne::DirectXResourceManager, and ne::VulkanResourceManager.

◆ resetManagers()

void ne::GpuResourceManager::resetManagers ( )
protected

Sets nullptr to all texture/shadow/etc managers' unique ptr to force destroy them (if exist).

Member Data Documentation

◆ iAliveResourceCount

std::atomic<size_t> ne::GpuResourceManager::iAliveResourceCount {0}
private

Total number of created resources that were not destroyed yet.

◆ pDynamicCpuWriteShaderResourceArrayManager

std::unique_ptr<DynamicCpuWriteShaderResourceArrayManager> ne::GpuResourceManager::pDynamicCpuWriteShaderResourceArrayManager
private

Manages dynamic CPU-write shader arrays.

◆ pRenderer

Renderer* const ne::GpuResourceManager::pRenderer = nullptr
private

Do not delete (free) this pointer. Renderer that owns this manager.

◆ pShadowMapManager

std::unique_ptr<ShadowMapManager> ne::GpuResourceManager::pShadowMapManager
private

Stores all shadow maps.

◆ pTextureManager

std::unique_ptr<TextureManager> ne::GpuResourceManager::pTextureManager
private

Stores all texture GPU resources.


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