Kompute
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
kp::Image Class Reference

#include <Image.hpp>

Inheritance diagram for kp::Image:
Inheritance graph
[legend]
Collaboration diagram for kp::Image:
Collaboration graph
[legend]

Public Member Functions

 Image (std::shared_ptr< vk::PhysicalDevice > physicalDevice, std::shared_ptr< vk::Device > device, void *data, size_t dataSize, uint32_t x, uint32_t y, uint32_t numChannels, const DataTypes &dataType, vk::ImageTiling tiling, const MemoryTypes &memoryType=MemoryTypes::eDevice)
 
 Image (std::shared_ptr< vk::PhysicalDevice > physicalDevice, std::shared_ptr< vk::Device > device, uint32_t x, uint32_t y, uint32_t numChannels, const DataTypes &dataType, vk::ImageTiling tiling, const MemoryTypes &memoryType=MemoryTypes::eDevice)
 
 Image (std::shared_ptr< vk::PhysicalDevice > physicalDevice, std::shared_ptr< vk::Device > device, void *data, size_t dataSize, uint32_t x, uint32_t y, uint32_t numChannels, const DataTypes &dataType, const MemoryTypes &memoryType=MemoryTypes::eDevice)
 
 Image (std::shared_ptr< vk::PhysicalDevice > physicalDevice, std::shared_ptr< vk::Device > device, uint32_t x, uint32_t y, uint32_t numChannels, const DataTypes &dataType, const MemoryTypes &memoryType=MemoryTypes::eDevice)
 
 Image (const Image &)=delete
 Make Image uncopyable.
 
 Image (const Image &&)=delete
 
Imageoperator= (const Image &)=delete
 
Imageoperator= (const Image &&)=delete
 
virtual ~Image ()
 
void destroy () override
 
bool isInit () override
 
void recordCopyFrom (const vk::CommandBuffer &commandBuffer, std::shared_ptr< Image > copyFromImage) override
 
void recordCopyFrom (const vk::CommandBuffer &commandBuffer, std::shared_ptr< Tensor > copyFromTensor) override
 
void recordCopyFromStagingToDevice (const vk::CommandBuffer &commandBuffer) override
 
void recordCopyFromDeviceToStaging (const vk::CommandBuffer &commandBuffer) override
 
void recordPrimaryMemoryBarrier (const vk::CommandBuffer &commandBuffer, vk::AccessFlagBits srcAccessMask, vk::AccessFlagBits dstAccessMask, vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask) override
 
void recordStagingMemoryBarrier (const vk::CommandBuffer &commandBuffer, vk::AccessFlagBits srcAccessMask, vk::AccessFlagBits dstAccessMask, vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask) override
 
void recordPrimaryImageBarrier (const vk::CommandBuffer &commandBuffer, vk::AccessFlagBits srcAccessMask, vk::AccessFlagBits dstAccessMask, vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask, vk::ImageLayout dstLayout)
 
vk::WriteDescriptorSet constructDescriptorSet (vk::DescriptorSet descriptorSet, uint32_t binding) override
 
std::shared_ptr< vk::Image > getPrimaryImage ()
 
vk::ImageLayout getPrimaryImageLayout ()
 
uint32_t getNumChannels ()
 
Type type () override
 
- Public Member Functions inherited from kp::Memory
 Memory (std::shared_ptr< vk::PhysicalDevice > physicalDevice, std::shared_ptr< vk::Device > device, const DataTypes &dataType, const MemoryTypes &memoryType, uint32_t x, uint32_t y)
 
 Memory (const Memory &)=delete
 Make Memory uncopyable.
 
 Memory (const Memory &&)=delete
 
Memoryoperator= (const Memory &)=delete
 
Memoryoperator= (const Memory &&)=delete
 
virtual ~Memory ()
 
MemoryTypes memoryType ()
 
DataTypes dataType ()
 
void recordCopyFrom (const vk::CommandBuffer &commandBuffer, std::shared_ptr< Memory > copyFromMemory)
 
