Lluvia
ll::Memory Class Reference

Class to manage allocation of objects into a specific type of memory. More...

#include <Memory.h>

Inheritance diagram for ll::Memory:
Collaboration diagram for ll::Memory:

Public Member Functions

 Memory ()=delete
 
 Memory (const Memory &memory)=delete
 
 Memory (Memory &&memory)=delete
 
 Memory (const std::shared_ptr< ll::vulkan::Device > &device, const ll::VkHeapInfo &heapInfo, const uint64_t pageSize)
 Constructs a new ll::Memory object. More...
 
 ~Memory ()
 
Memoryoperator= (const Memory &memory)=delete
 
Memoryoperator= (Memory &&memory)=delete
 
ll::MemoryPropertyFlags getMemoryPropertyFlags () const noexcept
 Gets the Vulkan memory property flags used to create this memory. More...
 
uint64_t getPageSize () const noexcept
 Gets the page size. More...
 
uint32_t getPageCount () const noexcept
 Gets the number of pages used. More...
 
bool isMappable () const noexcept
 Determines if this memory is mappable to host-visible memory. More...
 
bool isPageMappable (const uint32_t page) const noexcept
 Determines if a certain memory page is mappable. More...
 
std::shared_ptr< ll::BuffercreateBuffer (const uint64_t size)
 Creates a buffer. More...
 
std::shared_ptr< ll::BuffercreateBuffer (const uint64_t size, const ll::BufferUsageFlags usageFlags)
 Creates a new ll::Buffer object. More...
 
std::shared_ptr< ll::BuffercreateBufferWithUnsafeFlags (const uint64_t size, const uint32_t usageFlags)
 Creates buffer with usage flags passed as integer type. More...
 
std::shared_ptr< ll::ImagecreateImage (const ll::ImageDescriptor &descriptor)
 Creates a new ll::Image object. More...
 
std::shared_ptr< ll::ImageViewcreateImageView (const ll::ImageDescriptor &imgDescriptor, const ll::ImageViewDescriptor &viewDescriptor)
 Creates an image view. More...
 

Friends

class ll::Buffer
 
class ll::Image
 

Detailed Description

Class to manage allocation of objects into a specific type of memory.

Objects of this class contain a list of Vulkan memory objects. They are referred as memory page. Within each page, the memory for objects such as ll::Buffer and ll::Image is reserved. Several of such objets can be allocated in the same page. New pages are created on demand and managed by this class.

ll::Memory objects are constructed by calling ll::Session::createMemory on a valid session object.

auto session = ll::Session::create();
const auto hostMemFlags = vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent;;
const auto deviceMemFlags = vk::MemoryPropertyFlagBits::eDeviceLocal;
// host-visible memory with page size equals to 512 bytes
auto hostMemory = session->createMemory(hostMemFlags, 512);
// device-local memory with page size equals to 4096 bytes
auto deviceMemory = session->createMemory(deviceMemFlags, 4096);
static std::shared_ptr< ll::Session > create()
Creates a new ll::Session object.

TODO

  • Explain how objects are allocated and aligned inside a memory page.

Constructor & Destructor Documentation

◆ Memory() [1/4]

ll::Memory::Memory ( )
delete

◆ Memory() [2/4]

ll::Memory::Memory ( const Memory memory)
delete

◆ Memory() [3/4]

ll::Memory::Memory ( Memory &&  memory)
delete

◆ Memory() [4/4]

ll::Memory::Memory ( const std::shared_ptr< ll::vulkan::Device > &  device,
const ll::VkHeapInfo heapInfo,
const uint64_t  pageSize 
)

Constructs a new ll::Memory object.

Parameters
[in]sessionThe session this node was created from.
[in]deviceThe Vulkan device used for the construction.
[in]heapInfoThe heap information.
[in]pageSizeThe page size in bytes.

◆ ~Memory()

ll::Memory::~Memory ( )

Member Function Documentation

◆ createBuffer() [1/2]

std::shared_ptr<ll::Buffer> ll::Memory::createBuffer ( const uint64_t  size)

Creates a buffer.

The created buffer will hold a reference to this memory object, preventing it from destroying before the buffer is deleted.

The usage flags of the buffer will be set to vk::BufferUsageFlagBits::eStorageBuffer | vk::BufferUsageFlagBits::eTransferSrc | vk::BufferUsageFlagBits::eTransferDst. See https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VkBufferUsageFlagBits.

