blob: 5234a95fad128b04bd2a9580fdabae1fd592c2d3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright 2019 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <climits>
#include <vector>
#include "common/common_types.h"
#include "video_core/renderer_vulkan/vk_memory_manager.h"
#include "video_core/vulkan_common/vulkan_wrapper.h"
namespace Vulkan {
class Device;
class VKScheduler;
struct StagingBufferRef {
VkBuffer buffer;
std::span<u8> mapped_span;
};
class StagingBufferPool {
public:
explicit StagingBufferPool(const Device& device, VKMemoryManager& memory_manager,
VKScheduler& scheduler);
~StagingBufferPool();
StagingBufferRef Request(size_t size, bool host_visible);
void TickFrame();
private:
struct StagingBuffer {
vk::Buffer buffer;
MemoryCommit commit;
std::span<u8> mapped_span;
u64 tick = 0;
StagingBufferRef Ref() const noexcept {
return {
.buffer = *buffer,
.mapped_span = mapped_span,
};
}
};
struct StagingBuffers {
std::vector<StagingBuffer> entries;
size_t delete_index = 0;
size_t iterate_index = 0;
};
static constexpr size_t NUM_LEVELS = sizeof(size_t) * CHAR_BIT;
using StagingBuffersCache = std::array<StagingBuffers, NUM_LEVELS>;
std::optional<StagingBufferRef> TryGetReservedBuffer(size_t size, bool host_visible);
StagingBufferRef CreateStagingBuffer(size_t size, bool host_visible);
StagingBuffersCache& GetCache(bool host_visible);
void ReleaseCache(bool host_visible);
void ReleaseLevel(StagingBuffersCache& cache, size_t log2);
const Device& device;
VKMemoryManager& memory_manager;
VKScheduler& scheduler;
StagingBuffersCache host_staging_buffers;
StagingBuffersCache device_staging_buffers;
size_t current_delete_level = 0;
u64 buffer_index = 0;
};
} // namespace Vulkan
|