SleakEngine 0.1.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::RenderEngine::DirectX12Buffer Class Reference

D3D12 buffer wrapper: default-heap resource plus an upload heap for CPU-to-GPU copies. More...

#include <DirectX12Buffer.hpp>

Inheritance diagram for Sleak::RenderEngine::DirectX12Buffer:

Public Member Functions

 DirectX12Buffer (const DirectX12Buffer &)=delete
 DirectX12Buffer (DirectX12Buffer &&) noexcept
 DirectX12Buffer (ID3D12Device *device, ID3D12CommandQueue *queue, size_t size, BufferType type, DirectX12UploadContext *uploader=nullptr)
 Uploads go through the shared uploader when given, else they block.
 DirectX12Buffer (ID3D12Device *device, size_t size, D3D12_HEAP_TYPE heapType, D3D12_RESOURCE_STATES resourceState)
 ~DirectX12Buffer () override
void Cleanup () override
const void * GetConstantData () const
 Latest constant buffer contents, copied into the upload ring on bind.
size_t GetConstantDataSize () const
ID3D12Resource * GetD3DBuffer () const
void * GetData () override
D3D12_GPU_VIRTUAL_ADDRESS GetFrameAddress (uint64_t frame) const
 Ring address already holding the current contents for this frame, or 0.
D3D12_HEAP_TYPE GetHeapType () const
D3D12_RESOURCE_STATES GetResourceState () const
bool Initialize (const void *data, size_t size)
 Creates the buffer sized and pre-populated from a raw payload.
bool Initialize (void *Data) override
bool IsValid () const
bool Map () override
 Maps the buffer for CPU writes (upload-heap buffers only).
DirectX12Buffer & operator= (const DirectX12Buffer &)=delete
DirectX12Buffer & operator= (DirectX12Buffer &&) noexcept
void SetFrameAddress (uint64_t frame, D3D12_GPU_VIRTUAL_ADDRESS address)
 Remembers where this frame's copy of the contents lives in the ring.
void Unmap () override
void Update () override
void Update (void *data, size_t size) override
 Overwrites buffer contents via a fresh upload-heap copy.
Public Member Functions inherited from Sleak::RenderEngine::BufferBase
const void * GetCPUShadowCopy () const
size_t GetCPUShadowCopySize () const
size_t GetSize ()
int GetSlot () const
BufferType GetType ()
uint32_t GetVertexFormat () const
 Registered custom vertex layout of this buffer; 0 means the engine default Vertex.
void SetSlot (int slot)
void SetVertexFormat (uint32_t handle)
 Tags the buffer with a VertexFormatRegistry handle so backends pick the matching pipeline.
void StoreCPUShadowCopy (const void *data, size_t size)
 Copies up to 128 bytes into the inline shadow-copy storage, clamping oversized input.
Public Member Functions inherited from Sleak::ResourceBase
virtual ~ResourceBase ()=default

Static Public Member Functions

static void DeferCleanup (Microsoft::WRL::ComPtr< ID3D12Pageable > object)
 Queues a GPU object for release once the frame that used it is done.
static void ProcessDeferredCleanup (uint64_t completedValue)
 Releases every queued object whose fence value has completed.
static void TagDeferredCleanup (uint64_t fenceValue)
 Stamps everything queued since the last call with its retire value.

Additional Inherited Members

Protected Attributes inherited from Sleak::RenderEngine::BufferBase
bool bIsMapped = false
void * Data = nullptr
const void * m_cpuShadowCopy = nullptr
size_t m_cpuShadowCopySize = 0
char m_cpuShadowStorage [128] = {}
uint32_t m_vertexFormat = 0
size_t Size = 0
int Slot = 0
BufferType Type
Protected Attributes inherited from Sleak::ResourceBase
bool bIsInitialized
std::string Name

Detailed Description

D3D12 buffer wrapper: default-heap resource plus an upload heap for CPU-to-GPU copies.

Definition at line 17 of file DirectX12Buffer.hpp.

Constructor & Destructor Documentation

◆ DirectX12Buffer() [1/4]

Sleak::RenderEngine::DirectX12Buffer::DirectX12Buffer ( ID3D12Device * device,
ID3D12CommandQueue * queue,
size_t size,
BufferType type,
DirectX12UploadContext * uploader = nullptr )

Uploads go through the shared uploader when given, else they block.

Definition at line 12 of file DirectX12Buffer.cpp.

◆ DirectX12Buffer() [2/4]

Sleak::RenderEngine::DirectX12Buffer::DirectX12Buffer ( ID3D12Device * device,
size_t size,
D3D12_HEAP_TYPE heapType,
D3D12_RESOURCE_STATES resourceState )

Definition at line 26 of file DirectX12Buffer.cpp.

◆ DirectX12Buffer() [3/4]

Sleak::RenderEngine::DirectX12Buffer::DirectX12Buffer ( const DirectX12Buffer & )
delete

◆ DirectX12Buffer() [4/4]

Sleak::RenderEngine::DirectX12Buffer::DirectX12Buffer ( DirectX12Buffer && other)
noexcept

Definition at line 35 of file DirectX12Buffer.cpp.

◆ ~DirectX12Buffer()

Sleak::RenderEngine::DirectX12Buffer::~DirectX12Buffer ( )
override

Definition at line 82 of file DirectX12Buffer.cpp.

