Lluvia
ll::Buffer Class Reference

Objects to manage raw portions of allocated memory. More...

#include <Buffer.h>

Inheritance diagram for ll::Buffer:
Collaboration diagram for ll::Buffer:

Classes

struct  BufferMapDeleter
 Deleter for unmapping buffers from host memory. More...
 

Public Member Functions

 Buffer ()=delete
 
 Buffer (const Buffer &b)=delete
 
 Buffer (Buffer &&b)=delete
 
 ~Buffer ()
 
Bufferoperator= (const Buffer &buffer)=delete
 
Bufferoperator= (Buffer &&buffer)=delete
 
ll::ObjectType getType () const noexcept override
 Gets the object type. More...
 
ll::MemoryAllocationInfo getAllocationInfo () const noexcept
 Gets the allocation information. More...
 
const std::shared_ptr< ll::Memory > & getMemory () const noexcept
 Gets the memory this buffer was allocated from. More...
 
uint64_t getSize () const noexcept
 Gets the size of the buffer in bytes. More...
 
ll::BufferUsageFlags getUsageFlags () const noexcept
 Gets the Vulkan buffer usage flags. More...
 
uint32_t getUsageFlagsUnsafe () const noexcept
 Gets the usage flags casted to an integer type. More...
 
bool isMappable () const noexcept
 Determines if this buffer is mappable to host-visible memory. More...
 
template<typename T >
std::unique_ptr< T, ll::Buffer::BufferMapDeletermap ()
 Maps the memory content of this object to host-visible memory. More...
 
template<typename T >
void mapAndSet (T &&obj)
 
template<typename T >
void mapAndSetFromVector (const std::vector< T > &vec)
 
- Public Member Functions inherited from ll::Object
 Object ()=default
 Default constructor. More...
 
 Object (const Object &)=delete
 Copy constructor. More...
 
 Object (Object &&)=delete
 Move constructor. More...
 
virtual ~Object ()=default
 
Objectoperator= (const Object &)=delete
 Copy assignment. More...
 
Objectoperator= (Object &&)=delete
 Move assignment. More...
 

Friends

class ll::CommandBuffer
 
class ll::ComputeGraph
 
class ll::ComputeNode
 
class ll::Memory
 
class ll::Session
 

Detailed Description

Objects to manage raw portions of allocated memory.

Buffer objects are created by calling ll::Memory::createBuffer on a specific memory instance.

auto session = ll::Session::create();
// device-local memory with page size of 2048 bytes
auto memory = session->createMemory(vk::MemoryPropertyFlagBits::eDeviceLocal, 2048);
// creates a 128 bytes buffer
auto buffer = memory->createBuffer(128);
static std::shared_ptr< ll::Session > create()
Creates a new ll::Session object.

This object holds a reference to the ll::Memory it was created from, guaranteeing the memory is not deleted before this buffer is. Upon destruction of this object, the underlying memory space is released from the ll::Memory instance.

Constructor & Destructor Documentation

◆ Buffer() [1/3]

ll::Buffer::Buffer ( )
delete

◆ Buffer() [2/3]

ll::Buffer::Buffer ( const Buffer b)
delete

◆ Buffer() [3/3]

ll::Buffer::Buffer ( Buffer &&  b)
delete

◆ ~Buffer()

ll::Buffer::~Buffer ( )

Member Function Documentation

◆ getAllocationInfo()

ll::MemoryAllocationInfo ll::Buffer::getAllocationInfo ( ) const
noexcept

Gets the allocation information.

Returns
The allocation information.

◆ getMemory()

const std::shared_ptr<ll::Memory>& ll::Buffer::getMemory ( ) const
noexcept

Gets the memory this buffer was allocated from.

Returns
The memory.

◆ getSize()

uint64_t ll::Buffer::getSize ( ) const
noexcept

Gets the size of the buffer in bytes.

The size returned corresponds to the size requested by the user through Memory::createBuffer function. This size does not include padding or alignment bytes.

Returns
The size of the buffer in bytes.
See also
ll::Buffer::getAllocationInfo gets the allocation information.

◆ getType()

ll::ObjectType ll::Buffer::getType ( ) const
overridevirtualnoexcept

Gets the object type.

This method can be used for safely down-casting pointers of ll::Object type to its children.

ll::Object* ptr = ...
auto bufferPtr = static_cast<ll::Buffer*>(ptr);
}
Objects to manage raw portions of allocated memory.
Definition: Buffer.h:57
Base class for all types that can be used in computer shaders.
Definition: Object.h:94
virtual ll::ObjectType getType() const noexcept=0
Gets the object type.
Returns
The object type.

Implements ll::Object.

◆ getUsageFlags()

ll::BufferUsageFlags ll::Buffer::getUsageFlags ( ) const
noexcept

Gets the Vulkan buffer usage flags.

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

Returns
The usage flags.

◆ getUsageFlagsUnsafe()

uint32_t ll::Buffer::getUsageFlagsUnsafe ( ) const
noexcept

Gets the usage flags casted to an integer type.

Please do not use this method. It's for internal use only.

Returns
The usage flags unsafe.

◆ isMappable()

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

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

This function calls ll::Memory::isPageMappable from the memory this buffer was allocated from.

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

◆ map()

template<typename T >
std::unique_ptr<T, ll::Buffer::BufferMapDeleter> ll::Buffer::map ( )
inline

Maps the memory content of this object to host-visible memory.

The returned pointer can be used to read or write content from and to this buffer from the host.

auto session = ll::Session::create();
const auto hostMemFlags = memflags::eHostVisible | memflags::eHostCoherent;;
constexpr const auto bufferSize = 256u;
auto hostMemory = session->createMemory(hostMemFlags, bufferSize, false);
auto buffer1 = hostMemory->createBuffer(bufferSize);
{
// mapped as a uint8_t [] array
auto ptr = buffer->map<uint8_t[]>();
for (auto i = 0u; i < bufferSize; ++i) {
// print the value of ptr at i
std::cout << ptr[i] << std::endl;
}
} // unmap buffer then ptr goes out of scope

Once the returned pointer is no longer needed, the user must call ll::Buffer::unmap to release the mapped object.

Warning
This buffer object needs to be kept alive during the whole lifetime of the returned mapped pointer. Otherwise, the behavior is undefined when the mapped pointer is deleted.
Template Parameters
Ttype of the memory mapped. It can be either a normal type such as int or an array such as int[].
Returns
A std::unique_ptr to host-visible memory for this buffer. The buffer is unmapped automatically once this pointer is out of scope.
Exceptions
std::system_errorif the memory page containing this buffer has been previously mapped by this or any other object.
See also
ll::Buffer::isMappable Determines if this buffer is mappable to host-visible memory.

◆ mapAndSet()

template<typename T >
void ll::Buffer::mapAndSet ( T &&  obj)
inline

◆ mapAndSetFromVector()

template<typename T >
void ll::Buffer::mapAndSetFromVector ( const std::vector< T > &  vec)
inline

◆ operator=() [1/2]

Buffer& ll::Buffer::operator= ( Buffer &&  buffer)
delete

◆ operator=() [2/2]

Buffer& ll::Buffer::operator= ( const Buffer buffer)
delete

Friends And Related Function Documentation

◆ ll::CommandBuffer

friend class ll::CommandBuffer
friend

◆ ll::ComputeGraph

friend class ll::ComputeGraph
friend

◆ ll::ComputeNode

friend class ll::ComputeNode
friend

◆ ll::Memory

friend class ll::Memory
friend

◆ ll::Session

friend class ll::Session
friend

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