Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
foray::core::ManagedBuffer Class Reference

Wraps allocation and lifetime functionality of a VkBuffer. More...

#include <foray_managedbuffer.hpp>

Inheritance diagram for foray::core::ManagedBuffer:
foray::core::VulkanResource< VkObjectType::VK_OBJECT_TYPE_BUFFER > foray::core::ManagedResource foray::NoMoveDefaults

Classes

struct  CreateInfo
 Combines all structs used for initialization. More...
 

Public Member Functions

 ManagedBuffer ()
 
void Create (Context *context, const CreateInfo &createInfo)
 Creates the buffer based on createInfo.
 
void CreateForStaging (Context *context, VkDeviceSize size, const void *data=nullptr, std::string_view bufferName={})
 Creates the buffer with VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_HOST, VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT. If data is set, also maps writes and unmaps.
 
void Create (Context *context, VkBufferUsageFlags usage, VkDeviceSize size, VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags flags={}, std::string_view name="")
 Simplified version of Create that omits the use of a create info but should be sufficient for many usecases.
 
virtual void Destroy () override
 Destroy the resource.
 
virtual bool Exists () const override
 Return true, if the managed resource is allocated.
 
void WriteDataDeviceLocal (const void *data, VkDeviceSize size, VkDeviceSize offset=0)
 Employ a staging buffer to upload data.
 
void WriteDataDeviceLocal (HostSyncCommandBuffer &cmdBuffer, const void *data, VkDeviceSize size, VkDeviceSize offset=0)
 Create staging buffer, copy data to it, copy data to device buffer, destroy staging buffer.
 
void Map (void *&data)
 Maps the buffer to memory address data.
 
void Unmap ()
 Unmaps the buffer.
 
void MapAndWrite (const void *data, size_t size=0)
 Attempts to map buffer, write data, unmap.
 
virtual ~ManagedBuffer ()
 
 FORAY_GETTER_V (Buffer)
 
 FORAY_GETTER_V (IsMapped)
 
 FORAY_GETTER_V (Allocation)
 
 FORAY_GETTER_CR (AllocationInfo)
 
 FORAY_GETTER_V (Name)
 
 FORAY_GETTER_V (Size)
 
 FORAY_GETTER_V (Alignment)
 
VkDeviceAddress GetDeviceAddress () const
 Gets the buffers device address.
 
virtual void SetName (std::string_view name) override
 Sets the buffers name. Decorates VkBuffer, VmaAllocation and VulkanResource base class.
 
VkDescriptorBufferInfo GetVkDescriptorBufferInfo () const
 Fills VkDescriptorBufferInfo object with zero offset and full buffer size.
 
void FillVkDescriptorBufferInfo (VkDescriptorBufferInfo &bufferInfo) const
 Same as GetVkDescriptorBufferInfo, but writing to an existing object.
 
- Public Member Functions inherited from foray::core::VulkanResource< VkObjectType::VK_OBJECT_TYPE_BUFFER >
 VulkanResource ()
 
 VulkanResource (std::string_view name)
 
virtual std::string_view GetTypeName () const
 Returns <OBJECT_TYPE> stringified.
 
- Public Member Functions inherited from foray::core::ManagedResource
 ManagedResource ()
 Default constructor registers the resource.
 
 ManagedResource (std::string_view name)
 Registers the resource and sets its name.
 
virtual ~ManagedResource ()
 Unregisters the resource.
 
std::string_view GetName () const
 Return a custom name for the object.
 
std::string Print () const
 Print name and type in one string.
 
- Public Member Functions inherited from foray::NoMoveDefaults
 NoMoveDefaults ()=default
 
 NoMoveDefaults (const NoMoveDefaults &other)=delete
 
 NoMoveDefaults (NoMoveDefaults &&other)=default
 
NoMoveDefaultsoperator= (const NoMoveDefaults &other)=delete
 

Protected Member Functions

void UpdateDebugNames ()
 
- Protected Member Functions inherited from foray::core::VulkanResource< VkObjectType::VK_OBJECT_TYPE_BUFFER >
virtual void SetObjectName (core::Context *context, const void *handle, std::string_view name, bool updateResourceName=true)
 Set the object name. Sets both ManagedResource::mName aswell as vulkan debug object name.
 

Protected Attributes

ContextmContext {}
 
VkBuffer mBuffer {}
 
VmaAllocation mAllocation {}
 
VmaAllocationInfo mAllocationInfo {}
 
VkDeviceSize mSize = {}
 
VkDeviceSize mAlignment = {}
 
bool mIsMapped = false
 
- Protected Attributes inherited from foray::core::ManagedResource
std::string mName
 This objects custom name.
 

Additional Inherited Members

- Static Public Member Functions inherited from foray::core::ManagedResource
static void sPrintAllocatedResources (bool printAsWarning)
 Print a list of all registered existing resources.
 
static const std::unordered_set< ManagedResource * > * GetTotalAllocatedResources ()
 

Detailed Description

Wraps allocation and lifetime functionality of a VkBuffer.

Constructor & Destructor Documentation

◆ ManagedBuffer()

foray::core::ManagedBuffer::ManagedBuffer ( )
inline

◆ ~ManagedBuffer()

virtual foray::core::ManagedBuffer::~ManagedBuffer ( )
inlinevirtual

Member Function Documentation

◆ Create() [1/2]

void foray::core::ManagedBuffer::Create ( Context context,
const CreateInfo createInfo 
)

Creates the buffer based on createInfo.

Parameters
contextRequires Allocator, Device, DispatchTable (CommandPool for certain shorthands)

◆ Create() [2/2]

void foray::core::ManagedBuffer::Create ( Context context,
VkBufferUsageFlags  usage,
VkDeviceSize  size,
VmaMemoryUsage  memoryUsage,
VmaAllocationCreateFlags  flags = {},
std::string_view  name = "" 
)

Simplified version of Create that omits the use of a create info but should be sufficient for many usecases.

Parameters
contextRequires Allocator, Device, DispatchTable

◆ CreateForStaging()

void foray::core::ManagedBuffer::CreateForStaging ( Context context,
VkDeviceSize  size,
const void *  data = nullptr,
std::string_view  bufferName = {} 
)

Creates the buffer with VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_HOST, VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT. If data is set, also maps writes and unmaps.

Parameters
contextRequires Allocator, Device, DispatchTable

◆ Destroy()

virtual void foray::core::ManagedBuffer::Destroy ( )
overridevirtual

Destroy the resource.

Remarks
This method must be callable even if the resource has not been initialized yet. This method must call any Destroy() overloads of child objects and of base classes

Implements foray::core::ManagedResource.

◆ Exists()

virtual bool foray::core::ManagedBuffer::Exists ( ) const
inlineoverridevirtual

Return true, if the managed resource is allocated.

Example: Vulkan object stored could be nullptr or instantiated

Implements foray::core::ManagedResource.

◆ FillVkDescriptorBufferInfo()

void foray::core::ManagedBuffer::FillVkDescriptorBufferInfo ( VkDescriptorBufferInfo &  bufferInfo) const

Same as GetVkDescriptorBufferInfo, but writing to an existing object.

◆ FORAY_GETTER_CR()

foray::core::ManagedBuffer::FORAY_GETTER_CR ( AllocationInfo  )

◆ FORAY_GETTER_V() [1/6]

foray::core::ManagedBuffer::FORAY_GETTER_V ( Alignment  )

◆ FORAY_GETTER_V() [2/6]

foray::core::ManagedBuffer::FORAY_GETTER_V ( Allocation  )

◆ FORAY_GETTER_V() [3/6]

foray::core::ManagedBuffer::FORAY_GETTER_V ( Buffer  )

◆ FORAY_GETTER_V() [4/6]

foray::core::ManagedBuffer::FORAY_GETTER_V ( IsMapped  )

◆ FORAY_GETTER_V() [5/6]

foray::core::ManagedBuffer::FORAY_GETTER_V ( Name  )

◆ FORAY_GETTER_V() [6/6]

foray::core::ManagedBuffer::FORAY_GETTER_V ( Size  )

◆ GetDeviceAddress()

VkDeviceAddress foray::core::ManagedBuffer::GetDeviceAddress ( ) const

Gets the buffers device address.

◆ GetVkDescriptorBufferInfo()

VkDescriptorBufferInfo foray::core::ManagedBuffer::GetVkDescriptorBufferInfo ( ) const
inline

Fills VkDescriptorBufferInfo object with zero offset and full buffer size.

◆ Map()

void foray::core::ManagedBuffer::Map ( void *&  data)

Maps the buffer to memory address data.

◆ MapAndWrite()

void foray::core::ManagedBuffer::MapAndWrite ( const void *  data,
size_t  size = 0 
)

Attempts to map buffer, write data, unmap.

Parameters
sizeAmount to write. If zero, writes equal to the entire size of the buffer

◆ SetName()

virtual void foray::core::ManagedBuffer::SetName ( std::string_view  name)
overridevirtual

Sets the buffers name. Decorates VkBuffer, VmaAllocation and VulkanResource base class.

Reimplemented from foray::core::ManagedResource.

◆ Unmap()

void foray::core::ManagedBuffer::Unmap ( )

Unmaps the buffer.

◆ UpdateDebugNames()

void foray::core::ManagedBuffer::UpdateDebugNames ( )
protected

◆ WriteDataDeviceLocal() [1/2]

void foray::core::ManagedBuffer::WriteDataDeviceLocal ( const void *  data,
VkDeviceSize  size,
VkDeviceSize  offset = 0 
)

Employ a staging buffer to upload data.

Parameters
datadata
sizesize
offsetwrite offset into buffer

◆ WriteDataDeviceLocal() [2/2]

void foray::core::ManagedBuffer::WriteDataDeviceLocal ( HostSyncCommandBuffer cmdBuffer,
const void *  data,
VkDeviceSize  size,
VkDeviceSize  offset = 0 
)

Create staging buffer, copy data to it, copy data to device buffer, destroy staging buffer.

Parameters
cmdBufferSingle use command buffer. Must be completely reset, function will automatically begin, write, submit and resynchronize.
datadata
sizesize
offsetwrite offset into buffer

Member Data Documentation

◆ mAlignment

VkDeviceSize foray::core::ManagedBuffer::mAlignment = {}
protected

◆ mAllocation

VmaAllocation foray::core::ManagedBuffer::mAllocation {}
protected

◆ mAllocationInfo

VmaAllocationInfo foray::core::ManagedBuffer::mAllocationInfo {}
protected

◆ mBuffer

VkBuffer foray::core::ManagedBuffer::mBuffer {}
protected

◆ mContext

Context* foray::core::ManagedBuffer::mContext {}
protected

◆ mIsMapped

bool foray::core::ManagedBuffer::mIsMapped = false
protected

◆ mSize

VkDeviceSize foray::core::ManagedBuffer::mSize = {}
protected

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