Member Function Documentation

◆ Cleanup()

void Sleak::RenderEngine::DirectX12Buffer::Cleanup ( )
overridevirtual

Implements Sleak::ResourceBase.

Definition at line 247 of file DirectX12Buffer.cpp.

◆ DeferCleanup()

void Sleak::RenderEngine::DirectX12Buffer::DeferCleanup ( Microsoft::WRL::ComPtr< ID3D12Pageable > object)
static

Queues a GPU object for release once the frame that used it is done.

Definition at line 339 of file DirectX12Buffer.cpp.

◆ GetConstantData()

const void * Sleak::RenderEngine::DirectX12Buffer::GetConstantData ( ) const
inline

Latest constant buffer contents, copied into the upload ring on bind.

Definition at line 56 of file DirectX12Buffer.hpp.

◆ GetConstantDataSize()

size_t Sleak::RenderEngine::DirectX12Buffer::GetConstantDataSize ( ) const
inline

Definition at line 59 of file DirectX12Buffer.hpp.

◆ GetD3DBuffer()

ID3D12Resource * Sleak::RenderEngine::DirectX12Buffer::GetD3DBuffer ( ) const
inline

Definition at line 53 of file DirectX12Buffer.hpp.

◆ GetData()

void * Sleak::RenderEngine::DirectX12Buffer::GetData ( )
overridevirtual

Implements Sleak::RenderEngine::BufferBase.

Definition at line 325 of file DirectX12Buffer.cpp.

◆ GetFrameAddress()

D3D12_GPU_VIRTUAL_ADDRESS Sleak::RenderEngine::DirectX12Buffer::GetFrameAddress ( uint64_t frame) const
inline

Ring address already holding the current contents for this frame, or 0.

Definition at line 62 of file DirectX12Buffer.hpp.

◆ GetHeapType()

D3D12_HEAP_TYPE Sleak::RenderEngine::DirectX12Buffer::GetHeapType ( ) const
inline

Definition at line 73 of file DirectX12Buffer.hpp.

◆ GetResourceState()

D3D12_RESOURCE_STATES Sleak::RenderEngine::DirectX12Buffer::GetResourceState ( ) const
inline

Definition at line 74 of file DirectX12Buffer.hpp.

◆ Initialize() [1/2]

bool Sleak::RenderEngine::DirectX12Buffer::Initialize ( const void * data,
size_t size )

Creates the buffer sized and pre-populated from a raw payload.

Definition at line 138 of file DirectX12Buffer.cpp.

◆ Initialize() [2/2]

bool Sleak::RenderEngine::DirectX12Buffer::Initialize ( void * Data)
overridevirtual

Creates the default-heap resource and uploads initial data via a staging buffer, if any.

Implements Sleak::ResourceBase.

Definition at line 134 of file DirectX12Buffer.cpp.

◆ IsValid()

bool Sleak::RenderEngine::DirectX12Buffer::IsValid ( ) const
inline

Definition at line 72 of file DirectX12Buffer.hpp.

◆ Map()

bool Sleak::RenderEngine::DirectX12Buffer::Map ( )
overridevirtual

Maps the buffer for CPU writes (upload-heap buffers only).

Implements Sleak::RenderEngine::BufferBase.

Definition at line 270 of file DirectX12Buffer.cpp.

◆ operator=() [1/2]

DirectX12Buffer & Sleak::RenderEngine::DirectX12Buffer::operator= ( const DirectX12Buffer & )
delete

◆ operator=() [2/2]

DirectX12Buffer & Sleak::RenderEngine::DirectX12Buffer::operator= ( DirectX12Buffer && other)
noexcept

Definition at line 55 of file DirectX12Buffer.cpp.

◆ ProcessDeferredCleanup()

void Sleak::RenderEngine::DirectX12Buffer::ProcessDeferredCleanup ( uint64_t completedValue)
static

Releases every queued object whose fence value has completed.

Definition at line 350 of file DirectX12Buffer.cpp.

◆ SetFrameAddress()

void Sleak::RenderEngine::DirectX12Buffer::SetFrameAddress ( uint64_t frame,
D3D12_GPU_VIRTUAL_ADDRESS address )
inline

Remembers where this frame's copy of the contents lives in the ring.

Definition at line 66 of file DirectX12Buffer.hpp.

◆ TagDeferredCleanup()

void Sleak::RenderEngine::DirectX12Buffer::TagDeferredCleanup ( uint64_t fenceValue)
static

Stamps everything queued since the last call with its retire value.

Definition at line 344 of file DirectX12Buffer.cpp.

◆ Unmap()

void Sleak::RenderEngine::DirectX12Buffer::Unmap ( )
overridevirtual

Implements Sleak::RenderEngine::BufferBase.

Definition at line 291 of file DirectX12Buffer.cpp.

◆ Update() [1/2]

void Sleak::RenderEngine::DirectX12Buffer::Update ( )
overridevirtual

Implements Sleak::RenderEngine::BufferBase.

Definition at line 243 of file DirectX12Buffer.cpp.

◆ Update() [2/2]

void Sleak::RenderEngine::DirectX12Buffer::Update ( void * data,
size_t size )
overridevirtual

Overwrites buffer contents via a fresh upload-heap copy.

Implements Sleak::RenderEngine::BufferBase.

Definition at line 301 of file DirectX12Buffer.cpp.