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

#include <VulkanResourceManager.h>

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

Public Member Functions

 VulkanResourceManager (const VulkanResourceManager &)=delete
 
VulkanResourceManageroperator= (const VulkanResourceManager &)=delete
 
virtual size_t getTotalVideoMemoryInMb () const override
 
virtual size_t getUsedVideoMemoryInMb () const override
 
std::variant< std::unique_ptr< VulkanResource >, ErrorcreateBuffer (const std::string &sResourceName, const VkBufferCreateInfo &bufferInfo, const VmaAllocationCreateInfo &allocationInfo, unsigned int iElementSizeInBytes, unsigned int iElementCount)
 
std::variant< std::unique_ptr< VulkanResource >, ErrorcreateImage (const std::string &sResourceName, uint32_t iImageWidth, uint32_t iImageHeight, uint32_t iTextureMipLevelCount, VkSampleCountFlagBits sampleCount, VkFormat imageFormat, VkImageTiling imageTilingMode, VkImageUsageFlags imageUsage, std::optional< VkImageAspectFlags > viewDescription, bool bIsCubeMap=false)
 
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 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 VkFormat convertTextureResourceFormatToVkFormat (ShaderReadWriteTextureResourceFormat format)
 
static std::variant< std::unique_ptr< VulkanResourceManager >, Errorcreate (VulkanRenderer *pRenderer)
 

Private Member Functions

 VulkanResourceManager (VulkanRenderer *pRenderer, VmaAllocator pMemoryAllocator)
 
virtual std::variant< std::unique_ptr< GpuResource >, ErrorcreateShadowMapTexture (const std::string &sResourceName, unsigned int iTextureSize, bool bPointLightColorCubemap) override
 
std::variant< std::unique_ptr< VulkanResource >, ErrorcreateBuffer (const std::string &sResourceName, VkDeviceSize iBufferSize, VkBufferUsageFlags bufferUsage, bool bAllowCpuWrite, unsigned int iElementSizeInBytes, unsigned int iElementCount)
 

Static Private Member Functions

static std::optional< VkBufferUsageFlagBits > convertResourceUsageTypeToVkBufferUsageType (ResourceUsageType usage)
 

Private Attributes

VmaAllocator pMemoryAllocator = nullptr
 

Friends

class VulkanResource
 
class UploadBuffer
 
class KtxLoadingCallbackManager
 

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.

Constructor & Destructor Documentation

◆ VulkanResourceManager()

ne::VulkanResourceManager::VulkanResourceManager ( VulkanRenderer pRenderer,
VmaAllocator  pMemoryAllocator 
)
private

Constructor.

Parameters
pRendererDirectX renderer.
pMemoryAllocatorCreated memory allocator to use.

Member Function Documentation

◆ convertResourceUsageTypeToVkBufferUsageType()

std::optional< VkBufferUsageFlagBits > ne::VulkanResourceManager::convertResourceUsageTypeToVkBufferUsageType ( ResourceUsageType  usage)
staticprivate

Converts ResourceUsageType to VkBufferUsageFlagBits.

Parameters
usageResource usage type.
Returns
Empty if resource usage type is set to OTHER, otherwise Vulkan buffer usage flags.

◆ convertTextureResourceFormatToVkFormat()

VkFormat ne::VulkanResourceManager::convertTextureResourceFormatToVkFormat ( ShaderReadWriteTextureResourceFormat  format)
static

Converts texture resource format to Vulkan format.

Parameters
formatFormat to convert.
Returns
Vulkan format.

◆ create()

std::variant< std::unique_ptr< VulkanResourceManager >, Error > ne::VulkanResourceManager::create ( VulkanRenderer pRenderer)
static

Creates a new resource manager.

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

◆ createBuffer() [1/2]

std::variant< std::unique_ptr< VulkanResource >, Error > ne::VulkanResourceManager::createBuffer ( const std::string &  sResourceName,
const VkBufferCreateInfo &  bufferInfo,
const VmaAllocationCreateInfo &  allocationInfo,
unsigned int  iElementSizeInBytes,
unsigned int  iElementCount 
)

Creates a new buffer resource.

Parameters
sResourceNameName of the created resource.
bufferInfoDescription of the created buffer resource.
allocationInfoDescription of created buffer's memory allocation.
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.
Returns
Error if something went wrong, otherwise created buffer resource.

◆ createBuffer() [2/2]

std::variant< std::unique_ptr< VulkanResource >, Error > ne::VulkanResourceManager::createBuffer ( const std::string &  sResourceName,
VkDeviceSize  iBufferSize,
VkBufferUsageFlags  bufferUsage,
bool  bAllowCpuWrite,
unsigned int  iElementSizeInBytes,
unsigned int  iElementCount 
)
private

Creates a new buffer and allocates a new memory for it.

Parameters
sResourceNameName of the created buffer.
iBufferSizeSize of the buffer in bytes.
bufferUsageBuffer usage.
bAllowCpuWriteDescribes memory properties of the created buffer. If true the memory will be HOST_VISIBLE, HOST_COHERENT, otherwise DEVICE_LOCAL.
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.
Returns
Error if something went wrong, otherwise created resource.

◆ createImage()

std::variant< std::unique_ptr< VulkanResource >, Error > ne::VulkanResourceManager::createImage ( const std::string &  sResourceName,
uint32_t  iImageWidth,
uint32_t  iImageHeight,
uint32_t  iTextureMipLevelCount,
VkSampleCountFlagBits  sampleCount,
VkFormat  imageFormat,
VkImageTiling  imageTilingMode,
VkImageUsageFlags  imageUsage,
std::optional< VkImageAspectFlags >  viewDescription,
bool  bIsCubeMap = false 
)

Creates a new image and allocates a new memory for it.

Parameters
sResourceNameName of the created resource.
iImageWidthWidth of the image in pixels.
iImageHeightHeight of the image in pixels.
iTextureMipLevelCountThe number of mip level the texture has.
sampleCountThe number of samples per pixel. Usually 1 and more than 1 for MSAA.
imageFormatFormat of the image.
imageTilingModeImage tiling mode.
imageUsageImage usage.
viewDescriptionIf specified also creates an image view that references the image.
bIsCubeMaptrue if you need a cubemap, false if a single texture.
Returns
Created image.

◆ createResource()

std::variant< std::unique_ptr< GpuResource >, Error > ne::VulkanResourceManager::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::VulkanResourceManager::createResourceWithCpuWriteAccess ( const std::string &  sResourceName,
size_t  iElementSizeInBytes,
size_t  iElementCount,
std::optional< bool >  isUsedInShadersAsArrayResource 
)
overridevirtual

Creates a new GPU resource (buffer) with available CPU write access (only 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 (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()

std::variant< std::unique_ptr< GpuResource >, Error > ne::VulkanResourceManager::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::VulkanResourceManager::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::VulkanResourceManager::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.

◆ getCurrentStateInfo()

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

Dumps internal state of the resource manager in JSON format.

Returns
JSON string.

Implements ne::GpuResourceManager.

◆ getTotalVideoMemoryInMb()

size_t ne::VulkanResourceManager::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::VulkanResourceManager::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::VulkanResourceManager::loadTextureFromDisk ( const std::string &  sResourceName,
const std::filesystem::path &  pathToTextureFile 
)
overridevirtual

Loads a texture from a KTX 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.

Member Data Documentation

◆ pMemoryAllocator

VmaAllocator ne::VulkanResourceManager::pMemoryAllocator = nullptr
private

Vulkan memory allocator.


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