summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2019-11-26 21:19:15 +0100
committerLioncash <mathew1800@gmail.com>2019-11-27 03:55:38 +0100
commit3f08e8d8d4ef16cf2468620fbfbdac46e43dcaef (patch)
tree0e13cc5e2595d7019f8e9e80fe0279dc6a2b1d4c
parentcore: Prepare various classes for memory read/write migration (diff)
downloadyuzu-3f08e8d8d4ef16cf2468620fbfbdac46e43dcaef.tar
yuzu-3f08e8d8d4ef16cf2468620fbfbdac46e43dcaef.tar.gz
yuzu-3f08e8d8d4ef16cf2468620fbfbdac46e43dcaef.tar.bz2
yuzu-3f08e8d8d4ef16cf2468620fbfbdac46e43dcaef.tar.lz
yuzu-3f08e8d8d4ef16cf2468620fbfbdac46e43dcaef.tar.xz
yuzu-3f08e8d8d4ef16cf2468620fbfbdac46e43dcaef.tar.zst
yuzu-3f08e8d8d4ef16cf2468620fbfbdac46e43dcaef.zip
-rw-r--r--src/core/hle/kernel/server_session.cpp3
-rw-r--r--src/core/memory.cpp38
-rw-r--r--src/core/memory.h22
-rw-r--r--src/video_core/memory_manager.cpp4
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp3
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.cpp2
-rw-r--r--src/video_core/renderer_vulkan/vk_buffer_cache.cpp6
7 files changed, 53 insertions, 25 deletions
diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp
index 57878514d..1198c7a97 100644
--- a/src/core/hle/kernel/server_session.cpp
+++ b/src/core/hle/kernel/server_session.cpp
@@ -19,6 +19,7 @@
#include "core/hle/kernel/server_session.h"
#include "core/hle/kernel/session.h"
#include "core/hle/kernel/thread.h"
+#include "core/memory.h"
namespace Kernel {
@@ -133,7 +134,7 @@ ResultCode ServerSession::HandleSyncRequest(std::shared_ptr<Thread> thread,
// from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or
// similar.
Kernel::HLERequestContext context(SharedFrom(this), thread);
- u32* cmd_buf = (u32*)Memory::GetPointer(thread->GetTLSAddress());
+ u32* cmd_buf = (u32*)memory.GetPointer(thread->GetTLSAddress());
context.PopulateFromIncomingCommandBuffer(kernel.CurrentProcess()->GetHandleTable(), cmd_buf);
ResultCode result = RESULT_SUCCESS;
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 017033613..93cd67e39 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -195,6 +195,21 @@ struct Memory::Impl {
return IsValidVirtualAddress(*system.CurrentProcess(), vaddr);
}
+ u8* GetPointer(const VAddr vaddr) {
+ u8* const page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS];
+ if (page_pointer != nullptr) {
+ return page_pointer + (vaddr & PAGE_MASK);
+ }
+
+ if (current_page_table->attributes[vaddr >> PAGE_BITS] ==
+ Common::PageType::RasterizerCachedMemory) {
+ return GetPointerFromVMA(vaddr);
+ }
+
+ LOG_ERROR(HW_Memory, "Unknown GetPointer @ 0x{:016X}", vaddr);
+ return nullptr;
+ }
+
/**
* Maps a region of pages as a specific type.
*
@@ -276,6 +291,14 @@ bool Memory::IsValidVirtualAddress(const VAddr vaddr) const {
return impl->IsValidVirtualAddress(vaddr);
}
+u8* Memory::GetPointer(VAddr vaddr) {
+ return impl->GetPointer(vaddr);
+}
+
+const u8* Memory::GetPointer(VAddr vaddr) const {
+ return impl->GetPointer(vaddr);
+}
+
void SetCurrentPageTable(Kernel::Process& process) {
current_page_table = &process.VMManager().page_table;
@@ -292,21 +315,6 @@ bool IsKernelVirtualAddress(const VAddr vaddr) {
return KERNEL_REGION_VADDR <= vaddr && vaddr < KERNEL_REGION_END;
}
-u8* GetPointer(const VAddr vaddr) {
- u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS];
- if (page_pointer) {
- return page_pointer + (vaddr & PAGE_MASK);
- }
-
- if (current_page_table->attributes[vaddr >> PAGE_BITS] ==
- Common::PageType::RasterizerCachedMemory) {
- return GetPointerFromVMA(vaddr);
- }
-
- LOG_ERROR(HW_Memory, "Unknown GetPointer @ 0x{:016X}", vaddr);
- return nullptr;
-}
-
std::string ReadCString(VAddr vaddr, std::size_t max_length) {
std::string string;
string.reserve(max_length);
diff --git a/src/core/memory.h b/src/core/memory.h
index cacf4fb1a..59b9ce2bb 100644
--- a/src/core/memory.h
+++ b/src/core/memory.h
@@ -132,6 +132,26 @@ public:
*/
bool IsValidVirtualAddress(VAddr vaddr) const;
+ /**
+ * Gets a pointer to the given address.
+ *
+ * @param vaddr Virtual address to retrieve a pointer to.
+ *
+ * @returns The pointer to the given address, if the address is valid.
+ * If the address is not valid, nullptr will be returned.
+ */
+ u8* GetPointer(VAddr vaddr);
+
+ /**
+ * Gets a pointer to the given address.
+ *
+ * @param vaddr Virtual address to retrieve a pointer to.
+ *
+ * @returns The pointer to the given address, if the address is valid.
+ * If the address is not valid, nullptr will be returned.
+ */
+ const u8* GetPointer(VAddr vaddr) const;
+
private:
struct Impl;
std::unique_ptr<Impl> impl;
@@ -162,8 +182,6 @@ void WriteBlock(VAddr dest_addr, const void* src_buffer, std::size_t size);
void ZeroBlock(const Kernel::Process& process, VAddr dest_addr, std::size_t size);
void CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size);
-u8* GetPointer(VAddr vaddr);
-
std::string ReadCString(VAddr vaddr, std::size_t max_length);
/**
diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp
index bffae940c..11848fbce 100644
--- a/src/video_core/memory_manager.cpp
+++ b/src/video_core/memory_manager.cpp
@@ -52,7 +52,7 @@ GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, u64 size) {
const u64 aligned_size{Common::AlignUp(size, page_size)};
const GPUVAddr gpu_addr{FindFreeRegion(address_space_base, aligned_size)};
- MapBackingMemory(gpu_addr, Memory::GetPointer(cpu_addr), aligned_size, cpu_addr);
+ MapBackingMemory(gpu_addr, system.Memory().GetPointer(cpu_addr), aligned_size, cpu_addr);
ASSERT(system.CurrentProcess()
->VMManager()
.SetMemoryAttribute(cpu_addr, size, Kernel::MemoryAttribute::DeviceMapped,
@@ -67,7 +67,7 @@ GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, GPUVAddr gpu_addr, u64 size)
const u64 aligned_size{Common::AlignUp(size, page_size)};
- MapBackingMemory(gpu_addr, Memory::GetPointer(cpu_addr), aligned_size, cpu_addr);
+ MapBackingMemory(gpu_addr, system.Memory().GetPointer(cpu_addr), aligned_size, cpu_addr);
ASSERT(system.CurrentProcess()
->VMManager()
.SetMemoryAttribute(cpu_addr, size, Kernel::MemoryAttribute::DeviceMapped,
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 85f05544c..a568a4343 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -19,6 +19,7 @@
#include "common/scope_exit.h"
#include "core/core.h"
#include "core/hle/kernel/process.h"
+#include "core/memory.h"
#include "core/settings.h"
#include "video_core/engines/kepler_compute.h"
#include "video_core/engines/maxwell_3d.h"
@@ -838,7 +839,7 @@ bool RasterizerOpenGL::AccelerateDisplay(const Tegra::FramebufferConfig& config,
MICROPROFILE_SCOPE(OpenGL_CacheManagement);
const auto surface{
- texture_cache.TryFindFramebufferSurface(Memory::GetPointer(framebuffer_addr))};
+ texture_cache.TryFindFramebufferSurface(system.Memory().GetPointer(framebuffer_addr))};
if (!surface) {
return {};
}
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp
index 7646cbb0e..a57a564f7 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.cpp
+++ b/src/video_core/renderer_opengl/renderer_opengl.cpp
@@ -158,7 +158,7 @@ void RendererOpenGL::LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuf
VideoCore::Surface::PixelFormatFromGPUPixelFormat(framebuffer.pixel_format)};
const u32 bytes_per_pixel{VideoCore::Surface::GetBytesPerPixel(pixel_format)};
const u64 size_in_bytes{framebuffer.stride * framebuffer.height * bytes_per_pixel};
- const auto host_ptr{Memory::GetPointer(framebuffer_addr)};
+ u8* const host_ptr{system.Memory().GetPointer(framebuffer_addr)};
rasterizer->FlushRegion(ToCacheAddr(host_ptr), size_in_bytes);
// TODO(Rodrigo): Read this from HLE
diff --git a/src/video_core/renderer_vulkan/vk_buffer_cache.cpp b/src/video_core/renderer_vulkan/vk_buffer_cache.cpp
index 959638747..46da81aaa 100644
--- a/src/video_core/renderer_vulkan/vk_buffer_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_buffer_cache.cpp
@@ -50,9 +50,9 @@ u64 VKBufferCache::UploadMemory(GPUVAddr gpu_addr, std::size_t size, u64 alignme
// TODO: Figure out which size is the best for given games.
cache &= size >= 2048;
- const auto& host_ptr{Memory::GetPointer(*cpu_addr)};
+ u8* const host_ptr{cpu_memory.GetPointer(*cpu_addr)};
if (cache) {
- auto entry = TryGet(host_ptr);
+ const auto entry = TryGet(host_ptr);
if (entry) {
if (entry->GetSize() >= size && entry->GetAlignment() == alignment) {
return entry->GetOffset();
@@ -64,7 +64,7 @@ u64 VKBufferCache::UploadMemory(GPUVAddr gpu_addr, std::size_t size, u64 alignme
AlignBuffer(alignment);
const u64 uploaded_offset = buffer_offset;
- if (!host_ptr) {
+ if (host_ptr == nullptr) {
return uploaded_offset;
}