Polyphase Game Engine
Loading...
Searching...
No Matches
MultiBuffer.h
Go to the documentation of this file.
1#pragma once
2
3#if API_VULKAN
4
7
8class DestroyQueue;
9
10class MultiBuffer
11{
12public:
13
14 MultiBuffer(BufferType bufferType, size_t size, const char* debugName, const void* srcData = nullptr);
15
16 void Update(const void* srcData, size_t srcSize, size_t dstOffset = 0);
17
18 VkBuffer Get();
19 VkBuffer Get(uint32_t frameIndex);
20
21 Buffer* GetBuffer();
22 Buffer* GetBuffer(uint32_t frameIndex);
23
24 size_t GetSize() const;
25
26protected:
27
28 friend class DestroyQueue;
29 virtual ~MultiBuffer();
30
31 // Extra slots (MAX_FRAMES..MAX_FRAMES*2-1) are used by secondary screen
32 // rendering so that the main render's vertex data is not overwritten.
33 Buffer* mBuffers[MAX_FRAMES * 2] = {};
34};
35
36
37struct UniformBlock
38{
39 class UniformBuffer* mUniformBuffer = nullptr;
40 uint8_t* mData = nullptr;
41 uint32_t mOffset = 0;
42 uint32_t mSize = 0;
43};
44
45// TODO: For optimal memory usage, this should be converted to a Ring Buffer.
46class UniformBuffer : public MultiBuffer
47{
48public:
49 UniformBuffer(size_t size, const char* debugName, const void* srcData = nullptr);
50
51 void Reset(uint32_t frameIndex);
52
53 UniformBlock AllocBlock(uint32_t blockSize);
54
55 // Bring parameterized overloads into scope so they remain accessible.
56 using MultiBuffer::Get;
57 using MultiBuffer::GetBuffer;
58
59 // UniformBuffer data is always allocated via AllocBlock which uses the real
60 // frame index (no secondary screen offset). Hide the base class no-arg
61 // Get/GetBuffer so descriptor set building references the correct buffer.
62 VkBuffer Get();
63 Buffer* GetBuffer();
64
65protected:
66
67 int32_t mHead[MAX_FRAMES] = {};
68};
69
70#endif
bool Update()
Definition Engine.cpp:710