uint32_t size ()
 
uint32_t dataTypeMemorySize ()
 
uint32_t memorySize ()
 
vk::DescriptorType getDescriptorType ()
 
voidrawData ()
 
void setData (const void *data, size_t size)
 
template<typename T >
void setData (const std::vector< T > &data)
 
template<typename T >
Tdata ()
 
template<typename T >
std::vector< T > vector ()
 
uint32_t getX ()
 
uint32_t getY ()
 

Protected Attributes

uint32_t mNumChannels
 
vk::DescriptorImageInfo mDescriptorImageInfo
 
vk::ImageLayout mPrimaryImageLayout = vk::ImageLayout::eUndefined
 
vk::ImageLayout mStagingImageLayout = vk::ImageLayout::eUndefined
 
std::shared_ptr< vk::ImageView > mImageView = nullptr
 
vk::ImageTiling mTiling = vk::ImageTiling::eOptimal
 
- Protected Attributes inherited from kp::Memory
MemoryTypes mMemoryType
 
DataTypes mDataType
 
uint32_t mSize
 
uint32_t mDataTypeMemorySize
 
voidmRawData = nullptr
 
vk::DescriptorType mDescriptorType
 
bool mUnmapMemory = false
 
uint32_t mX
 
uint32_t mY
 
std::shared_ptr< vk::PhysicalDevice > mPhysicalDevice
 
std::shared_ptr< vk::Device > mDevice
 
std::shared_ptr< vk::DeviceMemory > mPrimaryMemory
 
bool mFreePrimaryMemory = false
 
std::shared_ptr< vk::DeviceMemory > mStagingMemory
 
bool mFreeStagingMemory = false
 

Additional Inherited Members

- Public Types inherited from kp::Memory
enum class  MemoryTypes { eDevice = 0 , eHost = 1 , eStorage = 2 , eDeviceAndHost }
 
enum class  DataTypes {
  eBool = 0 , eInt = 1 , eUnsignedInt = 2 , eFloat = 3 ,
  eDouble = 4 , eCustom = 5 , eShort = 6 , eUnsignedShort = 7 ,
  eChar = 8 , eUnsignedChar = 9
}
 
enum class  Type { eTensor = 0 , eImage = 1 }
 
- Static Public Member Functions inherited from kp::Memory
static std::string toString (MemoryTypes dt)
 
static std::string toString (DataTypes dt)
 
template<typename T >
static constexpr DataTypes dataType ()
 
static uint32_t dataTypeMemorySize (DataTypes dataType)
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
template<>
constexpr Memory::DataTypes dataType ()
 
- Protected Member Functions inherited from kp::Memory
void mapRawData ()
 
void unmapRawData ()
 
void updateRawData (void *data)
 
vk::MemoryPropertyFlags getPrimaryMemoryPropertyFlags ()
 
vk::MemoryPropertyFlags getStagingMemoryPropertyFlags ()
 

Detailed Description

Image data used in GPU operations.

Each image would has a respective Vulkan memory and image, which would be used to store their respective data. The images can be used for GPU data storage or transfer.

Constructor & Destructor Documentation

◆ Image() [1/4]

kp::Image::Image ( std::shared_ptr< vk::PhysicalDevice >  physicalDevice,
std::shared_ptr< vk::Device >  device,
void data,
size_t  dataSize,
uint32_t  x,
uint32_t  y,
uint32_t  numChannels,
const DataTypes &  dataType,
vk::ImageTiling  tiling,
const MemoryTypes memoryType = MemoryTypes::eDevice 
)
inline

Constructor with data provided which would be used to create the respective vulkan image and memory.

Parameters
physicalDeviceThe physical device to use to fetch properties
deviceThe device to use to create the image and memory from
dataPointer to data that will be used to initialise the image
dataSizeSize in bytes of the data pointed to by data
xWidth of the image in pixels
yHeight of the image in pixels
numChannelsThe number of channels in the image
dataTypeData type for the image which is of type DataTypes
memoryTypeType for the image which is of type MemoryTypes
tilingTiling mode to use for the image.

◆ Image() [2/4]

kp::Image::Image ( std::shared_ptr< vk::PhysicalDevice >  physicalDevice,
std::shared_ptr< vk::Device >  device,
uint32_t  x,
uint32_t  y,
uint32_t  numChannels,
const DataTypes &  dataType,
vk::ImageTiling  tiling,
const MemoryTypes memoryType = MemoryTypes::eDevice 
)
inline

Constructor with no data provided.

Parameters
physicalDeviceThe physical device to use to fetch properties
deviceThe device to use to create the image and memory from
xWidth of the image in pixels
yHeight of the image in pixels
dataTypeData type for the image which is of type ImageDataTypes
memoryTypeType for the image which is of type MemoryTypes
tilingTiling mode to use for the image.

◆ Image() [3/4]

kp::Image::Image ( std::shared_ptr< vk::PhysicalDevice >  physicalDevice,
std::shared_ptr< vk::Device >  device,
void data,
size_t  dataSize,
uint32_t  x,
uint32_t  y,
uint32_t  numChannels,
const DataTypes &  dataType,
const MemoryTypes memoryType = MemoryTypes::eDevice 
)
inline

Constructor with data provided which would be used to create the respective vulkan image and memory. No tiling has been provided so will be inferred from memoryType.

Parameters
physicalDeviceThe physical device to use to fetch properties
deviceThe device to use to create the image and memory from
dataPointer to data that will be used to initialise the image
dataSizeSize in bytes of the data pointed to by data
xWidth of the image in pixels
yHeight of the image in pixels
numChannelsThe number of channels in the image
dataTypeData type for the image which is of type DataTypes
memoryTypeType for the image which is of type MemoryTypes

◆ Image() [4/4]

kp::Image::Image ( std::shared_ptr< vk::PhysicalDevice >  physicalDevice,
std::shared_ptr< vk::Device >  device,
uint32_t  x,
uint32_t  y,
uint32_t  numChannels,
const DataTypes &  dataType,
const MemoryTypes memoryType = MemoryTypes::eDevice 
)
inline

Constructor with no data provided. No tiling has been provided so will be inferred from memoryType.

Parameters
physicalDeviceThe physical device to use to fetch properties
deviceThe device to use to create the image and memory from
xWidth of the image in pixels
yHeight of the image in pixels
dataTypeData type for the image which is of type ImageDataTypes
memoryTypeType for the image which is of type MemoryTypes

◆ ~Image()

virtual kp::Image::~Image ( )
virtual

Destructor which is in charge of freeing vulkan resources unless they have been provided externally.

Member Function Documentation

◆ constructDescriptorSet()

vk::WriteDescriptorSet kp::Image::constructDescriptorSet ( vk::DescriptorSet  descriptorSet,
uint32_t  binding 
)
overridevirtual

Adds this object to a Vulkan descriptor set at binding.

Parameters
descriptorSetThe descriptor set to add to.
bindingThe binding number to use.
Returns
Add this object to a descriptor set at binding.

Implements kp::Memory.

◆ destroy()

void kp::Image::destroy ( )
overridevirtual

Destroys and frees the GPU resources which include the image and memory.

Reimplemented from kp::Memory.

◆ isInit()

bool kp::Image::isInit ( )
overridevirtual

Check whether image is initialized based on the created gpu resources.

Returns
Boolean stating whether image is initialized

Implements kp::Memory.

◆ recordCopyFrom() [1/2]

void kp::Image::recordCopyFrom ( const vk::CommandBuffer &  commandBuffer,
std::shared_ptr< Image copyFromImage 
)
overridevirtual

Records a copy from the memory of the image provided to the current image. This is intended to pass memory into a processing, to perform a staging image transfer, or to gather output (between others).

Parameters
commandBufferVulkan Command Buffer to record the commands into
copyFromImageImage to copy the data from

Implements kp::Memory.

