started fixing the rsx textures

offset and format are done
This commit is contained in:
elisha464 2014-02-03 18:11:47 +02:00
parent 8467d8c8c7
commit ad4ad4e55d
7 changed files with 205 additions and 130 deletions

View File

@ -64,9 +64,9 @@ public:
void Init(RSXTexture& tex)
{
Bind();
if(!Memory.IsGoodAddr(tex.GetOffset()))
if(!Memory.IsGoodAddr(GetAddress(tex.GetOffset(), tex.GetLocation())))
{
ConLog.Error("Bad texture address=0x%x", tex.GetOffset());
ConLog.Error("Bad texture address=0x%x", GetAddress(tex.GetOffset(), tex.GetLocation()));
return;
}
//ConLog.Warning("texture addr = 0x%x, width = %d, height = %d, max_aniso=%d, mipmap=%d, remap=0x%x, zfunc=0x%x, wraps=0x%x, wrapt=0x%x, wrapr=0x%x, minlod=0x%x, maxlod=0x%x",
@ -78,7 +78,7 @@ public:
bool is_swizzled = (tex.GetFormat() & 0x20) == 0;
glPixelStorei(GL_PACK_ALIGNMENT, tex.m_pitch);
char* pixels = (char*)Memory.GetMemFromAddr(tex.GetOffset());
char* pixels = (char*)Memory.GetMemFromAddr(GetAddress(tex.GetOffset(), tex.GetLocation()));
switch(format)
{
@ -151,8 +151,8 @@ public:
default: ConLog.Error("Init tex error: Bad tex format (0x%x | 0x%x | 0x%x)", format, tex.GetFormat() & 0x20, tex.GetFormat() & 0x40); break;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, tex.m_mipmap - 1);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, tex.m_mipmap > 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, tex.Getmipmap() - 1);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, tex.Getmipmap() > 1);
if(format != 0x81 && format != 0x94)
{
@ -224,13 +224,13 @@ public:
void Save(RSXTexture& tex, const wxString& name)
{
if(!m_id || !tex.m_offset || !tex.m_width || !tex.m_height) return;
if(!m_id || !tex.GetOffset() || !tex.m_width || !tex.m_height) return;
u32* alldata = new u32[tex.m_width * tex.m_height];
Bind();
switch(tex.m_format & ~(0x20 | 0x40))
switch(tex.GetFormat() & ~(0x20 | 0x40))
{
case 0x81:
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, alldata);

136
rpcs3/Emu/GS/RSXTexture.cpp Normal file
View File

@ -0,0 +1,136 @@
#include "stdafx.h"
#include "RSXThread.h"
RSXTexture::RSXTexture()
: m_width(0)
, m_height(0)
, m_enabled(false)
, m_minlod(0)
, m_maxlod(1000)
, m_maxaniso(0)
, m_wraps(1)
, m_wrapt(1)
, m_wrapr(3)
, m_zfunc(0)
, m_gamma(0)
, m_bias(0)
, m_remap(0xE4)
, m_min_filter(1)
, m_mag_filter(2)
{
m_index = 0;
}
RSXTexture::RSXTexture(u8 index)
: m_width(0)
, m_height(0)
, m_enabled(false)
, m_minlod(0)
, m_maxlod(1000)
, m_maxaniso(0)
, m_wraps(1)
, m_wrapt(1)
, m_wrapr(3)
, m_zfunc(0)
, m_gamma(0)
, m_bias(0)
, m_remap(0xE4)
, m_min_filter(1)
, m_mag_filter(2)
{
m_index = index;
}
u32 RSXTexture::GetOffset() const
{
return methodRegisters[NV4097_SET_TEXTURE_OFFSET + (m_index*4)];
}
u8 RSXTexture::GetLocation() const
{
return (methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*4)] & 0x3) - 1;
}
bool RSXTexture::isCubemap() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*4)] >> 2) & 0x1);
}
u8 RSXTexture::GetBorderType() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*4)] >> 3) & 0x1);
}
u8 RSXTexture::GetDimension() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*4)] >> 4) & 0xf);
}
u8 RSXTexture::GetFormat() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*4)] >> 8) & 0xff);
}
u16 RSXTexture::Getmipmap() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*4)] >> 16) & 0xffff);
}
void RSXTexture::SetRect(const u32 width, const u32 height)
{
m_width = width;
m_height = height;
}
void RSXTexture::SetAddress(u8 wraps, u8 wrapt, u8 wrapr, u8 unsigned_remap, u8 zfunc, u8 gamma, u8 aniso_bias, u8 signed_remap)
{
m_wraps = wraps;
m_wrapt = wrapt;
m_wrapr = wrapr;
m_unsigned_remap = unsigned_remap;
m_zfunc = zfunc;
m_gamma = gamma;
m_aniso_bias = aniso_bias;
m_signed_remap = signed_remap;
}
void RSXTexture::SetControl0(const bool enable, const u16 minlod, const u16 maxlod, const u8 maxaniso)
{
m_enabled = enable;
m_minlod = minlod;
m_maxlod = maxlod;
m_maxaniso = maxaniso;
}
void RSXTexture::SetControl1(u32 remap)
{
m_remap = remap;
}
void RSXTexture::SetControl3(u16 depth, u32 pitch)
{
m_depth = depth;
m_pitch = pitch;
}
void RSXTexture::SetFilter(u16 bias, u8 min, u8 mag, u8 conv, u8 a_signed, u8 r_signed, u8 g_signed, u8 b_signed)
{
m_bias = bias;
m_min_filter = min;
m_mag_filter = mag;
m_conv = conv;
m_a_signed = a_signed;
m_r_signed = r_signed;
m_g_signed = g_signed;
m_b_signed = b_signed;
}
wxSize RSXTexture::GetRect() const
{
return wxSize(m_width, m_height);
}
bool RSXTexture::IsEnabled() const
{
return m_enabled;
}

