LiteFX 0.5.1.2025
Computer Graphics Engine
Loading...
Searching...
No Matches
LiteFX::Rendering::IDeviceMemory Class Referenceabstract

Describes a chunk of device memory. More...

#include <rendering_api.hpp>

Inherited by LiteFX::Rendering::IBuffer [virtual], and LiteFX::Rendering::IImage [virtual].

Classes

struct  PrepareMoveEventArgs
 Stores a reference to a barrier that can be used to synchronize accesses to the resource with a move operation. More...
 
struct  ResourceMovingEventArgs
 Stores the fence and the command queue to wait on for the fence before a moved resource can be used. More...
 

Public Member Functions

virtual ~IDeviceMemory () noexcept=default
 
virtual UInt32 elements () const noexcept=0
 Gets the number of sub-resources inside the memory chunk.
 
virtual size_t size () const noexcept=0
 Gets the size (in bytes) of the aligned memory chunk.
 
virtual size_t elementSize () const noexcept=0
 Returns the size of a single element within the buffer. If there is only one element, this is equal to size.
 
virtual size_t elementAlignment () const noexcept=0
 Returns the alignment of a single element.
 
virtual size_t alignedElementSize () const noexcept=0
 Returns the actual size of the element in device memory.
 
virtual ResourceUsage usage () const noexcept=0
 Returns the usage flags for the resource.
 
virtual UInt64 virtualAddress () const noexcept=0
 Gets the address of the resource in GPU memory.
 
virtual bool writable () const noexcept
 Returns true, if the resource can be bound to a read/write descriptor.
 
virtual bool volatileMove () const noexcept
 Returns true, if the contents of the resource should not be copied during a move.
 

Public Attributes

Event< const PrepareMoveEventArgs & > prepareMove
 An event that gets invoked to prepare a resource for a move operation.
 
Event< ResourceMovingEventArgsmoving
 An event that gets invoked before a resource is copied during a move.
 
Event< EventArgsmoved
 An event that gets invoked, after the resource has been moved to a different location, but before the old resource gets destroyed.
 

Protected Member Functions

 IDeviceMemory () noexcept=default
 
 IDeviceMemory (IDeviceMemory &&) noexcept=default
 
 IDeviceMemory (const IDeviceMemory &)=default
 
IDeviceMemoryoperator= (IDeviceMemory &&) noexcept=default
 
IDeviceMemoryoperator= (const IDeviceMemory &)=default
 

Detailed Description

Describes a chunk of device memory.

Constructor & Destructor Documentation

◆ IDeviceMemory() [1/3]

LiteFX::Rendering::IDeviceMemory::IDeviceMemory ( )
protecteddefaultnoexcept

◆ IDeviceMemory() [2/3]

LiteFX::Rendering::IDeviceMemory::IDeviceMemory ( IDeviceMemory && )
protecteddefaultnoexcept

◆ IDeviceMemory() [3/3]

LiteFX::Rendering::IDeviceMemory::IDeviceMemory ( const IDeviceMemory & )
protecteddefault

◆ ~IDeviceMemory()

virtual LiteFX::Rendering::IDeviceMemory::~IDeviceMemory ( )
virtualdefaultnoexcept

Member Function Documentation

◆ alignedElementSize()

virtual size_t LiteFX::Rendering::IDeviceMemory::alignedElementSize ( ) const
pure virtualnoexcept

Returns the actual size of the element in device memory.

For images, this method will return a value that equals the result of size, aligned by elementAlignment.

Returns
The actual size of the element in device memory.
See also
elementAlignment, elementSize

Implemented in LiteFX::Rendering::Backends::DirectX12Buffer, LiteFX::Rendering::Backends::DirectX12Image, LiteFX::Rendering::Backends::VulkanBuffer, and LiteFX::Rendering::Backends::VulkanImage.

◆ elementAlignment()

virtual size_t LiteFX::Rendering::IDeviceMemory::elementAlignment ( ) const
pure virtualnoexcept

◆ elements()

virtual UInt32 LiteFX::Rendering::IDeviceMemory::elements ( ) const
pure virtualnoexcept

Gets the number of sub-resources inside the memory chunk.

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 state method.

Returns
The number of array elements inside the memory chunk.
See also
state

Implemented in LiteFX::Rendering::Backends::DirectX12Buffer, LiteFX::Rendering::Backends::DirectX12Image, LiteFX::Rendering::Backends::VulkanBuffer, and LiteFX::Rendering::Backends::VulkanImage.

◆ elementSize()

virtual size_t LiteFX::Rendering::IDeviceMemory::elementSize ( ) const
pure virtualnoexcept

Returns the size of a single element within the buffer. If there is only one element, this is equal to size.

