citra-emu
/
citra
Archived
1
0
Fork 0

Memory: move GetPhysicalPointer and IsValidPhysicalAddress into class

This commit is contained in:
Weiyi Wang 2018-11-21 12:01:19 -05:00
parent cfee59c6db
commit 296c458e0e
18 changed files with 76 additions and 65 deletions

View File

@ -290,7 +290,7 @@ bool Source::DequeueBuffer() {
// This physical address masking occurs due to how the DSP DMA hardware is configured by the // This physical address masking occurs due to how the DSP DMA hardware is configured by the
// firmware. // firmware.
const u8* const memory = Memory::GetPhysicalPointer(buf.physical_address & 0xFFFFFFFC); const u8* const memory = memory_system->GetPhysicalPointer(buf.physical_address & 0xFFFFFFFC);
if (memory) { if (memory) {
const unsigned num_channels = buf.mono_or_stereo == MonoOrStereo::Stereo ? 2 : 1; const unsigned num_channels = buf.mono_or_stereo == MonoOrStereo::Stereo ? 2 : 1;
switch (buf.format) { switch (buf.format) {

View File

@ -17,6 +17,7 @@
#include "citra_qt/util/spinbox.h" #include "citra_qt/util/spinbox.h"
#include "citra_qt/util/util.h" #include "citra_qt/util/util.h"
#include "common/vector_math.h" #include "common/vector_math.h"
#include "core/core.h"
#include "core/memory.h" #include "core/memory.h"
#include "video_core/debug_utils/debug_utils.h" #include "video_core/debug_utils/debug_utils.h"
#include "video_core/pica_state.h" #include "video_core/pica_state.h"
@ -166,7 +167,8 @@ void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) {
const auto format = texture.format; const auto format = texture.format;
const auto info = Pica::Texture::TextureInfo::FromPicaRegister(config, 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); new_info_widget = new TextureInfoWidget(src, info);
} }
if (command_info_widget) { if (command_info_widget) {

View File

@ -14,6 +14,7 @@
#include "citra_qt/debugger/graphics/graphics_surface.h" #include "citra_qt/debugger/graphics/graphics_surface.h"
#include "citra_qt/util/spinbox.h" #include "citra_qt/util/spinbox.h"
#include "common/color.h" #include "common/color.h"
#include "core/core.h"
#include "core/hw/gpu.h" #include "core/hw/gpu.h"
#include "core/memory.h" #include "core/memory.h"
#include "video_core/pica_state.h" #include "video_core/pica_state.h"
@ -283,7 +284,7 @@ void GraphicsSurfaceWidget::Pick(int x, int y) {
return; return;
} }
u8* buffer = Memory::GetPhysicalPointer(surface_address); u8* buffer = Core::System::GetInstance().Memory().GetPhysicalPointer(surface_address);
if (buffer == nullptr) { if (buffer == nullptr) {
surface_info_label->setText(tr("(unable to access pixel data)")); surface_info_label->setText(tr("(unable to access pixel data)"));
surface_info_label->setAlignment(Qt::AlignCenter); surface_info_label->setAlignment(Qt::AlignCenter);
@ -549,7 +550,7 @@ void GraphicsSurfaceWidget::OnUpdate() {
// TODO: Implement a good way to visualize alpha components! // TODO: Implement a good way to visualize alpha components!
QImage decoded_image(surface_width, surface_height, QImage::Format_ARGB32); 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) { if (buffer == nullptr) {
surface_picture_label->hide(); surface_picture_label->hide();
@ -679,7 +680,7 @@ void GraphicsSurfaceWidget::SaveSurface() {
if (pixmap) if (pixmap)
pixmap->save(&file, "PNG"); pixmap->save(&file, "PNG");
} else if (selectedFilter == bin_filter) { } 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"); ASSERT_MSG(buffer != nullptr, "Memory not accessible");
QFile file(filename); QFile file(filename);

View File

@ -46,6 +46,7 @@ class SharedMemory;
class ThreadManager; class ThreadManager;
class TimerManager; class TimerManager;
class VMManager; class VMManager;
struct AddressMapping;
enum class ResetType { enum class ResetType {
OneShot, OneShot,
@ -216,6 +217,8 @@ public:
MemoryRegionInfo* GetMemoryRegion(MemoryRegion region); MemoryRegionInfo* GetMemoryRegion(MemoryRegion region);
void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping);
std::array<MemoryRegionInfo, 3> memory_regions; std::array<MemoryRegionInfo, 3> memory_regions;
/// Adds a port to the named port table /// Adds a port to the named port table

View File

@ -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; using namespace Memory;
struct MemoryArea { struct MemoryArea {
@ -128,7 +128,7 @@ void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mappin
return; 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 // 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; MemoryState memory_state = mapping.unk_flag ? MemoryState::Static : MemoryState::IO;

View File

@ -62,6 +62,4 @@ struct MemoryRegionInfo {
void Free(u32 offset, u32 size); void Free(u32 offset, u32 size);
}; };
void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping);
} // namespace Kernel } // namespace Kernel

View File

@ -136,7 +136,7 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) {
// Map special address mappings // Map special address mappings
kernel.MapSharedPages(vm_manager); kernel.MapSharedPages(vm_manager);
for (const auto& mapping : address_mappings) { for (const auto& mapping : address_mappings) {
HandleSpecialMapping(vm_manager, mapping); kernel.HandleSpecialMapping(vm_manager, mapping);
} }
status = ProcessStatus::Running; status = ProcessStatus::Running;

View File

@ -79,12 +79,12 @@ static void MemoryFill(const Regs::MemoryFillConfig& config) {
const PAddr end_addr = config.GetEndAddress(); const PAddr end_addr = config.GetEndAddress();
// TODO: do hwtest with these cases // 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); LOG_CRITICAL(HW_GPU, "invalid start address {:#010X}", start_addr);
return; return;
} }
if (!Memory::IsValidPhysicalAddress(end_addr)) { if (!g_memory->IsValidPhysicalAddress(end_addr)) {
LOG_CRITICAL(HW_GPU, "invalid end address {:#010X}", end_addr); LOG_CRITICAL(HW_GPU, "invalid end address {:#010X}", end_addr);
return; return;
} }
@ -95,8 +95,8 @@ static void MemoryFill(const Regs::MemoryFillConfig& config) {
return; return;
} }
u8* start = Memory::GetPhysicalPointer(start_addr); u8* start = g_memory->GetPhysicalPointer(start_addr);
u8* end = Memory::GetPhysicalPointer(end_addr); u8* end = g_memory->GetPhysicalPointer(end_addr);
if (VideoCore::g_renderer->Rasterizer()->AccelerateFill(config)) if (VideoCore::g_renderer->Rasterizer()->AccelerateFill(config))
return; return;
@ -132,12 +132,12 @@ static void DisplayTransfer(const Regs::DisplayTransferConfig& config) {
const PAddr dst_addr = config.GetPhysicalOutputAddress(); const PAddr dst_addr = config.GetPhysicalOutputAddress();
// TODO: do hwtest with these cases // 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); LOG_CRITICAL(HW_GPU, "invalid input address {:#010X}", src_addr);
return; return;
} }
if (!Memory::IsValidPhysicalAddress(dst_addr)) { if (!g_memory->IsValidPhysicalAddress(dst_addr)) {
LOG_CRITICAL(HW_GPU, "invalid output address {:#010X}", dst_addr); LOG_CRITICAL(HW_GPU, "invalid output address {:#010X}", dst_addr);
return; return;
} }
@ -165,8 +165,8 @@ static void DisplayTransfer(const Regs::DisplayTransferConfig& config) {
if (VideoCore::g_renderer->Rasterizer()->AccelerateDisplayTransfer(config)) if (VideoCore::g_renderer->Rasterizer()->AccelerateDisplayTransfer(config))
return; return;
u8* src_pointer = Memory::GetPhysicalPointer(src_addr); u8* src_pointer = g_memory->GetPhysicalPointer(src_addr);
u8* dst_pointer = Memory::GetPhysicalPointer(dst_addr); u8* dst_pointer = g_memory->GetPhysicalPointer(dst_addr);
if (config.scaling > config.ScaleXY) { if (config.scaling > config.ScaleXY) {
LOG_CRITICAL(HW_GPU, "Unimplemented display transfer scaling mode {}", 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(); const PAddr dst_addr = config.GetPhysicalOutputAddress();
// TODO: do hwtest with invalid addresses // 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); LOG_CRITICAL(HW_GPU, "invalid input address {:#010X}", src_addr);
return; return;
} }
if (!Memory::IsValidPhysicalAddress(dst_addr)) { if (!g_memory->IsValidPhysicalAddress(dst_addr)) {
LOG_CRITICAL(HW_GPU, "invalid output address {:#010X}", dst_addr); LOG_CRITICAL(HW_GPU, "invalid output address {:#010X}", dst_addr);
return; return;
} }
@ -321,8 +321,8 @@ static void TextureCopy(const Regs::DisplayTransferConfig& config) {
if (VideoCore::g_renderer->Rasterizer()->AccelerateTextureCopy(config)) if (VideoCore::g_renderer->Rasterizer()->AccelerateTextureCopy(config))
return; return;
u8* src_pointer = Memory::GetPhysicalPointer(src_addr); u8* src_pointer = g_memory->GetPhysicalPointer(src_addr);
u8* dst_pointer = Memory::GetPhysicalPointer(dst_addr); u8* dst_pointer = g_memory->GetPhysicalPointer(dst_addr);
u32 remaining_size = Common::AlignDown(config.texture_copy.size, 16); 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) { if (config.trigger & 1) {
MICROPROFILE_SCOPE(GPU_CmdlistProcessing); 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) { if (Pica::g_debug_context && Pica::g_debug_context->recorder) {
Pica::g_debug_context->recorder->MemoryAccessed((u8*)buffer, config.size, Pica::g_debug_context->recorder->MemoryAccessed((u8*)buffer, config.size,

View File

@ -206,7 +206,7 @@ bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr) {
return false; return false;
} }
bool IsValidPhysicalAddress(const PAddr paddr) { bool MemorySystem::IsValidPhysicalAddress(const PAddr paddr) {
return GetPhysicalPointer(paddr) != nullptr; return GetPhysicalPointer(paddr) != nullptr;
} }
@ -238,7 +238,7 @@ std::string ReadCString(VAddr vaddr, std::size_t max_length) {
return string; return string;
} }
u8* GetPhysicalPointer(PAddr address) { u8* MemorySystem::GetPhysicalPointer(PAddr address) {
struct MemoryArea { struct MemoryArea {
PAddr paddr_base; PAddr paddr_base;
u32 size; u32 size;

View File

@ -183,8 +183,6 @@ extern std::array<u8, Memory::FCRAM_N3DS_SIZE> fcram;
/// Determines if the given VAddr is valid for the specified process. /// Determines if the given VAddr is valid for the specified process.
bool IsValidVirtualAddress(const Kernel::Process& process, VAddr vaddr); bool IsValidVirtualAddress(const Kernel::Process& process, VAddr vaddr);
bool IsValidPhysicalAddress(PAddr paddr);
u8 Read8(VAddr addr); u8 Read8(VAddr addr);
u16 Read16(VAddr addr); u16 Read16(VAddr addr);
u32 Read32(VAddr addr); u32 Read32(VAddr addr);
@ -207,11 +205,6 @@ u8* GetPointer(VAddr vaddr);
std::string ReadCString(VAddr vaddr, std::size_t max_length); 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. * Mark each page touching the region as cached.
*/ */
@ -253,6 +246,13 @@ public:
void SetCurrentPageTable(PageTable* page_table); void SetCurrentPageTable(PageTable* page_table);
PageTable* GetCurrentPageTable(); 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 /// Gets offset in FCRAM from a pointer inside FCRAM range
u32 GetFCRAMOffset(u8* pointer); u32 GetFCRAMOffset(u8* pointer);
}; };

View File

@ -36,13 +36,13 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
SECTION("special regions should be valid after mapping them") { SECTION("special regions should be valid after mapping them") {
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0)); auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
SECTION("VRAM") { SECTION("VRAM") {
Kernel::HandleSpecialMapping(process->vm_manager, kernel.HandleSpecialMapping(process->vm_manager,
{Memory::VRAM_VADDR, Memory::VRAM_SIZE, false, false}); {Memory::VRAM_VADDR, Memory::VRAM_SIZE, false, false});
CHECK(Memory::IsValidVirtualAddress(*process, Memory::VRAM_VADDR) == true); CHECK(Memory::IsValidVirtualAddress(*process, Memory::VRAM_VADDR) == true);
} }
SECTION("IO (Not yet implemented)") { SECTION("IO (Not yet implemented)") {
Kernel::HandleSpecialMapping( kernel.HandleSpecialMapping(
process->vm_manager, {Memory::IO_AREA_VADDR, Memory::IO_AREA_SIZE, false, false}); process->vm_manager, {Memory::IO_AREA_VADDR, Memory::IO_AREA_SIZE, false, false});
CHECK_FALSE(Memory::IsValidVirtualAddress(*process, Memory::IO_AREA_VADDR) == true); CHECK_FALSE(Memory::IsValidVirtualAddress(*process, Memory::IO_AREA_VADDR) == true);
} }

View File

@ -269,7 +269,7 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
case PICA_REG_INDEX_WORKAROUND(pipeline.command_buffer.trigger[1], 0x23d): { case PICA_REG_INDEX_WORKAROUND(pipeline.command_buffer.trigger[1], 0x23d): {
unsigned index = unsigned index =
static_cast<unsigned>(id - PICA_REG_INDEX(pipeline.command_buffer.trigger[0])); static_cast<unsigned>(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)); regs.pipeline.command_buffer.GetPhysicalAddress(index));
g_state.cmd_list.head_ptr = g_state.cmd_list.current_ptr = head_ptr; 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); 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 // Load vertices
const auto& index_info = regs.pipeline.index_array; 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<const u16*>(index_address_8); const u16* index_address_16 = reinterpret_cast<const u16*>(index_address_8);
bool index_u16 = index_info.format != 0; bool index_u16 = index_info.format != 0;
@ -338,7 +339,8 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
if (!texture.enabled) if (!texture.enabled)
continue; continue;
u8* texture_data = Memory::GetPhysicalPointer(texture.config.GetPhysicalAddress()); u8* texture_data =
VideoCore::g_memory->GetPhysicalPointer(texture.config.GetPhysicalAddress());
g_debug_context->recorder->MemoryAccessed( g_debug_context->recorder->MemoryAccessed(
texture_data, texture_data,
Pica::TexturingRegs::NibblesPerPixel(texture.format) * texture.config.width / 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) { for (auto& range : memory_accesses.ranges) {
g_debug_context->recorder->MemoryAccessed(Memory::GetPhysicalPointer(range.first), g_debug_context->recorder->MemoryAccessed(
range.second, range.first); VideoCore::g_memory->GetPhysicalPointer(range.first), range.second, range.first);
} }
VideoCore::g_renderer->Rasterizer()->DrawTriangles(); VideoCore::g_renderer->Rasterizer()->DrawTriangles();

View File

@ -24,6 +24,7 @@
#include "video_core/renderer_opengl/gl_shader_gen.h" #include "video_core/renderer_opengl/gl_shader_gen.h"
#include "video_core/renderer_opengl/pica_to_gl.h" #include "video_core/renderer_opengl/pica_to_gl.h"
#include "video_core/renderer_opengl/renderer_opengl.h" #include "video_core/renderer_opengl/renderer_opengl.h"
#include "video_core/video_core.h"
namespace OpenGL { namespace OpenGL {
@ -259,7 +260,7 @@ RasterizerOpenGL::VertexArrayInfo RasterizerOpenGL::AnalyzeVertexArray(bool is_i
if (is_indexed) { if (is_indexed) {
const auto& index_info = regs.pipeline.index_array; const auto& index_info = regs.pipeline.index_array;
PAddr address = vertex_attributes.GetPhysicalBaseAddress() + index_info.offset; 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<const u16*>(index_address_8); const u16* index_address_16 = reinterpret_cast<const u16*>(index_address_8);
bool index_u16 = index_info.format != 0; 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; u32 data_size = loader.byte_count * vertex_num;
res_cache.FlushRegion(data_addr, data_size, nullptr); 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; array_ptr += data_size;
buffer_offset += data_size; buffer_offset += data_size;
@ -471,8 +472,8 @@ bool RasterizerOpenGL::AccelerateDrawBatchInternal(bool is_indexed, bool use_gs)
return false; return false;
} }
const u8* index_data = const u8* index_data = VideoCore::g_memory->GetPhysicalPointer(
Memory::GetPhysicalPointer(regs.pipeline.vertex_attributes.GetPhysicalBaseAddress() + regs.pipeline.vertex_attributes.GetPhysicalBaseAddress() +
regs.pipeline.index_array.offset); regs.pipeline.index_array.offset);
std::tie(buffer_ptr, buffer_offset, std::ignore) = index_buffer.Map(index_buffer_size, 4); std::tie(buffer_ptr, buffer_offset, std::ignore) = index_buffer.Map(index_buffer_size, 4);
std::memcpy(buffer_ptr, index_data, index_buffer_size); std::memcpy(buffer_ptr, index_data, index_buffer_size);

View File

@ -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) { if (start < aligned_start && !morton_to_gl) {
std::array<u8, tile_size> tmp_buf; std::array<u8, tile_size> 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) { void CachedSurface::LoadGLBuffer(PAddr load_start, PAddr load_end) {
ASSERT(type != SurfaceType::Fill); 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) if (texture_src_data == nullptr)
return; 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)); MICROPROFILE_DEFINE(OpenGL_SurfaceFlush, "OpenGL", "Surface Flush", MP_RGB(128, 192, 64));
void CachedSurface::FlushGLBuffer(PAddr flush_start, PAddr flush_end) { 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) if (dst_buffer == nullptr)
return; return;

View File

@ -228,7 +228,7 @@ void RendererOpenGL::LoadFBToScreenInfo(const GPU::Regs::FramebufferConfig& fram
Memory::RasterizerFlushRegion(framebuffer_addr, framebuffer.stride * framebuffer.height); 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.texture_units[0].texture_2d = screen_info.texture.resource.handle;
state.Apply(); state.Apply();

View File

@ -14,6 +14,7 @@
#include "video_core/regs_framebuffer.h" #include "video_core/regs_framebuffer.h"
#include "video_core/swrasterizer/framebuffer.h" #include "video_core/swrasterizer/framebuffer.h"
#include "video_core/utils.h" #include "video_core/utils.h"
#include "video_core/video_core.h"
namespace Pica { namespace Pica {
namespace Rasterizer { namespace Rasterizer {
@ -31,7 +32,7 @@ void DrawPixel(int x, int y, const Math::Vec4<u8>& color) {
GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(framebuffer.color_format.Value())); GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(framebuffer.color_format.Value()));
u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) +
coarse_y * framebuffer.width * 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) { switch (framebuffer.color_format) {
case FramebufferRegs::ColorFormat::RGBA8: case FramebufferRegs::ColorFormat::RGBA8:
@ -72,7 +73,7 @@ const Math::Vec4<u8> GetPixel(int x, int y) {
GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(framebuffer.color_format.Value())); GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(framebuffer.color_format.Value()));
u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) +
coarse_y * framebuffer.width * 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) { switch (framebuffer.color_format) {
case FramebufferRegs::ColorFormat::RGBA8: case FramebufferRegs::ColorFormat::RGBA8:
@ -102,7 +103,7 @@ const Math::Vec4<u8> GetPixel(int x, int y) {
u32 GetDepth(int x, int y) { u32 GetDepth(int x, int y) {
const auto& framebuffer = g_state.regs.framebuffer.framebuffer; const auto& framebuffer = g_state.regs.framebuffer.framebuffer;
const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress(); const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress();
u8* depth_buffer = Memory::GetPhysicalPointer(addr); u8* depth_buffer = VideoCore::g_memory->GetPhysicalPointer(addr);
y = framebuffer.height - y; y = framebuffer.height - y;
@ -131,7 +132,7 @@ u32 GetDepth(int x, int y) {
u8 GetStencil(int x, int y) { u8 GetStencil(int x, int y) {
const auto& framebuffer = g_state.regs.framebuffer.framebuffer; const auto& framebuffer = g_state.regs.framebuffer.framebuffer;
const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress(); const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress();
u8* depth_buffer = Memory::GetPhysicalPointer(addr); u8* depth_buffer = VideoCore::g_memory->GetPhysicalPointer(addr);
y = framebuffer.height - y; y = framebuffer.height - y;
@ -158,7 +159,7 @@ u8 GetStencil(int x, int y) {
void SetDepth(int x, int y, u32 value) { void SetDepth(int x, int y, u32 value) {
const auto& framebuffer = g_state.regs.framebuffer.framebuffer; const auto& framebuffer = g_state.regs.framebuffer.framebuffer;
const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress(); const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress();
u8* depth_buffer = Memory::GetPhysicalPointer(addr); u8* depth_buffer = VideoCore::g_memory->GetPhysicalPointer(addr);
y = framebuffer.height - y; y = framebuffer.height - y;
@ -193,7 +194,7 @@ void SetDepth(int x, int y, u32 value) {
void SetStencil(int x, int y, u8 value) { void SetStencil(int x, int y, u8 value) {
const auto& framebuffer = g_state.regs.framebuffer.framebuffer; const auto& framebuffer = g_state.regs.framebuffer.framebuffer;
const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress(); const PAddr addr = framebuffer.GetDepthBufferPhysicalAddress();
u8* depth_buffer = Memory::GetPhysicalPointer(addr); u8* depth_buffer = VideoCore::g_memory->GetPhysicalPointer(addr);
y = framebuffer.height - y; y = framebuffer.height - y;
@ -384,7 +385,7 @@ void DrawShadowMapPixel(int x, int y, u32 depth, u8 stencil) {
u32 bytes_per_pixel = 4; u32 bytes_per_pixel = 4;
u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) +
coarse_y * framebuffer.width * 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); auto ref = DecodeD24S8Shadow(dst_pixel);
u32 ref_z = ref.x; u32 ref_z = ref.x;

View File

@ -30,6 +30,7 @@
#include "video_core/swrasterizer/texturing.h" #include "video_core/swrasterizer/texturing.h"
#include "video_core/texture/texture_decode.h" #include "video_core/texture/texture_decode.h"
#include "video_core/utils.h" #include "video_core/utils.h"
#include "video_core/video_core.h"
namespace Pica { namespace Pica {
namespace Rasterizer { namespace Rasterizer {
@ -402,7 +403,8 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
t = texture.config.height - 1 - t = texture.config.height - 1 -
GetWrappedTexCoord(texture.config.wrap_t, t, texture.config.height); 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 = auto info =
Texture::TextureInfo::FromPicaRegister(texture.config, texture.format); Texture::TextureInfo::FromPicaRegister(texture.config, texture.format);

View File

@ -13,6 +13,7 @@
#include "video_core/regs_pipeline.h" #include "video_core/regs_pipeline.h"
#include "video_core/shader/shader.h" #include "video_core/shader/shader.h"
#include "video_core/vertex_loader.h" #include "video_core/vertex_loader.h"
#include "video_core/video_core.h"
namespace Pica { namespace Pica {
@ -95,32 +96,32 @@ void VertexLoader::LoadVertex(u32 base_address, int index, int vertex,
switch (vertex_attribute_formats[i]) { switch (vertex_attribute_formats[i]) {
case PipelineRegs::VertexAttributeFormat::BYTE: { case PipelineRegs::VertexAttributeFormat::BYTE: {
const s8* srcdata = const s8* srcdata = reinterpret_cast<const s8*>(
reinterpret_cast<const s8*>(Memory::GetPhysicalPointer(source_addr)); VideoCore::g_memory->GetPhysicalPointer(source_addr));
for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
input.attr[i][comp] = float24::FromFloat32(srcdata[comp]); input.attr[i][comp] = float24::FromFloat32(srcdata[comp]);
} }
break; break;
} }
case PipelineRegs::VertexAttributeFormat::UBYTE: { case PipelineRegs::VertexAttributeFormat::UBYTE: {
const u8* srcdata = const u8* srcdata = reinterpret_cast<const u8*>(
reinterpret_cast<const u8*>(Memory::GetPhysicalPointer(source_addr)); VideoCore::g_memory->GetPhysicalPointer(source_addr));
for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
input.attr[i][comp] = float24::FromFloat32(srcdata[comp]); input.attr[i][comp] = float24::FromFloat32(srcdata[comp]);
} }
break; break;
} }
case PipelineRegs::VertexAttributeFormat::SHORT: { case PipelineRegs::VertexAttributeFormat::SHORT: {
const s16* srcdata = const s16* srcdata = reinterpret_cast<const s16*>(
reinterpret_cast<const s16*>(Memory::GetPhysicalPointer(source_addr)); VideoCore::g_memory->GetPhysicalPointer(source_addr));
for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
input.attr[i][comp] = float24::FromFloat32(srcdata[comp]); input.attr[i][comp] = float24::FromFloat32(srcdata[comp]);
} }
break; break;
} }
case PipelineRegs::VertexAttributeFormat::FLOAT: { case PipelineRegs::VertexAttributeFormat::FLOAT: {
const float* srcdata = const float* srcdata = reinterpret_cast<const float*>(
reinterpret_cast<const float*>(Memory::GetPhysicalPointer(source_addr)); VideoCore::g_memory->GetPhysicalPointer(source_addr));
for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
input.attr[i][comp] = float24::FromFloat32(srcdata[comp]); input.attr[i][comp] = float24::FromFloat32(srcdata[comp]);
} }