SleakEngine
0.1.0
C++23 multi-backend game engine
Toggle main menu visibility
Loading...
Searching...
No Matches
DirectX12UploadRing.hpp
Go to the documentation of this file.
1
#ifndef _DIRECTX12_UPLOAD_RING_HPP_
2
#define _DIRECTX12_UPLOAD_RING_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
/// Per-frame linear allocator over upload heap pages for transient GPU data.
14
/// Each frame in flight owns its own pages, which are rewound by BeginFrame.
15
class
DirectX12UploadRing
{
16
public
:
17
/// CPU write pointer and matching GPU address of one allocation.
18
struct
Allocation
{
19
void
*
cpu
=
nullptr
;
20
D3D12_GPU_VIRTUAL_ADDRESS
gpu
= 0;
21
};
22
23
DirectX12UploadRing
() =
default
;
24
~DirectX12UploadRing
() {
Release
(); }
25
26
DirectX12UploadRing
(
const
DirectX12UploadRing
&) =
delete
;
27
DirectX12UploadRing
&
operator=
(
const
DirectX12UploadRing
&) =
delete
;
28
29
/// Stores the device and sizes the ring. Pages are created on demand.
30
void
Initialize
(ID3D12Device* device, uint32_t frameCount,
31
uint64_t pageSize);
32
33
/// Rewinds the frame's pages. The GPU must be done with that frame.
34
void
BeginFrame
(uint32_t frameIndex);
35
36
/// Returns 256-byte aligned memory valid until the frame is reused.
37
bool
Allocate
(uint64_t size,
Allocation
& out);
38
39
/// Unmaps and frees every page. The GPU must be idle.
40
void
Release
();
41
42
private
:
43
struct
Page {
44
Microsoft::WRL::ComPtr<ID3D12Resource> resource;
45
uint8_t* cpu =
nullptr
;
46
D3D12_GPU_VIRTUAL_ADDRESS gpu = 0;
47
uint64_t size = 0;
48
};
49
50
struct
Frame {
51
std::vector<Page> pages;
52
size_t
page = 0;
53
uint64_t offset = 0;
54
};
55
56
bool
CreatePage(uint64_t size, Page& out);
57
58
ID3D12Device* m_device =
nullptr
;
59
std::vector<Frame> m_frames;
60
uint32_t m_current = 0;
61
uint64_t m_pageSize = 0;
62
};
63
64
}
// namespace RenderEngine
65
}
// namespace Sleak
66
67
#endif
// _DIRECTX12_UPLOAD_RING_HPP_
Sleak::RenderEngine::DirectX12UploadRing::DirectX12UploadRing
DirectX12UploadRing(const DirectX12UploadRing &)=delete
Sleak::RenderEngine::DirectX12UploadRing::Release
void Release()
Unmaps and frees every page. The GPU must be idle.
Definition
DirectX12UploadRing.cpp:63
Sleak::RenderEngine::DirectX12UploadRing::DirectX12UploadRing
DirectX12UploadRing()=default
Sleak::RenderEngine::DirectX12UploadRing::~DirectX12UploadRing
~DirectX12UploadRing()
Definition
DirectX12UploadRing.hpp:24
Sleak::RenderEngine::DirectX12UploadRing::BeginFrame
void BeginFrame(uint32_t frameIndex)
Rewinds the frame's pages. The GPU must be done with that frame.
Definition
DirectX12UploadRing.cpp:25
Sleak::RenderEngine::DirectX12UploadRing::operator=
DirectX12UploadRing & operator=(const DirectX12UploadRing &)=delete
Sleak::RenderEngine::DirectX12UploadRing::Allocate
bool Allocate(uint64_t size, Allocation &out)
Returns 256-byte aligned memory valid until the frame is reused.
Definition
DirectX12UploadRing.cpp:32
Sleak::RenderEngine::DirectX12UploadRing::Initialize
void Initialize(ID3D12Device *device, uint32_t frameCount, uint64_t pageSize)
Stores the device and sizes the ring. Pages are created on demand.
Definition
DirectX12UploadRing.cpp:16
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
Sleak::RenderEngine::DirectX12UploadRing::Allocation
CPU write pointer and matching GPU address of one allocation.
Definition
DirectX12UploadRing.hpp:18
Sleak::RenderEngine::DirectX12UploadRing::Allocation::gpu
D3D12_GPU_VIRTUAL_ADDRESS gpu
Definition
DirectX12UploadRing.hpp:20
Sleak::RenderEngine::DirectX12UploadRing::Allocation::cpu
void * cpu
Definition
DirectX12UploadRing.hpp:19
include
private
Graphics
DirectX12
DirectX12UploadRing.hpp
Generated on
for SleakEngine by
1.18.0