1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

Improved Vertex Shader Decompiler.

Fixed VFS Manager crash.
Fixed SPU image loader.
Draft implementation of cellFsAioRead.
Improved Callbacks.
This commit is contained in:
DH 2014-01-07 22:11:02 +02:00
parent cbeadcf872
commit 7971db665e
12 changed files with 262 additions and 53 deletions

View File

@ -20,7 +20,11 @@ struct VFSManagerEntry
char* mount;
vfsDeviceType device;
VFSManagerEntry() : device(vfsDevice_LocalFile)
VFSManagerEntry()
: device(vfsDevice_LocalFile)
, device_path("")
, path("")
, mount("")
{
}
};

View File

@ -151,7 +151,7 @@ wxString GLVertexDecompilerThread::GetSRC(const u32 n, bool isSca)
return ret;
}
void GLVertexDecompilerThread::AddCode(bool is_sca, wxString code, bool src_mask)
void GLVertexDecompilerThread::AddCode(bool is_sca, wxString code, bool src_mask, bool set_dst)
{
if(d0.cond == 0) return;
enum
@ -179,7 +179,7 @@ void GLVertexDecompilerThread::AddCode(bool is_sca, wxString code, bool src_mask
}
//ConLog.Error("cond! %d (%d %s %d %d)", d0.cond, d0.dst_tmp, cond, d1.input_src, d1.const_src);
cond = wxString::Format("if(tmp%d.x %s 0) ", d0.dst_tmp, cond.mb_str());
cond = wxString::Format("if(rc %s 0) ", cond.mb_str());
}
wxString value = src_mask ? code + GetMask(is_sca) : code;
@ -189,40 +189,100 @@ void GLVertexDecompilerThread::AddCode(bool is_sca, wxString code, bool src_mask
value = "clamp(" + value + ", 0.0, 1.0)";
}
wxString dest;
if(d3.dst == 5 || d3.dst == 6)
if(set_dst)
{
int num = d3.dst == 5 ? 0 : 3;
if(d3.vec_writemask_x)
wxString dest;
if(d0.cond_update_enable_0)
{
ConLog.Error("Bad clip mask.");
dest = m_parr.AddParam(PARAM_NONE, "float", "rc");
}
else if(d3.dst == 5 || d3.dst == 6)
{
int num = d3.dst == 5 ? 0 : 3;
if(d3.vec_writemask_x)
{
ConLog.Error("Bad clip mask.");
}
//if(d3.vec_writemask_y) num += 0;
if(d3.vec_writemask_z) num += 1;
else if(d3.vec_writemask_w) num += 2;
dest = wxString::Format(GetDST(is_sca), num);
}
else
{
dest = GetDST(is_sca) + GetMask(is_sca);
}
//if(d3.vec_writemask_y) num += 0;
if(d3.vec_writemask_z) num += 1;
else if(d3.vec_writemask_w) num += 2;
dest = wxString::Format(GetDST(is_sca), num);
code = cond + dest + " = " + value;
}
else
{
dest = GetDST(is_sca) + GetMask(is_sca);
code = cond + value;
}
code = cond + dest + " = " + value;
main += "\t" + code + ";\n";
m_body.Add(code + wxString::Format(";//%d %d %d %d", d0.cond_reg_sel_1, d0.cond_test_enable, d0.cond_update_enable_0, d0.cond_update_enable_1));
}
void GLVertexDecompilerThread::AddVecCode(const wxString& code, bool src_mask)
wxString GLVertexDecompilerThread::GetFunc()
{
AddCode(false, code, src_mask);
u32 offset = (d2.iaddrh << 3) | d3.iaddrl;
wxString name = wxString::Format("func%u", offset);
for(uint i=0; i<m_funcs.GetCount(); ++i)
{
if(m_funcs[i].name.Cmp(name) == 0)
return name + "()";
}
uint idx = m_funcs.Add(new FuncInfo());
m_funcs[idx].offset = offset;
m_funcs[idx].name = name;
return name + "()";
}
void GLVertexDecompilerThread::AddScaCode(const wxString& code)
void GLVertexDecompilerThread::AddVecCode(const wxString& code, bool src_mask, bool set_dst)
{
AddCode(true, code, false);
AddCode(false, code, src_mask, set_dst);
}
void GLVertexDecompilerThread::AddScaCode(const wxString& code, bool set_dst)
{
AddCode(true, code, false, set_dst);
}
wxString GLVertexDecompilerThread::BuildFuncBody(const FuncInfo& func)
{
wxString result;
for(uint i=func.offset; i<m_body.GetCount(); ++i)
{
if(i != func.offset)
{
uint call_func = -1;
for(uint j=0; j<m_funcs.GetCount(); ++j)
{
if(m_funcs[j].offset == i)
{
call_func = j;
break;
}
}
if(call_func != -1)
{
result += '\t' + m_funcs[call_func].name + "();\n";
break;
}
}
result += '\t' + m_body[i] + '\n';
}
return result;
}
wxString GLVertexDecompilerThread::BuildCode()
@ -234,13 +294,30 @@ wxString GLVertexDecompilerThread::BuildCode()
p += m_parr.params[i].Format();
}
wxString fp = wxEmptyString;
for(int i=m_funcs.GetCount() - 1; i>=0; --i)
{
fp += wxString::Format("void %s();\n", m_funcs[i].name.mb_str());
}
wxString f = wxEmptyString;
f += wxString::Format("void %s()\n{\n\tgl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);\n%s}\n", m_funcs[0].name.mb_str(), BuildFuncBody(m_funcs[0]).mb_str());
for(uint i=1; i<m_funcs.GetCount(); ++i)
{
f += wxString::Format("\nvoid %s()\n{\n%s}\n", m_funcs[i].name.mb_str(), BuildFuncBody(m_funcs[i]).mb_str());
}
static const wxString& prot =
"#version 330\n"
"\n"
"%s\n"
"void main()\n{\n\tgl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);\n%s}\n";
"%s\n"
"%s";
return wxString::Format(prot, p.mb_str(), main.mb_str());
return wxString::Format(prot, p.mb_str(), fp.mb_str(), f.mb_str());
}
void GLVertexDecompilerThread::Task()
@ -268,11 +345,11 @@ void GLVertexDecompilerThread::Task()
case 0x05: AddScaCode("exp(" + GetSRC(2, true) + ")"); break; // EXP
case 0x06: AddScaCode("log(" + GetSRC(2, true) + ")"); break; // LOG
//case 0x07: break; // LIT
//case 0x08: break; // BRA
//case 0x09: break; // BRI : works differently (BRI o[1].x(TR) L0;)
//case 0x0a: break; // CAL : works same as BRI
//case 0x0b: break; // CLI : works same as BRI
//case 0x0c: break; // RET : works like BRI but shorter (RET o[1].x(TR);)
case 0x08: AddScaCode("{ /*BRA*/ " + GetFunc() + "; return; }", false); break; // BRA
case 0x09: AddScaCode("{ " + GetFunc() + "; return; }", false); break; // BRI : works differently (BRI o[1].x(TR) L0;)
case 0x0a: AddScaCode("/*CAL*/ " + GetFunc(), false); break; // CAL : works same as BRI
case 0x0b: AddScaCode("/*CLI*/ " + GetFunc(), false); break; // CLI : works same as BRI
case 0x0c: AddScaCode("return", false); break; // RET : works like BRI but shorter (RET o[1].x(TR);)
case 0x0d: AddScaCode("log2(" + GetSRC(2, true) + ")"); break; // LG2
case 0x0e: AddScaCode("exp2(" + GetSRC(2, true) + ")"); break; // EX2
case 0x0f: AddScaCode("sin(" + GetSRC(2, true) + ")"); break; // SIN
@ -283,6 +360,7 @@ void GLVertexDecompilerThread::Task()
//case 0x14: break; // POP : works differently (POP o[1].x;)
default:
m_body.Add(wxString::Format("//Unknown vp sca_opcode 0x%x", d1.sca_opcode));
ConLog.Error("Unknown vp sca_opcode 0x%x", d1.sca_opcode);
Emu.Pause();
break;
@ -314,17 +392,25 @@ void GLVertexDecompilerThread::Task()
case 0x16: AddVecCode("sign(" + GetSRC(0) + ")"); break; //SSG
default:
m_body.Add(wxString::Format("//Unknown vp opcode 0x%x", d1.vec_opcode));
ConLog.Error("Unknown vp opcode 0x%x", d1.vec_opcode);
Emu.Pause();
break;
}
if(d3.end) break;
if(d3.end)
{
if(i < m_data.GetCount())
ConLog.Error("Program end before buffer end.");
break;
}
}
m_shader = BuildCode();
main = wxEmptyString;
m_body.Clear();
m_funcs.RemoveAt(1, m_funcs.GetCount() - 1);
}
GLVertexProgram::GLVertexProgram()

View File

@ -127,7 +127,17 @@ struct GLVertexDecompilerThread : public ThreadBase
};
} src[3];
wxString main;
struct FuncInfo
{
u32 offset;
wxString name;
};
wxArrayString m_body;
ArrayF<FuncInfo> m_funcs;
//wxString main;
wxString& m_shader;
Array<u32>& m_data;
GLParamArray& m_parr;
@ -138,6 +148,10 @@ struct GLVertexDecompilerThread : public ThreadBase
, m_shader(shader)
, m_parr(parr)
{
m_funcs.Add(new FuncInfo());
m_funcs[0].offset = 0;
m_funcs[0].name = "main";
//m_cur_func->body = "\tgl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);\n";
}
wxString GetMask(bool is_sca);
@ -145,9 +159,11 @@ struct GLVertexDecompilerThread : public ThreadBase
wxString GetScaMask();
wxString GetDST(bool is_sca = false);
wxString GetSRC(const u32 n, bool is_sca = false);
void AddCode(bool is_sca, wxString code, bool src_mask = true);
void AddVecCode(const wxString& code, bool src_mask = true);
void AddScaCode(const wxString& code);
wxString GetFunc();
void AddCode(bool is_sca, wxString code, bool src_mask = true, bool set_dst = true);
void AddVecCode(const wxString& code, bool src_mask = true, bool set_dst = true);
void AddScaCode(const wxString& code, bool set_dst = true);
wxString BuildFuncBody(const FuncInfo& func);
wxString BuildCode();
virtual void Task();

View File

@ -104,6 +104,41 @@ u32 RSXVertexData::GetTypeSize()
index = (cmd - a) / m; \
case a \
#define case_32(a, m) \
case a + m: \
case a + m * 2: \
case a + m * 3: \
case a + m * 4: \
case a + m * 5: \
case a + m * 6: \
case a + m * 7: \
case a + m * 8: \
case a + m * 9: \
case a + m * 10: \
case a + m * 11: \
case a + m * 12: \
case a + m * 13: \
case a + m * 14: \
case a + m * 15: \
case a + m * 16: \
case a + m * 17: \
case a + m * 18: \
case a + m * 19: \
case a + m * 20: \
case a + m * 21: \
case a + m * 22: \
case a + m * 23: \
case a + m * 24: \
case a + m * 25: \
case a + m * 26: \
case a + m * 27: \
case a + m * 28: \
case a + m * 29: \
case a + m * 30: \
case a + m * 31: \
index = (cmd - a) / m; \
case a \
void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u32 count)
{
#if CMD_DEBUG
@ -170,6 +205,13 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u3
//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)
{
gcmBuffer* buffers = (gcmBuffer*)Memory.GetMemFromAddr(m_gcm_buffers_addr);
if(!tex.m_width) tex.m_width = re(buffers[m_gcm_current_buffer].width);
if(!tex.m_height) tex.m_height = re(buffers[m_gcm_current_buffer].height);
}
}
break;
@ -308,10 +350,24 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u3
{
RSXTexture& tex = m_textures[index];
const u16 height = args[0] & 0xffff;
const u16 width = args[0] >> 16;
u16 height = args[0] & 0xffff;
u16 width = args[0] >> 16;
CMD_LOG("width=%d, height=%d", width, height);
if(!width || !height)
{
ConLog.Warning("Bad texture rect: %dx%d (%dx%d)", width, height, tex.m_width, tex.m_height);
for(int i=0; i<count; ++i)
{
ConLog.Warning("*** 0x%x", args[i]);
}
if(!width) width = tex.m_width;
if(!height) height = tex.m_height;
}
tex.SetRect(width, height);
}
break;
@ -665,6 +721,8 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u3
case NV4097_SET_TRANSFORM_PROGRAM_LOAD:
{
//ConLog.Warning("NV4097_SET_TRANSFORM_PROGRAM_LOAD: prog = %d", args[0]);
m_cur_vertex_prog = &m_vertex_progs[args[0]];
m_cur_vertex_prog->data.Clear();
@ -677,8 +735,10 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u3
}
break;
case NV4097_SET_TRANSFORM_PROGRAM:
case_32(NV4097_SET_TRANSFORM_PROGRAM, 4):
{
//ConLog.Warning("NV4097_SET_TRANSFORM_PROGRAM[%d](%d)", index, count);
if(!m_cur_vertex_prog)
{
ConLog.Warning("NV4097_SET_TRANSFORM_PROGRAM: m_cur_vertex_prog == NULL");

View File

@ -226,7 +226,7 @@ class RSXThread : public ThreadBase
{
public:
static const uint m_textures_count = 16;
static const uint m_vertex_count = 16;
static const uint m_vertex_count = 32;
static const uint m_fragment_count = 16;
static const uint m_tiles_count = 15;

View File

@ -9,7 +9,9 @@ Callback::Callback(u32 slot, u64 addr)
, a1(0)
, a2(0)
, a3(0)
, a4(0)
, m_has_data(false)
, m_name("Callback")
{
}
@ -38,11 +40,12 @@ bool Callback::HasData() const
return m_has_data;
}
void Callback::Handle(u64 _a1, u64 _a2, u64 _a3)
void Callback::Handle(u64 _a1, u64 _a2, u64 _a3, u64 _a4)
{
a1 = _a1;
a2 = _a2;
a3 = _a3;
a4 = _a4;
m_has_data = true;
}
@ -55,11 +58,12 @@ void Callback::Branch(bool wait)
new_thread.SetEntry(m_addr);
new_thread.SetPrio(1001);
new_thread.SetStackSize(0x10000);
new_thread.SetName("Callback");
new_thread.SetName(m_name);
new_thread.SetArg(0, a1);
new_thread.SetArg(1, a2);
new_thread.SetArg(2, a3);
new_thread.SetArg(3, a4);
new_thread.Run();
new_thread.Exec();
@ -68,6 +72,11 @@ void Callback::Branch(bool wait)
GetCurrentPPCThread()->Wait(new_thread);
}
void Callback::SetName(const std::string& name)
{
m_name = name;
}
Callback::operator bool() const
{
return GetAddr() != 0;

View File

@ -8,10 +8,13 @@ protected:
bool m_has_data;
std::string m_name;
public:
u64 a1;
u64 a2;
u64 a3;
u64 a4;
u32 GetSlot() const;
u64 GetAddr() const;
@ -20,8 +23,9 @@ public:
bool HasData() const;
Callback(u32 slot = 0, u64 addr = 0);
void Handle(u64 a1 = 0, u64 a2 = 0, u64 a3 = 0);
void Handle(u64 a1 = 0, u64 a2 = 0, u64 a3 = 0, u64 a4 = 0);
void Branch(bool wait);
void SetName(const std::string& name);
operator bool() const;
};

View File

@ -135,6 +135,32 @@ int cellFsSdataOpen(u32 path_addr, int flags, mem32_t fd, mem32_t arg, u64 size)
return CELL_OK;
}
struct CellFsAio
{
be_t<u32> fd;
be_t<u64> offset;
be_t<u32> buf_addr;
be_t<u64> size;
be_t<u64> user_data;
};
int cellFsAioRead(mem_ptr_t<CellFsAio> aio, mem32_t id, mem32_t func_addr)
{
if(!aio.IsGood() || !id.IsGood() || !func_addr.IsGood())
return CELL_EFAULT;
//CellFsAio *xaio, CellFsErrno error, int xid, uint64_t size;
Callback callback;
callback.SetAddr(func_addr);
callback.SetName("cellFsAioReadCallback");
MemoryAllocator<be_t<u64>> nread;
int error = cellFsRead(aio->fd, id.GetAddr(), aio->size, nread);
callback.Handle(aio.GetAddr(), error, id, *nread);
callback.Branch(true);
return CELL_OK;
}
void sys_fs_init()
{
sys_fs.AddFunc(0x718bf5f8, cellFsOpen);
@ -155,6 +181,5 @@ void sys_fs_init()
sys_fs.AddFunc(0x0e2939e5, cellFsFtruncate);
sys_fs.AddFunc(0xc9dc3ac5, cellFsTruncate);
sys_fs.AddFunc(0xcb588dba, cellFsFGetBlockSize);
sys_fs.AddFunc(0xc1c507e7, cellFsAioRead);
}

