Skip to content
Snippets Groups Projects
Commit d71e19fd authored by Lioncash's avatar Lioncash
Browse files

video_core/memory_manager: Avoid repeated unnecessary page slot lookups

We don't need to keep calling the same function over and over again in a
loop, especially when the behavior is slightly non-trivial. We can just
keep a reference to the looked up location and do all the checking and
assignments based off it instead.
parent 316c994f
No related branches found
No related tags found
No related merge requests found
...@@ -13,8 +13,10 @@ GPUVAddr MemoryManager::AllocateSpace(u64 size, u64 align) { ...@@ -13,8 +13,10 @@ GPUVAddr MemoryManager::AllocateSpace(u64 size, u64 align) {
ASSERT(gpu_addr); ASSERT(gpu_addr);
for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { for (u64 offset = 0; offset < size; offset += PAGE_SIZE) {
ASSERT(PageSlot(*gpu_addr + offset) == static_cast<u64>(PageStatus::Unmapped)); VAddr& slot = PageSlot(*gpu_addr + offset);
PageSlot(*gpu_addr + offset) = static_cast<u64>(PageStatus::Allocated);
ASSERT(slot == static_cast<u64>(PageStatus::Unmapped));
slot = static_cast<u64>(PageStatus::Allocated);
} }
return *gpu_addr; return *gpu_addr;
...@@ -22,8 +24,10 @@ GPUVAddr MemoryManager::AllocateSpace(u64 size, u64 align) { ...@@ -22,8 +24,10 @@ GPUVAddr MemoryManager::AllocateSpace(u64 size, u64 align) {
GPUVAddr MemoryManager::AllocateSpace(GPUVAddr gpu_addr, u64 size, u64 align) { GPUVAddr MemoryManager::AllocateSpace(GPUVAddr gpu_addr, u64 size, u64 align) {
for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { for (u64 offset = 0; offset < size; offset += PAGE_SIZE) {
ASSERT(PageSlot(gpu_addr + offset) == static_cast<u64>(PageStatus::Unmapped)); VAddr& slot = PageSlot(gpu_addr + offset);
PageSlot(gpu_addr + offset) = static_cast<u64>(PageStatus::Allocated);
ASSERT(slot == static_cast<u64>(PageStatus::Unmapped));
slot = static_cast<u64>(PageStatus::Allocated);
} }
return gpu_addr; return gpu_addr;
...@@ -34,8 +38,10 @@ GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, u64 size) { ...@@ -34,8 +38,10 @@ GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, u64 size) {
ASSERT(gpu_addr); ASSERT(gpu_addr);
for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { for (u64 offset = 0; offset < size; offset += PAGE_SIZE) {
ASSERT(PageSlot(*gpu_addr + offset) == static_cast<u64>(PageStatus::Unmapped)); VAddr& slot = PageSlot(*gpu_addr + offset);
PageSlot(*gpu_addr + offset) = cpu_addr + offset;
ASSERT(slot == static_cast<u64>(PageStatus::Unmapped));
slot = cpu_addr + offset;
} }
MappedRegion region{cpu_addr, *gpu_addr, size}; MappedRegion region{cpu_addr, *gpu_addr, size};
...@@ -48,8 +54,10 @@ GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, GPUVAddr gpu_addr, u64 size) ...@@ -48,8 +54,10 @@ GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, GPUVAddr gpu_addr, u64 size)
ASSERT((gpu_addr & PAGE_MASK) == 0); ASSERT((gpu_addr & PAGE_MASK) == 0);
for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { for (u64 offset = 0; offset < size; offset += PAGE_SIZE) {
ASSERT(PageSlot(gpu_addr + offset) == static_cast<u64>(PageStatus::Allocated)); VAddr& slot = PageSlot(gpu_addr + offset);
PageSlot(gpu_addr + offset) = cpu_addr + offset;
ASSERT(slot == static_cast<u64>(PageStatus::Allocated));
slot = cpu_addr + offset;
} }
MappedRegion region{cpu_addr, gpu_addr, size}; MappedRegion region{cpu_addr, gpu_addr, size};
...@@ -62,9 +70,11 @@ GPUVAddr MemoryManager::UnmapBuffer(GPUVAddr gpu_addr, u64 size) { ...@@ -62,9 +70,11 @@ GPUVAddr MemoryManager::UnmapBuffer(GPUVAddr gpu_addr, u64 size) {
ASSERT((gpu_addr & PAGE_MASK) == 0); ASSERT((gpu_addr & PAGE_MASK) == 0);
for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { for (u64 offset = 0; offset < size; offset += PAGE_SIZE) {
ASSERT(PageSlot(gpu_addr + offset) != static_cast<u64>(PageStatus::Allocated) && VAddr& slot = PageSlot(gpu_addr + offset);
PageSlot(gpu_addr + offset) != static_cast<u64>(PageStatus::Unmapped));
PageSlot(gpu_addr + offset) = static_cast<u64>(PageStatus::Unmapped); ASSERT(slot != static_cast<u64>(PageStatus::Allocated) &&
slot != static_cast<u64>(PageStatus::Unmapped));
slot = static_cast<u64>(PageStatus::Unmapped);
} }
// Delete the region mappings that are contained within the unmapped region // Delete the region mappings that are contained within the unmapped region
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment