From 1c0b87edc2d8262c06ea4c301bcfc884875f918b Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 9 May 2015 00:39:56 -0300 Subject: Memory: Re-organize and rename memory area address constants --- src/video_core/pica.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/video_core') diff --git a/src/video_core/pica.h b/src/video_core/pica.h index a0ba715f3..4c48b6bf7 100644 --- a/src/video_core/pica.h +++ b/src/video_core/pica.h @@ -1003,7 +1003,7 @@ inline static u32 PAddrToVAddr(u32 addr) { if (addr >= Memory::VRAM_PADDR && addr < Memory::VRAM_PADDR + Memory::VRAM_SIZE) { return addr - Memory::VRAM_PADDR + Memory::VRAM_VADDR; } else if (addr >= Memory::FCRAM_PADDR && addr < Memory::FCRAM_PADDR + Memory::FCRAM_SIZE) { - return addr - Memory::FCRAM_PADDR + Memory::HEAP_LINEAR_VADDR; + return addr - Memory::FCRAM_PADDR + Memory::LINEAR_HEAP_VADDR; } else { return 0; } -- cgit v1.2.3 From 28a9e4c1d55c66e99b5cf16fda00dcb75ab27fde Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 9 May 2015 03:08:11 -0300 Subject: Memory: Support more regions in the VAddr-PAddr translation functions Also adds better documentation and removes the one-off reimplementation of the function in pica.h. --- src/video_core/command_processor.cpp | 4 ++-- src/video_core/pica.h | 11 ----------- src/video_core/rasterizer.cpp | 10 +++++----- 3 files changed, 7 insertions(+), 18 deletions(-) (limited to 'src/video_core') diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp index c4cdf672b..7c4047e33 100644 --- a/src/video_core/command_processor.cpp +++ b/src/video_core/command_processor.cpp @@ -102,7 +102,7 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) { bool is_indexed = (id == PICA_REG_INDEX(trigger_draw_indexed)); const auto& index_info = registers.index_array; - const u8* index_address_8 = Memory::GetPointer(PAddrToVAddr(base_address + index_info.offset)); + const u8* index_address_8 = Memory::GetPointer(Memory::PhysicalToVirtualAddress(base_address + index_info.offset)); const u16* index_address_16 = (u16*)index_address_8; bool index_u16 = index_info.format != 0; @@ -135,7 +135,7 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) { input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32()); } else { for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { - const u8* srcdata = Memory::GetPointer(PAddrToVAddr(vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i])); + const u8* srcdata = Memory::GetPointer(Memory::PhysicalToVirtualAddress(vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i])); const float srcval = (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::BYTE) ? *(s8*)srcdata : (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::UBYTE) ? *(u8*)srcdata : diff --git a/src/video_core/pica.h b/src/video_core/pica.h index 4c48b6bf7..e4a91058c 100644 --- a/src/video_core/pica.h +++ b/src/video_core/pica.h @@ -998,15 +998,4 @@ union CommandHeader { BitField<31, 1, u32> group_commands; }; -// TODO: Ugly, should fix PhysicalToVirtualAddress instead -inline static u32 PAddrToVAddr(u32 addr) { - if (addr >= Memory::VRAM_PADDR && addr < Memory::VRAM_PADDR + Memory::VRAM_SIZE) { - return addr - Memory::VRAM_PADDR + Memory::VRAM_VADDR; - } else if (addr >= Memory::FCRAM_PADDR && addr < Memory::FCRAM_PADDR + Memory::FCRAM_SIZE) { - return addr - Memory::FCRAM_PADDR + Memory::LINEAR_HEAP_VADDR; - } else { - return 0; - } -} - } // namespace diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp index 6ec253601..ab7776929 100644 --- a/src/video_core/rasterizer.cpp +++ b/src/video_core/rasterizer.cpp @@ -30,7 +30,7 @@ static void DrawPixel(int x, int y, const Math::Vec4& color) { const u32 coarse_y = y & ~7; u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value())); u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel; - u8* dst_pixel = Memory::GetPointer(PAddrToVAddr(addr)) + dst_offset; + u8* dst_pixel = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)) + dst_offset; switch (registers.framebuffer.color_format) { case registers.framebuffer.RGBA8: @@ -67,7 +67,7 @@ static const Math::Vec4 GetPixel(int x, int y) { const u32 coarse_y = y & ~7; u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value())); u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel; - u8* src_pixel = Memory::GetPointer(PAddrToVAddr(addr)) + src_offset; + u8* src_pixel = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)) + src_offset; switch (registers.framebuffer.color_format) { case registers.framebuffer.RGBA8: @@ -95,7 +95,7 @@ static const Math::Vec4 GetPixel(int x, int y) { static u32 GetDepth(int x, int y) { const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress(); - u8* depth_buffer = Memory::GetPointer(PAddrToVAddr(addr)); + u8* depth_buffer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)); y = (registers.framebuffer.height - y); @@ -122,7 +122,7 @@ static u32 GetDepth(int x, int y) { static void SetDepth(int x, int y, u32 value) { const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress(); - u8* depth_buffer = Memory::GetPointer(PAddrToVAddr(addr)); + u8* depth_buffer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)); y = (registers.framebuffer.height - y); @@ -361,7 +361,7 @@ static void ProcessTriangleInternal(const VertexShader::OutputVertex& v0, s = GetWrappedTexCoord(texture.config.wrap_s, s, texture.config.width); t = texture.config.height - 1 - GetWrappedTexCoord(texture.config.wrap_t, t, texture.config.height); - u8* texture_data = Memory::GetPointer(PAddrToVAddr(texture.config.GetPhysicalAddress())); + u8* texture_data = Memory::GetPointer(Memory::PhysicalToVirtualAddress(texture.config.GetPhysicalAddress())); auto info = DebugUtils::TextureInfo::FromPicaRegister(texture.config, texture.format); texture_color[i] = DebugUtils::LookupTexture(texture_data, s, t, info); -- cgit v1.2.3 From 17a8cae0038b82202149bad687823b89074aa696 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 9 May 2015 04:02:32 -0300 Subject: Memory: Add GetPhysicalPointer helper function --- src/video_core/command_processor.cpp | 4 ++-- src/video_core/rasterizer.cpp | 10 +++++----- src/video_core/renderer_opengl/renderer_opengl.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/video_core') diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp index 7c4047e33..1ea7cad07 100644 --- a/src/video_core/command_processor.cpp +++ b/src/video_core/command_processor.cpp @@ -102,7 +102,7 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) { bool is_indexed = (id == PICA_REG_INDEX(trigger_draw_indexed)); const auto& index_info = registers.index_array; - const u8* index_address_8 = Memory::GetPointer(Memory::PhysicalToVirtualAddress(base_address + index_info.offset)); + const u8* index_address_8 = Memory::GetPhysicalPointer(base_address + index_info.offset); const u16* index_address_16 = (u16*)index_address_8; bool index_u16 = index_info.format != 0; @@ -135,7 +135,7 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) { input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32()); } else { for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { - const u8* srcdata = Memory::GetPointer(Memory::PhysicalToVirtualAddress(vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i])); + const u8* srcdata = Memory::GetPhysicalPointer(vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i]); const float srcval = (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::BYTE) ? *(s8*)srcdata : (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::UBYTE) ? *(u8*)srcdata : diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp index ab7776929..3b3fef484 100644 --- a/src/video_core/rasterizer.cpp +++ b/src/video_core/rasterizer.cpp @@ -30,7 +30,7 @@ static void DrawPixel(int x, int y, const Math::Vec4& color) { const u32 coarse_y = y & ~7; u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value())); u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel; - u8* dst_pixel = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)) + dst_offset; + u8* dst_pixel = Memory::GetPhysicalPointer(addr) + dst_offset; switch (registers.framebuffer.color_format) { case registers.framebuffer.RGBA8: @@ -67,7 +67,7 @@ static const Math::Vec4 GetPixel(int x, int y) { const u32 coarse_y = y & ~7; u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value())); u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel; - u8* src_pixel = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)) + src_offset; + u8* src_pixel = Memory::GetPhysicalPointer(addr) + src_offset; switch (registers.framebuffer.color_format) { case registers.framebuffer.RGBA8: @@ -95,7 +95,7 @@ static const Math::Vec4 GetPixel(int x, int y) { static u32 GetDepth(int x, int y) { const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress(); - u8* depth_buffer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)); + u8* depth_buffer = Memory::GetPhysicalPointer(addr); y = (registers.framebuffer.height - y); @@ -122,7 +122,7 @@ static u32 GetDepth(int x, int y) { static void SetDepth(int x, int y, u32 value) { const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress(); - u8* depth_buffer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)); + u8* depth_buffer = Memory::GetPhysicalPointer(addr); y = (registers.framebuffer.height - y); @@ -361,7 +361,7 @@ static void ProcessTriangleInternal(const VertexShader::OutputVertex& v0, s = GetWrappedTexCoord(texture.config.wrap_s, s, texture.config.width); t = texture.config.height - 1 - GetWrappedTexCoord(texture.config.wrap_t, t, texture.config.height); - u8* texture_data = Memory::GetPointer(Memory::PhysicalToVirtualAddress(texture.config.GetPhysicalAddress())); + u8* texture_data = Memory::GetPhysicalPointer(texture.config.GetPhysicalAddress()); auto info = DebugUtils::TextureInfo::FromPicaRegister(texture.config, texture.format); texture_color[i] = DebugUtils::LookupTexture(texture_data, s, t, info); diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 6b242a6ed..0c072120d 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -119,15 +119,15 @@ void RendererOpenGL::SwapBuffers() { void RendererOpenGL::LoadFBToActiveGLTexture(const GPU::Regs::FramebufferConfig& framebuffer, const TextureInfo& texture) { - const VAddr framebuffer_vaddr = Memory::PhysicalToVirtualAddress( - framebuffer.active_fb == 0 ? framebuffer.address_left1 : framebuffer.address_left2); + const PAddr framebuffer_addr = framebuffer.active_fb == 0 ? + framebuffer.address_left1 : framebuffer.address_left2; LOG_TRACE(Render_OpenGL, "0x%08x bytes from 0x%08x(%dx%d), fmt %x", framebuffer.stride * framebuffer.height, - framebuffer_vaddr, (int)framebuffer.width, + framebuffer_addr, (int)framebuffer.width, (int)framebuffer.height, (int)framebuffer.format); - const u8* framebuffer_data = Memory::GetPointer(framebuffer_vaddr); + const u8* framebuffer_data = Memory::GetPhysicalPointer(framebuffer_addr); int bpp = GPU::Regs::BytesPerPixel(framebuffer.color_format); size_t pixel_stride = framebuffer.stride / bpp; -- cgit v1.2.3