summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2015-05-09 03:08:11 -0300
committerGravatar Yuri Kunde Schlesner2015-05-09 03:08:11 -0300
commit28a9e4c1d55c66e99b5cf16fda00dcb75ab27fde (patch)
tree9c40b519bff8a84c948b9343367763781cb64454 /src
parentMemory: Sort memory region variables by VAddr (diff)
downloadyuzu-28a9e4c1d55c66e99b5cf16fda00dcb75ab27fde.tar.gz
yuzu-28a9e4c1d55c66e99b5cf16fda00dcb75ab27fde.tar.xz
yuzu-28a9e4c1d55c66e99b5cf16fda00dcb75ab27fde.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/citra_qt/debugger/graphics_cmdlists.cpp4
-rw-r--r--src/citra_qt/debugger/graphics_framebuffer.cpp2
-rw-r--r--src/core/mem_map.h13
-rw-r--r--src/core/mem_map_funcs.cpp48
-rw-r--r--src/video_core/command_processor.cpp4
-rw-r--r--src/video_core/pica.h11
-rw-r--r--src/video_core/rasterizer.cpp10
7 files changed, 43 insertions, 49 deletions
diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp
index 9bcd25821..6727acf18 100644
--- a/src/citra_qt/debugger/graphics_cmdlists.cpp
+++ b/src/citra_qt/debugger/graphics_cmdlists.cpp
@@ -159,7 +159,7 @@ void TextureInfoDockWidget::OnStrideChanged(int value) {
159} 159}
160 160
161QPixmap TextureInfoDockWidget::ReloadPixmap() const { 161QPixmap TextureInfoDockWidget::ReloadPixmap() const {
162 u8* src = Memory::GetPointer(Pica::PAddrToVAddr(info.physical_address)); 162 u8* src = Memory::GetPointer(Memory::PhysicalToVirtualAddress(info.physical_address));
163 return QPixmap::fromImage(LoadTexture(src, info)); 163 return QPixmap::fromImage(LoadTexture(src, info));
164} 164}
165 165
@@ -274,7 +274,7 @@ void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) {
274 auto format = Pica::registers.GetTextures()[index].format; 274 auto format = Pica::registers.GetTextures()[index].format;
275 275
276 auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(config, format); 276 auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(config, format);
277 u8* src = Memory::GetPointer(Pica::PAddrToVAddr(config.GetPhysicalAddress())); 277 u8* src = Memory::GetPointer(Memory::PhysicalToVirtualAddress(config.GetPhysicalAddress()));
278 new_info_widget = new TextureInfoWidget(src, info); 278 new_info_widget = new TextureInfoWidget(src, info);
279 } else { 279 } else {
280 new_info_widget = new QWidget; 280 new_info_widget = new QWidget;
diff --git a/src/citra_qt/debugger/graphics_framebuffer.cpp b/src/citra_qt/debugger/graphics_framebuffer.cpp
index d621d7204..fa101a6a2 100644
--- a/src/citra_qt/debugger/graphics_framebuffer.cpp
+++ b/src/citra_qt/debugger/graphics_framebuffer.cpp
@@ -215,7 +215,7 @@ void GraphicsFramebufferWidget::OnUpdate()
215 u32 bytes_per_pixel = GraphicsFramebufferWidget::BytesPerPixel(framebuffer_format); 215 u32 bytes_per_pixel = GraphicsFramebufferWidget::BytesPerPixel(framebuffer_format);
216 216
217 QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32); 217 QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32);
218 u8* buffer = Memory::GetPointer(Pica::PAddrToVAddr(framebuffer_address)); 218 u8* buffer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(framebuffer_address));
219 219
220 for (unsigned int y = 0; y < framebuffer_height; ++y) { 220 for (unsigned int y = 0; y < framebuffer_height; ++y) {
221 for (unsigned int x = 0; x < framebuffer_width; ++x) { 221 for (unsigned int x = 0; x < framebuffer_width; ++x) {
diff --git a/src/core/mem_map.h b/src/core/mem_map.h
index 1591fc0a9..5a08cc105 100644
--- a/src/core/mem_map.h
+++ b/src/core/mem_map.h
@@ -181,10 +181,15 @@ inline const char* GetCharPointer(const VAddr address) {
181 return (const char *)GetPointer(address); 181 return (const char *)GetPointer(address);
182} 182}
183 183
184/// Converts a physical address to virtual address 184/**
185VAddr PhysicalToVirtualAddress(PAddr addr); 185 * Converts a virtual address inside a region with 1:1 mapping to physical memory to a physical
186 186 * address. This should be used by services to translate addresses for use by the hardware.
187/// Converts a virtual address to physical address 187 */
188PAddr VirtualToPhysicalAddress(VAddr addr); 188PAddr VirtualToPhysicalAddress(VAddr addr);
189 189
190/**
191 * Undoes a mapping performed by VirtualToPhysicalAddress().
192 */
193VAddr PhysicalToVirtualAddress(PAddr addr);
194
190} // namespace 195} // namespace
diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp
index f96ae6e9e..a8e0fed07 100644
--- a/src/core/mem_map_funcs.cpp
+++ b/src/core/mem_map_funcs.cpp
@@ -18,40 +18,40 @@ namespace Memory {
18static std::map<u32, MemoryBlock> heap_map; 18static std::map<u32, MemoryBlock> heap_map;
19static std::map<u32, MemoryBlock> heap_linear_map; 19static std::map<u32, MemoryBlock> heap_linear_map;
20 20
21/// Convert a physical address to virtual address 21PAddr VirtualToPhysicalAddress(const VAddr addr) {
22VAddr PhysicalToVirtualAddress(const PAddr addr) {
23 // Our memory interface read/write functions assume virtual addresses. Put any physical address
24 // to virtual address translations here. This is quite hacky, but necessary until we implement
25 // proper MMU emulation.
26 // TODO: Screw it, I'll let bunnei figure out how to do this properly.
27 if (addr == 0) { 22 if (addr == 0) {
28 return 0; 23 return 0;
29 } else if ((addr >= VRAM_PADDR) && (addr < VRAM_PADDR_END)) { 24 } else if (addr >= VRAM_VADDR && addr < VRAM_VADDR_END) {
30 return addr - VRAM_PADDR + VRAM_VADDR; 25 return addr - VRAM_VADDR + VRAM_PADDR;
31 } else if ((addr >= FCRAM_PADDR) && (addr < FCRAM_PADDR_END)) { 26 } else if (addr >= LINEAR_HEAP_VADDR && addr < LINEAR_HEAP_VADDR_END) {
32 return addr - FCRAM_PADDR + LINEAR_HEAP_VADDR; 27 return addr - LINEAR_HEAP_VADDR + FCRAM_PADDR;
28 } else if (addr >= DSP_RAM_VADDR && addr < DSP_RAM_VADDR_END) {
29 return addr - DSP_RAM_VADDR + DSP_RAM_PADDR;
30 } else if (addr >= IO_AREA_VADDR && addr < IO_AREA_VADDR_END) {
31 return addr - IO_AREA_VADDR + IO_AREA_PADDR;
33 } 32 }
34 33
35 LOG_ERROR(HW_Memory, "Unknown physical address @ 0x%08x", addr); 34 LOG_ERROR(HW_Memory, "Unknown virtual address @ 0x%08x", addr);
36 return addr; 35 // To help with debugging, set bit on address so that it's obviously invalid.
36 return addr | 0x80000000;
37} 37}
38 38
39/// Convert a physical address to virtual address 39VAddr PhysicalToVirtualAddress(const PAddr addr) {
40PAddr VirtualToPhysicalAddress(const VAddr addr) {
41 // Our memory interface read/write functions assume virtual addresses. Put any physical address
42 // to virtual address translations here. This is quite hacky, but necessary until we implement
43 // proper MMU emulation.
44 // TODO: Screw it, I'll let bunnei figure out how to do this properly.
45 if (addr == 0) { 40 if (addr == 0) {
46 return 0; 41 return 0;
47 } else if ((addr >= VRAM_VADDR) && (addr < VRAM_VADDR_END)) { 42 } else if (addr >= VRAM_PADDR && addr < VRAM_PADDR_END) {
48 return addr - VRAM_VADDR + VRAM_PADDR; 43 return addr - VRAM_PADDR + VRAM_VADDR;
49 } else if ((addr >= LINEAR_HEAP_VADDR) && (addr < LINEAR_HEAP_VADDR_END)) { 44 } else if (addr >= FCRAM_PADDR && addr < FCRAM_PADDR_END) {
50 return addr - LINEAR_HEAP_VADDR + FCRAM_PADDR; 45 return addr - FCRAM_PADDR + LINEAR_HEAP_VADDR;
46 } else if (addr >= DSP_RAM_PADDR && addr < DSP_RAM_PADDR_END) {
47 return addr - DSP_RAM_PADDR + DSP_RAM_VADDR;
48 } else if (addr >= IO_AREA_PADDR && addr < IO_AREA_PADDR_END) {
49 return addr - IO_AREA_PADDR + IO_AREA_VADDR;
51 } 50 }
52 51
53 LOG_ERROR(HW_Memory, "Unknown virtual address @ 0x%08x", addr); 52 LOG_ERROR(HW_Memory, "Unknown physical address @ 0x%08x", addr);
54 return addr; 53 // To help with debugging, set bit on address so that it's obviously invalid.
54 return addr | 0x80000000;
55} 55}
56 56
57template <typename T> 57template <typename T>
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) {
102 bool is_indexed = (id == PICA_REG_INDEX(trigger_draw_indexed)); 102 bool is_indexed = (id == PICA_REG_INDEX(trigger_draw_indexed));
103 103
104 const auto& index_info = registers.index_array; 104 const auto& index_info = registers.index_array;
105 const u8* index_address_8 = Memory::GetPointer(PAddrToVAddr(base_address + index_info.offset)); 105 const u8* index_address_8 = Memory::GetPointer(Memory::PhysicalToVirtualAddress(base_address + index_info.offset));
106 const u16* index_address_16 = (u16*)index_address_8; 106 const u16* index_address_16 = (u16*)index_address_8;
107 bool index_u16 = index_info.format != 0; 107 bool index_u16 = index_info.format != 0;
108 108
@@ -135,7 +135,7 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) {
135 input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32()); 135 input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32());
136 } else { 136 } else {
137 for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { 137 for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
138 const u8* srcdata = Memory::GetPointer(PAddrToVAddr(vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i])); 138 const u8* srcdata = Memory::GetPointer(Memory::PhysicalToVirtualAddress(vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i]));
139 139
140 const float srcval = (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::BYTE) ? *(s8*)srcdata : 140 const float srcval = (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::BYTE) ? *(s8*)srcdata :
141 (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::UBYTE) ? *(u8*)srcdata : 141 (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 {
998 BitField<31, 1, u32> group_commands; 998 BitField<31, 1, u32> group_commands;
999}; 999};
1000 1000
1001// TODO: Ugly, should fix PhysicalToVirtualAddress instead
1002inline static u32 PAddrToVAddr(u32 addr) {
1003 if (addr >= Memory::VRAM_PADDR && addr < Memory::VRAM_PADDR + Memory::VRAM_SIZE) {
1004 return addr - Memory::VRAM_PADDR + Memory::VRAM_VADDR;
1005 } else if (addr >= Memory::FCRAM_PADDR && addr < Memory::FCRAM_PADDR + Memory::FCRAM_SIZE) {
1006 return addr - Memory::FCRAM_PADDR + Memory::LINEAR_HEAP_VADDR;
1007 } else {
1008 return 0;
1009 }
1010}
1011
1012} // namespace 1001} // 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<u8>& color) {
30 const u32 coarse_y = y & ~7; 30 const u32 coarse_y = y & ~7;
31 u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value())); 31 u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value()));
32 u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel; 32 u32 dst_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel;
33 u8* dst_pixel = Memory::GetPointer(PAddrToVAddr(addr)) + dst_offset; 33 u8* dst_pixel = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)) + dst_offset;
34 34
35 switch (registers.framebuffer.color_format) { 35 switch (registers.framebuffer.color_format) {
36 case registers.framebuffer.RGBA8: 36 case registers.framebuffer.RGBA8:
@@ -67,7 +67,7 @@ static const Math::Vec4<u8> GetPixel(int x, int y) {
67 const u32 coarse_y = y & ~7; 67 const u32 coarse_y = y & ~7;
68 u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value())); 68 u32 bytes_per_pixel = GPU::Regs::BytesPerPixel(GPU::Regs::PixelFormat(registers.framebuffer.color_format.Value()));
69 u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel; 69 u32 src_offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * registers.framebuffer.width * bytes_per_pixel;
70 u8* src_pixel = Memory::GetPointer(PAddrToVAddr(addr)) + src_offset; 70 u8* src_pixel = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr)) + src_offset;
71 71
72 switch (registers.framebuffer.color_format) { 72 switch (registers.framebuffer.color_format) {
73 case registers.framebuffer.RGBA8: 73 case registers.framebuffer.RGBA8:
@@ -95,7 +95,7 @@ static const Math::Vec4<u8> GetPixel(int x, int y) {
95 95
96static u32 GetDepth(int x, int y) { 96static u32 GetDepth(int x, int y) {
97 const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress(); 97 const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress();
98 u8* depth_buffer = Memory::GetPointer(PAddrToVAddr(addr)); 98 u8* depth_buffer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr));
99 99
100 y = (registers.framebuffer.height - y); 100 y = (registers.framebuffer.height - y);
101 101
@@ -122,7 +122,7 @@ static u32 GetDepth(int x, int y) {
122 122
123static void SetDepth(int x, int y, u32 value) { 123static void SetDepth(int x, int y, u32 value) {
124 const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress(); 124 const PAddr addr = registers.framebuffer.GetDepthBufferPhysicalAddress();
125 u8* depth_buffer = Memory::GetPointer(PAddrToVAddr(addr)); 125 u8* depth_buffer = Memory::GetPointer(Memory::PhysicalToVirtualAddress(addr));
126 126
127 y = (registers.framebuffer.height - y); 127 y = (registers.framebuffer.height - y);
128 128
@@ -361,7 +361,7 @@ static void ProcessTriangleInternal(const VertexShader::OutputVertex& v0,
361 s = GetWrappedTexCoord(texture.config.wrap_s, s, texture.config.width); 361 s = GetWrappedTexCoord(texture.config.wrap_s, s, texture.config.width);
362 t = texture.config.height - 1 - GetWrappedTexCoord(texture.config.wrap_t, t, texture.config.height); 362 t = texture.config.height - 1 - GetWrappedTexCoord(texture.config.wrap_t, t, texture.config.height);
363 363
364 u8* texture_data = Memory::GetPointer(PAddrToVAddr(texture.config.GetPhysicalAddress())); 364 u8* texture_data = Memory::GetPointer(Memory::PhysicalToVirtualAddress(texture.config.GetPhysicalAddress()));
365 auto info = DebugUtils::TextureInfo::FromPicaRegister(texture.config, texture.format); 365 auto info = DebugUtils::TextureInfo::FromPicaRegister(texture.config, texture.format);
366 366
367 texture_color[i] = DebugUtils::LookupTexture(texture_data, s, t, info); 367 texture_color[i] = DebugUtils::LookupTexture(texture_data, s, t, info);