| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <cstddef> |
| 7 |
#include <deque> |
| 8 |
#include <memory> |
| 9 |
#include <utility> |
| 10 |
|
| 11 |
#include "Common/CommonTypes.h" |
| 12 |
#include "VideoBackends/Vulkan/Constants.h" |
| 13 |
|
| 14 |
namespace Vulkan |
| 15 |
{ |
| 16 |
class StreamBuffer |
| 17 |
{ |
| 18 |
public: |
| 19 |
StreamBuffer(VkBufferUsageFlags usage, u32 size); |
| 20 |
~StreamBuffer(); |
| 21 |
|
| 22 |
VkBuffer GetBuffer() const { return m_buffer; } |
| 23 |
u8* GetHostPointer() const { return m_host_pointer; } |
| 24 |
u8* GetCurrentHostPointer() const { return m_host_pointer + m_current_offset; } |
| 25 |
u32 GetCurrentSize() const { return m_size; } |
| 26 |
u32 GetCurrentOffset() const { return m_current_offset; } |
| 27 |
bool ReserveMemory(u32 num_bytes, u32 alignment); |
| 28 |
void CommitMemory(u32 final_num_bytes); |
| 29 |
|
| 30 |
static std::unique_ptr<StreamBuffer> Create(VkBufferUsageFlags usage, u32 size); |
| 31 |
|
| 32 |
private: |
| 33 |
bool AllocateBuffer(); |
| 34 |
void UpdateCurrentFencePosition(); |
| 35 |
void UpdateGPUPosition(); |
| 36 |
|
| 37 |
|
| 38 |
bool WaitForClearSpace(u32 num_bytes); |
| 39 |
|
| 40 |
VkBufferUsageFlags m_usage; |
| 41 |
u32 m_size; |
| 42 |
u32 m_current_offset = 0; |
| 43 |
u32 m_current_gpu_position = 0; |
| 44 |
u32 m_last_allocation_size = 0; |
| 45 |
|
| 46 |
VkBuffer m_buffer = VK_NULL_HANDLE; |
| 47 |
VmaAllocation m_alloc = VK_NULL_HANDLE; |
| 48 |
u8* m_host_pointer = nullptr; |
| 49 |
|
| 50 |
|
| 51 |
std::deque<std::pair<u64, u32>> m_tracked_fences; |
| 52 |
}; |
| 53 |
|
| 54 |
} |