Parameters
[in]sizeThe size in bytes
Returns
{ description_of_the_return_value }

◆ createBuffer() [2/2]

std::shared_ptr<ll::Buffer> ll::Memory::createBuffer ( const uint64_t  size,
const ll::BufferUsageFlags  usageFlags 
)

Creates a new ll::Buffer object.

The created buffer will hold a reference to this memory object, preventing it from destroying before the buffer is deleted.

Parameters
[in]sizeThe size of the buffer in bytes. If size is greater than the page size, a bigger page is created.
[in]usageFlagsThe usage flags of the buffer. See https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VkBufferUsageFlagBits.
Exceptions
std::system_errorif the Vulkan memory does not support allocating buffer objects.
Returns
A new ll::Buffer object.

◆ createBufferWithUnsafeFlags()

std::shared_ptr<ll::Buffer> ll::Memory::createBufferWithUnsafeFlags ( const uint64_t  size,
const uint32_t  usageFlags 
)

Creates buffer with usage flags passed as integer type.

Warning
Please do not use this method. It's for internal use only.
Parameters
[in]sizeThe size
[in]usageFlagsThe usage flags
Exceptions
std::system_errorif the Vulkan memory does not support allocating buffer objects.
Returns
A new ll::Buffer object.

◆ createImage()

std::shared_ptr<ll::Image> ll::Memory::createImage ( const ll::ImageDescriptor descriptor)

Creates a new ll::Image object.

The created image will hold a reference to this memory object, preventing it from destroying before the image is deleted.

Parameters
[in]descriptorThe image descriptor.
Exceptions
std::system_errorif the Vulkan memory does not support allocating image objects.
std::invalid_argumentif the image size in the descriptor is not valid. This happens if the width, height or depth are zero or if the channel count ins not in the rante [1, 4].
Returns
A new ll::Image object.

◆ createImageView()

std::shared_ptr<ll::ImageView> ll::Memory::createImageView ( const ll::ImageDescriptor imgDescriptor,
const ll::ImageViewDescriptor viewDescriptor 
)

Creates an image view.

This method is equivalent to

auto image = memory->createImage(imgDescriptor);
auto imageView = image->createImageView(videDescriptor);
Parameters
[in]imgDescriptorThe underlying ll::Image descriptor.
[in]viewDescriptorThe image view descriptor.
Exceptions
std::system_errorif the Vulkan memory does not support allocating image objects.
std::invalid_argumentif the image size in the descriptor is not valid. This happens if the width, height or depth are zero or if the channel count ins not in the rante [1, 4].
Returns
A new ImageView with the underlying image storage created in thise memory.

◆ getMemoryPropertyFlags()

ll::MemoryPropertyFlags ll::Memory::getMemoryPropertyFlags ( ) const
noexcept

Gets the Vulkan memory property flags used to create this memory.

See https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VkMemoryPropertyFlagBits for more information.

Returns
The memory property flags.

◆ getPageCount()

uint32_t ll::Memory::getPageCount ( ) const
noexcept

Gets the number of pages used.

Returns
The page count.

◆ getPageSize()

uint64_t ll::Memory::getPageSize ( ) const
noexcept

Gets the page size.

Returns
The page size.

◆ isMappable()

bool ll::Memory::isMappable ( ) const
noexcept

Determines if this memory is mappable to host-visible memory.

Returns
True if mappable, False otherwise.
See also
ll::Memory::isPageMappable Determines if a certain memory page is mappable.

◆ isPageMappable()

bool ll::Memory::isPageMappable ( const uint32_t  page) const
noexcept

Determines if a certain memory page is mappable.

This test checks if page is available to be mapped to host-memory by a given objects such as a ll::Buffer.

Parameters
[in]pageThe page index.
Returns
True if page mappable, False otherwise.

◆ operator=() [1/2]

Memory& ll::Memory::operator= ( const Memory memory)
delete

◆ operator=() [2/2]

Memory& ll::Memory::operator= ( Memory &&  memory)
delete

Friends And Related Function Documentation

◆ ll::Buffer

friend class ll::Buffer
friend

◆ ll::Image

friend class ll::Image
friend

The documentation for this class was generated from the following file: