summaryrefslogtreecommitdiff
path: root/src/core/device_memory.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2020-04-08 17:39:58 -0400
committerGravatar bunnei2020-04-17 00:59:31 -0400
commita040a152468bbd315781c3d50bea484c07e2e02a (patch)
tree2723c7160111f0328ce13aa09445c8badc02a3bb /src/core/device_memory.cpp
parentcommon: Add VirtualBuffer class, to abstract memory virtualization. (diff)
downloadyuzu-a040a152468bbd315781c3d50bea484c07e2e02a.tar.gz
yuzu-a040a152468bbd315781c3d50bea484c07e2e02a.tar.xz
yuzu-a040a152468bbd315781c3d50bea484c07e2e02a.zip
core: device_memory: Update to use VirtualBuffer class.
Diffstat (limited to 'src/core/device_memory.cpp')
-rw-r--r--src/core/device_memory.cpp38
1 files changed, 5 insertions, 33 deletions
diff --git a/src/core/device_memory.cpp b/src/core/device_memory.cpp
index 1e4187546..61429a6ac 100644
--- a/src/core/device_memory.cpp
+++ b/src/core/device_memory.cpp
@@ -2,49 +2,21 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#ifdef _WIN32
6#include <windows.h>
7#endif
8
9#include "common/assert.h"
10#include "core/core.h" 5#include "core/core.h"
11#include "core/device_memory.h" 6#include "core/device_memory.h"
12#include "core/memory.h" 7#include "core/memory.h"
13 8
14namespace Core { 9namespace Core {
15 10
16constexpr u64 DramSize{4ULL * 1024 * 1024 * 1024}; 11DeviceMemory::DeviceMemory(System& system) : buffer{DramMemoryMap::Size}, system{system} {}
17
18DeviceMemory::DeviceMemory(System& system) : system{system} {
19#ifdef _WIN32
20 base = static_cast<u8*>(
21 VirtualAlloc(nullptr, // System selects address
22 DramSize, // Size of allocation
23 MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, // Allocate reserved pages
24 PAGE_READWRITE)); // Protection = no access
25#else
26 physical_memory.resize(DramSize);
27 base = physical_memory.data();
28#endif
29}
30 12
31DeviceMemory::~DeviceMemory() { 13DeviceMemory::~DeviceMemory() = default;
32#ifdef _WIN32
33 ASSERT(VirtualFree(base, DramSize, MEM_RELEASE));
34#endif
35}
36 14
37PAddr DeviceMemory::GetPhysicalAddr(VAddr addr) { 15PAddr DeviceMemory::GetPhysicalAddr(VAddr addr) {
38 u8* pointer{system.Memory().GetPointer(addr)}; 16 const u8* const base{system.Memory().GetPointer(addr)};
39 ASSERT(pointer); 17 ASSERT(base);
40 const uintptr_t offset{static_cast<uintptr_t>(pointer - GetPointer(DramMemoryMap::Base))}; 18 const uintptr_t offset{static_cast<uintptr_t>(base - GetPointer(DramMemoryMap::Base))};
41 return DramMemoryMap::Base + offset; 19 return DramMemoryMap::Base + offset;
42} 20}
43 21
44u8* DeviceMemory::GetPointer(PAddr addr) {
45 ASSERT(addr >= DramMemoryMap::Base);
46 ASSERT(addr < DramMemoryMap::Base + DramSize);
47 return base + (addr - DramMemoryMap::Base);
48}
49
50} // namespace Core 22} // namespace Core