mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-12-26 20:20:07 +00:00
memory_manager: Cleanup FindFreeRegion.
This commit is contained in:
parent
5a5fccaa23
commit
2117edd0f8
@ -30,8 +30,7 @@ MemoryManager::MemoryManager() {
|
|||||||
|
|
||||||
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{
|
const GPUVAddr gpu_addr{FindFreeRegion(address_space_base, aligned_size)};
|
||||||
FindFreeRegion(address_space_base, aligned_size, align, VirtualMemoryArea::Type::Unmapped)};
|
|
||||||
|
|
||||||
AllocateMemory(gpu_addr, 0, aligned_size);
|
AllocateMemory(gpu_addr, 0, aligned_size);
|
||||||
|
|
||||||
@ -48,8 +47,7 @@ GPUVAddr MemoryManager::AllocateSpace(GPUVAddr gpu_addr, u64 size, u64 align) {
|
|||||||
|
|
||||||
GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, u64 size) {
|
GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, u64 size) {
|
||||||
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, page_size,
|
const GPUVAddr gpu_addr{FindFreeRegion(address_space_base, aligned_size)};
|
||||||
VirtualMemoryArea::Type::Unmapped)};
|
|
||||||
|
|
||||||
MapBackingMemory(gpu_addr, Memory::GetPointer(cpu_addr), aligned_size, cpu_addr);
|
MapBackingMemory(gpu_addr, Memory::GetPointer(cpu_addr), aligned_size, cpu_addr);
|
||||||
|
|
||||||
@ -79,14 +77,10 @@ GPUVAddr MemoryManager::UnmapBuffer(GPUVAddr gpu_addr, u64 size) {
|
|||||||
return gpu_addr;
|
return gpu_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GPUVAddr MemoryManager::FindFreeRegion(GPUVAddr region_start, u64 size, u64 align,
|
GPUVAddr MemoryManager::FindFreeRegion(GPUVAddr region_start, u64 size) {
|
||||||
VirtualMemoryArea::Type vma_type) {
|
|
||||||
|
|
||||||
align = (align + page_mask) & ~page_mask;
|
|
||||||
|
|
||||||
// Find the first Free VMA.
|
// Find the first Free VMA.
|
||||||
const VMAHandle vma_handle{std::find_if(vma_map.begin(), vma_map.end(), [&](const auto& vma) {
|
const VMAHandle vma_handle{std::find_if(vma_map.begin(), vma_map.end(), [&](const auto& vma) {
|
||||||
if (vma.second.type != vma_type) {
|
if (vma.second.type != VirtualMemoryArea::Type::Unmapped) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,8 +126,8 @@ private:
|
|||||||
/// Updates the pages corresponding to this VMA so they match the VMA's attributes.
|
/// Updates the pages corresponding to this VMA so they match the VMA's attributes.
|
||||||
void UpdatePageTableForVMA(const VirtualMemoryArea& vma);
|
void UpdatePageTableForVMA(const VirtualMemoryArea& vma);
|
||||||
|
|
||||||
GPUVAddr FindFreeRegion(GPUVAddr region_start, u64 size, u64 align,
|
/// Finds a free (unmapped region) of the specified size starting at the specified address.
|
||||||
VirtualMemoryArea::Type vma_type);
|
GPUVAddr FindFreeRegion(GPUVAddr region_start, u64 size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr u64 page_bits{16};
|
static constexpr u64 page_bits{16};
|
||||||
|
Loading…
Reference in New Issue
Block a user