View File

@ -3,6 +3,21 @@
#define ARGS(x) (Memory.Read32(Memory.RSXIOMem.GetStartAddr() + re(m_ctrl->get) + (4*(x+1))))
u32 methodRegisters[0xffff];
u32 GetAddress(u32 offset, u8 location)
{
switch(location)
{
case CELL_GCM_LOCATION_LOCAL: return Memory.RSXFBMem.GetStartAddr() + offset;
case CELL_GCM_LOCATION_MAIN: return Memory.RSXIOMem.getRealAddr(Memory.RSXIOMem.GetStartAddr() + offset);
}
ConLog.Error("GetAddress(offset=0x%x, location=0x%x)", location);
assert(0);
return 0;
}
RSXVertexData::RSXVertexData()
: frequency(0)
, stride(0)
@ -205,8 +220,6 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u3
if(!Memory.IsGoodAddr(tex_addr))
ConLog.Error("Bad texture[%d] addr = 0x%x #offset = 0x%x, location=%d", index, tex_addr, offset, location);
//ConLog.Warning("texture addr = 0x%x #offset = 0x%x, location=%d", tex_addr, offset, location);
tex.SetOffset(tex_addr);
tex.SetFormat(cubemap, dimension, format, mipmap);
if(!tex.m_width || !tex.m_height)
{
@ -1441,6 +1454,7 @@ void RSXThread::End()
void RSXThread::Task()
{
u8 inc;
ConLog.Write("RSX thread entry");
OnInitThread();
@ -1449,6 +1463,8 @@ void RSXThread::Task()
{
wxCriticalSectionLocker lock(m_cs_main);
inc=1;
u32 put, get;
se_t<u32>::func(put, std::atomic_load((volatile std::atomic<u32>*)((u8*)m_ctrl + offsetof(CellGcmControl, put))));
se_t<u32>::func(get, std::atomic_load((volatile std::atomic<u32>*)((u8*)m_ctrl + offsetof(CellGcmControl, get))));
@ -1499,6 +1515,7 @@ void RSXThread::Task()
if(cmd & CELL_GCM_METHOD_FLAG_NON_INCREMENT)
{
//ConLog.Warning("non increment cmd! 0x%x", cmd);
inc=0;
}
if(cmd == 0)
@ -1508,6 +1525,11 @@ void RSXThread::Task()
continue;
}
for(int i=0; i<count; i++)
{
methodRegisters[(cmd & 0xffff) + (i*4*inc)] = ARGS(i);
}
mem32_ptr_t args(Memory.RSXIOMem.GetStartAddr() + get + 4);
DoCmd(cmd, cmd & 0x3ffff, args, count);

View File

@ -12,19 +12,16 @@ enum Method
CELL_GCM_METHOD_FLAG_RETURN = 0x00020000,
};
extern u32 methodRegisters[0xffff];
u32 GetAddress(u32 offset, u8 location);
class RSXTexture
{
u8 m_index;
public:
bool m_enabled;
u32 m_width, m_height;
u32 m_offset;
bool m_cubemap;
u8 m_dimension;
u32 m_format;
u16 m_mipmap;
u32 m_pitch;
u16 m_depth;
@ -54,102 +51,25 @@ public:
u32 m_remap;
public:
RSXTexture()
: m_width(0), m_height(0)
, m_offset(0)
, m_enabled(false)
RSXTexture();
RSXTexture(u8 index);
, m_cubemap(false)
, m_dimension(0)
, m_format(0)
, m_mipmap(0)
, m_minlod(0)
, m_maxlod(1000)
, m_maxaniso(0)
{
}
u32 GetOffset() const;
u8 GetLocation() const;
bool isCubemap() const;
u8 GetBorderType() const;
u8 GetDimension() const;
u8 GetFormat() const;
u16 Getmipmap() const;
void SetRect(const u32 width, const u32 height)
{
m_width = width;
m_height = height;
}
void SetFormat(const bool cubemap, const u8 dimension, const u32 format, const u16 mipmap)
{
m_cubemap = cubemap;
m_dimension = dimension;
m_format = format;
m_mipmap = mipmap;
}
void SetAddress(u8 wraps, u8 wrapt, u8 wrapr, u8 unsigned_remap, u8 zfunc, u8 gamma, u8 aniso_bias, u8 signed_remap)
{
m_wraps = wraps;
m_wrapt = wrapt;
m_wrapr = wrapr;
m_unsigned_remap = unsigned_remap;
m_zfunc = zfunc;
m_gamma = gamma;
m_aniso_bias = aniso_bias;
m_signed_remap = signed_remap;
}
void SetControl0(const bool enable, const u16 minlod, const u16 maxlod, const u8 maxaniso)
{
m_enabled = enable;
m_minlod = minlod;
m_maxlod = maxlod;
m_maxaniso = maxaniso;
}
void SetControl1(u32 remap)
{
m_remap = remap;
}
void SetControl3(u16 depth, u32 pitch)
{
m_depth = depth;
m_pitch = pitch;
}
void SetFilter(u16 bias, u8 min, u8 mag, u8 conv, u8 a_signed, u8 r_signed, u8 g_signed, u8 b_signed)
{
m_bias = bias;
m_min_filter = min;
m_mag_filter = mag;
m_conv = conv;
m_a_signed = a_signed;
m_r_signed = r_signed;
m_g_signed = g_signed;
m_b_signed = b_signed;
}
u32 GetFormat() const
{
return m_format;
}
void SetOffset(const u32 offset)
{
m_offset = offset;
}
wxSize GetRect() const
{
return wxSize(m_width, m_height);
}
bool IsEnabled() const
{
return m_enabled;
}
u32 GetOffset() const
{
return m_offset;
}
void SetRect(const u32 width, const u32 height);
void SetAddress(u8 wraps, u8 wrapt, u8 wrapr, u8 unsigned_remap, u8 zfunc, u8 gamma, u8 aniso_bias, u8 signed_remap);
void SetControl0(const bool enable, const u16 minlod, const u16 maxlod, const u8 maxaniso);
void SetControl1(u32 remap);
void SetControl3(u16 depth, u32 pitch);
void SetFilter(u16 bias, u8 min, u8 mag, u8 conv, u8 a_signed, u8 r_signed, u8 g_signed, u8 b_signed);
wxSize GetRect() const;
bool IsEnabled() const;
};
struct RSXVertexData
@ -561,6 +481,12 @@ protected:
m_point_x = 0;
m_point_y = 0;
// Construct Textures
for(int i=0; i<16; i++)
{
m_textures[i] = RSXTexture(i);
}
Reset();
}
@ -636,19 +562,6 @@ protected:
virtual void ExecCMD() = 0;
virtual void Flip() = 0;
u32 GetAddress(u32 offset, u8 location)
{
switch(location)
{
case CELL_GCM_LOCATION_LOCAL: return m_local_mem_addr + offset;
case CELL_GCM_LOCATION_MAIN: return Memory.RSXIOMem.getRealAddr(Memory.RSXIOMem.GetStartAddr() + offset);
}
ConLog.Error("GetAddress(offset=0x%x, location=0x%x)", location);
assert(0);
return 0;
}
void LoadVertexData(u32 first, u32 count)
{
for(u32 i=0; i<m_vertex_count; ++i)

View File

@ -293,9 +293,9 @@ void RSXDebugger::OnClickBuffer(wxMouseEvent& event)
if (event.GetId() == p_buffer_colorD->GetId()) SHOW_BUFFER(3);
if (event.GetId() == p_buffer_tex->GetId())
{
if(Memory.IsGoodAddr(render.m_textures[m_cur_texture].m_offset) && render.m_textures[m_cur_texture].m_width && render.m_textures[m_cur_texture].m_height)
if(Memory.IsGoodAddr(GetAddress(render.m_textures[m_cur_texture].GetOffset(), render.m_textures[m_cur_texture].GetLocation())) && render.m_textures[m_cur_texture].m_width && render.m_textures[m_cur_texture].m_height)
MemoryViewerPanel::ShowImage(this,
render.m_textures[m_cur_texture].m_offset, 0,
GetAddress(render.m_textures[m_cur_texture].GetOffset(), render.m_textures[m_cur_texture].GetLocation()), 0,
render.m_textures[m_cur_texture].m_width,
render.m_textures[m_cur_texture].m_height, false);
}
@ -417,7 +417,7 @@ void RSXDebugger::GetBuffers()
}
// Draw Texture
u32 TexBuffer_addr = render.m_textures[m_cur_texture].m_offset;
u32 TexBuffer_addr = GetAddress(render.m_textures[m_cur_texture].GetOffset(), render.m_textures[m_cur_texture].GetLocation());
if(!Memory.IsGoodAddr(TexBuffer_addr))
return;
@ -485,12 +485,12 @@ void RSXDebugger::GetTexture()
for(uint i=0; i<RSXThread::m_textures_count; ++i)
{
m_list_texture->InsertItem(i, wxString::Format("%d", i));
m_list_texture->SetItem(i, 1, wxString::Format("0x%x", render.m_textures[i].m_offset));
m_list_texture->SetItem(i, 2, render.m_textures[i].m_cubemap ? "True" : "False");
m_list_texture->SetItem(i, 3, wxString::Format("%dD", render.m_textures[i].m_dimension));
m_list_texture->SetItem(i, 1, wxString::Format("0x%x", GetAddress(render.m_textures[m_cur_texture].GetOffset(), render.m_textures[m_cur_texture].GetLocation())));
m_list_texture->SetItem(i, 2, render.m_textures[i].isCubemap() ? "True" : "False");
m_list_texture->SetItem(i, 3, wxString::Format("%dD", render.m_textures[i].GetDimension()));
m_list_texture->SetItem(i, 4, render.m_textures[i].m_enabled ? "True" : "False");
m_list_texture->SetItem(i, 5, wxString::Format("0x%x", render.m_textures[i].m_format));
m_list_texture->SetItem(i, 6, wxString::Format("0x%x", render.m_textures[i].m_mipmap));
m_list_texture->SetItem(i, 5, wxString::Format("0x%x", render.m_textures[i].GetFormat()));
m_list_texture->SetItem(i, 6, wxString::Format("0x%x", render.m_textures[i].Getmipmap()));
m_list_texture->SetItem(i, 7, wxString::Format("0x%x", render.m_textures[i].m_pitch));
m_list_texture->SetItem(i, 8, wxString::Format("%dx%d",
render.m_textures[i].m_width,

View File

@ -235,6 +235,7 @@
<ClCompile Include="Emu\GS\GL\OpenGL.cpp" />
<ClCompile Include="Emu\GS\GSManager.cpp" />
<ClCompile Include="Emu\GS\GSRender.cpp" />
<ClCompile Include="Emu\GS\RSXTexture.cpp" />
<ClCompile Include="Emu\GS\RSXThread.cpp" />
<ClCompile Include="Emu\HDD\HDD.cpp" />
<ClCompile Include="Emu\Io\Keyboard.cpp" />

View File

@ -373,6 +373,9 @@
<ClCompile Include="Emu\SysCalls\lv2\SC_Lwcond.cpp">
<Filter>Emu\SysCalls\lv2</Filter>
</ClCompile>
<ClCompile Include="Emu\GS\RSXTexture.cpp">
<Filter>Emu\GS</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="rpcs3.rc" />