4#include "kompute/Core.hpp"
5#include "kompute/Memory.hpp"
6#include "kompute/Tensor.hpp"
7#include "logger/Logger.hpp"
39 std::shared_ptr<vk::Device>
device,
50 if (
dataType == DataTypes::eCustom) {
51 throw std::runtime_error(
52 "Custom data types are not supported for Kompute Images");
70 std::shared_ptr<vk::Device>
device,
106 std::shared_ptr<vk::Device>
device,
118 if (
dataType == DataTypes::eCustom) {
119 throw std::runtime_error(
120 "Custom data types are not supported for Kompute Images");
126 tiling = vk::ImageTiling::eLinear;
129 tiling = vk::ImageTiling::eOptimal;
131 throw std::runtime_error(
"Kompute Image unsupported memory type");
149 std::shared_ptr<vk::Device>
device,
302 std::shared_ptr<vk::Image> getPrimaryImage();
303 vk::ImageLayout getPrimaryImageLayout();
312 Type
type()
override {
return Type::eImage; }
317 vk::DescriptorImageInfo mDescriptorImageInfo;
318 vk::ImageLayout mPrimaryImageLayout = vk::ImageLayout::eUndefined;
319 vk::ImageLayout mStagingImageLayout = vk::ImageLayout::eUndefined;
320 std::shared_ptr<vk::ImageView> mImageView =
nullptr;
321 vk::ImageTiling mTiling = vk::ImageTiling::eOptimal;
325 std::shared_ptr<vk::Image> mPrimaryImage;
326 bool mFreePrimaryImage =
false;
327 std::shared_ptr<vk::Image> mStagingImage;
328 bool mFreeStagingImage =
false;
330 void allocateMemoryCreateGPUResources();
331 void createImage(std::shared_ptr<vk::Image> image,
334 void allocateBindMemory(std::shared_ptr<vk::Image> image,
335 std::shared_ptr<vk::DeviceMemory>
memory,
338 std::shared_ptr<vk::Image>
srcImage,
339 std::shared_ptr<vk::Image>
dstImage,
343 void recordCopyImageFromTensor(
const vk::CommandBuffer&
commandBuffer,
345 std::shared_ptr<vk::Image>
dstImage,
361 void recordStagingImageBarrier(
const vk::CommandBuffer&
commandBuffer,
368 void recordImageMemoryBarrier(
const vk::CommandBuffer&
commandBuffer,
369 const vk::Image& image,
378 vk::ImageUsageFlags getPrimaryImageUsageFlags();
379 vk::ImageUsageFlags getStagingImageUsageFlags();
381 vk::Format getFormat();
383 vk::DescriptorImageInfo constructDescriptorImageInfo();
385 void init(
void*
data,
401 ImageT(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
402 std::shared_ptr<vk::Device> device,
403 const std::vector<T>&
data,
406 uint32_t numChannels,
407 vk::ImageTiling tiling,
409 :
Image(physicalDevice,
422 "Custom data types are not supported for Kompute Images");
424 KP_LOG_DEBUG(
"Kompute imageT constructor with data size {}, x {}, "
425 "y {}, and num channels {}",
432 ImageT(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
433 std::shared_ptr<vk::Device> device,
434 const std::vector<T>&
data,
437 uint32_t numChannels,
439 :
Image(physicalDevice,
451 "Custom data types are not supported for Kompute Images");
453 KP_LOG_DEBUG(
"Kompute imageT constructor with data size {}, x {}, "
454 "y {}, and num channels {}",
461 ImageT(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
462 std::shared_ptr<vk::Device> device,
465 uint32_t numChannels,
466 vk::ImageTiling tiling,
468 :
Image(physicalDevice,
479 "Custom data types are not supported for Kompute Images");
481 KP_LOG_DEBUG(
"Kompute imageT constructor with no data, x {}, "
482 "y {}, and num channels {}",
488 ImageT(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
489 std::shared_ptr<vk::Device> device,
492 uint32_t numChannels,
494 :
Image(physicalDevice,
504 "Custom data types are not supported for Kompute Images");
506 KP_LOG_DEBUG(
"Kompute imageT constructor with no data, x {}, "
507 "y {}, and num channels {}",
513 ~ImageT() { KP_LOG_DEBUG(
"Kompute imageT destructor"); }
void recordCopyFrom(const vk::CommandBuffer &commandBuffer, std::shared_ptr< Tensor > copyFromTensor) override
void recordStagingMemoryBarrier(const vk::CommandBuffer &commandBuffer, vk::AccessFlagBits srcAccessMask, vk::AccessFlagBits dstAccessMask, vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask) override
Type type() override
Definition Image.hpp:312
vk::WriteDescriptorSet constructDescriptorSet(vk::DescriptorSet descriptorSet, uint32_t binding) override
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)
Definition Image.hpp:105
void recordPrimaryMemoryBarrier(const vk::CommandBuffer &commandBuffer, vk::AccessFlagBits srcAccessMask, vk::AccessFlagBits dstAccessMask, vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask) override
void recordCopyFromDeviceToStaging(const vk::CommandBuffer &commandBuffer) override
void recordCopyFromStagingToDevice(const vk::CommandBuffer &commandBuffer) override
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)
Definition Image.hpp:38
void recordPrimaryImageBarrier(const vk::CommandBuffer &commandBuffer, vk::AccessFlagBits srcAccessMask, vk::AccessFlagBits dstAccessMask, vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask, vk::ImageLayout dstLayout)
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)
Definition Image.hpp:69
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)
Definition Image.hpp:148
void recordCopyFrom(const vk::CommandBuffer &commandBuffer, std::shared_ptr< Image > copyFromImage) override
Image(const Image &)=delete
Make Image uncopyable.
static constexpr DataTypes dataType()
std::vector< T > vector()
Definition Memory.hpp:282
T * data()
Definition Memory.hpp:265
MemoryTypes
Definition Memory.hpp:28
@ eDeviceAndHost
Type is host-visible and host-coherent device memory.
@ eDevice
Type is device memory, source and destination.
@ eHost
Type is host memory, source and destination.
@ eStorage
Type is Device memory (only)