diff options
author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2021-01-03 22:38:15 +0100 |
---|---|---|
committer | ReinUsesLisp <reinuseslisp@airmail.cc> | 2021-01-15 20:19:39 +0100 |
commit | 72541af3bc8973fba0f0e3d1302fcd0fa7fb9f06 (patch) | |
tree | 4fc56ddc8b3e1dfe06a4980696025247b5f9d24a /src/video_core/vulkan_common/vulkan_memory_allocator.h | |
parent | vulkan_common: Move allocator to the common directory (diff) | |
download | yuzu-72541af3bc8973fba0f0e3d1302fcd0fa7fb9f06.tar yuzu-72541af3bc8973fba0f0e3d1302fcd0fa7fb9f06.tar.gz yuzu-72541af3bc8973fba0f0e3d1302fcd0fa7fb9f06.tar.bz2 yuzu-72541af3bc8973fba0f0e3d1302fcd0fa7fb9f06.tar.lz yuzu-72541af3bc8973fba0f0e3d1302fcd0fa7fb9f06.tar.xz yuzu-72541af3bc8973fba0f0e3d1302fcd0fa7fb9f06.tar.zst yuzu-72541af3bc8973fba0f0e3d1302fcd0fa7fb9f06.zip |
Diffstat (limited to '')
-rw-r--r-- | src/video_core/vulkan_common/vulkan_memory_allocator.h | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/video_core/vulkan_common/vulkan_memory_allocator.h b/src/video_core/vulkan_common/vulkan_memory_allocator.h index 69a6341e1..efb32167a 100644 --- a/src/video_core/vulkan_common/vulkan_memory_allocator.h +++ b/src/video_core/vulkan_common/vulkan_memory_allocator.h @@ -17,7 +17,16 @@ class Device; class MemoryMap; class MemoryAllocation; -class MemoryCommit final { +/// Hints and requirements for the backing memory type of a commit +enum class MemoryUsage { + DeviceLocal, ///< Hints device local usages, fastest memory type to read and write from the GPU + Upload, ///< Requires a host visible memory type optimized for CPU to GPU uploads + Download, ///< Requires a host visible memory type optimized for GPU to CPU readbacks +}; + +/// Ownership handle of a memory commitment. +/// Points to a subregion of a memory allocation. +class MemoryCommit { public: explicit MemoryCommit() noexcept = default; explicit MemoryCommit(const Device& device_, MemoryAllocation* allocation_, @@ -54,7 +63,9 @@ private: std::span<u8> span; ///< Host visible memory span. Empty if not queried before. }; -class MemoryAllocator final { +/// Memory allocator container. +/// Allocates and releases memory allocations on demand. +class MemoryAllocator { public: explicit MemoryAllocator(const Device& device_); ~MemoryAllocator(); @@ -71,13 +82,13 @@ public: * * @returns A memory commit. */ - MemoryCommit Commit(const VkMemoryRequirements& requirements, bool host_visible); + MemoryCommit Commit(const VkMemoryRequirements& requirements, MemoryUsage usage); /// Commits memory required by the buffer and binds it. - MemoryCommit Commit(const vk::Buffer& buffer, bool host_visible); + MemoryCommit Commit(const vk::Buffer& buffer, MemoryUsage usage); /// Commits memory required by the image and binds it. - MemoryCommit Commit(const vk::Image& image, bool host_visible); + MemoryCommit Commit(const vk::Image& image, MemoryUsage usage); private: /// Allocates a chunk of memory. @@ -92,4 +103,7 @@ private: std::vector<std::unique_ptr<MemoryAllocation>> allocations; ///< Current allocations. }; +/// Returns true when a memory usage is guaranteed to be host visible. +bool IsHostVisible(MemoryUsage usage) noexcept; + } // namespace Vulkan |