From 5a5fccaa23f8670d85666efd6ea12b42883c4edc Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 20 Mar 2019 22:58:49 -0400 Subject: memory_manager: Use Common::AlignUp in public interface as needed. --- src/video_core/memory_manager.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src/video_core') diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp index 0c4cf3974..6dc133c93 100644 --- a/src/video_core/memory_manager.cpp +++ b/src/video_core/memory_manager.cpp @@ -29,30 +29,39 @@ MemoryManager::MemoryManager() { } GPUVAddr MemoryManager::AllocateSpace(u64 size, u64 align) { + const u64 aligned_size{Common::AlignUp(size, page_size)}; const GPUVAddr gpu_addr{ - FindFreeRegion(address_space_base, size, align, VirtualMemoryArea::Type::Unmapped)}; - AllocateMemory(gpu_addr, 0, size); + FindFreeRegion(address_space_base, aligned_size, align, VirtualMemoryArea::Type::Unmapped)}; + + AllocateMemory(gpu_addr, 0, aligned_size); + return gpu_addr; } GPUVAddr MemoryManager::AllocateSpace(GPUVAddr gpu_addr, u64 size, u64 align) { - AllocateMemory(gpu_addr, 0, size); + const u64 aligned_size{Common::AlignUp(size, page_size)}; + + AllocateMemory(gpu_addr, 0, aligned_size); + return gpu_addr; } GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, u64 size) { - const GPUVAddr gpu_addr{ - FindFreeRegion(address_space_base, size, page_size, VirtualMemoryArea::Type::Unmapped)}; - MapBackingMemory(gpu_addr, Memory::GetPointer(cpu_addr), ((size + page_mask) & ~page_mask), - cpu_addr); + const u64 aligned_size{Common::AlignUp(size, page_size)}; + const GPUVAddr gpu_addr{FindFreeRegion(address_space_base, aligned_size, page_size, + VirtualMemoryArea::Type::Unmapped)}; + + MapBackingMemory(gpu_addr, Memory::GetPointer(cpu_addr), aligned_size, cpu_addr); + return gpu_addr; } GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, GPUVAddr gpu_addr, u64 size) { ASSERT((gpu_addr & page_mask) == 0); - MapBackingMemory(gpu_addr, Memory::GetPointer(cpu_addr), ((size + page_mask) & ~page_mask), - cpu_addr); + const u64 aligned_size{Common::AlignUp(size, page_size)}; + + MapBackingMemory(gpu_addr, Memory::GetPointer(cpu_addr), aligned_size, cpu_addr); return gpu_addr; } @@ -60,10 +69,12 @@ GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, GPUVAddr gpu_addr, u64 size) GPUVAddr MemoryManager::UnmapBuffer(GPUVAddr gpu_addr, u64 size) { ASSERT((gpu_addr & page_mask) == 0); + const u64 aligned_size{Common::AlignUp(size, page_size)}; const CacheAddr cache_addr{ToCacheAddr(GetPointer(gpu_addr))}; - Core::System::GetInstance().Renderer().Rasterizer().FlushAndInvalidateRegion(cache_addr, size); - UnmapRange(gpu_addr, ((size + page_mask) & ~page_mask)); + Core::System::GetInstance().Renderer().Rasterizer().FlushAndInvalidateRegion(cache_addr, + aligned_size); + UnmapRange(gpu_addr, aligned_size); return gpu_addr; } -- cgit v1.2.3