Nameless Engine
|
#include <VulkanResourceManager.h>
Public Member Functions | |
VulkanResourceManager (const VulkanResourceManager &)=delete | |
VulkanResourceManager & | operator= (const VulkanResourceManager &)=delete |
virtual size_t | getTotalVideoMemoryInMb () const override |
virtual size_t | getUsedVideoMemoryInMb () const override |
std::variant< std::unique_ptr< VulkanResource >, Error > | createBuffer (const std::string &sResourceName, const VkBufferCreateInfo &bufferInfo, const VmaAllocationCreateInfo &allocationInfo, unsigned int iElementSizeInBytes, unsigned int iElementCount) |
std::variant< std::unique_ptr< VulkanResource >, Error > | 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) |
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 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 VkFormat | convertTextureResourceFormatToVkFormat (ShaderReadWriteTextureResourceFormat format) |
static std::variant< std::unique_ptr< VulkanResourceManager >, Error > | create (VulkanRenderer *pRenderer) |
Private Member Functions | |
VulkanResourceManager (VulkanRenderer *pRenderer, VmaAllocator pMemoryAllocator) | |
virtual std::variant< std::unique_ptr< GpuResource >, Error > | createShadowMapTexture (const std::string &sResourceName, unsigned int iTextureSize, bool bPointLightColorCubemap) override |
std::variant< std::unique_ptr< VulkanResource >, Error > | createBuffer (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 >, 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.
|
private |
Constructor.
pRenderer | DirectX renderer. |
pMemoryAllocator | Created memory allocator to use. |
|
staticprivate |
Converts ResourceUsageType
to VkBufferUsageFlagBits
.
usage | Resource usage type. |
OTHER
, otherwise Vulkan buffer usage flags.
|
static |
Converts texture resource format to Vulkan format.
format | Format to convert. |
|
static |
Creates a new resource manager.
pRenderer | Vulkan renderer. |
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.
sResourceName | Name of the created resource. |
bufferInfo | Description of the created buffer resource. |
allocationInfo | Description of created buffer's memory allocation. |
iElementSizeInBytes | Resource size information. Size of one array element (if array), otherwise specify size of the whole resource. |
iElementCount | Resource size information. Total number of elements in the array (if array), otherwise specify 1. |
|
private |
Creates a new buffer and allocates a new memory for it.
sResourceName | Name of the created buffer. |
iBufferSize | Size of the buffer in bytes. |
bufferUsage | Buffer usage. |
bAllowCpuWrite | Describes memory properties of the created buffer. If true the memory will be HOST_VISIBLE , HOST_COHERENT , otherwise DEVICE_LOCAL . |
iElementSizeInBytes | Resource size information. Size of one array element (if array), otherwise specify size of the whole resource. |
iElementCount | Resource size information. Total number of elements in the array (if array), otherwise specify 1. |
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.
sResourceName | Name of the created resource. |
iImageWidth | Width of the image in pixels. |
iImageHeight | Height of the image in pixels. |
iTextureMipLevelCount | The number of mip level the texture has. |
sampleCount | The number of samples per pixel. Usually 1 and more than 1 for MSAA. |
imageFormat | Format of the image. |
imageTilingMode | Image tiling mode. |
imageUsage | Image usage. |
viewDescription | If specified also creates an image view that references the image. |
bIsCubeMap | true if you need a cubemap, false if a single texture. |
|
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 (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:
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.
|
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.
|
overridevirtual |
Dumps internal state of the resource manager in JSON format.
Implements ne::GpuResourceManager.
|
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 KTX file in the GPU memory.
sResourceName | Resource name, used for logging. |
pathToTextureFile | Path to the image file that stores texture data. |
Implements ne::GpuResourceManager.
|
private |
Vulkan memory allocator.