MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
VKImage.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <vulkan/vulkan.hpp>
5
6namespace MayaFlux::Core {
7
8/**
9 * @struct VKImageResources
10 * @brief Vulkan image resource handles
11 *
12 * Stores all Vulkan handles associated with an image.
13 * Set by backend after allocation.
14 */
16 vk::Image image;
17 vk::ImageView image_view;
18 vk::DeviceMemory memory;
19 vk::Sampler sampler; // Optional, can be null
20};
21
22/**
23 * @class VKImage
24 * @brief Lightweight Vulkan image wrapper for MayaFlux processing pipeline
25 *
26 * VKImage is a backend-level representation of a GPU image/texture. Like VKBuffer,
27 * it is a semantic container that stores metadata and Vulkan handles but does not
28 * perform allocation itself. The backend (VulkanBackend) handles actual resource
29 * creation via BufferService-style patterns.
30 *
31 * Responsibilities:
32 * - Store image dimensions, format, usage intent, and semantic modality
33 * - Provide inferred data dimensions for processors and pipeline inspection
34 * - Hold Vulkan handles (VkImage, VkImageView, VkDeviceMemory) assigned by backend
35 * - Provide convenience helpers for Vulkan creation flags and memory properties
36 * - Track current layout for automatic layout transitions
37 *
38 * Does NOT handle:
39 * - Actual Vulkan allocation (that's VulkanBackend)
40 * - Layout transitions (that's command buffer operations)
41 * - Descriptor set binding (that's VKDescriptorManager)
42 *
43 * Integration points:
44 * - Created by Portal::Graphics::TextureLoom
45 * - Allocated by VulkanBackend::initialize_image()
46 * - Wrapped by Kakshya::Visual::TextureStream (future)
47 * - Used by Yantra::Graphics::RenderPipeline (future)
48 */
49class MAYAFLUX_API VKImage {
50public:
51 enum class Usage : uint8_t {
52 TEXTURE_2D, ///< Sampled texture (shader read)
53 RENDER_TARGET, ///< Color attachment for rendering
54 DEPTH_STENCIL, ///< Depth/stencil attachment
55 STORAGE, ///< Storage image (compute shader read/write)
56 TRANSFER_SRC, ///< Transfer source
57 TRANSFER_DST, ///< Transfer destination
58 STAGING ///< Host-visible staging image (rare)
59 };
60
61 enum class Type : uint8_t {
62 TYPE_1D,
63 TYPE_2D,
64 TYPE_3D,
65 TYPE_CUBE
66 };
67
68 /**
69 * @brief Construct an uninitialized VKImage
70 *
71 * Creates a VKImage object with requested parameters. No Vulkan resources
72 * are created by this constructor - registration with the backend is required.
73 *
74 * @param width Image width in pixels
75 * @param height Image height in pixels
76 * @param depth Image depth (for 3D textures, 1 for 2D)
77 * @param format Vulkan image format
78 * @param usage Intended usage pattern
79 * @param type Image dimensionality
80 * @param mip_levels Number of mipmap levels (1 for no mipmaps)
81 * @param array_layers Number of array layers (1 for single image, 6 for cubemap)
82 * @param modality Semantic interpretation of image contents
83 */
84 VKImage(
85 uint32_t width,
86 uint32_t height,
87 uint32_t depth,
88 vk::Format format,
89 Usage usage,
90 Type type = Type::TYPE_2D,
91 uint32_t mip_levels = 1,
92 uint32_t array_layers = 1,
93 Kakshya::DataModality modality = Kakshya::DataModality::IMAGE_COLOR);
94
95 VKImage() = default;
96 ~VKImage() = default;
97
98 VKImage(const VKImage&) = delete;
99 VKImage& operator=(const VKImage&) = delete;
100 VKImage(VKImage&&) noexcept = default;
101 VKImage& operator=(VKImage&&) noexcept = default;
102
103 //==========================================================================
104 // Vulkan Handle Access
105 //==========================================================================
106
107 /** Get VkImage handle (VK_NULL_HANDLE if not initialized) */
108 [[nodiscard]] vk::Image get_image() const { return m_resources.image; }
109
110 /** Get VkImageView handle (VK_NULL_HANDLE if not initialized) */
111 [[nodiscard]] vk::ImageView get_image_view() const { return m_resources.image_view; }
112
113 /** Get VkDeviceMemory handle (VK_NULL_HANDLE if not initialized) */
114 [[nodiscard]] vk::DeviceMemory get_memory() const { return m_resources.memory; }
115
116 /** Get VkSampler handle (VK_NULL_HANDLE if none assigned) */
117 [[nodiscard]] vk::Sampler get_sampler() const { return m_resources.sampler; }
118
119 /** Get all image resources at once */
120 [[nodiscard]] const VKImageResources& get_image_resources() const { return m_resources; }
121
122 /** Set VkImage handle after backend allocation */
123 void set_image(vk::Image image) { m_resources.image = image; }
124
125 /** Set VkImageView handle after backend allocation */
126 void set_image_view(vk::ImageView view) { m_resources.image_view = view; }
127
128 /** Set VkDeviceMemory handle after backend allocation */
129 void set_memory(vk::DeviceMemory memory) { m_resources.memory = memory; }
130
131 /** Set VkSampler handle (optional) */
132 void set_sampler(vk::Sampler sampler) { m_resources.sampler = sampler; }
133
134 /** Set all image resources at once */
135 void set_image_resources(const VKImageResources& resources) { m_resources = resources; }
136
137 /** Check whether Vulkan handles are present (image registered) */
138 [[nodiscard]] bool is_initialized() const { return m_resources.image != VK_NULL_HANDLE; }
139
140 //==========================================================================
141 // Image Properties
142 //==========================================================================
143
144 [[nodiscard]] uint32_t get_width() const { return m_width; }
145 [[nodiscard]] uint32_t get_height() const { return m_height; }
146 [[nodiscard]] uint32_t get_depth() const { return m_depth; }
147 [[nodiscard]] vk::Format get_format() const { return m_format; }
148 [[nodiscard]] Usage get_usage() const { return m_usage; }
149 [[nodiscard]] Type get_type() const { return m_type; }
150 [[nodiscard]] uint32_t get_mip_levels() const { return m_mip_levels; }
151 [[nodiscard]] uint32_t get_array_layers() const { return m_array_layers; }
152 [[nodiscard]] Kakshya::DataModality get_modality() const { return m_modality; }
153
154 /** Get the inferred data dimensions for the image contents */
155 [[nodiscard]] const std::vector<Kakshya::DataDimension>& get_dimensions() const { return m_dimensions; }
156
157 /** Update the semantic modality and re-infer dimensions */
158 void set_modality(Kakshya::DataModality modality);
159
160 //==========================================================================
161 // Layout Tracking
162 //==========================================================================
163
164 /** Get current image layout (for synchronization) */
165 [[nodiscard]] vk::ImageLayout get_current_layout() const { return m_current_layout; }
166
167 /** Set current layout (called after transitions) */
168 void set_current_layout(vk::ImageLayout layout) { m_current_layout = layout; }
169
170 //==========================================================================
171 // Vulkan Creation Helpers (for backend use)
172 //==========================================================================
173
174 /**
175 * @brief Get appropriate VkImageUsageFlags based on Usage
176 * @return VkImageUsageFlags to use when creating VkImage
177 */
178 [[nodiscard]] vk::ImageUsageFlags get_usage_flags() const;
179
180 /**
181 * @brief Get appropriate VkMemoryPropertyFlags based on Usage
182 * @return VkMemoryPropertyFlags for memory allocation
183 */
184 [[nodiscard]] vk::MemoryPropertyFlags get_memory_properties() const;
185
186 /**
187 * @brief Get appropriate VkImageAspectFlags based on format
188 * @return VkImageAspectFlags for image view creation
189 */
190 [[nodiscard]] vk::ImageAspectFlags get_aspect_flags() const;
191
192 /**
193 * @brief Whether this image should be host-visible (staging images)
194 * @return True for staging images, false for device-local
195 */
196 [[nodiscard]] bool is_host_visible() const { return m_usage == Usage::STAGING; }
197
198 /**
199 * @brief Get total size in bytes (for memory allocation)
200 * @return Estimated size in bytes
201 */
202 [[nodiscard]] size_t get_size_bytes() const;
203
204private:
206
207 uint32_t m_width { 0 };
208 uint32_t m_height { 0 };
209 uint32_t m_depth { 1 };
210 vk::Format m_format { vk::Format::eUndefined };
211 Usage m_usage { Usage::TEXTURE_2D };
212 Type m_type { Type::TYPE_2D };
213 uint32_t m_mip_levels { 1 };
214 uint32_t m_array_layers { 1 };
215
216 vk::ImageLayout m_current_layout { vk::ImageLayout::eUndefined };
217
219 std::vector<Kakshya::DataDimension> m_dimensions;
220
221 /**
222 * @brief Infer Kakshya::DataDimension entries from image parameters
223 *
224 * Uses current modality, dimensions, and format to populate m_dimensions
225 * so processors and UI code can reason about the image layout.
226 */
227 void infer_dimensions_from_parameters();
228};
229
230} // namespace MayaFlux::Core
uint32_t get_array_layers() const
Definition VKImage.hpp:151
VKImage & operator=(const VKImage &)=delete
void set_image(vk::Image image)
Set VkImage handle after backend allocation.
Definition VKImage.hpp:123
void set_current_layout(vk::ImageLayout layout)
Set current layout (called after transitions)
Definition VKImage.hpp:168
void set_image_view(vk::ImageView view)
Set VkImageView handle after backend allocation.
Definition VKImage.hpp:126
bool is_host_visible() const
Whether this image should be host-visible (staging images)
Definition VKImage.hpp:196
VKImage(const VKImage &)=delete
const VKImageResources & get_image_resources() const
Get all image resources at once.
Definition VKImage.hpp:120
uint32_t get_mip_levels() const
Definition VKImage.hpp:150
void set_sampler(vk::Sampler sampler)
Set VkSampler handle (optional)
Definition VKImage.hpp:132
Usage get_usage() const
Definition VKImage.hpp:148
void set_image_resources(const VKImageResources &resources)
Set all image resources at once.
Definition VKImage.hpp:135
VKImageResources m_resources
Definition VKImage.hpp:205
vk::ImageLayout get_current_layout() const
Get current image layout (for synchronization)
Definition VKImage.hpp:165
const std::vector< Kakshya::DataDimension > & get_dimensions() const
Get the inferred data dimensions for the image contents.
Definition VKImage.hpp:155
void set_memory(vk::DeviceMemory memory)
Set VkDeviceMemory handle after backend allocation.
Definition VKImage.hpp:129
Type get_type() const
Definition VKImage.hpp:149
uint32_t get_width() const
Definition VKImage.hpp:144
vk::Sampler get_sampler() const
Get VkSampler handle (VK_NULL_HANDLE if none assigned)
Definition VKImage.hpp:117
bool is_initialized() const
Check whether Vulkan handles are present (image registered)
Definition VKImage.hpp:138
uint32_t get_depth() const
Definition VKImage.hpp:146
std::vector< Kakshya::DataDimension > m_dimensions
Definition VKImage.hpp:219
Kakshya::DataModality m_modality
Definition VKImage.hpp:218
vk::Format get_format() const
Definition VKImage.hpp:147
Kakshya::DataModality get_modality() const
Definition VKImage.hpp:152
vk::ImageView get_image_view() const
Get VkImageView handle (VK_NULL_HANDLE if not initialized)
Definition VKImage.hpp:111
uint32_t get_height() const
Definition VKImage.hpp:145
vk::DeviceMemory get_memory() const
Get VkDeviceMemory handle (VK_NULL_HANDLE if not initialized)
Definition VKImage.hpp:114
VKImage(VKImage &&) noexcept=default
Lightweight Vulkan image wrapper for MayaFlux processing pipeline.
Definition VKImage.hpp:49
DataModality
Data modality types for cross-modal analysis.
Definition NDData.hpp:78
Vulkan image resource handles.
Definition VKImage.hpp:15