SleakEngine
0.1.0
C++23 multi-backend game engine
Toggle main menu visibility
Loading...
Searching...
No Matches
DirectX12UploadContext.hpp
Go to the documentation of this file.
1
#ifndef _DIRECTX12_UPLOAD_CONTEXT_HPP_
2
#define _DIRECTX12_UPLOAD_CONTEXT_HPP_
3
4
#include <d3d12.h>
5
#include <wrl/client.h>
6
7
#include <cstdint>
8
#include <vector>
9
10
namespace
Sleak
{
11
namespace
RenderEngine
{
12
13
/// Batches CPU to GPU copies into one command list on the direct queue.
14
/// Staging memory is freed once the batch that used it is done on the GPU.
15
class
DirectX12UploadContext
{
16
public
:
17
DirectX12UploadContext
() =
default
;
18
~DirectX12UploadContext
() {
Release
(); }
19
20
DirectX12UploadContext
(
const
DirectX12UploadContext
&) =
delete
;
21
DirectX12UploadContext
&
operator=
(
const
DirectX12UploadContext
&) =
delete
;
22
23
/// Creates the fence used to track submitted batches.
24
bool
Initialize
(ID3D12Device* device, ID3D12CommandQueue* queue);
25
26
/// Returns the open copy command list, starting a new batch if needed.
27
ID3D12GraphicsCommandList*
GetCommandList
();
28
29
/// Returns a mapped upload buffer that lives until the open batch is done.
30
void
*
AllocateStaging
(uint64_t size, ID3D12Resource** resource);
31
32
/// Executes the recorded copies without waiting for them.
33
void
Submit
();
34
35
/// Submits and blocks until every batch has finished on the GPU.
36
void
Flush
();
37
38
/// Frees staging memory of batches the GPU has finished.
39
void
Retire
();
40
41
/// Flushes outstanding work and frees everything.
42
void
Release
();
43
44
private
:
45
struct
Batch {
46
Microsoft::WRL::ComPtr<ID3D12CommandAllocator> allocator;
47
std::vector<Microsoft::WRL::ComPtr<ID3D12Resource>> staging;
48
uint64_t fenceValue = 0;
49
};
50
51
ID3D12Device* m_device =
nullptr
;
52
ID3D12CommandQueue* m_queue =
nullptr
;
53
Microsoft::WRL::ComPtr<ID3D12GraphicsCommandList> m_commandList;
54
Microsoft::WRL::ComPtr<ID3D12Fence> m_fence;
55
HANDLE m_event =
nullptr
;
56
uint64_t m_fenceValue = 0;
57
58
Batch m_open;
59
bool
m_recording =
false
;
60
std::vector<Batch> m_inFlight;
61
std::vector<Microsoft::WRL::ComPtr<ID3D12CommandAllocator>>
62
m_freeAllocators;
63
};
64
65
}
// namespace RenderEngine
66
}
// namespace Sleak
67
68
#endif
// _DIRECTX12_UPLOAD_CONTEXT_HPP_
Sleak::RenderEngine::DirectX12UploadContext::Release
void Release()
Flushes outstanding work and frees everything.
Definition
DirectX12UploadContext.cpp:157
Sleak::RenderEngine::DirectX12UploadContext::AllocateStaging
void * AllocateStaging(uint64_t size, ID3D12Resource **resource)
Returns a mapped upload buffer that lives until the open batch is done.
Definition
DirectX12UploadContext.cpp:72
Sleak::RenderEngine::DirectX12UploadContext::GetCommandList
ID3D12GraphicsCommandList * GetCommandList()
Returns the open copy command list, starting a new batch if needed.
Definition
DirectX12UploadContext.cpp:33
Sleak::RenderEngine::DirectX12UploadContext::DirectX12UploadContext
DirectX12UploadContext()=default
Sleak::RenderEngine::DirectX12UploadContext::DirectX12UploadContext
DirectX12UploadContext(const DirectX12UploadContext &)=delete
Sleak::RenderEngine::DirectX12UploadContext::Retire
void Retire()
Frees staging memory of batches the GPU has finished.
Definition
DirectX12UploadContext.cpp:144
Sleak::RenderEngine::DirectX12UploadContext::operator=
DirectX12UploadContext & operator=(const DirectX12UploadContext &)=delete
Sleak::RenderEngine::DirectX12UploadContext::Initialize
bool Initialize(ID3D12Device *device, ID3D12CommandQueue *queue)
Creates the fence used to track submitted batches.
Definition
DirectX12UploadContext.cpp:8
Sleak::RenderEngine::DirectX12UploadContext::Submit
void Submit()
Executes the recorded copies without waiting for them.
Definition
DirectX12UploadContext.cpp:113
Sleak::RenderEngine::DirectX12UploadContext::~DirectX12UploadContext
~DirectX12UploadContext()
Definition
DirectX12UploadContext.hpp:18
Sleak::RenderEngine::DirectX12UploadContext::Flush
void Flush()
Submits and blocks until every batch has finished on the GPU.
Definition
DirectX12UploadContext.cpp:134
Sleak::RenderEngine
Backend-facing rendering layer shared by the four graphics backends.
Definition
Application.hpp:60
Sleak
Root namespace for everything the engine exposes.
Definition
Camera.hpp:10
include
private
Graphics
DirectX12
DirectX12UploadContext.hpp
Generated on
for SleakEngine by
1.18.0