|
@@ -8,6 +8,7 @@
|
|
|
|
|
|
|
|
#include <fmt/format.h>
|
|
#include <fmt/format.h>
|
|
|
|
|
|
|
|
|
|
+#include "common/assert.h"
|
|
|
#include "common/bit_util.h"
|
|
#include "common/bit_util.h"
|
|
|
#include "common/common_types.h"
|
|
#include "common/common_types.h"
|
|
|
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
|
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
|
@@ -23,23 +24,24 @@ StagingBufferPool::StagingBufferPool(const Device& device_, MemoryAllocator& mem
|
|
|
|
|
|
|
|
StagingBufferPool::~StagingBufferPool() = default;
|
|
StagingBufferPool::~StagingBufferPool() = default;
|
|
|
|
|
|
|
|
-StagingBufferRef StagingBufferPool::Request(size_t size, bool host_visible) {
|
|
|
|
|
- if (const std::optional<StagingBufferRef> ref = TryGetReservedBuffer(size, host_visible)) {
|
|
|
|
|
|
|
+StagingBufferRef StagingBufferPool::Request(size_t size, MemoryUsage usage) {
|
|
|
|
|
+ if (const std::optional<StagingBufferRef> ref = TryGetReservedBuffer(size, usage)) {
|
|
|
return *ref;
|
|
return *ref;
|
|
|
}
|
|
}
|
|
|
- return CreateStagingBuffer(size, host_visible);
|
|
|
|
|
|
|
+ return CreateStagingBuffer(size, usage);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void StagingBufferPool::TickFrame() {
|
|
void StagingBufferPool::TickFrame() {
|
|
|
current_delete_level = (current_delete_level + 1) % NUM_LEVELS;
|
|
current_delete_level = (current_delete_level + 1) % NUM_LEVELS;
|
|
|
|
|
|
|
|
- ReleaseCache(true);
|
|
|
|
|
- ReleaseCache(false);
|
|
|
|
|
|
|
+ ReleaseCache(MemoryUsage::DeviceLocal);
|
|
|
|
|
+ ReleaseCache(MemoryUsage::Upload);
|
|
|
|
|
+ ReleaseCache(MemoryUsage::Download);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
std::optional<StagingBufferRef> StagingBufferPool::TryGetReservedBuffer(size_t size,
|
|
std::optional<StagingBufferRef> StagingBufferPool::TryGetReservedBuffer(size_t size,
|
|
|
- bool host_visible) {
|
|
|
|
|
- StagingBuffers& cache_level = GetCache(host_visible)[Common::Log2Ceil64(size)];
|
|
|
|
|
|
|
+ MemoryUsage usage) {
|
|
|
|
|
+ StagingBuffers& cache_level = GetCache(usage)[Common::Log2Ceil64(size)];
|
|
|
|
|
|
|
|
const auto is_free = [this](const StagingBuffer& entry) {
|
|
const auto is_free = [this](const StagingBuffer& entry) {
|
|
|
return scheduler.IsFree(entry.tick);
|
|
return scheduler.IsFree(entry.tick);
|
|
@@ -58,7 +60,7 @@ std::optional<StagingBufferRef> StagingBufferPool::TryGetReservedBuffer(size_t s
|
|
|
return it->Ref();
|
|
return it->Ref();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-StagingBufferRef StagingBufferPool::CreateStagingBuffer(size_t size, bool host_visible) {
|
|
|
|
|
|
|
+StagingBufferRef StagingBufferPool::CreateStagingBuffer(size_t size, MemoryUsage usage) {
|
|
|
const u32 log2 = Common::Log2Ceil64(size);
|
|
const u32 log2 = Common::Log2Ceil64(size);
|
|
|
vk::Buffer buffer = device.GetLogical().CreateBuffer({
|
|
vk::Buffer buffer = device.GetLogical().CreateBuffer({
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
|
@@ -76,10 +78,10 @@ StagingBufferRef StagingBufferPool::CreateStagingBuffer(size_t size, bool host_v
|
|
|
++buffer_index;
|
|
++buffer_index;
|
|
|
buffer.SetObjectNameEXT(fmt::format("Staging Buffer {}", buffer_index).c_str());
|
|
buffer.SetObjectNameEXT(fmt::format("Staging Buffer {}", buffer_index).c_str());
|
|
|
}
|
|
}
|
|
|
- MemoryCommit commit = memory_allocator.Commit(buffer, host_visible);
|
|
|
|
|
- const std::span<u8> mapped_span = host_visible ? commit.Map() : std::span<u8>{};
|
|
|
|
|
|
|
+ MemoryCommit commit = memory_allocator.Commit(buffer, usage);
|
|
|
|
|
+ const std::span<u8> mapped_span = IsHostVisible(usage) ? commit.Map() : std::span<u8>{};
|
|
|
|
|
|
|
|
- StagingBuffer& entry = GetCache(host_visible)[log2].entries.emplace_back(StagingBuffer{
|
|
|
|
|
|
|
+ StagingBuffer& entry = GetCache(usage)[log2].entries.emplace_back(StagingBuffer{
|
|
|
.buffer = std::move(buffer),
|
|
.buffer = std::move(buffer),
|
|
|
.commit = std::move(commit),
|
|
.commit = std::move(commit),
|
|
|
.mapped_span = mapped_span,
|
|
.mapped_span = mapped_span,
|
|
@@ -88,12 +90,22 @@ StagingBufferRef StagingBufferPool::CreateStagingBuffer(size_t size, bool host_v
|
|
|
return entry.Ref();
|
|
return entry.Ref();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-StagingBufferPool::StagingBuffersCache& StagingBufferPool::GetCache(bool host_visible) {
|
|
|
|
|
- return host_visible ? host_staging_buffers : device_staging_buffers;
|
|
|
|
|
|
|
+StagingBufferPool::StagingBuffersCache& StagingBufferPool::GetCache(MemoryUsage usage) {
|
|
|
|
|
+ switch (usage) {
|
|
|
|
|
+ case MemoryUsage::DeviceLocal:
|
|
|
|
|
+ return device_local_cache;
|
|
|
|
|
+ case MemoryUsage::Upload:
|
|
|
|
|
+ return upload_cache;
|
|
|
|
|
+ case MemoryUsage::Download:
|
|
|
|
|
+ return download_cache;
|
|
|
|
|
+ default:
|
|
|
|
|
+ UNREACHABLE_MSG("Invalid memory usage={}", usage);
|
|
|
|
|
+ return upload_cache;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void StagingBufferPool::ReleaseCache(bool host_visible) {
|
|
|
|
|
- ReleaseLevel(GetCache(host_visible), current_delete_level);
|
|
|
|
|
|
|
+void StagingBufferPool::ReleaseCache(MemoryUsage usage) {
|
|
|
|
|
+ ReleaseLevel(GetCache(usage), current_delete_level);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void StagingBufferPool::ReleaseLevel(StagingBuffersCache& cache, size_t log2) {
|
|
void StagingBufferPool::ReleaseLevel(StagingBuffersCache& cache, size_t log2) {
|