From 296c458e0e1a293aca746b5990b512d17a56bc93 Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Wed, 21 Nov 2018 12:01:19 -0500 Subject: [PATCH] Memory: move GetPhysicalPointer and IsValidPhysicalAddress into class --- src/audio_core/hle/source.cpp | 2 +- .../debugger/graphics/graphics_cmdlists.cpp | 4 ++- .../debugger/graphics/graphics_surface.cpp | 7 ++--- src/core/hle/kernel/kernel.h | 3 +++ src/core/hle/kernel/memory.cpp | 4 +-- src/core/hle/kernel/memory.h | 2 -- src/core/hle/kernel/process.cpp | 2 +- src/core/hw/gpu.cpp | 26 +++++++++---------- src/core/memory.cpp | 4 +-- src/core/memory.h | 14 +++++----- src/tests/core/memory/memory.cpp | 6 ++--- src/video_core/command_processor.cpp | 12 +++++---- .../renderer_opengl/gl_rasterizer.cpp | 11 ++++---- .../renderer_opengl/gl_rasterizer_cache.cpp | 6 ++--- .../renderer_opengl/renderer_opengl.cpp | 2 +- src/video_core/swrasterizer/framebuffer.cpp | 15 ++++++----- src/video_core/swrasterizer/rasterizer.cpp | 4 ++- src/video_core/vertex_loader.cpp | 17 ++++++------ 18 files changed, 76 insertions(+), 65 deletions(-) diff --git a/src/audio_core/hle/source.cpp b/src/audio_core/hle/source.cpp index 8d42b0b52b..704a79f059 100644 --- a/src/audio_core/hle/source.cpp +++ b/src/audio_core/hle/source.cpp @@ -290,7 +290,7 @@ bool Source::DequeueBuffer() { // This physical address masking occurs due to how the DSP DMA hardware is configured by the // firmware. - const u8* const memory = Memory::GetPhysicalPointer(buf.physical_address & 0xFFFFFFFC); + const u8* const memory = memory_system->GetPhysicalPointer(buf.physical_address & 0xFFFFFFFC); if (memory) { const unsigned num_channels = buf.mono_or_stereo == MonoOrStereo::Stereo ? 2 : 1; switch (buf.format) { diff --git a/src/citra_qt/debugger/graphics/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics/graphics_cmdlists.cpp index 069f84b8e2..6fdfbee1ee 100644 --- a/src/citra_qt/debugger/graphics/graphics_cmdlists.cpp +++ b/src/citra_qt/debugger/graphics/graphics_cmdlists.cpp @@ -17,6 +17,7 @@ #include "citra_qt/util/spinbox.h" #include "citra_qt/util/util.h" #include "common/vector_math.h" +#include "core/core.h" #include "core/memory.h" #include "video_core/debug_utils/debug_utils.h" #include "video_core/pica_state.h" @@ -166,7 +167,8 @@ void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) { const auto format = texture.format; const auto info = Pica::Texture::TextureInfo::FromPicaRegister(config, format); - const u8* src = Memory::GetPhysicalPointer(config.GetPhysicalAddress()); + const u8* src = + Core::System::GetInstance().Memory().GetPhysicalPointer(config.GetPhysicalAddress()); new_info_widget = new TextureInfoWidget(src, info); } if (command_info_widget) { diff --git a/src/citra_qt/debugger/graphics/graphics_surface.cpp b/src/citra_qt/debugger/graphics/graphics_surface.cpp index d480505b06..8b2aa4c9f0 100644 --- a/src/citra_qt/debugger/graphics/graphics_surface.cpp +++ b/src/citra_qt/debugger/graphics/graphics_surface.cpp @@ -14,6 +14,7 @@ #include "citra_qt/debugger/graphics/graphics_surface.h" #include "citra_qt/util/spinbox.h" #include "common/color.h" +#include "core/core.h" #include "core/hw/gpu.h" #include "core/memory.h" #include "video_core/pica_state.h" @@ -283,7 +284,7 @@ void GraphicsSurfaceWidget::Pick(int x, int y) { return; } - u8* buffer = Memory::GetPhysicalPointer(surface_address); + u8* buffer = Core::System::GetInstance().Memory().GetPhysicalPointer(surface_address); if (buffer == nullptr) { surface_info_label->setText(tr("(unable to access pixel data)")); surface_info_label->setAlignment(Qt::AlignCenter); @@ -549,7 +550,7 @@ void GraphicsSurfaceWidget::OnUpdate() { // TODO: Implement a good way to visualize alpha components! QImage decoded_image(surface_width, surface_height, QImage::Format_ARGB32); - u8* buffer = Memory::GetPhysicalPointer(surface_address); + u8* buffer = Core::System::GetInstance().Memory().GetPhysicalPointer(surface_address); if (buffer == nullptr) { surface_picture_label->hide(); @@ -679,7 +680,7 @@ void GraphicsSurfaceWidget::SaveSurface() { if (pixmap) pixmap->save(&file, "PNG"); } else if (selectedFilter == bin_filter) { - const u8* buffer = Memory::GetPhysicalPointer(surface_address); + const u8* buffer = Core::System::GetInstance().Memory().GetPhysicalPointer(surface_address); ASSERT_MSG(buffer != nullptr, "Memory not accessible"); QFile file(filename); diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 7864ec8f9d..0a4aefec09 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -46,6 +46,7 @@ class SharedMemory; class ThreadManager; class TimerManager; class VMManager; +struct AddressMapping; enum class ResetType { OneShot, @@ -216,6 +217,8 @@ public: MemoryRegionInfo* GetMemoryRegion(MemoryRegion region); + void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping); + std::array memory_regions; /// Adds a port to the named port table diff --git a/src/core/hle/kernel/memory.cpp b/src/core/hle/kernel/memory.cpp index b53c273fef..c2d4d3053b 100644 --- a/src/core/hle/kernel/memory.cpp +++ b/src/core/hle/kernel/memory.cpp @@ -83,7 +83,7 @@ MemoryRegionInfo* KernelSystem::GetMemoryRegion(MemoryRegion region) { } } -void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping) { +void KernelSystem::HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping) { using namespace Memory; struct MemoryArea { @@ -128,7 +128,7 @@ void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mappin return; } - u8* target_pointer = Memory::GetPhysicalPointer(area->paddr_base + offset_into_region); + u8* target_pointer = memory.GetPhysicalPointer(area->paddr_base + offset_into_region); // TODO(yuriks): This flag seems to have some other effect, but it's unknown what MemoryState memory_state = mapping.unk_flag ? MemoryState::Static : MemoryState::IO; diff --git a/src/core/hle/kernel/memory.h b/src/core/hle/kernel/memory.h index 67512df79e..bb4e174f79 100644 --- a/src/core/hle/kernel/memory.h +++ b/src/core/hle/kernel/memory.h @@ -62,6 +62,4 @@ struct MemoryRegionInfo { void Free(u32 offset, u32 size); }; -void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping); - } // namespace Kernel diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 62b0caea12..7887832c35 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -136,7 +136,7 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) { // Map special address mappings kernel.MapSharedPages(vm_manager); for (const auto& mapping : address_mappings) { - HandleSpecialMapping(vm_manager, mapping); + kernel.HandleSpecialMapping(vm_manager, mapping); } status = ProcessStatus::Running; diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp index 34ecc08a5d..07dbd0d94f 100644 --- a/src/core/hw/gpu.cpp +++ b/src/core/hw/gpu.cpp @@ -79,12 +79,12 @@ static void MemoryFill(const Regs::MemoryFillConfig& config) { const PAddr end_addr = config.GetEndAddress(); // TODO: do hwtest with these cases - if (!Memory::IsValidPhysicalAddress(start_addr)) { + if (!g_memory->IsValidPhysicalAddress(start_addr)) { LOG_CRITICAL(HW_GPU, "invalid start address {:#010X}", start_addr); return; } - if (!Memory::IsValidPhysicalAddress(end_addr)) { + if (!g_memory->IsValidPhysicalAddress(end_addr)) { LOG_CRITICAL(HW_GPU, "invalid end address {:#010X}", end_addr); return; } @@ -95,8 +95,8 @@ static void MemoryFill(const Regs::MemoryFillConfig& config) { return; } - u8* start = Memory::GetPhysicalPointer(start_addr); - u8* end = Memory::GetPhysicalPointer(end_addr); + u8* start = g_memory->GetPhysicalPointer(start_addr); + u8* end = g_memory->GetPhysicalPointer(end_addr); if (VideoCore::g_renderer->Rasterizer()->AccelerateFill(config)) return; @@ -132,12 +132,12 @@ static void DisplayTransfer(const Regs::DisplayTransferConfig& config) { const PAddr dst_addr = config.GetPhysicalOutputAddress(); // TODO: do hwtest with these cases - if (!Memory::IsValidPhysicalAddress(src_addr)) { + if (!g_memory->IsValidPhysicalAddress(src_addr)) { LOG_CRITICAL(HW_GPU, "invalid input address {:#010X}", src_addr); return; } - if (!Memory::IsValidPhysicalAddress(dst_addr)) { + if (!g_memory->IsValidPhysicalAddress(dst_addr)) { LOG_CRITICAL(HW_GPU, "invalid output address {:#010X}", dst_addr); return; } @@ -165,8 +165,8 @@ static void DisplayTransfer(const Regs::DisplayTransferConfig& config) { if (VideoCore::g_renderer->Rasterizer()->AccelerateDisplayTransfer(config)) return; - u8* src_pointer = Memory::GetPhysicalPointer(src_addr); - u8* dst_pointer = Memory::GetPhysicalPointer(dst_addr); + u8* src_pointer = g_memory->GetPhysicalPointer(src_addr); + u8* dst_pointer = g_memory->GetPhysicalPointer(dst_addr); if (config.scaling > config.ScaleXY) { LOG_CRITICAL(HW_GPU, "Unimplemented display transfer scaling mode {}", @@ -308,12 +308,12 @@ static void TextureCopy(const Regs::DisplayTransferConfig& config) { const PAddr dst_addr = config.GetPhysicalOutputAddress(); // TODO: do hwtest with invalid addresses - if (!Memory::IsValidPhysicalAddress(src_addr)) { + if (!g_memory->IsValidPhysicalAddress(src_addr)) { LOG_CRITICAL(HW_GPU, "invalid input address {:#010X}", src_addr); return; } - if (!Memory::IsValidPhysicalAddress(dst_addr)) { + if (!g_memory->IsValidPhysicalAddress(dst_addr)) { LOG_CRITICAL(HW_GPU, "invalid output address {:#010X}", dst_addr); return; } @@ -321,8 +321,8 @@ static void TextureCopy(const Regs::DisplayTransferConfig& config) { if (VideoCore::g_renderer->Rasterizer()->AccelerateTextureCopy(config)) return; - u8* src_pointer = Memory::GetPhysicalPointer(src_addr); - u8* dst_pointer = Memory::GetPhysicalPointer(dst_addr); + u8* src_pointer = g_memory->GetPhysicalPointer(src_addr); + u8* dst_pointer = g_memory->GetPhysicalPointer(dst_addr); u32 remaining_size = Common::AlignDown(config.texture_copy.size, 16); @@ -471,7 +471,7 @@ inline void Write(u32 addr, const T data) { if (config.trigger & 1) { MICROPROFILE_SCOPE(GPU_CmdlistProcessing); - u32* buffer = (u32*)Memory::GetPhysicalPointer(config.GetPhysicalAddress()); + u32* buffer = (u32*)g_memory->GetPhysicalPointer(config.GetPhysicalAddress()); if (Pica::g_debug_context && Pica::g_debug_context->recorder) { Pica::g_debug_context->recorder->MemoryAccessed((u8*)buffer, config.size, diff --git a/src/core/memory.cpp b/src/core/memory.cpp index f2bc11f6e4..0f91040d3b 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -206,7 +206,7 @@ bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) { return false; } -bool IsValidPhysicalAddress(const PAddr paddr) { +bool MemorySystem::IsValidPhysicalAddress(const PAddr paddr) { return GetPhysicalPointer(paddr) != nullptr; } @@ -238,7 +238,7 @@ std::string ReadCString(VAddr vaddr, std::size_t max_length) { return string; } -u8* GetPhysicalPointer(PAddr address) { +u8* MemorySystem::GetPhysicalPointer(PAddr address) { struct MemoryArea { PAddr paddr_base; u32 size; diff --git a/src/core/memory.h b/src/core/memory.h index fe4333d250..1f66a3e648 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -183,8 +183,6 @@ extern std::array fcram; /// Determines if the given VAddr is valid for the specified process. bool IsValidVirtualAddress(const Kernel::Process& process, VAddr vaddr); -bool IsValidPhysicalAddress(PAddr paddr); - u8 Read8(VAddr addr); u16 Read16(VAddr addr); u32 Read32(VAddr addr); @@ -207,11 +205,6 @@ u8* GetPointer(VAddr vaddr); std::string ReadCString(VAddr vaddr, std::size_t max_length); -/** - * Gets a pointer to the memory region beginning at the specified physical address. - */ -u8* GetPhysicalPointer(PAddr address); - /** * Mark each page touching the region as cached. */ @@ -253,6 +246,13 @@ public: void SetCurrentPageTable(PageTable* page_table); PageTable* GetCurrentPageTable(); + /** + * Gets a pointer to the memory region beginning at the specified physical address. + */ + u8* GetPhysicalPointer(PAddr address); + + bool IsValidPhysicalAddress(PAddr paddr); + /// Gets offset in FCRAM from a pointer inside FCRAM range u32 GetFCRAMOffset(u8* pointer); }; diff --git a/src/tests/core/memory/memory.cpp b/src/tests/core/memory/memory.cpp index 88ad5d7443..376eb283a3 100644 --- a/src/tests/core/memory/memory.cpp +++ b/src/tests/core/memory/memory.cpp @@ -36,13 +36,13 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") { SECTION("special regions should be valid after mapping them") { auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0)); SECTION("VRAM") { - Kernel::HandleSpecialMapping(process->vm_manager, - {Memory::VRAM_VADDR, Memory::VRAM_SIZE, false, false}); + kernel.HandleSpecialMapping(process->vm_manager, + {Memory::VRAM_VADDR, Memory::VRAM_SIZE, false, false}); CHECK(Memory::IsValidVirtualAddress(*process, Memory::VRAM_VADDR) == true); } SECTION("IO (Not yet implemented)") { - Kernel::HandleSpecialMapping( + kernel.HandleSpecialMapping( process->vm_manager, {Memory::IO_AREA_VADDR, Memory::IO_AREA_SIZE, false, false}); CHECK_FALSE(Memory::IsValidVirtualAddress(*process, Memory::IO_AREA_VADDR) == true); } diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp index 7aec9de987..5810537b97 100644 --- a/src/video_core/command_processor.cpp +++ b/src/video_core/command_processor.cpp @@ -269,7 +269,7 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) { case PICA_REG_INDEX_WORKAROUND(pipeline.command_buffer.trigger[1], 0x23d): { unsigned index = static_cast(id - PICA_REG_INDEX(pipeline.command_buffer.trigger[0])); - u32* head_ptr = (u32*)Memory::GetPhysicalPointer( + u32* head_ptr = (u32*)VideoCore::g_memory->GetPhysicalPointer( regs.pipeline.command_buffer.GetPhysicalAddress(index)); g_state.cmd_list.head_ptr = g_state.cmd_list.current_ptr = head_ptr; g_state.cmd_list.length = regs.pipeline.command_buffer.GetSize(index) / sizeof(u32); @@ -328,7 +328,8 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) { // Load vertices const auto& index_info = regs.pipeline.index_array; - const u8* index_address_8 = Memory::GetPhysicalPointer(base_address + index_info.offset); + const u8* index_address_8 = + VideoCore::g_memory->GetPhysicalPointer(base_address + index_info.offset); const u16* index_address_16 = reinterpret_cast(index_address_8); bool index_u16 = index_info.format != 0; @@ -338,7 +339,8 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) { if (!texture.enabled) continue; - u8* texture_data = Memory::GetPhysicalPointer(texture.config.GetPhysicalAddress()); + u8* texture_data = + VideoCore::g_memory->GetPhysicalPointer(texture.config.GetPhysicalAddress()); g_debug_context->recorder->MemoryAccessed( texture_data, Pica::TexturingRegs::NibblesPerPixel(texture.format) * texture.config.width / @@ -424,8 +426,8 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) { } for (auto& range : memory_accesses.ranges) { - g_debug_context->recorder->MemoryAccessed(Memory::GetPhysicalPointer(range.first), - range.second, range.first); + g_debug_context->recorder->MemoryAccessed( + VideoCore::g_memory->GetPhysicalPointer(range.first), range.second, range.first); } VideoCore::g_renderer->Rasterizer()->DrawTriangles(); diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index b62320064a..50f89a656b 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -24,6 +24,7 @@ #include "video_core/renderer_opengl/gl_shader_gen.h" #include "video_core/renderer_opengl/pica_to_gl.h" #include "video_core/renderer_opengl/renderer_opengl.h" +#include "video_core/video_core.h" namespace OpenGL { @@ -259,7 +260,7 @@ RasterizerOpenGL::VertexArrayInfo RasterizerOpenGL::AnalyzeVertexArray(bool is_i if (is_indexed) { const auto& index_info = regs.pipeline.index_array; PAddr address = vertex_attributes.GetPhysicalBaseAddress() + index_info.offset; - const u8* index_address_8 = Memory::GetPhysicalPointer(address); + const u8* index_address_8 = VideoCore::g_memory->GetPhysicalPointer(address); const u16* index_address_16 = reinterpret_cast(index_address_8); bool index_u16 = index_info.format != 0; @@ -340,7 +341,7 @@ void RasterizerOpenGL::SetupVertexArray(u8* array_ptr, GLintptr buffer_offset, u32 data_size = loader.byte_count * vertex_num; res_cache.FlushRegion(data_addr, data_size, nullptr); - std::memcpy(array_ptr, Memory::GetPhysicalPointer(data_addr), data_size); + std::memcpy(array_ptr, VideoCore::g_memory->GetPhysicalPointer(data_addr), data_size); array_ptr += data_size; buffer_offset += data_size; @@ -471,9 +472,9 @@ bool RasterizerOpenGL::AccelerateDrawBatchInternal(bool is_indexed, bool use_gs) return false; } - const u8* index_data = - Memory::GetPhysicalPointer(regs.pipeline.vertex_attributes.GetPhysicalBaseAddress() + - regs.pipeline.index_array.offset); + const u8* index_data = VideoCore::g_memory->GetPhysicalPointer( + regs.pipeline.vertex_attributes.GetPhysicalBaseAddress() + + regs.pipeline.index_array.offset); std::tie(buffer_ptr, buffer_offset, std::ignore) = index_buffer.Map(index_buffer_size, 4); std::memcpy(buffer_ptr, index_data, index_buffer_size); index_buffer.Unmap(index_buffer_size); diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index 638096e34e..6342ede2a2 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -134,7 +134,7 @@ static void MortonCopy(u32 stride, u32 height, u8* gl_buffer, PAddr base, PAddr } }; - u8* tile_buffer = Memory::GetPhysicalPointer(start); + u8* tile_buffer = VideoCore::g_memory->GetPhysicalPointer(start); if (start < aligned_start && !morton_to_gl) { std::array tmp_buf; @@ -625,7 +625,7 @@ MICROPROFILE_DEFINE(OpenGL_SurfaceLoad, "OpenGL", "Surface Load", MP_RGB(128, 19 void CachedSurface::LoadGLBuffer(PAddr load_start, PAddr load_end) { ASSERT(type != SurfaceType::Fill); - const u8* const texture_src_data = Memory::GetPhysicalPointer(addr); + const u8* const texture_src_data = VideoCore::g_memory->GetPhysicalPointer(addr); if (texture_src_data == nullptr) return; @@ -680,7 +680,7 @@ void CachedSurface::LoadGLBuffer(PAddr load_start, PAddr load_end) { MICROPROFILE_DEFINE(OpenGL_SurfaceFlush, "OpenGL", "Surface Flush", MP_RGB(128, 192, 64)); void CachedSurface::FlushGLBuffer(PAddr flush_start, PAddr flush_end) { - u8* const dst_buffer = Memory::GetPhysicalPointer(addr); + u8* const dst_buffer = VideoCore::g_memory->GetPhysicalPointer(addr); if (dst_buffer == nullptr) return; diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index c764aee5a2..1b00695d7e 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -228,7 +228,7 @@ void RendererOpenGL::LoadFBToScreenInfo(const GPU::Regs::FramebufferConfig& fram Memory::RasterizerFlushRegion(framebuffer_addr, framebuffer.stride * framebuffer.height); - const u8* framebuffer_data = Memory::GetPhysicalPointer(framebuffer_addr); + const u8* framebuffer_data = VideoCore::g_memory->GetPhysicalPointer(framebuffer_addr); state.texture_units[0].texture_2d = screen_info.texture.resource.handle; state.Apply(); diff --git a/src/video_core/swrasterizer/framebuffer.cpp b/src/video_core/swrasterizer/framebuffer.cpp index 509d2ce455..1365a98359 100644 --- a/src/video_core/swrasterizer/framebuffer.cpp +++ b/src/video_core/swrasterizer/framebuffer.cpp @@ -14,6 +14,7 @@ #include "video_core/regs_framebuffer.h" #include "video_core/swrasterizer/framebuffer.h" #include "video_core/utils.h" +#include "video_core/video_core.h" namespace Pica { namespace Rasterizer { @@ -31,7 +32,7 @@ void DrawPixel(int x, int y, const Math::Vec4& color) { GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(framebuffer.color_format.Value())); u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * framebuffer.width * bytes_per_pixel; - u8* dst_pixel = Memory::GetPhysicalPointer(addr) + dst_offset; + u8* dst_pixel = VideoCore::g_memory->GetPhysicalPointer(addr) + dst_offset; switch (framebuffer.color_format) { case FramebufferRegs::ColorFormat::RGBA8: @@ -72,7 +73,7 @@ const Math::Vec4 GetPixel(int x, int y) { GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(framebuffer.color_format.Value())); u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * framebuffer.width * bytes_per_pixel; - u8* src_pixel = Memory::GetPhysicalPointer(addr) + src_offset; + u8* src_pixel = VideoCore::g_memory->GetPhysicalPointer(addr) + src_offset; switch (framebuffer.color_format) { case FramebufferRegs::ColorFormat::RGBA8: @@ -102,7 +103,7 @@ const Math::Vec4 GetPixel(int x, int y) { u32 GetDepth(int x, int y) { const auto& framebuffer = g_state.regs.framebuffer.framebuffer; const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress(); - u8* depth_buffer = Memory::GetPhysicalPointer(addr); + u8* depth_buffer = VideoCore::g_memory->GetPhysicalPointer(addr); y = framebuffer.height - y; @@ -131,7 +132,7 @@ u32 GetDepth(int x, int y) { u8 GetStencil(int x, int y) { const auto& framebuffer = g_state.regs.framebuffer.framebuffer; const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress(); - u8* depth_buffer = Memory::GetPhysicalPointer(addr); + u8* depth_buffer = VideoCore::g_memory->GetPhysicalPointer(addr); y = framebuffer.height - y; @@ -158,7 +159,7 @@ u8 GetStencil(int x, int y) { void SetDepth(int x, int y, u32 value) { const auto& framebuffer = g_state.regs.framebuffer.framebuffer; const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress(); - u8* depth_buffer = Memory::GetPhysicalPointer(addr); + u8* depth_buffer = VideoCore::g_memory->GetPhysicalPointer(addr); y = framebuffer.height - y; @@ -193,7 +194,7 @@ void SetDepth(int x, int y, u32 value) { void SetStencil(int x, int y, u8 value) { const auto& framebuffer = g_state.regs.framebuffer.framebuffer; const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress(); - u8* depth_buffer = Memory::GetPhysicalPointer(addr); + u8* depth_buffer = VideoCore::g_memory->GetPhysicalPointer(addr); y = framebuffer.height - y; @@ -384,7 +385,7 @@ void DrawShadowMapPixel(int x, int y, u32 depth, u8 stencil) { u32 bytes_per_pixel = 4; u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * framebuffer.width * bytes_per_pixel; - u8* dst_pixel = Memory::GetPhysicalPointer(addr) + dst_offset; + u8* dst_pixel = VideoCore::g_memory->GetPhysicalPointer(addr) + dst_offset; auto ref = DecodeD24S8Shadow(dst_pixel); u32 ref_z = ref.x; diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp index 53ddfd8d50..52650926de 100644 --- a/src/video_core/swrasterizer/rasterizer.cpp +++ b/src/video_core/swrasterizer/rasterizer.cpp @@ -30,6 +30,7 @@ #include "video_core/swrasterizer/texturing.h" #include "video_core/texture/texture_decode.h" #include "video_core/utils.h" +#include "video_core/video_core.h" namespace Pica { namespace Rasterizer { @@ -402,7 +403,8 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve t = texture.config.height - 1 - GetWrappedTexCoord(texture.config.wrap_t, t, texture.config.height); - const u8* texture_data = Memory::GetPhysicalPointer(texture_address); + const u8* texture_data = + VideoCore::g_memory->GetPhysicalPointer(texture_address); auto info = Texture::TextureInfo::FromPicaRegister(texture.config, texture.format); diff --git a/src/video_core/vertex_loader.cpp b/src/video_core/vertex_loader.cpp index a6cfd60808..7c65defc5b 100644 --- a/src/video_core/vertex_loader.cpp +++ b/src/video_core/vertex_loader.cpp @@ -13,6 +13,7 @@ #include "video_core/regs_pipeline.h" #include "video_core/shader/shader.h" #include "video_core/vertex_loader.h" +#include "video_core/video_core.h" namespace Pica { @@ -95,32 +96,32 @@ void VertexLoader::LoadVertex(u32 base_address, int index, int vertex, switch (vertex_attribute_formats[i]) { case PipelineRegs::VertexAttributeFormat::BYTE: { - const s8* srcdata = - reinterpret_cast(Memory::GetPhysicalPointer(source_addr)); + const s8* srcdata = reinterpret_cast( + VideoCore::g_memory->GetPhysicalPointer(source_addr)); for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { input.attr[i][comp] = float24::FromFloat32(srcdata[comp]); } break; } case PipelineRegs::VertexAttributeFormat::UBYTE: { - const u8* srcdata = - reinterpret_cast(Memory::GetPhysicalPointer(source_addr)); + const u8* srcdata = reinterpret_cast( + VideoCore::g_memory->GetPhysicalPointer(source_addr)); for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { input.attr[i][comp] = float24::FromFloat32(srcdata[comp]); } break; } case PipelineRegs::VertexAttributeFormat::SHORT: { - const s16* srcdata = - reinterpret_cast(Memory::GetPhysicalPointer(source_addr)); + const s16* srcdata = reinterpret_cast( + VideoCore::g_memory->GetPhysicalPointer(source_addr)); for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { input.attr[i][comp] = float24::FromFloat32(srcdata[comp]); } break; } case PipelineRegs::VertexAttributeFormat::FLOAT: { - const float* srcdata = - reinterpret_cast(Memory::GetPhysicalPointer(source_addr)); + const float* srcdata = reinterpret_cast( + VideoCore::g_memory->GetPhysicalPointer(source_addr)); for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { input.attr[i][comp] = float24::FromFloat32(srcdata[comp]); }