SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
spark::render::vk::VulkanImage Class Referencefinal

Vulkan implementation of IImage. More...

#include <VulkanImage.h>

Inheritance diagram for spark::render::vk::VulkanImage:
spark::render::vk::IVulkanImage spark::render::Resource< VkImage > spark::render::StateResource spark::render::IImage spark::render::IResource< VkImage > spark::render::IResource< VkImage > spark::render::IStateResource spark::render::IStateResource spark::render::IDeviceMemory

Classes

struct  Impl
 

Public Member Functions

 VulkanImage (const VulkanDevice &device, VkImage image, const math::Vector3< unsigned > &extent, Format format, ImageDimensions dimensions, unsigned levels, unsigned layers, MultiSamplingLevel samples, bool writable, ImageLayout initial_layout, VmaAllocator allocator=nullptr, VmaAllocation allocation=nullptr, const std::string &name="")
 Initializes a new VulkanImage.
 
 VulkanImage (const VulkanImage &other)=delete
 
 VulkanImage (VulkanImage &&other) noexcept=delete
 
VulkanImageoperator= (const VulkanImage &other)=delete
 
VulkanImageoperator= (VulkanImage &&other) noexcept=delete
 
VkImageAspectFlags aspectMask () const noexcept override
 Gets the image aspect mask for all sub-resources.
 
VkImageAspectFlags aspectMask (unsigned plane) const override
 Gets the image aspect mask for all sub-resources.
 
const VkImageView & imageView (unsigned plane=0) const override
 Gets an image view for the given sub-resource.
 
unsigned elements () const noexcept override
 Get the number of sub-resources in the memory chunk.
 
std::size_t size () const noexcept override
 Gets the size (in bytes) of the memory chunk.
 
std::size_t elementSize () const noexcept override
 Gets the size (in bytes) of one element in the memory chunk. If there is only one element, this equals the result of IDeviceMemory::size().
 
std::size_t elementAlignment () const override
 Gets the alignment of one element in the memory chunk.
 
std::size_t alignedElementSize () const noexcept override
 Gets the real size (in bytes) of the memory chunk.
 
bool writable () const noexcept override
 Checks if the resource can be bound to a read/write descriptor.
 
std::size_t size (unsigned level) const override
 Gets the size (in bytes) of the memory chunk.
 
math::Vector3< unsigned > extent (unsigned level) const noexcept override
 Get the extent of the image at the specified mip-map level.
 
Format format () const noexcept override
 Gets the internal format of the image.
 
ImageDimensions dimensions () const noexcept override
 Gets the dimensions of the image. (1D, 2D, 3D, Cube)
 
unsigned levels () const noexcept override
 Gets the number of mip-map levels of the image.
 
unsigned layers () const noexcept override
 Gets the number of layers of the image.
 
unsigned planes () const noexcept override
 Returns the number of planes of the image.
 
MultiSamplingLevel samples () const noexcept override
 Gets the number of samples with which the image is sampled.
 
ImageLayout layout (unsigned sub_resource) const override
 Gets the layout of the image.
 
- Public Member Functions inherited from spark::render::vk::IVulkanImage
virtual VkImageAspectFlags aspectMask (unsigned int plane=0) const =0
 Gets the image aspect mask for the given sub-resource.
 
virtual const VkImageView & imageView (unsigned int plane=0) const =0
 Gets an image view for the given sub-resource.
 
- Public Member Functions inherited from spark::render::IImage
virtual std::size_t size (unsigned int level) const =0
 Get the size of the image (in bytes) at the specified mip-map level.
 
virtual ImageLayout layout (unsigned int sub_resource=0) const =0
 Gets the layout of the image.
 
virtual unsigned int subResourceId (unsigned &level, unsigned &layer, unsigned &plane) const noexcept
 Returns the sub-resource ID for a combination of mip-map level, array layer and plane.
 
std::tuple< unsigned, unsigned, unsigned > resolveSubresource (const unsigned subresource) const noexcept
 Returns the sub-resource ID for a combination of mip-map level, array layer and plane.
 
- Public Member Functions inherited from spark::render::Resource< VkImage >
 Resource (VkImage handle) noexcept
 Initializes the managed resource with the given handle.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other) noexcept=delete
 
Resourceoperator= (const Resource &other)=delete
 
Resourceoperator= (Resource &&other) noexcept=delete
 
const VkImage & handle () const final
 Gets the managed resource handle.
 
- Public Member Functions inherited from spark::render::StateResource
 StateResource (std::string_view name) noexcept
 Initializes a new StateResource instance.
 
 StateResource (const StateResource &other)=delete
 
 StateResource (StateResource &&other) noexcept
 
StateResourceoperator= (const StateResource &other)=delete
 
StateResourceoperator= (StateResource &&other) noexcept
 
const std::string & name () const noexcept final
 Gets the name of the state resource.
 

Static Public Member Functions

