2016-08-13 12:57:50 +00:00
|
|
|
// Copyright 2016 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-08-13 12:57:50 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2016-10-01 03:07:50 +00:00
|
|
|
#include <cstddef>
|
2016-08-13 12:57:50 +00:00
|
|
|
#include <deque>
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
2017-02-01 15:56:13 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2016-08-13 12:57:50 +00:00
|
|
|
#include "VideoBackends/Vulkan/Constants.h"
|
|
|
|
|
|
|
|
namespace Vulkan
|
|
|
|
{
|
|
|
|
class StreamBuffer
|
|
|
|
{
|
|
|
|
public:
|
2019-02-15 01:59:50 +00:00
|
|
|
StreamBuffer(VkBufferUsageFlags usage, u32 size);
|
2016-08-13 12:57:50 +00:00
|
|
|
~StreamBuffer();
|
|
|
|
|
|
|
|
VkBuffer GetBuffer() const { return m_buffer; }
|
|
|
|
u8* GetHostPointer() const { return m_host_pointer; }
|
|
|
|
u8* GetCurrentHostPointer() const { return m_host_pointer + m_current_offset; }
|
2019-02-15 01:59:50 +00:00
|
|
|
u32 GetCurrentSize() const { return m_size; }
|
|
|
|
u32 GetCurrentOffset() const { return m_current_offset; }
|
|
|
|
bool ReserveMemory(u32 num_bytes, u32 alignment);
|
|
|
|
void CommitMemory(u32 final_num_bytes);
|
2016-08-13 12:57:50 +00:00
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
static std::unique_ptr<StreamBuffer> Create(VkBufferUsageFlags usage, u32 size);
|
2016-08-13 12:57:50 +00:00
|
|
|
|
|
|
|
private:
|
2019-02-15 01:59:50 +00:00
|
|
|
bool AllocateBuffer();
|
|
|
|
void UpdateCurrentFencePosition();
|
2019-03-17 05:59:22 +00:00
|
|
|
void UpdateGPUPosition();
|
2016-08-13 12:57:50 +00:00
|
|
|
|
|
|
|
// Waits for as many fences as needed to allocate num_bytes bytes from the buffer.
|
2019-02-15 01:59:50 +00:00
|
|
|
bool WaitForClearSpace(u32 num_bytes);
|
2016-08-13 12:57:50 +00:00
|
|
|
|
|
|
|
VkBufferUsageFlags m_usage;
|
2019-02-15 01:59:50 +00:00
|
|
|
u32 m_size;
|
|
|
|
u32 m_current_offset = 0;
|
|
|
|
u32 m_current_gpu_position = 0;
|
|
|
|
u32 m_last_allocation_size = 0;
|
2016-08-13 12:57:50 +00:00
|
|
|
|
|
|
|
VkBuffer m_buffer = VK_NULL_HANDLE;
|
2022-10-07 21:48:11 +00:00
|
|
|
VmaAllocation m_alloc = VK_NULL_HANDLE;
|
2016-08-13 12:57:50 +00:00
|
|
|
u8* m_host_pointer = nullptr;
|
|
|
|
|
|
|
|
// List of fences and the corresponding positions in the buffer
|
2019-03-17 05:59:22 +00:00
|
|
|
std::deque<std::pair<u64, u32>> m_tracked_fences;
|
2016-08-13 12:57:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Vulkan
|