◆ recordCopyFrom() [2/2]

void kp::Image::recordCopyFrom ( const vk::CommandBuffer &  commandBuffer,
std::shared_ptr< Tensor copyFromTensor 
)
overridevirtual

Records a copy from the memory of the tensor provided to the current image. This is intended to pass memory into a processing, to perform a staging image transfer, or to gather output (between others).

Parameters
commandBufferVulkan Command Buffer to record the commands into
copyFromTensorTensor to copy the data from

Implements kp::Memory.

◆ recordCopyFromDeviceToStaging()

void kp::Image::recordCopyFromDeviceToStaging ( const vk::CommandBuffer &  commandBuffer)
overridevirtual

Records a copy from the internal device memory to the staging memory using an optional barrier to wait for the operation. This function would only be relevant for kp::images of type eDevice.

Parameters
commandBufferVulkan Command Buffer to record the commands into

Implements kp::Memory.

◆ recordCopyFromStagingToDevice()

void kp::Image::recordCopyFromStagingToDevice ( const vk::CommandBuffer &  commandBuffer)
overridevirtual

Records a copy from the internal staging memory to the device memory using an optional barrier to wait for the operation. This function would only be relevant for kp::images of type eDevice.

Parameters
commandBufferVulkan Command Buffer to record the commands into

Implements kp::Memory.

◆ recordPrimaryImageBarrier()

void kp::Image::recordPrimaryImageBarrier ( const vk::CommandBuffer &  commandBuffer,
vk::AccessFlagBits  srcAccessMask,
vk::AccessFlagBits  dstAccessMask,
vk::PipelineStageFlagBits  srcStageMask,
vk::PipelineStageFlagBits  dstStageMask,
vk::ImageLayout  dstLayout 
)

Records the image memory barrier into the primary image and command buffer which ensures that relevant data transfers are carried out correctly.

Parameters
commandBufferVulkan Command Buffer to record the commands into
srcAccessMaskAccess flags for source access mask
dstAccessMaskAccess flags for destination access mask
scrStageMaskPipeline stage flags for source stage mask
dstStageMaskPipeline stage flags for destination stage mask
dstLayoutImage layout for the image after the barrier completes

◆ recordPrimaryMemoryBarrier()

void kp::Image::recordPrimaryMemoryBarrier ( const vk::CommandBuffer &  commandBuffer,
vk::AccessFlagBits  srcAccessMask,
vk::AccessFlagBits  dstAccessMask,
vk::PipelineStageFlagBits  srcStageMask,
vk::PipelineStageFlagBits  dstStageMask 
)
overridevirtual

Records the image memory barrier into the primary image and command buffer which ensures that relevant data transfers are carried out correctly.

Parameters
commandBufferVulkan Command Buffer to record the commands into
srcAccessMaskAccess flags for source access mask
dstAccessMaskAccess flags for destination access mask
scrStageMaskPipeline stage flags for source stage mask
dstStageMaskPipeline stage flags for destination stage mask

Implements kp::Memory.

◆ recordStagingMemoryBarrier()

void kp::Image::recordStagingMemoryBarrier ( const vk::CommandBuffer &  commandBuffer,
vk::AccessFlagBits  srcAccessMask,
vk::AccessFlagBits  dstAccessMask,
vk::PipelineStageFlagBits  srcStageMask,
vk::PipelineStageFlagBits  dstStageMask 
)
overridevirtual

Records the image memory barrier into the staging image and command buffer which ensures that relevant data transfers are carried out correctly.

Parameters
commandBufferVulkan Command Buffer to record the commands into
srcAccessMaskAccess flags for source access mask
dstAccessMaskAccess flags for destination access mask
scrStageMaskPipeline stage flags for source stage mask
dstStageMaskPipeline stage flags for destination stage mask

Implements kp::Memory.

◆ type()

Type kp::Image::type ( )
inlineoverridevirtual

Return the object type of this Memory object.

Returns
The object type of the Memory object.

Implements kp::Memory.


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