yuzu-emu
/
yuzu
Archived
1
0
Fork 0

memory_manager: Make use of [[nodiscard]] in the interface

This commit is contained in:
Lioncash 2020-08-26 20:14:13 -04:00
parent d12d59f62a
commit 7b50c48df7
1 changed files with 17 additions and 17 deletions

View File

@ -31,19 +31,19 @@ public:
constexpr PageEntry(State state) : state{state} {} constexpr PageEntry(State state) : state{state} {}
constexpr PageEntry(VAddr addr) : state{static_cast<State>(addr >> ShiftBits)} {} constexpr PageEntry(VAddr addr) : state{static_cast<State>(addr >> ShiftBits)} {}
constexpr bool IsUnmapped() const { [[nodiscard]] constexpr bool IsUnmapped() const {
return state == State::Unmapped; return state == State::Unmapped;
} }
constexpr bool IsAllocated() const { [[nodiscard]] constexpr bool IsAllocated() const {
return state == State::Allocated; return state == State::Allocated;
} }
constexpr bool IsValid() const { [[nodiscard]] constexpr bool IsValid() const {
return !IsUnmapped() && !IsAllocated(); return !IsUnmapped() && !IsAllocated();
} }
constexpr VAddr ToAddress() const { [[nodiscard]] constexpr VAddr ToAddress() const {
if (!IsValid()) { if (!IsValid()) {
return {}; return {};
} }
@ -51,7 +51,7 @@ public:
return static_cast<VAddr>(state) << ShiftBits; return static_cast<VAddr>(state) << ShiftBits;
} }
constexpr PageEntry operator+(u64 offset) const { [[nodiscard]] constexpr PageEntry operator+(u64 offset) const {
// If this is a reserved value, offsets do not apply // If this is a reserved value, offsets do not apply
if (!IsValid()) { if (!IsValid()) {
return *this; return *this;
@ -74,16 +74,16 @@ public:
/// Binds a renderer to the memory manager. /// Binds a renderer to the memory manager.
void BindRasterizer(VideoCore::RasterizerInterface& rasterizer); void BindRasterizer(VideoCore::RasterizerInterface& rasterizer);
std::optional<VAddr> GpuToCpuAddress(GPUVAddr addr) const; [[nodiscard]] std::optional<VAddr> GpuToCpuAddress(GPUVAddr addr) const;
template <typename T> template <typename T>
T Read(GPUVAddr addr) const; [[nodiscard]] T Read(GPUVAddr addr) const;
template <typename T> template <typename T>
void Write(GPUVAddr addr, T data); void Write(GPUVAddr addr, T data);
u8* GetPointer(GPUVAddr addr); [[nodiscard]] u8* GetPointer(GPUVAddr addr);
const u8* GetPointer(GPUVAddr addr) const; [[nodiscard]] const u8* GetPointer(GPUVAddr addr) const;
/** /**
* ReadBlock and WriteBlock are full read and write operations over virtual * ReadBlock and WriteBlock are full read and write operations over virtual
@ -112,24 +112,24 @@ public:
/** /**
* IsGranularRange checks if a gpu region can be simply read with a pointer. * IsGranularRange checks if a gpu region can be simply read with a pointer.
*/ */
bool IsGranularRange(GPUVAddr gpu_addr, std::size_t size) const; [[nodiscard]] bool IsGranularRange(GPUVAddr gpu_addr, std::size_t size) const;
GPUVAddr Map(VAddr cpu_addr, GPUVAddr gpu_addr, std::size_t size); [[nodiscard]] GPUVAddr Map(VAddr cpu_addr, GPUVAddr gpu_addr, std::size_t size);
GPUVAddr MapAllocate(VAddr cpu_addr, std::size_t size, std::size_t align); [[nodiscard]] GPUVAddr MapAllocate(VAddr cpu_addr, std::size_t size, std::size_t align);
std::optional<GPUVAddr> AllocateFixed(GPUVAddr gpu_addr, std::size_t size); [[nodiscard]] std::optional<GPUVAddr> AllocateFixed(GPUVAddr gpu_addr, std::size_t size);
GPUVAddr Allocate(std::size_t size, std::size_t align); [[nodiscard]] GPUVAddr Allocate(std::size_t size, std::size_t align);
void Unmap(GPUVAddr gpu_addr, std::size_t size); void Unmap(GPUVAddr gpu_addr, std::size_t size);
private: private:
PageEntry GetPageEntry(GPUVAddr gpu_addr) const; [[nodiscard]] PageEntry GetPageEntry(GPUVAddr gpu_addr) const;
void SetPageEntry(GPUVAddr gpu_addr, PageEntry page_entry, std::size_t size = page_size); void SetPageEntry(GPUVAddr gpu_addr, PageEntry page_entry, std::size_t size = page_size);
GPUVAddr UpdateRange(GPUVAddr gpu_addr, PageEntry page_entry, std::size_t size); GPUVAddr UpdateRange(GPUVAddr gpu_addr, PageEntry page_entry, std::size_t size);
std::optional<GPUVAddr> FindFreeRange(std::size_t size, std::size_t align) const; [[nodiscard]] std::optional<GPUVAddr> FindFreeRange(std::size_t size, std::size_t align) const;
void TryLockPage(PageEntry page_entry, std::size_t size); void TryLockPage(PageEntry page_entry, std::size_t size);
void TryUnlockPage(PageEntry page_entry, std::size_t size); void TryUnlockPage(PageEntry page_entry, std::size_t size);
static constexpr std::size_t PageEntryIndex(GPUVAddr gpu_addr) { [[nodiscard]] static constexpr std::size_t PageEntryIndex(GPUVAddr gpu_addr) {
return (gpu_addr >> page_bits) & page_table_mask; return (gpu_addr >> page_bits) & page_table_mask;
} }