summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Tony Wasserka2014-12-15 21:28:45 +0100
committerGravatar Tony Wasserka2014-12-20 18:06:53 +0100
commit40f123b7c0eaf1507d51f6b87192ec2f956e5d5e (patch)
tree7f87847435d510ed0e70a10cd67129a3b2511335 /src
parentPica: Further improve Tev emulation. (diff)
downloadyuzu-40f123b7c0eaf1507d51f6b87192ec2f956e5d5e.tar.gz
yuzu-40f123b7c0eaf1507d51f6b87192ec2f956e5d5e.tar.xz
yuzu-40f123b7c0eaf1507d51f6b87192ec2f956e5d5e.zip
Pica: Unify ugly address translation hacks.
Diffstat (limited to 'src')
-rw-r--r--src/citra_qt/debugger/graphics_cmdlists.cpp8
-rw-r--r--src/citra_qt/debugger/graphics_framebuffer.cpp8
-rw-r--r--src/video_core/command_processor.cpp4
-rw-r--r--src/video_core/debug_utils/debug_utils.cpp2
-rw-r--r--src/video_core/debug_utils/debug_utils.h2
-rw-r--r--src/video_core/pica.h25
-rw-r--r--src/video_core/rasterizer.cpp8
7 files changed, 33 insertions, 24 deletions
diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp
index 01ff31d44..bf35f035f 100644
--- a/src/citra_qt/debugger/graphics_cmdlists.cpp
+++ b/src/citra_qt/debugger/graphics_cmdlists.cpp
@@ -47,7 +47,7 @@ public:
47}; 47};
48 48
49TextureInfoDockWidget::TextureInfoDockWidget(const Pica::DebugUtils::TextureInfo& info, QWidget* parent) 49TextureInfoDockWidget::TextureInfoDockWidget(const Pica::DebugUtils::TextureInfo& info, QWidget* parent)
50 : QDockWidget(tr("Texture 0x%1").arg(info.address, 8, 16, QLatin1Char('0'))), 50 : QDockWidget(tr("Texture 0x%1").arg(info.physical_address, 8, 16, QLatin1Char('0'))),
51 info(info) { 51 info(info) {
52 52
53 QWidget* main_widget = new QWidget; 53 QWidget* main_widget = new QWidget;
@@ -60,7 +60,7 @@ TextureInfoDockWidget::TextureInfoDockWidget(const Pica::DebugUtils::TextureInfo
60 phys_address_spinbox->SetBase(16); 60 phys_address_spinbox->SetBase(16);
61 phys_address_spinbox->SetRange(0, 0xFFFFFFFF); 61 phys_address_spinbox->SetRange(0, 0xFFFFFFFF);
62 phys_address_spinbox->SetPrefix("0x"); 62 phys_address_spinbox->SetPrefix("0x");
63 phys_address_spinbox->SetValue(info.address); 63 phys_address_spinbox->SetValue(info.physical_address);
64 connect(phys_address_spinbox, SIGNAL(ValueChanged(qint64)), this, SLOT(OnAddressChanged(qint64))); 64 connect(phys_address_spinbox, SIGNAL(ValueChanged(qint64)), this, SLOT(OnAddressChanged(qint64)));
65 65
66 QComboBox* format_choice = new QComboBox; 66 QComboBox* format_choice = new QComboBox;
@@ -125,7 +125,7 @@ TextureInfoDockWidget::TextureInfoDockWidget(const Pica::DebugUtils::TextureInfo
125} 125}
126 126
127void TextureInfoDockWidget::OnAddressChanged(qint64 value) { 127void TextureInfoDockWidget::OnAddressChanged(qint64 value) {
128 info.address = value; 128 info.physical_address = value;
129 emit UpdatePixmap(ReloadPixmap()); 129 emit UpdatePixmap(ReloadPixmap());
130} 130}
131 131
@@ -150,7 +150,7 @@ void TextureInfoDockWidget::OnStrideChanged(int value) {
150} 150}
151 151
152QPixmap TextureInfoDockWidget::ReloadPixmap() const { 152QPixmap TextureInfoDockWidget::ReloadPixmap() const {
153 u8* src = Memory::GetPointer(info.address); 153 u8* src = Memory::GetPointer(Pica::PAddrToVAddr(info.physical_address));
154 return QPixmap::fromImage(LoadTexture(src, info)); 154 return QPixmap::fromImage(LoadTexture(src, info));
155} 155}
156 156
diff --git a/src/citra_qt/debugger/graphics_framebuffer.cpp b/src/citra_qt/debugger/graphics_framebuffer.cpp
index c055299a4..484be1db5 100644
--- a/src/citra_qt/debugger/graphics_framebuffer.cpp
+++ b/src/citra_qt/debugger/graphics_framebuffer.cpp
@@ -199,7 +199,7 @@ void GraphicsFramebufferWidget::OnUpdate()
199 auto framebuffer = Pica::registers.framebuffer; 199 auto framebuffer = Pica::registers.framebuffer;
200 using Framebuffer = decltype(framebuffer); 200 using Framebuffer = decltype(framebuffer);
201 201
202 framebuffer_address = framebuffer.GetColorBufferAddress(); 202 framebuffer_address = framebuffer.GetColorBufferPhysicalAddress();
203 framebuffer_width = framebuffer.GetWidth(); 203 framebuffer_width = framebuffer.GetWidth();
204 framebuffer_height = framebuffer.GetHeight(); 204 framebuffer_height = framebuffer.GetHeight();
205 framebuffer_format = static_cast<Format>(framebuffer.color_format); 205 framebuffer_format = static_cast<Format>(framebuffer.color_format);
@@ -224,7 +224,7 @@ void GraphicsFramebufferWidget::OnUpdate()
224 case Format::RGBA8: 224 case Format::RGBA8:
225 { 225 {
226 QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32); 226 QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32);
227 u32* color_buffer = (u32*)Memory::GetPointer(framebuffer_address); 227 u32* color_buffer = (u32*)Memory::GetPointer(Pica::PAddrToVAddr(framebuffer_address));
228 for (unsigned y = 0; y < framebuffer_height; ++y) { 228 for (unsigned y = 0; y < framebuffer_height; ++y) {
229 for (unsigned x = 0; x < framebuffer_width; ++x) { 229 for (unsigned x = 0; x < framebuffer_width; ++x) {
230 u32 value = *(color_buffer + x + y * framebuffer_width); 230 u32 value = *(color_buffer + x + y * framebuffer_width);
@@ -239,7 +239,7 @@ void GraphicsFramebufferWidget::OnUpdate()
239 case Format::RGB8: 239 case Format::RGB8:
240 { 240 {
241 QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32); 241 QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32);
242 u8* color_buffer = Memory::GetPointer(framebuffer_address); 242 u8* color_buffer = Memory::GetPointer(Pica::PAddrToVAddr(framebuffer_address));
243 for (unsigned y = 0; y < framebuffer_height; ++y) { 243 for (unsigned y = 0; y < framebuffer_height; ++y) {
244 for (unsigned x = 0; x < framebuffer_width; ++x) { 244 for (unsigned x = 0; x < framebuffer_width; ++x) {
245 u8* pixel_pointer = color_buffer + x * 3 + y * 3 * framebuffer_width; 245 u8* pixel_pointer = color_buffer + x * 3 + y * 3 * framebuffer_width;
@@ -254,7 +254,7 @@ void GraphicsFramebufferWidget::OnUpdate()
254 case Format::RGBA5551: 254 case Format::RGBA5551:
255 { 255 {
256 QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32); 256 QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32);
257 u32* color_buffer = (u32*)Memory::GetPointer(framebuffer_address); 257 u32* color_buffer = (u32*)Memory::GetPointer(Pica::PAddrToVAddr(framebuffer_address));
258 for (unsigned y = 0; y < framebuffer_height; ++y) { 258 for (unsigned y = 0; y < framebuffer_height; ++y) {
259 for (unsigned x = 0; x < framebuffer_width; ++x) { 259 for (unsigned x = 0; x < framebuffer_width; ++x) {
260 u16 value = *(u16*)(((u8*)color_buffer) + x * 2 + y * framebuffer_width * 2); 260 u16 value = *(u16*)(((u8*)color_buffer) + x * 2 + y * framebuffer_width * 2);
diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp
index b74cd3261..3d06ac7e6 100644
--- a/src/video_core/command_processor.cpp
+++ b/src/video_core/command_processor.cpp
@@ -56,7 +56,7 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) {
56 g_debug_context->OnEvent(DebugContext::Event::IncomingPrimitiveBatch, nullptr); 56 g_debug_context->OnEvent(DebugContext::Event::IncomingPrimitiveBatch, nullptr);
57 57
58 const auto& attribute_config = registers.vertex_attributes; 58 const auto& attribute_config = registers.vertex_attributes;
59 const u8* const base_address = Memory::GetPointer(attribute_config.GetBaseAddress()); 59 const u8* const base_address = Memory::GetPointer(PAddrToVAddr(attribute_config.GetPhysicalBaseAddress()));
60 60
61 // Information about internal vertex attributes 61 // Information about internal vertex attributes
62 const u8* vertex_attribute_sources[16]; 62 const u8* vertex_attribute_sources[16];
@@ -116,7 +116,7 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) {
116 input.attr[i][comp] = float24::FromFloat32(srcval); 116 input.attr[i][comp] = float24::FromFloat32(srcval);
117 LOG_TRACE(HW_GPU, "Loaded component %x of attribute %x for vertex %x (index %x) from 0x%08x + 0x%08lx + 0x%04lx: %f", 117 LOG_TRACE(HW_GPU, "Loaded component %x of attribute %x for vertex %x (index %x) from 0x%08x + 0x%08lx + 0x%04lx: %f",
118 comp, i, vertex, index, 118 comp, i, vertex, index,
119 attribute_config.GetBaseAddress(), 119 PAddrToVAddr(attribute_config.GetPhysicalBaseAddress()),
120 vertex_attribute_sources[i] - base_address, 120 vertex_attribute_sources[i] - base_address,
121 srcdata - vertex_attribute_sources[i], 121 srcdata - vertex_attribute_sources[i],
122 input.attr[i][comp].ToFloat32()); 122 input.attr[i][comp].ToFloat32());
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp
index 3cc22f436..08ecd4ccb 100644
--- a/src/video_core/debug_utils/debug_utils.cpp
+++ b/src/video_core/debug_utils/debug_utils.cpp
@@ -455,7 +455,7 @@ TextureInfo TextureInfo::FromPicaRegister(const Regs::TextureConfig& config,
455 const Regs::TextureFormat& format) 455 const Regs::TextureFormat& format)
456{ 456{
457 TextureInfo info; 457 TextureInfo info;
458 info.address = config.GetPhysicalAddress(); 458 info.physical_address = config.GetPhysicalAddress();
459 info.width = config.width; 459 info.width = config.width;
460 info.height = config.height; 460 info.height = config.height;
461 info.format = format; 461 info.format = format;
diff --git a/src/video_core/debug_utils/debug_utils.h b/src/video_core/debug_utils/debug_utils.h
index f950356f3..2a764e121 100644
--- a/src/video_core/debug_utils/debug_utils.h
+++ b/src/video_core/debug_utils/debug_utils.h
@@ -192,7 +192,7 @@ void OnPicaRegWrite(u32 id, u32 value);
192std::unique_ptr<PicaTrace> FinishPicaTracing(); 192std::unique_ptr<PicaTrace> FinishPicaTracing();
193 193
194struct TextureInfo { 194struct TextureInfo {
195 unsigned int address; 195 PAddr physical_address;
196 int width; 196 int width;
197 int height; 197 int height;
198 int stride; 198 int stride;
diff --git a/src/video_core/pica.h b/src/video_core/pica.h
index 5712439e1..7d82d733d 100644
--- a/src/video_core/pica.h
+++ b/src/video_core/pica.h
@@ -127,7 +127,7 @@ struct Regs {
127 u32 address; 127 u32 address;
128 128
129 u32 GetPhysicalAddress() const { 129 u32 GetPhysicalAddress() const {
130 return DecodeAddressRegister(address) - Memory::FCRAM_PADDR + Memory::HEAP_LINEAR_VADDR; 130 return DecodeAddressRegister(address);
131 } 131 }
132 132
133 // texture1 and texture2 store the texture format directly after the address 133 // texture1 and texture2 store the texture format directly after the address
@@ -317,11 +317,11 @@ struct Regs {
317 317
318 INSERT_PADDING_WORDS(0x1); 318 INSERT_PADDING_WORDS(0x1);
319 319
320 inline u32 GetColorBufferAddress() const { 320 inline u32 GetColorBufferPhysicalAddress() const {
321 return Memory::PhysicalToVirtualAddress(DecodeAddressRegister(color_buffer_address)); 321 return DecodeAddressRegister(color_buffer_address);
322 } 322 }
323 inline u32 GetDepthBufferAddress() const { 323 inline u32 GetDepthBufferPhysicalAddress() const {
324 return Memory::PhysicalToVirtualAddress(DecodeAddressRegister(depth_buffer_address)); 324 return DecodeAddressRegister(depth_buffer_address);
325 } 325 }
326 326
327 inline u32 GetWidth() const { 327 inline u32 GetWidth() const {
@@ -345,9 +345,8 @@ struct Regs {
345 345
346 BitField<0, 29, u32> base_address; 346 BitField<0, 29, u32> base_address;
347 347
348 inline u32 GetBaseAddress() const { 348 u32 GetPhysicalBaseAddress() const {
349 // TODO: Ugly, should fix PhysicalToVirtualAddress instead 349 return DecodeAddressRegister(base_address);
350 return DecodeAddressRegister(base_address) - Memory::FCRAM_PADDR + Memory::HEAP_LINEAR_VADDR;
351 } 350 }
352 351
353 // Descriptor for internal vertex attributes 352 // Descriptor for internal vertex attributes
@@ -779,5 +778,15 @@ union CommandHeader {
779 BitField<31, 1, u32> group_commands; 778 BitField<31, 1, u32> group_commands;
780}; 779};
781 780
781// TODO: Ugly, should fix PhysicalToVirtualAddress instead
782inline static u32 PAddrToVAddr(u32 addr) {
783 if (addr >= Memory::VRAM_PADDR && addr < Memory::VRAM_PADDR + Memory::VRAM_SIZE) {
784 return addr - Memory::VRAM_PADDR + Memory::VRAM_VADDR;
785 } else if (addr >= Memory::FCRAM_PADDR && addr < Memory::FCRAM_PADDR + Memory::FCRAM_SIZE) {
786 return addr - Memory::FCRAM_PADDR + Memory::HEAP_LINEAR_VADDR;
787 } else {
788 return 0;
789 }
790}
782 791
783} // namespace 792} // namespace
diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp
index 25efd49c8..bd79e4413 100644
--- a/src/video_core/rasterizer.cpp
+++ b/src/video_core/rasterizer.cpp
@@ -18,7 +18,7 @@ namespace Pica {
18namespace Rasterizer { 18namespace Rasterizer {
19 19
20static void DrawPixel(int x, int y, const Math::Vec4<u8>& color) { 20static void DrawPixel(int x, int y, const Math::Vec4<u8>& color) {
21 u32* color_buffer = (u32*)Memory::GetPointer(registers.framebuffer.GetColorBufferAddress()); 21 u32* color_buffer = (u32*)Memory::GetPointer(PAddrToVAddr(registers.framebuffer.GetColorBufferPhysicalAddress()));
22 u32 value = (color.a() << 24) | (color.r() << 16) | (color.g() << 8) | color.b(); 22 u32 value = (color.a() << 24) | (color.r() << 16) | (color.g() << 8) | color.b();
23 23
24 // Assuming RGBA8 format until actual framebuffer format handling is implemented 24 // Assuming RGBA8 format until actual framebuffer format handling is implemented
@@ -26,14 +26,14 @@ static void DrawPixel(int x, int y, const Math::Vec4<u8>& color) {
26} 26}
27 27
28static u32 GetDepth(int x, int y) { 28static u32 GetDepth(int x, int y) {
29 u16* depth_buffer = (u16*)Memory::GetPointer(registers.framebuffer.GetDepthBufferAddress()); 29 u16* depth_buffer = (u16*)Memory::GetPointer(PAddrToVAddr(registers.framebuffer.GetDepthBufferPhysicalAddress()));
30 30
31 // Assuming 16-bit depth buffer format until actual format handling is implemented 31 // Assuming 16-bit depth buffer format until actual format handling is implemented
32 return *(depth_buffer + x + y * registers.framebuffer.GetWidth()); 32 return *(depth_buffer + x + y * registers.framebuffer.GetWidth());
33} 33}
34 34
35static void SetDepth(int x, int y, u16 value) { 35static void SetDepth(int x, int y, u16 value) {
36 u16* depth_buffer = (u16*)Memory::GetPointer(registers.framebuffer.GetDepthBufferAddress()); 36 u16* depth_buffer = (u16*)Memory::GetPointer(PAddrToVAddr(registers.framebuffer.GetDepthBufferPhysicalAddress()));
37 37
38 // Assuming 16-bit depth buffer format until actual format handling is implemented 38 // Assuming 16-bit depth buffer format until actual format handling is implemented
39 *(depth_buffer + x + y * registers.framebuffer.GetWidth()) = value; 39 *(depth_buffer + x + y * registers.framebuffer.GetWidth()) = value;
@@ -204,7 +204,7 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0,
204 s = GetWrappedTexCoord(registers.texture0.wrap_s, s, registers.texture0.width); 204 s = GetWrappedTexCoord(registers.texture0.wrap_s, s, registers.texture0.width);
205 t = GetWrappedTexCoord(registers.texture0.wrap_t, t, registers.texture0.height); 205 t = GetWrappedTexCoord(registers.texture0.wrap_t, t, registers.texture0.height);
206 206
207 u8* texture_data = Memory::GetPointer(texture.config.GetPhysicalAddress()); 207 u8* texture_data = Memory::GetPointer(PAddrToVAddr(texture.config.GetPhysicalAddress()));
208 auto info = DebugUtils::TextureInfo::FromPicaRegister(texture.config, texture.format); 208 auto info = DebugUtils::TextureInfo::FromPicaRegister(texture.config, texture.format);
209 209
210 texture_color[i] = DebugUtils::LookupTexture(texture_data, s, t, info); 210 texture_color[i] = DebugUtils::LookupTexture(texture_data, s, t, info);