View File

@ -24,16 +24,21 @@ struct SpuGroupInfo
};
u64 g_last_spu_offset = 0;
static const u64 g_spu_alloc_size = 0x1000000;
u32 LoadSpuImage(vfsStream& stream)
u32 LoadSpuImage(vfsStream& stream, u64 address)
{
ELFLoader l(stream);
l.LoadInfo();
u32 alloc_size = 0xFFFFED - stream.GetSize();
g_last_spu_offset = Memory.MainMem.Alloc(alloc_size);
l.LoadData(g_last_spu_offset);
l.LoadData(address);
return g_last_spu_offset + l.GetEntry();
return address + l.GetEntry();
}
u32 LoadSpuImage(vfsStream& stream)
{
g_last_spu_offset = Memory.MainMem.Alloc(g_spu_alloc_size);
return LoadSpuImage(stream, g_last_spu_offset);
}
//156

View File

@ -493,7 +493,7 @@ void RSXDebugger::GetTexture()
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, 7, wxString::Format("0x%x", render.m_textures[i].m_pitch));
m_list_texture->SetItem(i, 8, wxString::Format("%d x %d",
m_list_texture->SetItem(i, 8, wxString::Format("%dx%d",
render.m_textures[i].m_width,
render.m_textures[i].m_height));

View File

@ -188,7 +188,7 @@ void VFSManagerDialog::OnAdd(wxCommandEvent& event)
m_list->SetItemState(i, i == idx ? wxLIST_STATE_SELECTED : ~wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
}
wxCommandEvent ce;
wxCommandEvent ce;
OnEntryConfig(ce);
}

View File

@ -119,8 +119,8 @@ bool ELF32Loader::LoadShdrInfo()
if(ehdr.e_shstrndx >= shdr_arr.GetCount())
{
ConLog.Error("LoadShdr32 error: shstrndx too big!");
return false;
ConLog.Warning("LoadShdr32 error: shstrndx too big!");
return true;
}
for(u32 i=0; i<shdr_arr.GetCount(); ++i)