For images, this method will return a value that equals the result of size.

Returns
The size of a single element within the buffer
See also
elementAlignment, alignedElementSize

Implemented in LiteFX::Rendering::Backends::DirectX12Buffer, LiteFX::Rendering::Backends::DirectX12Image, LiteFX::Rendering::Backends::VulkanBuffer, and LiteFX::Rendering::Backends::VulkanImage.

◆ operator=() [1/2]

IDeviceMemory & LiteFX::Rendering::IDeviceMemory::operator= ( const IDeviceMemory & )
protecteddefault

◆ operator=() [2/2]

IDeviceMemory & LiteFX::Rendering::IDeviceMemory::operator= ( IDeviceMemory && )
protecteddefaultnoexcept

◆ size()

virtual size_t LiteFX::Rendering::IDeviceMemory::size ( ) const
pure virtualnoexcept

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

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 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 alignedElementSize. The size of the memory block, the elements get aligned to is returned by elementAlignment.

Returns
The size (in bytes) of the memory chunk.
See also
elements, elementSize, elementAlignment, alignedElementSize

Implemented in LiteFX::Rendering::Backends::DirectX12Buffer, LiteFX::Rendering::Backends::DirectX12Image, LiteFX::Rendering::Backends::VulkanBuffer, LiteFX::Rendering::Backends::VulkanImage, and LiteFX::Rendering::IImage.

◆ usage()

virtual ResourceUsage LiteFX::Rendering::IDeviceMemory::usage ( ) const
pure virtualnoexcept

◆ virtualAddress()

virtual UInt64 LiteFX::Rendering::IDeviceMemory::virtualAddress ( ) const
pure virtualnoexcept

Gets the address of the resource in GPU memory.

Note that this may not be supported for all resource types in all backends. For example, Vulkan does not support obtaining virtual addresses of image resources.

Returns
The address of the resource in GPU memory.

Implemented in LiteFX::Rendering::Backends::DirectX12Buffer, LiteFX::Rendering::Backends::DirectX12Image, LiteFX::Rendering::Backends::VulkanBuffer, and LiteFX::Rendering::Backends::VulkanImage.

◆ volatileMove()

virtual bool LiteFX::Rendering::IDeviceMemory::volatileMove ( ) const
inlinevirtualnoexcept

Returns true, if the contents of the resource should not be copied during a move.

To set this flag, include ResourceUsage::Volatile in the resource usage flags.

Returns
true, if the contents of the resource should not be copied during a move and false otherwise.
See also
moving, usage, ResourceUsage::Volatile

◆ writable()

virtual bool LiteFX::Rendering::IDeviceMemory::writable ( ) const
inlinevirtualnoexcept

Returns true, if the resource can be bound to a read/write descriptor.

If the resource is not writable, attempting to bind it to a writable descriptor will result in an exception.

Returns
true, if the resource can be bound to a read/write descriptor.

Member Data Documentation

◆ moved

Event<EventArgs> LiteFX::Rendering::IDeviceMemory::moved
mutable

An event that gets invoked, after the resource has been moved to a different location, but before the old resource gets destroyed.

This event gets invoked during defragmentation to inform any subscribers about a relocation. You might want to subscribe to this event is to update any descriptor bindings, as they become invalid after the previous resource gets removed. Additionally, you may want to insert barriers to transition the resource back into the desired layout.

Note that this event is invoked on the thread that executes the defragmentation process, which means you potentially might want to synchronize the handler with other resource accesses.

See also
moving, IGraphicsFactory::defragment

◆ moving

Event<ResourceMovingEventArgs> LiteFX::Rendering::IDeviceMemory::moving
mutable

An event that gets invoked before a resource is copied during a move.

This event gets invoked during defragmentation to inform any subscribers about the relocation. Moving a resource involves an asynchronous copy-command. This event is invoked after this command has been submitted, but before it has been executed. The moved event executes after the resource has been copied to the new location.

Note that this event is invoked on the thread that executes the defragmentation process, which means you potentially might want to synchronize the handler with other potential resource accesses.

See also
moved, IGraphicsFactory::defragment

◆ prepareMove

Event<const PrepareMoveEventArgs&> LiteFX::Rendering::IDeviceMemory::prepareMove
mutable

An event that gets invoked to prepare a resource for a move operation.

The purpose of this event is to prepare a barrier that synchronizes the resource with other accesses. The event arguments of this event contain a reference to a barrier instance, that can be used to insert a barrier for the resource. Note that the transition must be supported on the underlying command queue that executes the move.

Note that both, the DirectX 12 as well as the Vulkan backend expect images to be in ImageLayout::Common layout before moving them.

See also
IGraphicsFactory::defragment