yuzu-emu
/
yuzu
Archived
1
0
Fork 0

vulkan_memory_allocator: Remove unnecesary 'device' memory from commits

This commit is contained in:
ReinUsesLisp 2021-01-06 01:18:37 -03:00
parent 432f045dba
commit 301e2b5b7a
2 changed files with 15 additions and 15 deletions

View File

@ -71,7 +71,7 @@ public:
.end = *alloc + size, .end = *alloc + size,
}; };
commits.insert(std::ranges::upper_bound(commits, *alloc, {}, &Range::begin), range); commits.insert(std::ranges::upper_bound(commits, *alloc, {}, &Range::begin), range);
return std::make_optional<MemoryCommit>(device, this, *memory, *alloc, *alloc + size); return std::make_optional<MemoryCommit>(this, *memory, *alloc, *alloc + size);
} }
void Free(u64 begin) { void Free(u64 begin) {
@ -127,9 +127,9 @@ private:
std::span<u8> memory_mapped_span; ///< Memory mapped span. Empty if not queried before. std::span<u8> memory_mapped_span; ///< Memory mapped span. Empty if not queried before.
}; };
MemoryCommit::MemoryCommit(const Device& device_, MemoryAllocation* allocation_, MemoryCommit::MemoryCommit(MemoryAllocation* allocation_, VkDeviceMemory memory_, u64 begin_,
VkDeviceMemory memory_, u64 begin, u64 end) noexcept u64 end_) noexcept
: device{&device_}, allocation{allocation_}, memory{memory_}, interval{begin, end} {} : allocation{allocation_}, memory{memory_}, begin{begin_}, end{end_} {}
MemoryCommit::~MemoryCommit() { MemoryCommit::~MemoryCommit() {
Release(); Release();
@ -137,28 +137,28 @@ MemoryCommit::~MemoryCommit() {
MemoryCommit& MemoryCommit::operator=(MemoryCommit&& rhs) noexcept { MemoryCommit& MemoryCommit::operator=(MemoryCommit&& rhs) noexcept {
Release(); Release();
device = rhs.device;
allocation = std::exchange(rhs.allocation, nullptr); allocation = std::exchange(rhs.allocation, nullptr);
memory = rhs.memory; memory = rhs.memory;
interval = rhs.interval; begin = rhs.begin;
end = rhs.end;
span = std::exchange(rhs.span, std::span<u8>{}); span = std::exchange(rhs.span, std::span<u8>{});
return *this; return *this;
} }
MemoryCommit::MemoryCommit(MemoryCommit&& rhs) noexcept MemoryCommit::MemoryCommit(MemoryCommit&& rhs) noexcept
: device{rhs.device}, allocation{std::exchange(rhs.allocation, nullptr)}, memory{rhs.memory}, : allocation{std::exchange(rhs.allocation, nullptr)}, memory{rhs.memory}, begin{rhs.begin},
interval{rhs.interval}, span{std::exchange(rhs.span, std::span<u8>{})} {} end{rhs.end}, span{std::exchange(rhs.span, std::span<u8>{})} {}
std::span<u8> MemoryCommit::Map() { std::span<u8> MemoryCommit::Map() {
if (span.empty()) { if (span.empty()) {
span = allocation->Map().subspan(interval.first, interval.second - interval.first); span = allocation->Map().subspan(begin, end - begin);
} }
return span; return span;
} }
void MemoryCommit::Release() { void MemoryCommit::Release() {
if (allocation) { if (allocation) {
allocation->Free(interval.first); allocation->Free(begin);
} }
} }

View File

@ -29,8 +29,8 @@ enum class MemoryUsage {
class MemoryCommit { class MemoryCommit {
public: public:
explicit MemoryCommit() noexcept = default; explicit MemoryCommit() noexcept = default;
explicit MemoryCommit(const Device& device_, MemoryAllocation* allocation_, explicit MemoryCommit(MemoryAllocation* allocation_, VkDeviceMemory memory_, u64 begin_,
VkDeviceMemory memory_, u64 begin, u64 end) noexcept; u64 end_) noexcept;
~MemoryCommit(); ~MemoryCommit();
MemoryCommit& operator=(MemoryCommit&&) noexcept; MemoryCommit& operator=(MemoryCommit&&) noexcept;
@ -50,16 +50,16 @@ public:
/// Returns the start position of the commit relative to the allocation. /// Returns the start position of the commit relative to the allocation.
VkDeviceSize Offset() const { VkDeviceSize Offset() const {
return static_cast<VkDeviceSize>(interval.first); return static_cast<VkDeviceSize>(begin);
} }
private: private:
void Release(); void Release();
const Device* device{}; ///< Vulkan device.
MemoryAllocation* allocation{}; ///< Pointer to the large memory allocation. MemoryAllocation* allocation{}; ///< Pointer to the large memory allocation.
VkDeviceMemory memory{}; ///< Vulkan device memory handler. VkDeviceMemory memory{}; ///< Vulkan device memory handler.
std::pair<u64, u64> 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<u8> span; ///< Host visible memory span. Empty if not queried before. std::span<u8> span; ///< Host visible memory span. Empty if not queried before.
}; };