static std::unique_ptr< VulkanImageAllocate (const VulkanDevice &device, const math::Vector3< unsigned > &extent, Format format, ImageDimensions dimensions, unsigned levels, unsigned layers, MultiSamplingLevel samples, bool writable, ImageLayout initial_layout, VmaAllocator &allocator, const VkImageCreateInfo &create_info, const VmaAllocationCreateInfo &allocation_info, VmaAllocationInfo *allocation_result=nullptr)
 
static std::unique_ptr< VulkanImageAllocate (const std::string &name, const VulkanDevice &device, const math::Vector3< unsigned > &extent, Format format, ImageDimensions dimensions, unsigned levels, unsigned layers, MultiSamplingLevel samples, bool writable, ImageLayout initial_layout, VmaAllocator &allocator, const VkImageCreateInfo &create_info, const VmaAllocationCreateInfo &allocation_info, VmaAllocationInfo *allocation_result=nullptr)
 

Additional Inherited Members

- Public Types inherited from spark::render::IResource< VkImage >
using handle_type
 
- Protected Member Functions inherited from spark::render::Resource< VkImage >
VkImage & handle () final
 Gets the managed resource handle.
 
- Protected Member Functions inherited from spark::render::StateResource
 StateResource () noexcept
 Initializes a new StateResource instance with an empty name.
 
std::string & name () noexcept
 Gets the name of the state resource.
 

Detailed Description

Vulkan implementation of IImage.

Constructor & Destructor Documentation

◆ VulkanImage()

spark::render::vk::VulkanImage::VulkanImage ( const VulkanDevice & device,
VkImage image,
const math::Vector3< unsigned > & extent,
Format format,
ImageDimensions dimensions,
unsigned levels,
unsigned layers,
MultiSamplingLevel samples,
bool writable,
ImageLayout initial_layout,
VmaAllocator allocator = nullptr,
VmaAllocation allocation = nullptr,
const std::string & name = "" )
explicit

Initializes a new VulkanImage.

Parameters
device
image
extent
format
dimensions
levels
layers
samples
writable
initial_layout
allocator
allocation
name

Member Function Documentation

◆ alignedElementSize()

std::size_t spark::render::vk::VulkanImage::alignedElementSize ( ) const
nodiscardoverridevirtualnoexcept

Gets the real size (in bytes) of the memory chunk.

Returns
The real size of the memory chunk in bytes.
Note
For images, this method will return a value that equals the result of IDeviceMemory::size(), aligned by IDeviceMemory::elementAlignment().

Implements spark::render::IDeviceMemory.

◆ Allocate() [1/2]

std::unique_ptr< VulkanImage > spark::render::vk::VulkanImage::Allocate ( const std::string & name,
const VulkanDevice & device,
const math::Vector3< unsigned > & extent,
Format format,
ImageDimensions dimensions,
unsigned levels,
unsigned layers,
MultiSamplingLevel samples,
bool writable,
ImageLayout initial_layout,
VmaAllocator & allocator,
const VkImageCreateInfo & create_info,
const VmaAllocationCreateInfo & allocation_info,
VmaAllocationInfo * allocation_result = nullptr )
static
Parameters
name
device
extent
format
dimensions
levels
layers
samples
writable
initial_layout
allocator
create_info
allocation_info
allocation_result
Returns

◆ Allocate() [2/2]

std::unique_ptr< VulkanImage > spark::render::vk::VulkanImage::Allocate ( const VulkanDevice & device,
const math::Vector3< unsigned > & extent,
Format format,
ImageDimensions dimensions,
unsigned levels,
unsigned layers,
MultiSamplingLevel samples,
bool writable,
ImageLayout initial_layout,
VmaAllocator & allocator,
const VkImageCreateInfo & create_info,
const VmaAllocationCreateInfo & allocation_info,
VmaAllocationInfo * allocation_result = nullptr )
static
Parameters
device
extent
format
dimensions
levels
layers
samples
writable
initial_layout
allocator
create_info
allocation_info
allocation_result
Returns

◆ aspectMask() [1/2]

VkImageAspectFlags spark::render::vk::VulkanImage::aspectMask ( ) const
nodiscardoverridevirtualnoexcept

Gets the image aspect mask for all sub-resources.

Returns
A VkImageAspectFlags representing the image aspect mask.

Implements spark::render::vk::IVulkanImage.

◆ aspectMask() [2/2]

VkImageAspectFlags spark::render::vk::VulkanImage::aspectMask ( unsigned plane) const
nodiscardoverride

Gets the image aspect mask for all sub-resources.

Returns
A VkImageAspectFlags representing the image aspect mask.

◆ dimensions()

ImageDimensions spark::render::vk::VulkanImage::dimensions ( ) const
nodiscardoverridevirtualnoexcept

Gets the dimensions of the image. (1D, 2D, 3D, Cube)

Returns
A ImageDimensions that describes the dimensions of the image.
Note
This imply various things, especially which values of the extent() are valid.

Implements spark::render::IImage.

◆ elementAlignment()

std::size_t spark::render::vk::VulkanImage::elementAlignment ( ) const
nodiscardoverridevirtual

