SleakEngine 0.1.0
C++23 multi-backend game engine
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
10namespace Sleak {
11namespace 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.
16 public:
19
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_
void Release()
Flushes outstanding work and frees everything.
void * AllocateStaging(uint64_t size, ID3D12Resource **resource)
Returns a mapped upload buffer that lives until the open batch is done.
ID3D12GraphicsCommandList * GetCommandList()
Returns the open copy command list, starting a new batch if needed.
DirectX12UploadContext(const DirectX12UploadContext &)=delete
void Retire()
Frees staging memory of batches the GPU has finished.
DirectX12UploadContext & operator=(const DirectX12UploadContext &)=delete
bool Initialize(ID3D12Device *device, ID3D12CommandQueue *queue)
Creates the fence used to track submitted batches.
void Submit()
Executes the recorded copies without waiting for them.
void Flush()
Submits and blocks until every batch has finished on the GPU.
Backend-facing rendering layer shared by the four graphics backends.
Root namespace for everything the engine exposes.
Definition Camera.hpp:10