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

#include <VulkanResource.h>

Inheritance diagram for ne::VulkanResource:
ne::GpuResource

Public Member Functions

 VulkanResource (const VulkanResource &)=delete
 
VulkanResourceoperator= (const VulkanResource &)=delete
 
VkBuffer getInternalBufferResource () const
 
VkImageView getInternalImageView () const
 
VkImageView getInternalCubemapImageView (size_t iCubemapFaceIndex=0)
 
VkImageView getInternalImageViewDepthAspect () const
 
VkImage getInternalImage () const
 
std::pair< std::recursive_mutex, VmaAllocation > * getInternalResourceMemory ()
 
- 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

 VulkanResource (VulkanResourceManager *pResourceManager, const std::string &sResourceName, std::variant< VkBuffer, VkImage > pInternalResource, VmaAllocation pResourceMemory, unsigned int iElementSizeInBytes, unsigned int iElementCount)
 
 VulkanResource (VulkanResourceManager *pResourceManager, const std::string &sResourceName, ktxVulkanTexture ktxTexture)
 

Static Private Member Functions

static std::variant< std::unique_ptr< VulkanResource >, Errorcreate (VulkanResourceManager *pResourceManager, const std::string &sResourceName, VmaAllocator pMemoryAllocator, const VkBufferCreateInfo &bufferInfo, const VmaAllocationCreateInfo &allocationInfo, unsigned int iElementSizeInBytes, unsigned int iElementCount)
 
static std::variant< std::unique_ptr< VulkanResource >, Errorcreate (VulkanResourceManager *pResourceManager, const std::string &sResourceName, VmaAllocator pMemoryAllocator, const VkImageCreateInfo &imageInfo, const VmaAllocationCreateInfo &allocationInfo, std::optional< VkImageAspectFlags > viewDescription, bool bIsCubeMapView=false)
 
static std::variant< std::unique_ptr< VulkanResource >, Errorcreate (VulkanResourceManager *pResourceManager, const std::string &sResourceName, ktxVulkanTexture ktxTexture)
 

Private Attributes

std::optional< ktxVulkanTexture > optionalKtxTexture
 
VkBuffer pBufferResource = nullptr
 
VkImage pImageResource = nullptr
 
VkImageView pImageView = nullptr
 
VkImageView pDepthAspectImageView = nullptr
 
std::vector< VkImageView > vCubeMapViews
 
std::pair< std::recursive_mutex, VmaAllocation > mtxResourceMemory
 

Friends

class VulkanResourceManager
 

Detailed Description

Vulkan buffer/memory wrapper.

Constructor & Destructor Documentation

◆ VulkanResource() [1/2]

ne::VulkanResource::VulkanResource ( VulkanResourceManager pResourceManager,
const std::string &  sResourceName,
std::variant< VkBuffer, VkImage >  pInternalResource,
VmaAllocation  pResourceMemory,
unsigned int  iElementSizeInBytes,
unsigned int  iElementCount 
)
private

Constructor. Creates an empty resource.

Parameters
pResourceManagerOwner resource manager.
sResourceNameName of the resource.
pInternalResourceCreated Vulkan resource.
pResourceMemoryAllocated memory for the created Vulkan 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.

◆ VulkanResource() [2/2]

ne::VulkanResource::VulkanResource ( VulkanResourceManager pResourceManager,
const std::string &  sResourceName,
ktxVulkanTexture  ktxTexture 
)
private

Constructor. Initializes resources as a wrapper for KTX image.

Parameters
pResourceManagerOwner resource manager.
sResourceNameName of the resource.
ktxTextureCreated KTX texture (already loaded in the GPU memory) that this resource will wrap.

Member Function Documentation

◆ create() [1/3]

std::variant< std::unique_ptr< VulkanResource >, Error > ne::VulkanResource::create ( VulkanResourceManager pResourceManager,
const std::string &  sResourceName,
ktxVulkanTexture  ktxTexture 
)
staticprivate

Creates a new image resource.

Parameters
pResourceManagerOwner resource manager.
sResourceNameResource name, used for logging.
ktxTextureCreated KTX texture (already loaded in the GPU memory) that this resource will wrap.
Returns
Error if something went wrong, otherwise created resource.

◆ create() [2/3]

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

Creates a new buffer resource.

Parameters
pResourceManagerOwner resource manager.
sResourceNameResource name, used for logging.
pMemoryAllocatorAllocator to create resource.
bufferInfoBuffer creation info.
allocationInfoAllocation creation info.
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.

