NDEVR
API Documentation
VulkanImage.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Graphics
28File: VulkanImage
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "VulkanDefines.h"
34#include "VulkanDevice.h"
35#include <NDEVR/Image.h>
36#include <NDEVR/Pointer.h>
37#include <NDEVR/File.h>
38#include <NDEVR/RGBColor.h>
39#include <NDEVR/Dictionary.h>
40#include <NDEVR/Buffer.h>
41
42typedef uint32_t VkImageUsageFlags;
43typedef uint32_t VkMemoryPropertyFlags;
44namespace NDEVR
45{
46 class File;
47 class VulkanInstance;
48 class VulkanBuffer;
53 class VulkanImageData : public Image
54 {
55 public:
61 VulkanImageData(VulkanImageData&& instance) noexcept;
66 VulkanImageData(const ConstPointer<VulkanDevice>& instance, const StringView& image_id, uint04 mip_map_depth);
71 VulkanImageData(const ConstPointer<VulkanDevice>& instance, Buffer<String>& image_ids, uint04 mip_map_depth);
81 VulkanImageData(const ConstPointer<VulkanDevice>& instance, VkImage image, Vector<2, uint04> size, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, bool image_owner);
89 VulkanImageData(const ConstPointer<VulkanDevice>& instance, Vector<2, uint04> size, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties);
95 void clear(const RGBColor& color = RGBColor(0,0,0,0), VkCommandBuffer_T* command = nullptr);
97 uint04 mipMapDepth() const { return m_mip_map_depth; };
99 void setMipMapDepth(uint04 depth) { m_mip_map_depth = depth; };
100
102 uint04 arrayLayers() const { return m_array_layers; }
104 void setArrayLayers(uint04 array_layers) { m_array_layers = array_layers; }
105
108 const Time& getModifiedTime() const { return m_modified_time; }
114 VkFormat getFormat() const;
116 void setFormat(VkFormat format);
117
123 void cleanup(bool destroy_memory = true);
125 Vector<2, uint04> size() const final override;
127 ConstPointer<VulkanDevice> device() const { return m_device; }
128
130 VkImage vulkanImage() const { return m_vulkan_image; };
132 VkDeviceMemory vkMemory() const { return m_image_memory; }
136 static VkSampleCountFlagBits getSampleBitflags(uint04 multi_sample_count);
143 void setImageProperties(Vector<2, uint04> size, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties);
144
148 void transitionImageLayout(VkImageLayout newLayout, VkCommandBuffer_T* command = nullptr);
154 void transitionImageLayout(VkImageLayout newLayout, uint04 miplevel, uint04 level, VkCommandBuffer_T* command = nullptr);
156 void setMultiSampleCount(uint04 count) { m_multi_sample_count = count; };
160 void setData(const StringView& image_id, uint04 layer);
164 void setData(VkImage image, bool image_owner);
166 bool hasAlpha() const { return m_has_alpha; }
169 void rawSetLayout(VkImageLayout layout);
173 VkImageLayout layout(uint04 mip_level = 0) const;
177 void checkAndUpdateMemory(VkMemoryPropertyFlags properties, bool bind_image);
178 public:
183 void createImage(VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties);
184 private:
185 uint04 computeOffset(uint04 mip_level, uint04 image_layer);
186 VkImage m_vulkan_image;
187 Time m_modified_time;
188 Vector<2, uint04> m_size;
189 uint04 m_allocated_size;
190 VkDeviceMemory m_image_memory;
192 uint08 m_layout[32];
193 uint08 m_format;
194 uint04 m_mip_map_depth;
195 uint04 m_array_layers;
196 uint04 m_multi_sample_count;
197 uint04 m_bytes_per_pixel = 4;
198 bool m_has_alpha;
199 bool m_image_owner;
200 };
201
230
236 {
237 public:
242 VulkanImageView(const ConstPointer<VulkanImageData>& data, uint04 aspectFlags, bool create = true);
250 bool needsUpdate() const;
252 void create();
255 VkImageView vkImageView() const { return m_view; }
257 void cleanup();
258 private:
259 VkImageView m_view;
260 VkImage m_last_image;
262 uint04 m_aspect_flags;
263 };
264}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition Pointer.hpp:276
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
A root class that stores an an array of pixel data that can be displayed as an Image.
Definition Image.h:40
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:57
The core String View class for the NDEVR API.
Definition StringView.h:58
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
A GPU buffer managed through the Vulkan API, used for vertex, index, and uniform data.
A GraphicsDevice for managing Vulkan limitations and actions.
Vector< 2, uint04 > size() const final override
Returns the image dimensions.
void clear(const RGBColor &color=RGBColor(0, 0, 0, 0), VkCommandBuffer_T *command=nullptr)
Clears the image to the given color.
VkImageLayout layout(uint04 mip_level=0) const
Returns the current layout of the specified mip level.
VkFormat getFormat() const
Returns the Vulkan format of this image.
uint04 arrayLayers() const
Returns the number of array layers.
const Time & getModifiedTime() const
Returns the last modification time of the image data.
VulkanImageData(const ConstPointer< VulkanDevice > &instance)
Constructs an empty Vulkan image on the given device.
static VkSampleCountFlagBits getSampleBitflags(uint04 multi_sample_count)
Converts a multi-sample count to Vulkan sample count flags.
VkDeviceMemory vkMemory() const
Returns the device memory backing this image.
VulkanImageData(VulkanImageData &&instance) noexcept
Move constructor.
void setArrayLayers(uint04 array_layers)
Sets the number of array layers.
void rawSetLayout(VkImageLayout layout)
Directly sets the tracked layout without issuing a transition command.
VulkanImageData(const ConstPointer< VulkanDevice > &instance, const StringView &image_id, uint04 mip_map_depth)
Constructs a Vulkan image from a single image file.
void setData(const StringView &image_id, uint04 layer)
Loads image data from a file into a specific array layer.
void cleanup(bool destroy_memory=true)
Releases Vulkan resources.
void transitionImageLayout(VkImageLayout newLayout, uint04 miplevel, uint04 level, VkCommandBuffer_T *command=nullptr)
Transitions a specific mip level range to a new layout.
void setDevice(const ConstPointer< VulkanDevice > &instance)
Sets the Vulkan device for this image.
void createImage(VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties)
Creates the Vulkan image object with the specified properties.
~VulkanImageData()
Destructor.
ConstPointer< VulkanDevice > device() const
Returns the Vulkan device.
Vector< 2, uint04 > getMipSize(uint04 level) const
Calculates the dimensions of a specific mip level.
VulkanImageData(const ConstPointer< VulkanDevice > &instance, VkImage image, Vector< 2, uint04 > size, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, bool image_owner)
Constructs a Vulkan image wrapping an existing VkImage handle.
void setMipMapDepth(uint04 depth)
Sets the mip map depth.
Definition VulkanImage.h:99
void setMultiSampleCount(uint04 count)
Sets the multi-sample count.
void setData(VkImage image, bool image_owner)
Assigns an existing VkImage to this object.
VulkanImageData(const ConstPointer< VulkanDevice > &instance, Buffer< String > &image_ids, uint04 mip_map_depth)
Constructs a Vulkan image array from multiple image files.
uint04 mipMapDepth() const
Returns the mip map depth.
Definition VulkanImage.h:97
void checkAndUpdateMemory(VkMemoryPropertyFlags properties, bool bind_image)
Checks and updates the memory allocation to match the required properties.
bool hasAlpha() const
Returns whether the image has an alpha channel.
void setFormat(VkFormat format)
Sets the Vulkan format for this image.
VkImage vulkanImage() const
Returns the underlying VkImage handle.
VulkanImageData(const ConstPointer< VulkanDevice > &instance, Vector< 2, uint04 > size, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties)
Constructs a new Vulkan image with the given properties.
void transitionImageLayout(VkImageLayout newLayout, VkCommandBuffer_T *command=nullptr)
Transitions the entire image to a new layout.
void setImageProperties(Vector< 2, uint04 > size, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties)
Configures the image properties and allocates resources.
VulkanImageManager(const ConstPointer< VulkanDevice > &instance)
Constructs an image manager for the given device.
ConstPointer< VulkanDevice > m_device
The Vulkan device.
Time m_check_time
The last time images were checked for updates.
~VulkanImageManager()
Destructor.
ConstPointer< VulkanImageData > getImage(const StringView &file)
Retrieves or loads a Vulkan image from a file path.
bool updateImages()
Updates all managed images that have changed on disk.
uint04 m_mip_map_depth
The mip map depth used for new images.
Dictionary< String, DynamicPointer< VulkanImageData > > m_file_map
Maps file paths to loaded image data.
bool needsImageUpdate(Time time)
Checks whether any images need updating since the given time.
bool needsUpdate() const
Checks whether the view needs to be recreated due to image changes.
void create()
Creates or recreates the Vulkan image view.
VkImageView vkImageView() const
Returns the underlying Vulkan image view handle.
VulkanImageView(const ConstPointer< VulkanImageData > &data, uint04 aspectFlags, bool create=true)
Constructs an image view for the given image data.
~VulkanImageView()
Destructor.
void cleanup()
Releases the Vulkan image view resources.
VulkanImageView(VulkanImageView &&old)
Move constructor.
The connection between the NDEVR API and the Vulkan library.
The primary namespace for the NDEVR SDK.
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
@ file
The source file path associated with this object.