From 301e2b5b7a130730f42de2bb6615c0cacd78c7de Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Wed, 6 Jan 2021 01:18:37 -0300 Subject: vulkan_memory_allocator: Remove unnecesary 'device' memory from commits --- .../vulkan_common/vulkan_memory_allocator.cpp | 20 ++++++++++---------- .../vulkan_common/vulkan_memory_allocator.h | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/video_core') diff --git a/src/video_core/vulkan_common/vulkan_memory_allocator.cpp b/src/video_core/vulkan_common/vulkan_memory_allocator.cpp index f15061d0c..d6eb3af31 100644 --- a/src/video_core/vulkan_common/vulkan_memory_allocator.cpp +++ b/src/video_core/vulkan_common/vulkan_memory_allocator.cpp @@ -71,7 +71,7 @@ public: .end = *alloc + size, }; commits.insert(std::ranges::upper_bound(commits, *alloc, {}, &Range::begin), range); - return std::make_optional(device, this, *memory, *alloc, *alloc + size); + return std::make_optional(this, *memory, *alloc, *alloc + size); } void Free(u64 begin) { @@ -127,9 +127,9 @@ private: std::span memory_mapped_span; ///< Memory mapped span. Empty if not queried before. }; -MemoryCommit::MemoryCommit(const Device& device_, MemoryAllocation* allocation_, - VkDeviceMemory memory_, u64 begin, u64 end) noexcept - : device{&device_}, allocation{allocation_}, memory{memory_}, interval{begin, end} {} +MemoryCommit::MemoryCommit(MemoryAllocation* allocation_, VkDeviceMemory memory_, u64 begin_, + u64 end_) noexcept + : allocation{allocation_}, memory{memory_}, begin{begin_}, end{end_} {} MemoryCommit::~MemoryCommit() { Release(); @@ -137,28 +137,28 @@ MemoryCommit::~MemoryCommit() { MemoryCommit& MemoryCommit::operator=(MemoryCommit&& rhs) noexcept { Release(); - device = rhs.device; allocation = std::exchange(rhs.allocation, nullptr); memory = rhs.memory; - interval = rhs.interval; + begin = rhs.begin; + end = rhs.end; span = std::exchange(rhs.span, std::span{}); return *this; } MemoryCommit::MemoryCommit(MemoryCommit&& rhs) noexcept - : device{rhs.device}, allocation{std::exchange(rhs.allocation, nullptr)}, memory{rhs.memory}, - interval{rhs.interval}, span{std::exchange(rhs.span, std::span{})} {} + : allocation{std::exchange(rhs.allocation, nullptr)}, memory{rhs.memory}, begin{rhs.begin}, + end{rhs.end}, span{std::exchange(rhs.span, std::span{})} {} std::span MemoryCommit::Map() { if (span.empty()) { - span = allocation->Map().subspan(interval.first, interval.second - interval.first); + span = allocation->Map().subspan(begin, end - begin); } return span; } void MemoryCommit::Release() { if (allocation) { - allocation->Free(interval.first); + allocation->Free(begin); } } diff --git a/src/video_core/vulkan_common/vulkan_memory_allocator.h b/src/video_core/vulkan_common/vulkan_memory_allocator.h index d4e34c843..53b3b275a 100644 --- a/src/video_core/vulkan_common/vulkan_memory_allocator.h +++ b/src/video_core/vulkan_common/vulkan_memory_allocator.h @@ -29,8 +29,8 @@ enum class MemoryUsage { class MemoryCommit { public: explicit MemoryCommit() noexcept = default; - explicit MemoryCommit(const Device& device_, MemoryAllocation* allocation_, - VkDeviceMemory memory_, u64 begin, u64 end) noexcept; + explicit MemoryCommit(MemoryAllocation* allocation_, VkDeviceMemory memory_, u64 begin_, + u64 end_) noexcept; ~MemoryCommit(); MemoryCommit& operator=(MemoryCommit&&) noexcept; @@ -50,16 +50,16 @@ public: /// Returns the start position of the commit relative to the allocation. VkDeviceSize Offset() const { - return static_cast(interval.first); + return static_cast(begin); } private: void Release(); - const Device* device{}; ///< Vulkan device. MemoryAllocation* allocation{}; ///< Pointer to the large memory allocation. VkDeviceMemory memory{}; ///< Vulkan device memory handler. - std::pair interval{}; ///< Interval where the commit exists. + u64 begin{}; ///< Beginning offset in bytes to where the commit exists. + u64 end{}; ///< Offset in bytes where the commit ends. std::span span; ///< Host visible memory span. Empty if not queried before. }; -- cgit v1.2.3