◆ create() [3/3]

std::variant< std::unique_ptr< VulkanResource >, Error > ne::VulkanResource::create ( VulkanResourceManager pResourceManager,
const std::string &  sResourceName,
VmaAllocator  pMemoryAllocator,
const VkImageCreateInfo &  imageInfo,
const VmaAllocationCreateInfo &  allocationInfo,
std::optional< VkImageAspectFlags >  viewDescription,
bool  bIsCubeMapView = false 
)
staticprivate

Creates a new image resource.

Parameters
pResourceManagerOwner resource manager.
sResourceNameResource name, used for logging.
pMemoryAllocatorAllocator to create resource.
imageInfoImage creation info.
allocationInfoAllocation creation info.
viewDescriptionIf specified also creates an image view that references the image.
bIsCubeMapViewtrue to create a view to a cubemap, false to create a 2D texture view. Ignored if view description is not specified.
Returns
Error if something went wrong, otherwise created resource.

◆ getInternalBufferResource()

VkBuffer ne::VulkanResource::getInternalBufferResource ( ) const
inline

Returns internal buffer resource.

Remarks
Do not delete (free) returned pointer.
Returned pointer is only valid while this object is valid.
Returns
nullptr if this resource uses image as internal resource not a buffer, otherwise internal buffer resource.

◆ getInternalCubemapImageView()

VkImageView ne::VulkanResource::getInternalCubemapImageView ( size_t  iCubemapFaceIndex = 0)
inline

Returns internal image view for cubemap textures.

Remarks
Do not delete (free) returned pointer.
Returned pointer is only valid while this object is valid.
Parameters
iCubemapFaceIndexIndex of the cubemap face to get the view to.
Returns
nullptr if this resource uses buffer as internal resource not an image or not a cubemap, otherwise internal image view.

◆ getInternalImage()

VkImage ne::VulkanResource::getInternalImage ( ) const
inline

Returns internal image.

Remarks
Do not delete (free) returned pointer.
Returned pointer is only valid while this object is valid.
Returns
nullptr if this resource uses buffer as internal resource not an image, otherwise internal image.

◆ getInternalImageView()

VkImageView ne::VulkanResource::getInternalImageView ( ) const
inline

Returns internal image view.

Remarks
Do not delete (free) returned pointer.
Returned pointer is only valid while this object is valid.
Returns
nullptr if this resource uses buffer as internal resource not an image, otherwise internal image view.

◆ getInternalImageViewDepthAspect()

VkImageView ne::VulkanResource::getInternalImageViewDepthAspect ( ) const
inline

Returns internal image view that only references depth aspect of the image.

Remarks
Do not delete (free) returned pointer.
Returned pointer is only valid while this object is valid.
Returns
Image view that only references depth aspect if the image was created with depth and stencil aspects, otherwise nullptr.

◆ getInternalResourceMemory()

std::pair< std::recursive_mutex, VmaAllocation > * ne::VulkanResource::getInternalResourceMemory ( )
inline

Returns memory allocation of the internal resource.

Remarks
Do not delete (free) returned pointer.
Returned pointer is only valid while this object is valid.
Returns
Memory allocation of the internal resource.

Member Data Documentation

◆ mtxResourceMemory

std::pair<std::recursive_mutex, VmaAllocation> ne::VulkanResource::mtxResourceMemory
private

Allocated memory for created resource.

Remarks
Using mutex because "access to a VmaAllocation object must be externally synchronized".

◆ optionalKtxTexture

std::optional<ktxVulkanTexture> ne::VulkanResource::optionalKtxTexture
private

Not empty if the object was created as a wrapper around KTX texture.

◆ pBufferResource

VkBuffer ne::VulkanResource::pBufferResource = nullptr
private

Created buffer Vulkan resource.

Remarks
nullptr if pImageResource is used.

◆ pDepthAspectImageView

VkImageView ne::VulkanResource::pDepthAspectImageView = nullptr
private

Optional view that references pImageResource depth aspect.

Remarks
Only used when pImageResource specified both depth and stencil aspects.

◆ pImageResource

VkImage ne::VulkanResource::pImageResource = nullptr
private

Created image Vulkan resource.

Remarks
nullptr if pBufferResource is used.

◆ pImageView

VkImageView ne::VulkanResource::pImageView = nullptr
private

Optional view that references pImageResource.

◆ vCubeMapViews

std::vector<VkImageView> ne::VulkanResource::vCubeMapViews
private

Views to each face of the cubemap texture (only valid if the resource is a cubemap texture).


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