Pica: Unify ugly address translation hacks.
This commit is contained in:
parent
7e210e0229
commit
40f123b7c0
7 changed files with 33 additions and 24 deletions
|
@ -56,7 +56,7 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) {
|
|||
g_debug_context->OnEvent(DebugContext::Event::IncomingPrimitiveBatch, nullptr);
|
||||
|
||||
const auto& attribute_config = registers.vertex_attributes;
|
||||
const u8* const base_address = Memory::GetPointer(attribute_config.GetBaseAddress());
|
||||
const u8* const base_address = Memory::GetPointer(PAddrToVAddr(attribute_config.GetPhysicalBaseAddress()));
|
||||
|
||||
// Information about internal vertex attributes
|
||||
const u8* vertex_attribute_sources[16];
|
||||
|
@ -116,7 +116,7 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) {
|
|||
input.attr[i][comp] = float24::FromFloat32(srcval);
|
||||
LOG_TRACE(HW_GPU, "Loaded component %x of attribute %x for vertex %x (index %x) from 0x%08x + 0x%08lx + 0x%04lx: %f",
|
||||
comp, i, vertex, index,
|
||||
attribute_config.GetBaseAddress(),
|
||||
PAddrToVAddr(attribute_config.GetPhysicalBaseAddress()),
|
||||
vertex_attribute_sources[i] - base_address,
|
||||
srcdata - vertex_attribute_sources[i],
|
||||
input.attr[i][comp].ToFloat32());
|
||||
|
|
|
@ -455,7 +455,7 @@ TextureInfo TextureInfo::FromPicaRegister(const Regs::TextureConfig& config,
|
|||
const Regs::TextureFormat& format)
|
||||
{
|
||||
TextureInfo info;
|
||||
info.address = config.GetPhysicalAddress();
|
||||
info.physical_address = config.GetPhysicalAddress();
|
||||
info.width = config.width;
|
||||
info.height = config.height;
|
||||
info.format = format;
|
||||
|
|
|
@ -192,7 +192,7 @@ void OnPicaRegWrite(u32 id, u32 value);
|
|||
std::unique_ptr<PicaTrace> FinishPicaTracing();
|
||||
|
||||
struct TextureInfo {
|
||||
unsigned int address;
|
||||
PAddr physical_address;
|
||||
int width;
|
||||
int height;
|
||||
int stride;
|
||||
|
|
|
@ -127,7 +127,7 @@ struct Regs {
|
|||
u32 address;
|
||||
|
||||
u32 GetPhysicalAddress() const {
|
||||
return DecodeAddressRegister(address) - Memory::FCRAM_PADDR + Memory::HEAP_LINEAR_VADDR;
|
||||
return DecodeAddressRegister(address);
|
||||
}
|
||||
|
||||
// texture1 and texture2 store the texture format directly after the address
|
||||
|
@ -317,11 +317,11 @@ struct Regs {
|
|||
|
||||
INSERT_PADDING_WORDS(0x1);
|
||||
|
||||
inline u32 GetColorBufferAddress() const {
|
||||
return Memory::PhysicalToVirtualAddress(DecodeAddressRegister(color_buffer_address));
|
||||
inline u32 GetColorBufferPhysicalAddress() const {
|
||||
return DecodeAddressRegister(color_buffer_address);
|
||||
}
|
||||
inline u32 GetDepthBufferAddress() const {
|
||||
return Memory::PhysicalToVirtualAddress(DecodeAddressRegister(depth_buffer_address));
|
||||
inline u32 GetDepthBufferPhysicalAddress() const {
|
||||
return DecodeAddressRegister(depth_buffer_address);
|
||||
}
|
||||
|
||||
inline u32 GetWidth() const {
|
||||
|
@ -345,9 +345,8 @@ struct Regs {
|
|||
|
||||
BitField<0, 29, u32> base_address;
|
||||
|
||||
inline u32 GetBaseAddress() const {
|
||||
// TODO: Ugly, should fix PhysicalToVirtualAddress instead
|
||||
return DecodeAddressRegister(base_address) - Memory::FCRAM_PADDR + Memory::HEAP_LINEAR_VADDR;
|
||||
u32 GetPhysicalBaseAddress() const {
|
||||
return DecodeAddressRegister(base_address);
|
||||
}
|
||||
|
||||
// Descriptor for internal vertex attributes
|
||||
|
@ -779,5 +778,15 @@ 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::HEAP_LINEAR_VADDR;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Pica {
|
|||
namespace Rasterizer {
|
||||
|
||||
static void DrawPixel(int x, int y, const Math::Vec4<u8>& color) {
|
||||
u32* color_buffer = (u32*)Memory::GetPointer(registers.framebuffer.GetColorBufferAddress());
|
||||
u32* color_buffer = (u32*)Memory::GetPointer(PAddrToVAddr(registers.framebuffer.GetColorBufferPhysicalAddress()));
|
||||
u32 value = (color.a() << 24) | (color.r() << 16) | (color.g() << 8) | color.b();
|
||||
|
||||
// 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) {
|
|||
}
|
||||
|
||||
static u32 GetDepth(int x, int y) {
|
||||
u16* depth_buffer = (u16*)Memory::GetPointer(registers.framebuffer.GetDepthBufferAddress());
|
||||
u16* depth_buffer = (u16*)Memory::GetPointer(PAddrToVAddr(registers.framebuffer.GetDepthBufferPhysicalAddress()));
|
||||
|
||||
// Assuming 16-bit depth buffer format until actual format handling is implemented
|
||||
return *(depth_buffer + x + y * registers.framebuffer.GetWidth());
|
||||
}
|
||||
|
||||
static void SetDepth(int x, int y, u16 value) {
|
||||
u16* depth_buffer = (u16*)Memory::GetPointer(registers.framebuffer.GetDepthBufferAddress());
|
||||
u16* depth_buffer = (u16*)Memory::GetPointer(PAddrToVAddr(registers.framebuffer.GetDepthBufferPhysicalAddress()));
|
||||
|
||||
// Assuming 16-bit depth buffer format until actual format handling is implemented
|
||||
*(depth_buffer + x + y * registers.framebuffer.GetWidth()) = value;
|
||||
|
@ -204,7 +204,7 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0,
|
|||
s = GetWrappedTexCoord(registers.texture0.wrap_s, s, registers.texture0.width);
|
||||
t = GetWrappedTexCoord(registers.texture0.wrap_t, t, registers.texture0.height);
|
||||
|
||||
u8* texture_data = Memory::GetPointer(texture.config.GetPhysicalAddress());
|
||||
u8* texture_data = Memory::GetPointer(PAddrToVAddr(texture.config.GetPhysicalAddress()));
|
||||
auto info = DebugUtils::TextureInfo::FromPicaRegister(texture.config, texture.format);
|
||||
|
||||
texture_color[i] = DebugUtils::LookupTexture(texture_data, s, t, info);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue