Lluvia
Image.h
Go to the documentation of this file.
1 
8 #ifndef LLUVIA_CORE_IMAGE_IMAGE_H_
9 #define LLUVIA_CORE_IMAGE_IMAGE_H_
10 
11 #include "lluvia/core/Object.h"
17 #include "lluvia/core/types.h"
18 
20 
21 #include <array>
22 #include <cstdint>
23 #include <memory>
24 #include <string>
25 #include <tuple>
26 #include <vector>
27 
28 namespace ll {
29 
30 namespace vulkan {
31  class Device;
32 } // namespace vulkan
33 
34 class CommandBuffer;
35 class ComputeNode;
36 class ComputeGraph;
37 class ImageView;
38 class ImageViewDescriptor;
39 class Memory;
40 class Session;
41 
73 class Image : public Object,
74  public std::enable_shared_from_this<ll::Image> {
75 
76 public:
77  Image() = delete;
78  Image(const Image&) = delete;
79  Image(Image&&) = delete;
80 
81  ~Image();
82 
83  Image& operator=(const Image&) = delete;
84  Image& operator=(Image&&) = delete;
85 
86  ll::ObjectType getType() const noexcept override;
87 
94 
100  const std::shared_ptr<ll::Memory>& getMemory() const noexcept;
101 
113  uint64_t getSize() const noexcept;
114 
128  uint64_t getMinimumSize() const noexcept;
129 
135  const ll::ImageDescriptor& getDescriptor() const noexcept;
136 
145  ll::ImageUsageFlags getUsageFlags() const noexcept;
146 
154  uint32_t getUsageFlagsUnsafe() const noexcept;
155 
166  ll::ImageLayout getLayout() const noexcept;
167 
173  ll::ImageTiling getTiling() const noexcept;
174 
180  ll::ChannelType getChannelType() const noexcept;
181 
187  uint64_t getChannelTypeSize() const noexcept;
188 
196  template <typename T = ll::ChannelCount>
197  T getChannelCount() const noexcept
198  {
199  return m_descriptor.getChannelCount<T>();
200  }
201 
207  uint32_t getWidth() const noexcept;
208 
214  uint32_t getHeight() const noexcept;
215 
221  uint32_t getDepth() const noexcept;
222 
234  ll::vec3ui getShape() const noexcept;
235 
243  std::shared_ptr<ll::ImageView> createImageView(const ll::ImageViewDescriptor& tDescriptor);
244 
254  void changeImageLayout(const ll::ImageLayout newLayout);
255 
264  void clear();
265 
275  void copyTo(ll::Image& dst);
276 
277 private:
278  Image(const std::shared_ptr<ll::vulkan::Device>& device,
279  const vk::Image& vkImage,
280  const ll::ImageDescriptor& descriptor,
281  const std::shared_ptr<ll::Memory>& memory,
282  const ll::MemoryAllocationInfo& allocInfo,
283  const ll::ImageLayout layout);
284 
285  std::shared_ptr<ll::vulkan::Device> m_device;
286 
287  ll::ImageDescriptor m_descriptor;
288  ll::MemoryAllocationInfo m_allocInfo;
289 
290  vk::Image m_vkImage;
291  ll::ImageLayout m_layout;
292 
293  // Shared pointer to the memory this image was created from
294  // This will keep the memory alive until this image is deleted
295  // avoiding reference to a corrupted memory location.
296  std::shared_ptr<ll::Memory> m_memory;
297 
298  friend class ll::CommandBuffer;
299  friend class ll::ComputeNode;
300  friend class ll::ComputeGraph;
301  friend class ll::ImageView;
302  friend class ll::Memory;
303  friend class ll::Session;
304 };
305 
306 } // namespace ll
307 
308 #endif /* LLUVIA_CORE_IMAGE_IMAGE_H_ */
ImageDescriptor class and related enumerations.
ImageLayout enum.
Structures and methods for storing memory allocation information.
Object class and related enums.
Class for command buffer.
Definition: CommandBuffer.h:63
Class representing compute nodes.
Definition: ComputeNode.h:38
Stores all relevant information for creating ll::Image objects.
Definition: ImageDescriptor.h:189
T getChannelCount() const noexcept
Gets the channel count.
Definition: ImageDescriptor.h:336
Descriptor for ll::ImageView objects.
Definition: ImageViewDescriptor.h:41
Represents portions of a ll::Image to be sent as parameter to a GLSL shader.
Definition: ImageView.h:149
Objects to manage images.
Definition: Image.h:74
ll::ImageLayout getLayout() const noexcept
Gets the Vulkan image layout.
uint64_t getSize() const noexcept
Gets the memory allocation size in bytes.
void changeImageLayout(const ll::ImageLayout newLayout)
Immediately changes the image layout.
Image(Image &&)=delete
ll::ImageTiling getTiling() const noexcept
Gets the vulkan image tiling.
ll::vec3ui getShape() const noexcept
Gets the shape of the image.
ll::MemoryAllocationInfo getAllocationInfo() const noexcept
Gets the allocation information.
ll::ImageUsageFlags getUsageFlags() const noexcept
Gets the Vulkan image usage flags.
uint32_t getDepth() const noexcept
Gets the image depth in pixels.
Image & operator=(const Image &)=delete
ll::ObjectType getType() const noexcept override
Gets the object type.
void clear()
Immediately clears the image pixels to zero.
std::shared_ptr< ll::ImageView > createImageView(const ll::ImageViewDescriptor &tDescriptor)
Creates an image view from this image.
void copyTo(ll::Image &dst)
Immediately copies the content of this image into the destination.
ll::ChannelType getChannelType() const noexcept
Gets the channel type.
T getChannelCount() const noexcept
Gets the channel count.
Definition: Image.h:197
Image()=delete
uint32_t getHeight() const noexcept
Gets the image height in pixels.
uint32_t getWidth() const noexcept
Gets the image width in pixels.
const std::shared_ptr< ll::Memory > & getMemory() const noexcept
Gets the memory this image was allocated from.
Image(const Image &)=delete
uint32_t getUsageFlagsUnsafe() const noexcept
Gets the usage flags casted to an integer type.
uint64_t getChannelTypeSize() const noexcept
Gets the channel type size.
Image & operator=(Image &&)=delete
uint64_t getMinimumSize() const noexcept
Gets the minimum number of bytes to store the image contiguously in memory.
const ll::ImageDescriptor & getDescriptor() const noexcept
Gets the descriptor.
Class to manage allocation of objects into a specific type of memory.
Definition: Memory.h:92
Base class for all types that can be used in computer shaders.
Definition: Object.h:94
Class that contains all the state required to run compute operations on a compute device.
Definition: Session.h:51
Definition: Buffer.h:28
ImageLayout
Definition: ImageLayout.h:16
ObjectType
Object types.
Definition: Object.h:29
ChannelType
Supported image channel types.
Definition: ImageDescriptor.h:33
ImageTiling
Definition: ImageTiling.h:16
ChannelCount
Supported image channel count.
Definition: ImageDescriptor.h:53
Structure to hold the allocation information of objects in memory.
Definition: MemoryAllocationInfo.h:19
Common types.