diff options
| author | 2021-01-03 18:17:57 -0300 | |
|---|---|---|
| committer | 2021-01-15 16:19:39 -0300 | |
| commit | fade63b58e020d7cc72fa8be26914a89ef21c653 (patch) | |
| tree | 48a0c32e7c695a8ec8491e446371a67ad3b65bc0 /src/video_core/renderer_vulkan | |
| parent | renderer_vulkan: Rename Vulkan memory manager to memory allocator (diff) | |
| download | yuzu-fade63b58e020d7cc72fa8be26914a89ef21c653.tar.gz yuzu-fade63b58e020d7cc72fa8be26914a89ef21c653.tar.xz yuzu-fade63b58e020d7cc72fa8be26914a89ef21c653.zip | |
vulkan_common: Move allocator to the common directory
Allow using the abstraction from the OpenGL backend.
Diffstat (limited to 'src/video_core/renderer_vulkan')
10 files changed, 8 insertions, 330 deletions
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index 657de69a5..61796e33a 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp | |||
| @@ -23,7 +23,6 @@ | |||
| 23 | #include "video_core/renderer_vulkan/renderer_vulkan.h" | 23 | #include "video_core/renderer_vulkan/renderer_vulkan.h" |
| 24 | #include "video_core/renderer_vulkan/vk_blit_screen.h" | 24 | #include "video_core/renderer_vulkan/vk_blit_screen.h" |
| 25 | #include "video_core/renderer_vulkan/vk_master_semaphore.h" | 25 | #include "video_core/renderer_vulkan/vk_master_semaphore.h" |
| 26 | #include "video_core/renderer_vulkan/vk_memory_manager.h" | ||
| 27 | #include "video_core/renderer_vulkan/vk_rasterizer.h" | 26 | #include "video_core/renderer_vulkan/vk_rasterizer.h" |
| 28 | #include "video_core/renderer_vulkan/vk_scheduler.h" | 27 | #include "video_core/renderer_vulkan/vk_scheduler.h" |
| 29 | #include "video_core/renderer_vulkan/vk_state_tracker.h" | 28 | #include "video_core/renderer_vulkan/vk_state_tracker.h" |
| @@ -32,6 +31,7 @@ | |||
| 32 | #include "video_core/vulkan_common/vulkan_device.h" | 31 | #include "video_core/vulkan_common/vulkan_device.h" |
| 33 | #include "video_core/vulkan_common/vulkan_instance.h" | 32 | #include "video_core/vulkan_common/vulkan_instance.h" |
| 34 | #include "video_core/vulkan_common/vulkan_library.h" | 33 | #include "video_core/vulkan_common/vulkan_library.h" |
| 34 | #include "video_core/vulkan_common/vulkan_memory_allocator.h" | ||
| 35 | #include "video_core/vulkan_common/vulkan_surface.h" | 35 | #include "video_core/vulkan_common/vulkan_surface.h" |
| 36 | #include "video_core/vulkan_common/vulkan_wrapper.h" | 36 | #include "video_core/vulkan_common/vulkan_wrapper.h" |
| 37 | 37 | ||
diff --git a/src/video_core/renderer_vulkan/vk_blit_screen.cpp b/src/video_core/renderer_vulkan/vk_blit_screen.cpp index 79d8ef71a..f06af06c8 100644 --- a/src/video_core/renderer_vulkan/vk_blit_screen.cpp +++ b/src/video_core/renderer_vulkan/vk_blit_screen.cpp | |||
| @@ -22,13 +22,13 @@ | |||
| 22 | #include "video_core/renderer_vulkan/renderer_vulkan.h" | 22 | #include "video_core/renderer_vulkan/renderer_vulkan.h" |
| 23 | #include "video_core/renderer_vulkan/vk_blit_screen.h" | 23 | #include "video_core/renderer_vulkan/vk_blit_screen.h" |
| 24 | #include "video_core/renderer_vulkan/vk_master_semaphore.h" | 24 | #include "video_core/renderer_vulkan/vk_master_semaphore.h" |
| 25 | #include "video_core/renderer_vulkan/vk_memory_manager.h" | ||
| 26 | #include "video_core/renderer_vulkan/vk_scheduler.h" | 25 | #include "video_core/renderer_vulkan/vk_scheduler.h" |
| 27 | #include "video_core/renderer_vulkan/vk_shader_util.h" | 26 | #include "video_core/renderer_vulkan/vk_shader_util.h" |
| 28 | #include "video_core/renderer_vulkan/vk_swapchain.h" | 27 | #include "video_core/renderer_vulkan/vk_swapchain.h" |
| 29 | #include "video_core/surface.h" | 28 | #include "video_core/surface.h" |
| 30 | #include "video_core/textures/decoders.h" | 29 | #include "video_core/textures/decoders.h" |
| 31 | #include "video_core/vulkan_common/vulkan_device.h" | 30 | #include "video_core/vulkan_common/vulkan_device.h" |
| 31 | #include "video_core/vulkan_common/vulkan_memory_allocator.h" | ||
| 32 | #include "video_core/vulkan_common/vulkan_wrapper.h" | 32 | #include "video_core/vulkan_common/vulkan_wrapper.h" |
| 33 | 33 | ||
| 34 | namespace Vulkan { | 34 | namespace Vulkan { |
diff --git a/src/video_core/renderer_vulkan/vk_blit_screen.h b/src/video_core/renderer_vulkan/vk_blit_screen.h index e52d9885e..b52576957 100644 --- a/src/video_core/renderer_vulkan/vk_blit_screen.h +++ b/src/video_core/renderer_vulkan/vk_blit_screen.h | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | 8 | ||
| 9 | #include "video_core/renderer_vulkan/vk_memory_manager.h" | 9 | #include "video_core/vulkan_common/vulkan_memory_allocator.h" |
| 10 | #include "video_core/vulkan_common/vulkan_wrapper.h" | 10 | #include "video_core/vulkan_common/vulkan_wrapper.h" |
| 11 | 11 | ||
| 12 | namespace Core { | 12 | namespace Core { |
diff --git a/src/video_core/renderer_vulkan/vk_buffer_cache.h b/src/video_core/renderer_vulkan/vk_buffer_cache.h index 4db5259ef..41d577510 100644 --- a/src/video_core/renderer_vulkan/vk_buffer_cache.h +++ b/src/video_core/renderer_vulkan/vk_buffer_cache.h | |||
| @@ -8,9 +8,9 @@ | |||
| 8 | 8 | ||
| 9 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | #include "video_core/buffer_cache/buffer_cache.h" | 10 | #include "video_core/buffer_cache/buffer_cache.h" |
| 11 | #include "video_core/renderer_vulkan/vk_memory_manager.h" | ||
| 12 | #include "video_core/renderer_vulkan/vk_staging_buffer_pool.h" | 11 | #include "video_core/renderer_vulkan/vk_staging_buffer_pool.h" |
| 13 | #include "video_core/renderer_vulkan/vk_stream_buffer.h" | 12 | #include "video_core/renderer_vulkan/vk_stream_buffer.h" |
| 13 | #include "video_core/vulkan_common/vulkan_memory_allocator.h" | ||
| 14 | #include "video_core/vulkan_common/vulkan_wrapper.h" | 14 | #include "video_core/vulkan_common/vulkan_wrapper.h" |
| 15 | 15 | ||
| 16 | namespace Vulkan { | 16 | namespace Vulkan { |
diff --git a/src/video_core/renderer_vulkan/vk_memory_manager.cpp b/src/video_core/renderer_vulkan/vk_memory_manager.cpp deleted file mode 100644 index cabf0b6ca..000000000 --- a/src/video_core/renderer_vulkan/vk_memory_manager.cpp +++ /dev/null | |||
| @@ -1,227 +0,0 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <bit> | ||
| 7 | #include <optional> | ||
| 8 | #include <tuple> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "common/alignment.h" | ||
| 12 | #include "common/assert.h" | ||
| 13 | #include "common/common_types.h" | ||
| 14 | #include "common/logging/log.h" | ||
| 15 | #include "video_core/renderer_vulkan/vk_memory_manager.h" | ||
| 16 | #include "video_core/vulkan_common/vulkan_device.h" | ||
| 17 | #include "video_core/vulkan_common/vulkan_wrapper.h" | ||
| 18 | |||
| 19 | namespace Vulkan { | ||
| 20 | namespace { | ||
| 21 | struct Range { | ||
| 22 | u64 begin; | ||
| 23 | u64 end; | ||
| 24 | |||
| 25 | [[nodiscard]] bool Contains(u64 iterator, u64 size) const noexcept { | ||
| 26 | return iterator < end && begin < iterator + size; | ||
| 27 | } | ||
| 28 | }; | ||
| 29 | |||
| 30 | [[nodiscard]] u64 GetAllocationChunkSize(u64 required_size) { | ||
| 31 | static constexpr std::array sizes{ | ||
| 32 | 0x1000ULL << 10, 0x1400ULL << 10, 0x1800ULL << 10, 0x1c00ULL << 10, 0x2000ULL << 10, | ||
| 33 | 0x3200ULL << 10, 0x4000ULL << 10, 0x6000ULL << 10, 0x8000ULL << 10, 0xA000ULL << 10, | ||
| 34 | 0x10000ULL << 10, 0x18000ULL << 10, 0x20000ULL << 10, | ||
| 35 | }; | ||
| 36 | static_assert(std::is_sorted(sizes.begin(), sizes.end())); | ||
| 37 | |||
| 38 | const auto it = std::ranges::lower_bound(sizes, required_size); | ||
| 39 | return it != sizes.end() ? *it : Common::AlignUp(required_size, 4ULL << 20); | ||
| 40 | } | ||
| 41 | } // Anonymous namespace | ||
| 42 | |||
| 43 | class MemoryAllocation { | ||
| 44 | public: | ||
| 45 | explicit MemoryAllocation(const Device& device_, vk::DeviceMemory memory_, | ||
| 46 | VkMemoryPropertyFlags properties_, u64 allocation_size_, u32 type_) | ||
| 47 | : device{device_}, memory{std::move(memory_)}, properties{properties_}, | ||
| 48 | allocation_size{allocation_size_}, shifted_type{ShiftType(type_)} {} | ||
| 49 | |||
| 50 | [[nodiscard]] std::optional<MemoryCommit> Commit(VkDeviceSize size, VkDeviceSize alignment) { | ||
| 51 | const std::optional<u64> alloc = FindFreeRegion(size, alignment); | ||
| 52 | if (!alloc) { | ||
| 53 | // Signal out of memory, it'll try to do more allocations. | ||
| 54 | return std::nullopt; | ||
| 55 | } | ||
| 56 | const Range range{ | ||
| 57 | .begin = *alloc, | ||
| 58 | .end = *alloc + size, | ||
| 59 | }; | ||
| 60 | commits.insert(std::ranges::upper_bound(commits, *alloc, {}, &Range::begin), range); | ||
| 61 | return std::make_optional<MemoryCommit>(device, this, *memory, *alloc, *alloc + size); | ||
| 62 | } | ||
| 63 | |||
| 64 | void Free(u64 begin) { | ||
| 65 | const auto it = std::ranges::find(commits, begin, &Range::begin); | ||
| 66 | ASSERT_MSG(it != commits.end(), "Invalid commit"); | ||
| 67 | commits.erase(it); | ||
| 68 | } | ||
| 69 | |||
| 70 | [[nodiscard]] std::span<u8> Map() { | ||
| 71 | if (!memory_mapped_span.empty()) { | ||
| 72 | return memory_mapped_span; | ||
| 73 | } | ||
| 74 | u8* const raw_pointer = memory.Map(0, allocation_size); | ||
| 75 | memory_mapped_span = std::span<u8>(raw_pointer, allocation_size); | ||
| 76 | return memory_mapped_span; | ||
| 77 | } | ||
| 78 | |||
| 79 | /// Returns whether this allocation is compatible with the arguments. | ||
| 80 | [[nodiscard]] bool IsCompatible(VkMemoryPropertyFlags wanted_properties, u32 type_mask) const { | ||
| 81 | return (wanted_properties & properties) && (type_mask & shifted_type) != 0; | ||
| 82 | } | ||
| 83 | |||
| 84 | private: | ||
| 85 | [[nodiscard]] static constexpr u32 ShiftType(u32 type) { | ||
| 86 | return 1U << type; | ||
| 87 | } | ||
| 88 | |||
| 89 | [[nodiscard]] std::optional<u64> FindFreeRegion(u64 size, u64 alignment) noexcept { | ||
| 90 | ASSERT(std::has_single_bit(alignment)); | ||
| 91 | const u64 alignment_log2 = std::countr_zero(alignment); | ||
| 92 | std::optional<u64> candidate; | ||
| 93 | u64 iterator = 0; | ||
| 94 | auto commit = commits.begin(); | ||
| 95 | while (iterator + size <= allocation_size) { | ||
| 96 | candidate = candidate.value_or(iterator); | ||
| 97 | if (commit == commits.end()) { | ||
| 98 | break; | ||
| 99 | } | ||
| 100 | if (commit->Contains(*candidate, size)) { | ||
| 101 | candidate = std::nullopt; | ||
| 102 | } | ||
| 103 | iterator = Common::AlignUpLog2(commit->end, alignment_log2); | ||
| 104 | ++commit; | ||
| 105 | } | ||
| 106 | return candidate; | ||
| 107 | } | ||
| 108 | |||
| 109 | const Device& device; ///< Vulkan device. | ||
| 110 | const vk::DeviceMemory memory; ///< Vulkan memory allocation handler. | ||
| 111 | const VkMemoryPropertyFlags properties; ///< Vulkan properties. | ||
| 112 | const u64 allocation_size; ///< Size of this allocation. | ||
| 113 | const u32 shifted_type; ///< Stored Vulkan type of this allocation, shifted. | ||
| 114 | std::vector<Range> commits; ///< All commit ranges done from this allocation. | ||
| 115 | std::span<u8> memory_mapped_span; ///< Memory mapped span. Empty if not queried before. | ||
| 116 | }; | ||
| 117 | |||
| 118 | MemoryCommit::MemoryCommit(const Device& device_, MemoryAllocation* allocation_, | ||
| 119 | VkDeviceMemory memory_, u64 begin, u64 end) noexcept | ||
| 120 | : device{&device_}, allocation{allocation_}, memory{memory_}, interval{begin, end} {} | ||
| 121 | |||
| 122 | MemoryCommit::~MemoryCommit() { | ||
| 123 | Release(); | ||
| 124 | } | ||
| 125 | |||
| 126 | MemoryCommit& MemoryCommit::operator=(MemoryCommit&& rhs) noexcept { | ||
| 127 | Release(); | ||
| 128 | device = rhs.device; | ||
| 129 | allocation = std::exchange(rhs.allocation, nullptr); | ||
| 130 | memory = rhs.memory; | ||
| 131 | interval = rhs.interval; | ||
| 132 | span = std::exchange(rhs.span, std::span<u8>{}); | ||
| 133 | return *this; | ||
| 134 | } | ||
| 135 | |||
| 136 | MemoryCommit::MemoryCommit(MemoryCommit&& rhs) noexcept | ||
| 137 | : device{rhs.device}, allocation{std::exchange(rhs.allocation, nullptr)}, memory{rhs.memory}, | ||
| 138 | interval{rhs.interval}, span{std::exchange(rhs.span, std::span<u8>{})} {} | ||
| 139 | |||
| 140 | std::span<u8> MemoryCommit::Map() { | ||
| 141 | if (!span.empty()) { | ||
| 142 | return span; | ||
| 143 | } | ||
| 144 | span = allocation->Map().subspan(interval.first, interval.second - interval.first); | ||
| 145 | return span; | ||
| 146 | } | ||
| 147 | |||
| 148 | void MemoryCommit::Release() { | ||
| 149 | if (allocation) { | ||
| 150 | allocation->Free(interval.first); | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | MemoryAllocator::MemoryAllocator(const Device& device_) | ||
| 155 | : device{device_}, properties{device_.GetPhysical().GetMemoryProperties()} {} | ||
| 156 | |||
| 157 | MemoryAllocator::~MemoryAllocator() = default; | ||
| 158 | |||
| 159 | MemoryCommit MemoryAllocator::Commit(const VkMemoryRequirements& requirements, bool host_visible) { | ||
| 160 | const u64 chunk_size = GetAllocationChunkSize(requirements.size); | ||
| 161 | |||
| 162 | // When a host visible commit is asked, search for host visible and coherent, otherwise search | ||
| 163 | // for a fast device local type. | ||
| 164 | const VkMemoryPropertyFlags wanted_properties = | ||
| 165 | host_visible ? VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | ||
| 166 | : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; | ||
| 167 | if (std::optional<MemoryCommit> commit = TryAllocCommit(requirements, wanted_properties)) { | ||
| 168 | return std::move(*commit); | ||
| 169 | } | ||
| 170 | // Commit has failed, allocate more memory. | ||
| 171 | // TODO(Rodrigo): Handle out of memory situations in some way like flushing to guest memory. | ||
| 172 | AllocMemory(wanted_properties, requirements.memoryTypeBits, chunk_size); | ||
| 173 | |||
| 174 | // Commit again, this time it won't fail since there's a fresh allocation above. | ||
| 175 | // If it does, there's a bug. | ||
| 176 | return TryAllocCommit(requirements, wanted_properties).value(); | ||
| 177 | } | ||
| 178 | |||
| 179 | MemoryCommit MemoryAllocator::Commit(const vk::Buffer& buffer, bool host_visible) { | ||
| 180 | auto commit = Commit(device.GetLogical().GetBufferMemoryRequirements(*buffer), host_visible); | ||
| 181 | buffer.BindMemory(commit.Memory(), commit.Offset()); | ||
| 182 | return commit; | ||
| 183 | } | ||
| 184 | |||
| 185 | MemoryCommit MemoryAllocator::Commit(const vk::Image& image, bool host_visible) { | ||
| 186 | auto commit = Commit(device.GetLogical().GetImageMemoryRequirements(*image), host_visible); | ||
| 187 | image.BindMemory(commit.Memory(), commit.Offset()); | ||
| 188 | return commit; | ||
| 189 | } | ||
| 190 | |||
| 191 | void MemoryAllocator::AllocMemory(VkMemoryPropertyFlags wanted_properties, u32 type_mask, | ||
| 192 | u64 size) { | ||
| 193 | const u32 type = [&] { | ||
| 194 | for (u32 type_index = 0; type_index < properties.memoryTypeCount; ++type_index) { | ||
| 195 | const auto flags = properties.memoryTypes[type_index].propertyFlags; | ||
| 196 | if ((type_mask & (1U << type_index)) && (flags & wanted_properties)) { | ||
| 197 | // The type matches in type and in the wanted properties. | ||
| 198 | return type_index; | ||
| 199 | } | ||
| 200 | } | ||
| 201 | UNREACHABLE_MSG("Couldn't find a compatible memory type!"); | ||
| 202 | return 0U; | ||
| 203 | }(); | ||
| 204 | vk::DeviceMemory memory = device.GetLogical().AllocateMemory({ | ||
| 205 | .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, | ||
| 206 | .pNext = nullptr, | ||
| 207 | .allocationSize = size, | ||
| 208 | .memoryTypeIndex = type, | ||
| 209 | }); | ||
| 210 | allocations.push_back(std::make_unique<MemoryAllocation>(device, std::move(memory), | ||
| 211 | wanted_properties, size, type)); | ||
| 212 | } | ||
| 213 | |||
| 214 | std::optional<MemoryCommit> MemoryAllocator::TryAllocCommit( | ||
| 215 | const VkMemoryRequirements& requirements, VkMemoryPropertyFlags wanted_properties) { | ||
| 216 | for (auto& allocation : allocations) { | ||
| 217 | if (!allocation->IsCompatible(wanted_properties, requirements.memoryTypeBits)) { | ||
| 218 | continue; | ||
| 219 | } | ||
| 220 | if (auto commit = allocation->Commit(requirements.size, requirements.alignment)) { | ||
| 221 | return commit; | ||
| 222 | } | ||
| 223 | } | ||
| 224 | return std::nullopt; | ||
| 225 | } | ||
| 226 | |||
| 227 | } // namespace Vulkan | ||
diff --git a/src/video_core/renderer_vulkan/vk_memory_manager.h b/src/video_core/renderer_vulkan/vk_memory_manager.h deleted file mode 100644 index 69a6341e1..000000000 --- a/src/video_core/renderer_vulkan/vk_memory_manager.h +++ /dev/null | |||
| @@ -1,95 +0,0 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | #include <span> | ||
| 9 | #include <utility> | ||
| 10 | #include <vector> | ||
| 11 | #include "common/common_types.h" | ||
| 12 | #include "video_core/vulkan_common/vulkan_wrapper.h" | ||
| 13 | |||
| 14 | namespace Vulkan { | ||
| 15 | |||
| 16 | class Device; | ||
| 17 | class MemoryMap; | ||
| 18 | class MemoryAllocation; | ||
| 19 | |||
| 20 | class MemoryCommit final { | ||
| 21 | public: | ||
| 22 | explicit MemoryCommit() noexcept = default; | ||
| 23 | explicit MemoryCommit(const Device& device_, MemoryAllocation* allocation_, | ||
| 24 | VkDeviceMemory memory_, u64 begin, u64 end) noexcept; | ||
| 25 | ~MemoryCommit(); | ||
| 26 | |||
| 27 | MemoryCommit& operator=(MemoryCommit&&) noexcept; | ||
| 28 | MemoryCommit(MemoryCommit&&) noexcept; | ||
| 29 | |||
| 30 | MemoryCommit& operator=(const MemoryCommit&) = delete; | ||
| 31 | MemoryCommit(const MemoryCommit&) = delete; | ||
| 32 | |||
| 33 | /// Returns a host visible memory map. | ||
| 34 | /// It will map the backing allocation if it hasn't been mapped before. | ||
| 35 | std::span<u8> Map(); | ||
| 36 | |||
| 37 | /// Returns the Vulkan memory handler. | ||
| 38 | VkDeviceMemory Memory() const { | ||
| 39 | return memory; | ||
| 40 | } | ||
| 41 | |||
| 42 | /// Returns the start position of the commit relative to the allocation. | ||
| 43 | VkDeviceSize Offset() const { | ||
| 44 | return static_cast<VkDeviceSize>(interval.first); | ||
| 45 | } | ||
| 46 | |||
| 47 | private: | ||
| 48 | void Release(); | ||
| 49 | |||
| 50 | const Device* device{}; ///< Vulkan device. | ||
| 51 | MemoryAllocation* allocation{}; ///< Pointer to the large memory allocation. | ||
| 52 | VkDeviceMemory memory{}; ///< Vulkan device memory handler. | ||
| 53 | std::pair<u64, u64> interval{}; ///< Interval where the commit exists. | ||
| 54 | std::span<u8> span; ///< Host visible memory span. Empty if not queried before. | ||
| 55 | }; | ||
| 56 | |||
| 57 | class MemoryAllocator final { | ||
| 58 | public: | ||
| 59 | explicit MemoryAllocator(const Device& device_); | ||
| 60 | ~MemoryAllocator(); | ||
| 61 | |||
| 62 | MemoryAllocator& operator=(const MemoryAllocator&) = delete; | ||
| 63 | MemoryAllocator(const MemoryAllocator&) = delete; | ||
| 64 | |||
| 65 | /** | ||
| 66 | * Commits a memory with the specified requeriments. | ||
| 67 | * | ||
| 68 | * @param requirements Requirements returned from a Vulkan call. | ||
| 69 | * @param host_visible Signals the allocator that it *must* use host visible and coherent | ||
| 70 | * memory. When passing false, it will try to allocate device local memory. | ||
| 71 | * | ||
| 72 | * @returns A memory commit. | ||
| 73 | */ | ||
| 74 | MemoryCommit Commit(const VkMemoryRequirements& requirements, bool host_visible); | ||
| 75 | |||
| 76 | /// Commits memory required by the buffer and binds it. | ||
| 77 | MemoryCommit Commit(const vk::Buffer& buffer, bool host_visible); | ||
| 78 | |||
| 79 | /// Commits memory required by the image and binds it. | ||
| 80 | MemoryCommit Commit(const vk::Image& image, bool host_visible); | ||
| 81 | |||
| 82 | private: | ||
| 83 | /// Allocates a chunk of memory. | ||
| 84 | void AllocMemory(VkMemoryPropertyFlags wanted_properties, u32 type_mask, u64 size); | ||
| 85 | |||
| 86 | /// Tries to allocate a memory commit. | ||
| 87 | std::optional<MemoryCommit> TryAllocCommit(const VkMemoryRequirements& requirements, | ||
| 88 | VkMemoryPropertyFlags wanted_properties); | ||
| 89 | |||
| 90 | const Device& device; ///< Device handler. | ||
| 91 | const VkPhysicalDeviceMemoryProperties properties; ///< Physical device properties. | ||
| 92 | std::vector<std::unique_ptr<MemoryAllocation>> allocations; ///< Current allocations. | ||
| 93 | }; | ||
| 94 | |||
| 95 | } // namespace Vulkan | ||
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.h b/src/video_core/renderer_vulkan/vk_rasterizer.h index 72e679ffd..8e261b9bd 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.h +++ b/src/video_core/renderer_vulkan/vk_rasterizer.h | |||
| @@ -21,7 +21,6 @@ | |||
| 21 | #include "video_core/renderer_vulkan/vk_compute_pass.h" | 21 | #include "video_core/renderer_vulkan/vk_compute_pass.h" |
| 22 | #include "video_core/renderer_vulkan/vk_descriptor_pool.h" | 22 | #include "video_core/renderer_vulkan/vk_descriptor_pool.h" |
| 23 | #include "video_core/renderer_vulkan/vk_fence_manager.h" | 23 | #include "video_core/renderer_vulkan/vk_fence_manager.h" |
| 24 | #include "video_core/renderer_vulkan/vk_memory_manager.h" | ||
| 25 | #include "video_core/renderer_vulkan/vk_pipeline_cache.h" | 24 | #include "video_core/renderer_vulkan/vk_pipeline_cache.h" |
| 26 | #include "video_core/renderer_vulkan/vk_query_cache.h" | 25 | #include "video_core/renderer_vulkan/vk_query_cache.h" |
| 27 | #include "video_core/renderer_vulkan/vk_scheduler.h" | 26 | #include "video_core/renderer_vulkan/vk_scheduler.h" |
| @@ -30,6 +29,7 @@ | |||
| 30 | #include "video_core/renderer_vulkan/vk_texture_cache.h" | 29 | #include "video_core/renderer_vulkan/vk_texture_cache.h" |
| 31 | #include "video_core/renderer_vulkan/vk_update_descriptor.h" | 30 | #include "video_core/renderer_vulkan/vk_update_descriptor.h" |
| 32 | #include "video_core/shader/async_shaders.h" | 31 | #include "video_core/shader/async_shaders.h" |
| 32 | #include "video_core/vulkan_common/vulkan_memory_allocator.h" | ||
| 33 | #include "video_core/vulkan_common/vulkan_wrapper.h" | 33 | #include "video_core/vulkan_common/vulkan_wrapper.h" |
| 34 | 34 | ||
| 35 | namespace Core { | 35 | namespace Core { |
diff --git a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h index 05697e47c..1a4338609 100644 --- a/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h +++ b/src/video_core/renderer_vulkan/vk_staging_buffer_pool.h | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 11 | 11 | ||
| 12 | #include "video_core/renderer_vulkan/vk_memory_manager.h" | 12 | #include "video_core/vulkan_common/vulkan_memory_allocator.h" |
| 13 | #include "video_core/vulkan_common/vulkan_wrapper.h" | 13 | #include "video_core/vulkan_common/vulkan_wrapper.h" |
| 14 | 14 | ||
| 15 | namespace Vulkan { | 15 | namespace Vulkan { |
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index a0a9b9559..15cd50c24 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp | |||
| @@ -10,12 +10,12 @@ | |||
| 10 | #include "video_core/engines/fermi_2d.h" | 10 | #include "video_core/engines/fermi_2d.h" |
| 11 | #include "video_core/renderer_vulkan/blit_image.h" | 11 | #include "video_core/renderer_vulkan/blit_image.h" |
| 12 | #include "video_core/renderer_vulkan/maxwell_to_vk.h" | 12 | #include "video_core/renderer_vulkan/maxwell_to_vk.h" |
| 13 | #include "video_core/renderer_vulkan/vk_memory_manager.h" | ||
| 14 | #include "video_core/renderer_vulkan/vk_rasterizer.h" | 13 | #include "video_core/renderer_vulkan/vk_rasterizer.h" |
| 15 | #include "video_core/renderer_vulkan/vk_scheduler.h" | 14 | #include "video_core/renderer_vulkan/vk_scheduler.h" |
| 16 | #include "video_core/renderer_vulkan/vk_staging_buffer_pool.h" | 15 | #include "video_core/renderer_vulkan/vk_staging_buffer_pool.h" |
| 17 | #include "video_core/renderer_vulkan/vk_texture_cache.h" | 16 | #include "video_core/renderer_vulkan/vk_texture_cache.h" |
| 18 | #include "video_core/vulkan_common/vulkan_device.h" | 17 | #include "video_core/vulkan_common/vulkan_device.h" |
| 18 | #include "video_core/vulkan_common/vulkan_memory_allocator.h" | ||
| 19 | #include "video_core/vulkan_common/vulkan_wrapper.h" | 19 | #include "video_core/vulkan_common/vulkan_wrapper.h" |
| 20 | 20 | ||
| 21 | namespace Vulkan { | 21 | namespace Vulkan { |
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.h b/src/video_core/renderer_vulkan/vk_texture_cache.h index 6a276d578..5da791a56 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.h +++ b/src/video_core/renderer_vulkan/vk_texture_cache.h | |||
| @@ -7,8 +7,8 @@ | |||
| 7 | #include <compare> | 7 | #include <compare> |
| 8 | #include <span> | 8 | #include <span> |
| 9 | 9 | ||
| 10 | #include "video_core/renderer_vulkan/vk_memory_manager.h" | ||
| 11 | #include "video_core/texture_cache/texture_cache.h" | 10 | #include "video_core/texture_cache/texture_cache.h" |
| 11 | #include "video_core/vulkan_common/vulkan_memory_allocator.h" | ||
| 12 | #include "video_core/vulkan_common/vulkan_wrapper.h" | 12 | #include "video_core/vulkan_common/vulkan_wrapper.h" |
| 13 | 13 | ||
| 14 | namespace Vulkan { | 14 | namespace Vulkan { |