mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-06 06:55:09 +00:00
Improved Vertex Shader Decompiler.
Fixed VFS Manager crash. Fixed SPU image loader. Draft implementation of cellFsAioRead. Improved Callbacks.
This commit is contained in:
parent
cbeadcf872
commit
7971db665e
12 changed files with 262 additions and 53 deletions
|
|
@ -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()
|
||||
|
|
@ -233,14 +293,31 @@ 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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue