Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
blowbox::GpuBuffer Class Referenceabstract

#include <gpu_buffer.h>

Public Member Functions

virtual ~GpuBuffer ()
 
virtual void Destroy ()
 
virtual void Create (const WString &name, UINT num_elements, UINT element_size, void *initial_data=nullptr, bool create_views=true)
 
const UINT & GetUAV () const
 
const UINT & GetSRV () const
 
const D3D12_GPU_VIRTUAL_ADDRESS & GetRootCBV () const
 
D3D12_GPU_VIRTUAL_ADDRESS GetRootCBV ()
 
D3D12_VERTEX_BUFFER_VIEW GetVertexBufferView (UINT offset, UINT size, UINT stride) const
 
D3D12_VERTEX_BUFFER_VIEW GetVertexBufferView (UINT base_vertex_index=0) const
 
D3D12_INDEX_BUFFER_VIEW GetIndexBufferView (UINT offset, UINT size, bool is_32_bit=false) const
 
D3D12_INDEX_BUFFER_VIEW GetIndexBufferView (UINT start_index=0) const
 
- Public Member Functions inherited from blowbox::GpuResource
 GpuResource ()
 
 GpuResource (ID3D12Resource *resource, D3D12_RESOURCE_STATES current_state)
 
virtual ~GpuResource ()
 
void Associate (ID3D12Resource *resource, D3D12_RESOURCE_STATES current_state)
 
void Destroy ()
 
ID3D12Resource * operator-> ()
 
const ID3D12Resource * operator-> () const
 
 operator ID3D12Resource * ()
 
ID3D12Resource * Get ()
 
const D3D12_RESOURCE_STATES & GetState () const
 
const D3D12_RESOURCE_STATES & GetTransitionState () const
 

Protected Member Functions

 GpuBuffer ()
 
D3D12_RESOURCE_DESC DescribeBuffer ()
 
virtual void CreateDerivedViews ()=0
 
- Protected Member Functions inherited from blowbox::GpuResource
void AddToMemoryProfiler ()
 
void RemoveFromMemoryProfiler ()
 

Protected Attributes

UINT uav_id_
 
UINT srv_id_
 
UINT element_count_
 
UINT element_size_
 
UINT buffer_size_
 
D3D12_RESOURCE_FLAGS resource_flags_
 
- Protected Attributes inherited from blowbox::GpuResource
WString name_
 
ID3D12Resource * resource_
 
D3D12_RESOURCE_STATES usage_state_
 
D3D12_RESOURCE_STATES transition_state_
 
D3D12_GPU_VIRTUAL_ADDRESS gpu_virtual_address_
 

Detailed Description

Wraps buffer-type GpuResource's.

Any type of buffer resource in Blowbox is based on the GpuBuffer. The GpuBuffer automatically creates the necessary resource descriptors for you when you call GpuBuffer::Create(). You can retrieve those by calling GpuBuffer::GetUAV() or GpuBuffer::GetSRV().

Inheritance diagram for blowbox::GpuBuffer:
blowbox::GpuResource blowbox::ByteAddressBuffer blowbox::StructuredBuffer blowbox::TypedBuffer blowbox::UploadBuffer

Constructor & Destructor Documentation

virtual blowbox::GpuBuffer::~GpuBuffer ( )
inlinevirtual

Destructs the GpuBuffer.

blowbox::GpuBuffer::GpuBuffer ( )
protected

Constructs a GpuBuffer.

Member Function Documentation

void blowbox::GpuBuffer::Create ( const WString name,
UINT  num_elements,
UINT  element_size,
void *  initial_data = nullptr,
bool  create_views = true 
)
virtual

Creates actual buffer resource.

Parameters
[in]nameThe name of the buffer resource.
[in]num_elementsThe number of elements that exist in the buffer.
[in]element_sizeThe size of each element in the buffer.
[in]initial_dataIf the buffer should be initialized immediately with data, enter a pointer to it here. Pointer should be of size num_elements * element_size.
[in]create_viewsWhether the resource descriptors (views) should automatically be created.
virtual void blowbox::GpuBuffer::CreateDerivedViews ( )
protectedpure virtual

Creates the descriptors (views) for this GpuBuffer.

Implemented in blowbox::UploadBuffer, blowbox::TypedBuffer, blowbox::StructuredBuffer, and blowbox::ByteAddressBuffer.

D3D12_RESOURCE_DESC blowbox::GpuBuffer::DescribeBuffer ( )
protected

Generates a D3D12_RESOURCE_DESC based on the buffer size and resource flags.

Returns
A D3D12_RESOURCE_DESC for buffer-type resources based on this GpuBuffer's settings.
void blowbox::GpuBuffer::Destroy ( )
virtual

Destroys the GpuBuffer.

Reimplemented in blowbox::UploadBuffer, and blowbox::StructuredBuffer.

D3D12_INDEX_BUFFER_VIEW blowbox::GpuBuffer::GetIndexBufferView ( UINT  offset,
UINT  size,
bool  is_32_bit = false 
) const
Returns
An IndexBufferView for this buffer.
Parameters
[in]offsetAn offset into the buffer from which the IBV should start.
[in]sizeThe size of the VBV - i.e. how many bytes the IBV should cover. (most likely equal to num_elements * element_size)
[in]is_32_bitWhether every index in the buffer is 32 bit or 16 bit. 16 bit usually suffices.
D3D12_INDEX_BUFFER_VIEW blowbox::GpuBuffer::GetIndexBufferView ( UINT  start_index = 0) const
Returns
An IndexBufferView for this buffer, created automatically based on which index should be first.
Parameters
[in]start_indexThe index of the first index that the IBV should base itself around.
const D3D12_GPU_VIRTUAL_ADDRESS& blowbox::GpuBuffer::GetRootCBV ( ) const
inline
Returns
The GPU VRAM address of this resource, which can directly be used as a root CBV via GraphicsContext::SetConstantBuffer().
D3D12_GPU_VIRTUAL_ADDRESS blowbox::GpuBuffer::GetRootCBV ( )
inline
Returns
The GPU VRAM address of this resource, which can directly be used as a root CBV via GraphicsContext::SetConstantBuffer().
const UINT& blowbox::GpuBuffer::GetSRV ( ) const
inline
Returns
The SRV for this resource.
const UINT& blowbox::GpuBuffer::GetUAV ( ) const
inline
Returns
The UAV for this resource.
D3D12_VERTEX_BUFFER_VIEW blowbox::GpuBuffer::GetVertexBufferView ( UINT  offset,
UINT  size,
UINT  stride 
) const
Returns
A VertexBufferView for this buffer.
Parameters
[in]offsetAn offset into the buffer from which the VBV should start.
[in]sizeThe size of the VBV - i.e. how many bytes the VBV should cover. (most likely equal to num_elements * element_size)
[in]strideThe stride size of each vertex in the buffer (most likely equal to element_size)
D3D12_VERTEX_BUFFER_VIEW blowbox::GpuBuffer::GetVertexBufferView ( UINT  base_vertex_index = 0) const
Returns
A VertexBufferView for this buffer, created automatically based on which element should be first.
Parameters
[in]base_vertex_indexThe index of the first vertex that the VBV should base itself around.

Member Data Documentation

UINT blowbox::GpuBuffer::buffer_size_
protected

The total buffer size of this GpuBuffer.

UINT blowbox::GpuBuffer::element_count_
protected

The number of elements in this GpuBuffer.

UINT blowbox::GpuBuffer::element_size_
protected

The size of each element in this GpuBuffer.

D3D12_RESOURCE_FLAGS blowbox::GpuBuffer::resource_flags_
protected

The resource flags set on this GpuBuffer.

UINT blowbox::GpuBuffer::srv_id_
protected

The SRV descriptor for this GpuBuffer.

UINT blowbox::GpuBuffer::uav_id_
protected

The UAV descriptor for this GpuBuffer.


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