Gets the alignment of one element in the memory chunk.

Returns
The alignment of one element in the memory chunk.

Implements spark::render::IDeviceMemory.

◆ elements()

unsigned spark::render::vk::VulkanImage::elements ( ) const
nodiscardoverridevirtualnoexcept

Get the number of sub-resources in the memory chunk.

Returns
The number of array elements in the memory chunk.
Note
For buffers, this equals the number of array elements. For images, this equals the product of layers, levels and planes. This number represents the number of states, that can be obtained by calling the IDeviceMemory::state() method.

Implements spark::render::IDeviceMemory.

◆ elementSize()

std::size_t spark::render::vk::VulkanImage::elementSize ( ) const
nodiscardoverridevirtualnoexcept

Gets the size (in bytes) of one element in the memory chunk. If there is only one element, this equals the result of IDeviceMemory::size().

Returns
The size of one element in the memory chunk.
Note
For images, this method will return a value that equals the result of IDeviceMemory::size().

Implements spark::render::IDeviceMemory.

◆ extent()

math::Vector3< unsigned > spark::render::vk::VulkanImage::extent ( unsigned level) const
nodiscardoverridevirtualnoexcept

Get the extent of the image at the specified mip-map level.

Parameters
levelThe mip-map level for which to get the extent.
Returns
The extent of the image at the specified mip-map level or 0 if the mip-map level is invalid.
Note
Not all components of the returned extent are valid for all image dimensions. For example, a 1D image only has a valid x component. See ImageDimensions.

Implements spark::render::IImage.

◆ format()

Format spark::render::vk::VulkanImage::format ( ) const
nodiscardoverridevirtualnoexcept

Gets the internal format of the image.

Returns
A Format that describes the internal format of the image.

Implements spark::render::IImage.

◆ imageView()

const VkImageView & spark::render::vk::VulkanImage::imageView ( unsigned plane = 0) const
nodiscardoverride

Gets an image view for the given sub-resource.

Parameters
planeThe sub-resource index to get the image view for.
Returns
A VkImageView representing the image view for the given sub-resource.

◆ layers()

unsigned spark::render::vk::VulkanImage::layers ( ) const
nodiscardoverridevirtualnoexcept

Gets the number of layers of the image.

Returns
The number of layers (slices) of the image.

Implements spark::render::IImage.

◆ layout()

ImageLayout spark::render::vk::VulkanImage::layout ( unsigned sub_resource) const
nodiscardoverride

Gets the layout of the image.

Parameters
sub_resourceThe sub-resource id for which to get the layout.
Returns
The layout of the image.

◆ levels()

unsigned spark::render::vk::VulkanImage::levels ( ) const
nodiscardoverridevirtualnoexcept

Gets the number of mip-map levels of the image.

Returns
The number of mip-map levels of the image.

Implements spark::render::IImage.

◆ planes()

unsigned spark::render::vk::VulkanImage::planes ( ) const
nodiscardoverridevirtualnoexcept

Returns the number of planes of the image.

Returns
The number of planes of the image.
Note
This values is dictated from the format() of the image.

Implements spark::render::IImage.

◆ samples()

MultiSamplingLevel spark::render::vk::VulkanImage::samples ( ) const
nodiscardoverridevirtualnoexcept

Gets the number of samples with which the image is sampled.

Returns
The number of samples of the image.

Implements spark::render::IImage.

◆ size() [1/2]

std::size_t spark::render::vk::VulkanImage::size ( ) const
nodiscardoverridevirtualnoexcept

Gets the size (in bytes) of the memory chunk.

Returns
The size of the memory chunk in bytes.
Note
The size of the device memory block depends on different factors. The actual used memory of one element can be obtained by calling by the IDeviceMemory::elementSize(). For different reasons, though, elements may be required to be aligned to a certain size. The size of one aligned element is returned by IDeviceMemory::alignedElementSize(). The size of the memory block, the elements get aligned to is returned by IDeviceMemory::elementAlignment().

Reimplemented from spark::render::IImage.

◆ size() [2/2]

std::size_t spark::render::vk::VulkanImage::size ( unsigned level) const
nodiscardoverride

Gets the size (in bytes) of the memory chunk.

Returns
The size of the memory chunk in bytes.
Note
The size of the device memory block depends on different factors. The actual used memory of one element can be obtained by calling by the IDeviceMemory::elementSize(). For different reasons, though, elements may be required to be aligned to a certain size. The size of one aligned element is returned by IDeviceMemory::alignedElementSize(). The size of the memory block, the elements get aligned to is returned by IDeviceMemory::elementAlignment().

◆ writable()

bool spark::render::vk::VulkanImage::writable ( ) const
nodiscardoverridevirtualnoexcept

Checks if the resource can be bound to a read/write descriptor.

Returns
true if the resource can be bound to a read/write descriptor, false otherwise.
Note
If the resource is not writable, attempting to bind it to a writable descriptor will result in an exception.

Implements spark::render::IDeviceMemory.