LiteFX 0.3.1.2022
Computer Graphics Engine
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].

Public Member Functions

virtual ~IDeviceMemory () noexcept=default
 
virtual const UInt32elements () const noexcept=0
 Gets the number of sub-resources inside the memory chunk. More...
 
virtual size_t size () const noexcept=0
 Gets the size (in bytes) of the aligned memory chunk. More...
 
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. More...
 
virtual size_t elementAlignment () const noexcept=0
 Returns the alignment of a single element. More...
 
virtual size_t alignedElementSize () const noexcept=0
 Returns the actual size of the element in device memory. More...
 
virtual const bool & writable () const noexcept=0
 Returns true, if the resource can be bound to a read/write descriptor. More...
 
virtual const ResourceState & state (const UInt32 &subresource=0) const =0
 Returns the current state of the resource. More...
 
virtual ResourceState & state (const UInt32 &subresource=0)=0
 Returns a reference of the current state of the resource. More...
 

Detailed Description

Describes a chunk of device memory.

Constructor & Destructor Documentation

◆ ~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 const 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.

◆ 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, and LiteFX::Rendering::Backends::VulkanImage.

◆ state() [1/2]

virtual const ResourceState & LiteFX::Rendering::IDeviceMemory::state ( const UInt32 subresource = 0) const
pure virtual

Returns the current state of the resource.

Parameters
subresourceThe index of the sub-resource for which the state is requested.
Returns
The current state of the resource.
Exceptions
ArgumentOutOfRangeExceptionThrown, if the specified sub-resource is not an element of the resource.

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

◆ state() [2/2]

virtual ResourceState & LiteFX::Rendering::IDeviceMemory::state ( const UInt32 subresource = 0)
pure virtual

Returns a reference of the current state of the resource.

This overload can be used to change the internal resource state. It exists, to support external resource transitions in certain scenarios, where automatic resource state tracking is not supported. For example, there might be implicit state transitions in some scenarios. Usually those scenarios do not require you to transition the resource into another state, however if you have to, the internal state of the resource does not match the actual state. In order for the barrier to be well-formed, you have to set the proper state first.

In most cases, however, use a Barrier to transition between resource states.

Parameters
subresourceThe index of the sub-resource for which the state is requested.
Returns
A reference of the current state of the resource.
Exceptions
ArgumentOutOfRangeExceptionThrown, if the specified sub-resource is not an element of the resource.

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

◆ writable()

virtual const bool & LiteFX::Rendering::IDeviceMemory::writable ( ) const
pure virtualnoexcept

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.

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