diff options
| -rw-r--r-- | src/video_core/memory_manager.cpp | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp index 2f814a184..ca923d17d 100644 --- a/src/video_core/memory_manager.cpp +++ b/src/video_core/memory_manager.cpp | |||
| @@ -13,8 +13,10 @@ GPUVAddr MemoryManager::AllocateSpace(u64 size, u64 align) { | |||
| 13 | ASSERT(gpu_addr); | 13 | ASSERT(gpu_addr); |
| 14 | 14 | ||
| 15 | for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { | 15 | for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { |
| 16 | ASSERT(PageSlot(*gpu_addr + offset) == static_cast<u64>(PageStatus::Unmapped)); | 16 | VAddr& slot = PageSlot(*gpu_addr + offset); |
| 17 | PageSlot(*gpu_addr + offset) = static_cast<u64>(PageStatus::Allocated); | 17 | |
| 18 | ASSERT(slot == static_cast<u64>(PageStatus::Unmapped)); | ||
| 19 | slot = static_cast<u64>(PageStatus::Allocated); | ||
| 18 | } | 20 | } |
| 19 | 21 | ||
| 20 | return *gpu_addr; | 22 | return *gpu_addr; |
| @@ -22,8 +24,10 @@ GPUVAddr MemoryManager::AllocateSpace(u64 size, u64 align) { | |||
| 22 | 24 | ||
| 23 | GPUVAddr MemoryManager::AllocateSpace(GPUVAddr gpu_addr, u64 size, u64 align) { | 25 | GPUVAddr MemoryManager::AllocateSpace(GPUVAddr gpu_addr, u64 size, u64 align) { |
| 24 | for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { | 26 | for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { |
| 25 | ASSERT(PageSlot(gpu_addr + offset) == static_cast<u64>(PageStatus::Unmapped)); | 27 | VAddr& slot = PageSlot(gpu_addr + offset); |
| 26 | PageSlot(gpu_addr + offset) = static_cast<u64>(PageStatus::Allocated); | 28 | |
| 29 | ASSERT(slot == static_cast<u64>(PageStatus::Unmapped)); | ||
| 30 | slot = static_cast<u64>(PageStatus::Allocated); | ||
| 27 | } | 31 | } |
| 28 | 32 | ||
| 29 | return gpu_addr; | 33 | return gpu_addr; |
| @@ -34,8 +38,10 @@ GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, u64 size) { | |||
| 34 | ASSERT(gpu_addr); | 38 | ASSERT(gpu_addr); |
| 35 | 39 | ||
| 36 | for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { | 40 | for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { |
| 37 | ASSERT(PageSlot(*gpu_addr + offset) == static_cast<u64>(PageStatus::Unmapped)); | 41 | VAddr& slot = PageSlot(*gpu_addr + offset); |
| 38 | PageSlot(*gpu_addr + offset) = cpu_addr + offset; | 42 | |
| 43 | ASSERT(slot == static_cast<u64>(PageStatus::Unmapped)); | ||
| 44 | slot = cpu_addr + offset; | ||
| 39 | } | 45 | } |
| 40 | 46 | ||
| 41 | MappedRegion region{cpu_addr, *gpu_addr, size}; | 47 | MappedRegion region{cpu_addr, *gpu_addr, size}; |
| @@ -48,8 +54,10 @@ GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, GPUVAddr gpu_addr, u64 size) | |||
| 48 | ASSERT((gpu_addr & PAGE_MASK) == 0); | 54 | ASSERT((gpu_addr & PAGE_MASK) == 0); |
| 49 | 55 | ||
| 50 | for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { | 56 | for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { |
| 51 | ASSERT(PageSlot(gpu_addr + offset) == static_cast<u64>(PageStatus::Allocated)); | 57 | VAddr& slot = PageSlot(gpu_addr + offset); |
| 52 | PageSlot(gpu_addr + offset) = cpu_addr + offset; | 58 | |
| 59 | ASSERT(slot == static_cast<u64>(PageStatus::Allocated)); | ||
| 60 | slot = cpu_addr + offset; | ||
| 53 | } | 61 | } |
| 54 | 62 | ||
| 55 | MappedRegion region{cpu_addr, gpu_addr, size}; | 63 | MappedRegion region{cpu_addr, gpu_addr, size}; |
| @@ -62,9 +70,11 @@ GPUVAddr MemoryManager::UnmapBuffer(GPUVAddr gpu_addr, u64 size) { | |||
| 62 | ASSERT((gpu_addr & PAGE_MASK) == 0); | 70 | ASSERT((gpu_addr & PAGE_MASK) == 0); |
| 63 | 71 | ||
| 64 | for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { | 72 | for (u64 offset = 0; offset < size; offset += PAGE_SIZE) { |
| 65 | ASSERT(PageSlot(gpu_addr + offset) != static_cast<u64>(PageStatus::Allocated) && | 73 | VAddr& slot = PageSlot(gpu_addr + offset); |
| 66 | PageSlot(gpu_addr + offset) != static_cast<u64>(PageStatus::Unmapped)); | 74 | |
| 67 | PageSlot(gpu_addr + offset) = static_cast<u64>(PageStatus::Unmapped); | 75 | ASSERT(slot != static_cast<u64>(PageStatus::Allocated) && |
| 76 | slot != static_cast<u64>(PageStatus::Unmapped)); | ||
| 77 | slot = static_cast<u64>(PageStatus::Unmapped); | ||
| 68 | } | 78 | } |
| 69 | 79 | ||
| 70 | // Delete the region mappings that are contained within the unmapped region | 80 | // Delete the region mappings that are contained within the unmapped region |
| @@ -128,9 +138,7 @@ VAddr& MemoryManager::PageSlot(GPUVAddr gpu_addr) { | |||
| 128 | auto& block = page_table[(gpu_addr >> (PAGE_BITS + PAGE_TABLE_BITS)) & PAGE_TABLE_MASK]; | 138 | auto& block = page_table[(gpu_addr >> (PAGE_BITS + PAGE_TABLE_BITS)) & PAGE_TABLE_MASK]; |
| 129 | if (!block) { | 139 | if (!block) { |
| 130 | block = std::make_unique<PageBlock>(); | 140 | block = std::make_unique<PageBlock>(); |
| 131 | for (unsigned index = 0; index < PAGE_BLOCK_SIZE; index++) { | 141 | block->fill(static_cast<VAddr>(PageStatus::Unmapped)); |
| 132 | (*block)[index] = static_cast<u64>(PageStatus::Unmapped); | ||
| 133 | } | ||
| 134 | } | 142 | } |
| 135 | return (*block)[(gpu_addr >> PAGE_BITS) & PAGE_BLOCK_MASK]; | 143 | return (*block)[(gpu_addr >> PAGE_BITS) & PAGE_BLOCK_MASK]; |
| 136 | } | 144 | } |