diff options
author | Mai M <mathew1800@gmail.com> | 2021-06-11 14:26:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-11 14:26:54 -0400 |
commit | 9951322e5a37a604e185ae7013af7c4cfc5c35f8 (patch) | |
tree | 6d765e2d635990de4acb98c1e2b6ce125546f629 /src/common/host_memory.h | |
parent | 0c0c1a039ec73937db4bc24e0bcbc478e3e6704b (diff) | |
parent | 7f85abb28120fbb57bb813b828ee42f2a2031990 (diff) |
Merge pull request #6422 from FernandoS27/i-am-the-senate
Implement/Port Fastmem from Citra to Yuzu
Diffstat (limited to 'src/common/host_memory.h')
-rw-r--r-- | src/common/host_memory.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/common/host_memory.h b/src/common/host_memory.h new file mode 100644 index 000000000..9b8326d0f --- /dev/null +++ b/src/common/host_memory.h @@ -0,0 +1,70 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <memory> +#include "common/common_types.h" +#include "common/virtual_buffer.h" + +namespace Common { + +/** + * A low level linear memory buffer, which supports multiple mappings + * Its purpose is to rebuild a given sparse memory layout, including mirrors. + */ +class HostMemory { +public: + explicit HostMemory(size_t backing_size_, size_t virtual_size_); + ~HostMemory(); + + /** + * Copy constructors. They shall return a copy of the buffer without the mappings. + * TODO: Implement them with COW if needed. + */ + HostMemory(const HostMemory& other) = delete; + HostMemory& operator=(const HostMemory& other) = delete; + + /** + * Move constructors. They will move the buffer and the mappings to the new object. + */ + HostMemory(HostMemory&& other) noexcept; + HostMemory& operator=(HostMemory&& other) noexcept; + + void Map(size_t virtual_offset, size_t host_offset, size_t length); + + void Unmap(size_t virtual_offset, size_t length); + + void Protect(size_t virtual_offset, size_t length, bool read, bool write); + + [[nodiscard]] u8* BackingBasePointer() noexcept { + return backing_base; + } + [[nodiscard]] const u8* BackingBasePointer() const noexcept { + return backing_base; + } + + [[nodiscard]] u8* VirtualBasePointer() noexcept { + return virtual_base; + } + [[nodiscard]] const u8* VirtualBasePointer() const noexcept { + return virtual_base; + } + +private: + size_t backing_size{}; + size_t virtual_size{}; + + // Low level handler for the platform dependent memory routines + class Impl; + std::unique_ptr<Impl> impl; + u8* backing_base{}; + u8* virtual_base{}; + size_t virtual_base_offset{}; + + // Fallback if fastmem is not supported on this platform + std::unique_ptr<Common::VirtualBuffer<u8>> fallback_buffer; +}; + +} // namespace Common |