Diligent Engine
 
Loading...
Searching...
No Matches
Diligent::DynamicBuffer Class Reference

Dynamically resizable buffer. More...

#include <DynamicBuffer.hpp>

Public Member Functions

 DynamicBuffer (IRenderDevice *pDevice, const DynamicBufferCreateInfo &CreateInfo)
 Initializes the dynamic buffer.
 
IBufferResize (IRenderDevice *pDevice, IDeviceContext *pContext, Uint64 NewSize, bool DiscardContent=false)
 Resizes the buffer to the new size.
 
IBufferUpdate (IRenderDevice *pDevice, IDeviceContext *pContext)
 Updates the internal buffer object, initializing or resizing it if necessary.
 
IBufferGetBuffer () const
 Returns a pointer to the buffer object.
 
bool PendingUpdate () const
 
const BufferDescGetDesc () const
 Returns the buffer description.
 
Uint32 GetVersion () const
 Returns the dynamic buffer version.
 
Uint64 GetVirtualSize () const
 Returns the logical virtual size of the sparse buffer.
 

Detailed Description

Dynamically resizable buffer.

Constructor & Destructor Documentation

◆ DynamicBuffer()

Diligent::DynamicBuffer::DynamicBuffer ( IRenderDevice * pDevice,
const DynamicBufferCreateInfo & CreateInfo )

Initializes the dynamic buffer.

Parameters
[in]pDevice- Render device that will be used to create the buffer. This parameter may be null (see remarks).
[in]CreateInfo- Create information, see Diligent::DynamicBufferCreateInfo.

If pDevice is null, internal buffer creation will be postponed until Update() or Resize() is called.

Member Function Documentation

◆ GetBuffer()

IBuffer * Diligent::DynamicBuffer::GetBuffer ( ) const
inline

Returns a pointer to the buffer object.

If the buffer has not been initialized, the method returns null. If the buffer may need to be updated (resized or initialized), use the Update() method.

◆ GetVersion()

Uint32 Diligent::DynamicBuffer::GetVersion ( ) const
inline

Returns the dynamic buffer version.

The version is incremented every time a new internal buffer is created.

◆ GetVirtualSize()

Uint64 Diligent::DynamicBuffer::GetVirtualSize ( ) const
inline

Returns the logical virtual size of the sparse buffer.

The actual size of the sparse buffer may be larger than the logical size due to alignment requirements. Use GetBuffer()->GetDesc().Size to get the actual size.

◆ PendingUpdate()

bool Diligent::DynamicBuffer::PendingUpdate ( ) const
inline

Returns true if the buffer must be updated before use (e.g. it has been resized, but internal buffer has not been initialized or updated). When update is not pending, Update() may be called with null device and context.

◆ Resize()

IBuffer * Diligent::DynamicBuffer::Resize ( IRenderDevice * pDevice,
IDeviceContext * pContext,
Uint64 NewSize,
bool DiscardContent = false )

Resizes the buffer to the new size.

Parameters
[in]pDevice- Render device that will be used create the new internal buffer. This parameter may be null (see remarks).
[in]pContext- Device context that will be used to copy existing contents to the new buffer (for non-sparse buffer), or commit new memory pages (for sparse buffer). This parameter may be null (see remarks).
[in]NewSize- New buffer size. Can be zero.
[in]DiscardContent- Whether to discard previous buffer content.
Returns
Pointer to the new buffer.

The method operation depends on which of pDevice and pContext parameters are not null:

  • Both pDevice and pContext are not null: the new internal buffer is created and existing contents is copied (for non-sparse buffer), or memory pages are committed (for sparse buffer). Update() may be called with both pDevice and pContext being null.
  • pDevice is not null, pContext is null: internal buffer is created, but existing contents is not copied or memory is not committed. An application must provide non-null device context when calling Update().
  • Both pDevice and pContext are null: internal buffer is not created. An application must provide non-null device and device context when calling Update().

Typically pDevice and pContext should be null when the method is called from a worker thread.

If NewSize is zero, internal buffer will be released.

◆ Update()

IBuffer * Diligent::DynamicBuffer::Update ( IRenderDevice * pDevice,
IDeviceContext * pContext )

Updates the internal buffer object, initializing or resizing it if necessary.

Parameters
[in]pDevice- Render device that will be used to create a new buffer, if necessary (see remarks).
[in]pContext- Device context that will be used to copy existing buffer contents or commit memory pages, if necessary (see remarks).
Returns
A pointer to the buffer object.

If the buffer has been resized, but internal buffer object has not been initialized, pDevice and pContext must not be null.

If buffer does not need to be updated (PendingUpdate() returns false), both pDevice and pContext may be null.