mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-07-04 23:31:19 +01:00
Merge pull request #2462 from lioncash/video-mm
video_core/memory_manager: Minor tidying
This commit is contained in:
commit
c4d549919f
2 changed files with 20 additions and 17 deletions
|
@ -25,6 +25,8 @@ MemoryManager::MemoryManager(VideoCore::RasterizerInterface& rasterizer) : raste
|
||||||
UpdatePageTableForVMA(initial_vma);
|
UpdatePageTableForVMA(initial_vma);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MemoryManager::~MemoryManager() = default;
|
||||||
|
|
||||||
GPUVAddr MemoryManager::AllocateSpace(u64 size, u64 align) {
|
GPUVAddr MemoryManager::AllocateSpace(u64 size, u64 align) {
|
||||||
const u64 aligned_size{Common::AlignUp(size, page_size)};
|
const u64 aligned_size{Common::AlignUp(size, page_size)};
|
||||||
const GPUVAddr gpu_addr{FindFreeRegion(address_space_base, aligned_size)};
|
const GPUVAddr gpu_addr{FindFreeRegion(address_space_base, aligned_size)};
|
||||||
|
@ -199,11 +201,11 @@ const u8* MemoryManager::GetPointer(GPUVAddr addr) const {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MemoryManager::IsBlockContinous(const GPUVAddr start, const std::size_t size) {
|
bool MemoryManager::IsBlockContinuous(const GPUVAddr start, const std::size_t size) const {
|
||||||
const GPUVAddr end = start + size;
|
const GPUVAddr end = start + size;
|
||||||
const auto host_ptr_start = reinterpret_cast<std::uintptr_t>(GetPointer(start));
|
const auto host_ptr_start = reinterpret_cast<std::uintptr_t>(GetPointer(start));
|
||||||
const auto host_ptr_end = reinterpret_cast<std::uintptr_t>(GetPointer(end));
|
const auto host_ptr_end = reinterpret_cast<std::uintptr_t>(GetPointer(end));
|
||||||
const std::size_t range = static_cast<std::size_t>(host_ptr_end - host_ptr_start);
|
const auto range = static_cast<std::size_t>(host_ptr_end - host_ptr_start);
|
||||||
return range == size;
|
return range == size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,8 @@ struct VirtualMemoryArea {
|
||||||
|
|
||||||
class MemoryManager final {
|
class MemoryManager final {
|
||||||
public:
|
public:
|
||||||
MemoryManager(VideoCore::RasterizerInterface& rasterizer);
|
explicit MemoryManager(VideoCore::RasterizerInterface& rasterizer);
|
||||||
|
~MemoryManager();
|
||||||
|
|
||||||
GPUVAddr AllocateSpace(u64 size, u64 align);
|
GPUVAddr AllocateSpace(u64 size, u64 align);
|
||||||
GPUVAddr AllocateSpace(GPUVAddr addr, u64 size, u64 align);
|
GPUVAddr AllocateSpace(GPUVAddr addr, u64 size, u64 align);
|
||||||
|
@ -65,18 +66,18 @@ public:
|
||||||
u8* GetPointer(GPUVAddr addr);
|
u8* GetPointer(GPUVAddr addr);
|
||||||
const u8* GetPointer(GPUVAddr addr) const;
|
const u8* GetPointer(GPUVAddr addr) const;
|
||||||
|
|
||||||
// Returns true if the block is continous in host memory, false otherwise
|
/// Returns true if the block is continuous in host memory, false otherwise
|
||||||
bool IsBlockContinous(const GPUVAddr start, const std::size_t size);
|
bool IsBlockContinuous(GPUVAddr start, std::size_t size) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ReadBlock and WriteBlock are full read and write operations over virtual
|
* ReadBlock and WriteBlock are full read and write operations over virtual
|
||||||
* GPU Memory. It's important to use these when GPU memory may not be continous
|
* GPU Memory. It's important to use these when GPU memory may not be continuous
|
||||||
* in the Host Memory counterpart. Note: This functions cause Host GPU Memory
|
* in the Host Memory counterpart. Note: This functions cause Host GPU Memory
|
||||||
* Flushes and Invalidations, respectively to each operation.
|
* Flushes and Invalidations, respectively to each operation.
|
||||||
*/
|
*/
|
||||||
void ReadBlock(GPUVAddr src_addr, void* dest_buffer, const std::size_t size) const;
|
void ReadBlock(GPUVAddr src_addr, void* dest_buffer, std::size_t size) const;
|
||||||
void WriteBlock(GPUVAddr dest_addr, const void* src_buffer, const std::size_t size);
|
void WriteBlock(GPUVAddr dest_addr, const void* src_buffer, std::size_t size);
|
||||||
void CopyBlock(GPUVAddr dest_addr, GPUVAddr src_addr, const std::size_t size);
|
void CopyBlock(GPUVAddr dest_addr, GPUVAddr src_addr, std::size_t size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ReadBlockUnsafe and WriteBlockUnsafe are special versions of ReadBlock and
|
* ReadBlockUnsafe and WriteBlockUnsafe are special versions of ReadBlock and
|
||||||
|
@ -88,9 +89,9 @@ public:
|
||||||
* WriteBlockUnsafe instead of WriteBlock since it shouldn't invalidate the texture
|
* WriteBlockUnsafe instead of WriteBlock since it shouldn't invalidate the texture
|
||||||
* being flushed.
|
* being flushed.
|
||||||
*/
|
*/
|
||||||
void ReadBlockUnsafe(GPUVAddr src_addr, void* dest_buffer, const std::size_t size) const;
|
void ReadBlockUnsafe(GPUVAddr src_addr, void* dest_buffer, std::size_t size) const;
|
||||||
void WriteBlockUnsafe(GPUVAddr dest_addr, const void* src_buffer, const std::size_t size);
|
void WriteBlockUnsafe(GPUVAddr dest_addr, const void* src_buffer, std::size_t size);
|
||||||
void CopyBlockUnsafe(GPUVAddr dest_addr, GPUVAddr src_addr, const std::size_t size);
|
void CopyBlockUnsafe(GPUVAddr dest_addr, GPUVAddr src_addr, std::size_t size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using VMAMap = std::map<GPUVAddr, VirtualMemoryArea>;
|
using VMAMap = std::map<GPUVAddr, VirtualMemoryArea>;
|
||||||
|
@ -113,8 +114,8 @@ private:
|
||||||
*
|
*
|
||||||
* @param target The guest address to start the mapping at.
|
* @param target The guest address to start the mapping at.
|
||||||
* @param memory The memory to be mapped.
|
* @param memory The memory to be mapped.
|
||||||
* @param size Size of the mapping.
|
* @param size Size of the mapping in bytes.
|
||||||
* @param state MemoryState tag to attach to the VMA.
|
* @param backing_addr The base address of the range to back this mapping.
|
||||||
*/
|
*/
|
||||||
VMAHandle MapBackingMemory(GPUVAddr target, u8* memory, u64 size, VAddr backing_addr);
|
VMAHandle MapBackingMemory(GPUVAddr target, u8* memory, u64 size, VAddr backing_addr);
|
||||||
|
|
||||||
|
@ -124,7 +125,7 @@ private:
|
||||||
/// Converts a VMAHandle to a mutable VMAIter.
|
/// Converts a VMAHandle to a mutable VMAIter.
|
||||||
VMAIter StripIterConstness(const VMAHandle& iter);
|
VMAIter StripIterConstness(const VMAHandle& iter);
|
||||||
|
|
||||||
/// Marks as the specfied VMA as allocated.
|
/// Marks as the specified VMA as allocated.
|
||||||
VMAIter Allocate(VMAIter vma);
|
VMAIter Allocate(VMAIter vma);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue