SleakEngine 0.1.0
C++23 multi-backend game engine
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
10namespace Sleak {
11namespace 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.
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
25
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_
DirectX12UploadRing(const DirectX12UploadRing &)=delete
void Release()
Unmaps and frees every page. The GPU must be idle.
void BeginFrame(uint32_t frameIndex)
Rewinds the frame's pages. The GPU must be done with that frame.
DirectX12UploadRing & operator=(const DirectX12UploadRing &)=delete
bool Allocate(uint64_t size, Allocation &out)
Returns 256-byte aligned memory valid until the frame is reused.
void Initialize(ID3D12Device *device, uint32_t frameCount, uint64_t pageSize)
Stores the device and sizes the ring. Pages are created on demand.
Backend-facing rendering layer shared by the four graphics backends.
Root namespace for everything the engine exposes.
Definition Camera.hpp:10
CPU write pointer and matching GPU address of one allocation.