From b0f8611f490e6bd2ce9ba0fb0eb3bba7e3989abf Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 5 Oct 2015 19:30:06 +0200 Subject: [PATCH] Common/GL/D3D12: Fix int vector ctor in vertex shader and a compare opcode. --- .../RSX/Common/VertexProgramDecompiler.cpp | 24 +++++++++---------- .../Emu/RSX/Common/VertexProgramDecompiler.h | 4 ++++ .../D3D12/D3D12VertexProgramDecompiler.cpp | 5 ++++ .../RSX/D3D12/D3D12VertexProgramDecompiler.h | 1 + rpcs3/Emu/RSX/GL/GLVertexProgram.cpp | 6 +++++ rpcs3/Emu/RSX/GL/GLVertexProgram.h | 1 + 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.cpp b/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.cpp index 1c9f18e059..dd47e05978 100644 --- a/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.cpp +++ b/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.cpp @@ -232,16 +232,15 @@ std::string VertexProgramDecompiler::GetCond() if (d0.cond == 0) return "false"; if (d0.cond == (lt | gt | eq)) return "true"; - static const char* cond_string_table[(lt | gt | eq) + 1] = + static const COMPARE cond_string_table[(lt | gt | eq) + 1] = { - "error", - "lessThan", - "equal", - "lessThanEqual", - "greaterThan", - "notEqual", - "greaterThanEqual", - "error" + COMPARE::FUNCTION_SLT, // "error" + COMPARE::FUNCTION_SLT, + COMPARE::FUNCTION_SEQ, + COMPARE::FUNCTION_SLE, + COMPARE::FUNCTION_SGT, + COMPARE::FUNCTION_SNE, + COMPARE::FUNCTION_SGE, }; static const char f[4] = { 'x', 'y', 'z', 'w' }; @@ -253,8 +252,7 @@ std::string VertexProgramDecompiler::GetCond() swizzle += f[d0.mask_w]; swizzle = swizzle == "xyzw" ? "" : "." + swizzle; - - return fmt::format("any(%s(cc%d%s, vec4(0.0)%s))", cond_string_table[d0.cond], d0.cond_reg_sel_1, swizzle.c_str(), swizzle.c_str()); + return "any(" + compareFunction(cond_string_table[d0.cond], "cc" + std::to_string(d0.cond_reg_sel_1), getFloatTypeName(4) + "(0., 0., 0., 0.)" + swizzle) + ")"; } void VertexProgramDecompiler::AddCodeCond(const std::string& dst, const std::string& src) @@ -330,7 +328,7 @@ std::string VertexProgramDecompiler::AddAddrMask() std::string VertexProgramDecompiler::AddAddrReg() { static const char f[] = { 'x', 'y', 'z', 'w' }; - return m_parr.AddParam(PF_PARAM_NONE, "ivec4", "a" + std::to_string(d0.addr_reg_sel_1), "ivec4(0)") + AddAddrMask(); + return m_parr.AddParam(PF_PARAM_NONE, getFloatTypeName(4), "a" + std::to_string(d0.addr_reg_sel_1), getFloatTypeName(4) + "(0, 0, 0, 0)") + AddAddrMask(); } u32 VertexProgramDecompiler::GetAddr() @@ -659,7 +657,7 @@ std::string VertexProgramDecompiler::Decompile() case RSX_VEC_OPCODE_MAX: SetDSTVec("max($0, $1)"); break; case RSX_VEC_OPCODE_SLT: SetDSTVec(getFloatTypeName(4) + "(" + compareFunction(COMPARE::FUNCTION_SLT, "$0", "$1") + ")"); break; case RSX_VEC_OPCODE_SGE: SetDSTVec(getFloatTypeName(4) + "(" + compareFunction(COMPARE::FUNCTION_SGE, "$0", "$1") + ")"); break; - case RSX_VEC_OPCODE_ARL: AddCode("$ifcond $a = ivec4($0)$am;"); break; + case RSX_VEC_OPCODE_ARL: AddCode("$ifcond $a = " + getIntTypeName(4) + "($0)$am;"); break; case RSX_VEC_OPCODE_FRC: SetDSTVec(getFunction(FUNCTION::FUNCTION_FRACT)); break; case RSX_VEC_OPCODE_FLR: SetDSTVec("floor($0)"); break; case RSX_VEC_OPCODE_SEQ: SetDSTVec(getFloatTypeName(4) + "(" + compareFunction(COMPARE::FUNCTION_SEQ, "$0", "$1") + ")"); break; diff --git a/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.h b/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.h index c34e2c14a0..6fbe1807e0 100644 --- a/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.h +++ b/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.h @@ -80,6 +80,10 @@ protected: */ virtual std::string getFloatTypeName(size_t elementCount) = 0; + /** returns the type name of int vectors. + */ + virtual std::string getIntTypeName(size_t elementCount) = 0; + /** returns string calling function where arguments are passed via * $0 $1 $2 substring. */ diff --git a/rpcs3/Emu/RSX/D3D12/D3D12VertexProgramDecompiler.cpp b/rpcs3/Emu/RSX/D3D12/D3D12VertexProgramDecompiler.cpp index 555881380a..f968cbcdc7 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12VertexProgramDecompiler.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12VertexProgramDecompiler.cpp @@ -11,6 +11,11 @@ std::string D3D12VertexProgramDecompiler::getFloatTypeName(size_t elementCount) return getFloatTypeNameImp(elementCount); } +std::string D3D12VertexProgramDecompiler::getIntTypeName(size_t elementCount) +{ + return "int4"; +} + std::string D3D12VertexProgramDecompiler::getFunction(enum class FUNCTION f) { return getFunctionImp(f); diff --git a/rpcs3/Emu/RSX/D3D12/D3D12VertexProgramDecompiler.h b/rpcs3/Emu/RSX/D3D12/D3D12VertexProgramDecompiler.h index d61642c18b..7d12546cc4 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12VertexProgramDecompiler.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12VertexProgramDecompiler.h @@ -8,6 +8,7 @@ struct D3D12VertexProgramDecompiler : public VertexProgramDecompiler { protected: virtual std::string getFloatTypeName(size_t elementCount) override; + std::string getIntTypeName(size_t elementCount) override; virtual std::string getFunction(enum class FUNCTION) override; virtual std::string compareFunction(enum class COMPARE, const std::string &, const std::string &) override; diff --git a/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp b/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp index ea69a65c3d..3abc3a78ef 100644 --- a/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp +++ b/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp @@ -10,6 +10,12 @@ std::string GLVertexDecompilerThread::getFloatTypeName(size_t elementCount) return getFloatTypeNameImpl(elementCount); } +std::string GLVertexDecompilerThread::getIntTypeName(size_t elementCount) +{ + return "ivec4"; +} + + std::string GLVertexDecompilerThread::getFunction(FUNCTION f) { return getFunctionImpl(f); diff --git a/rpcs3/Emu/RSX/GL/GLVertexProgram.h b/rpcs3/Emu/RSX/GL/GLVertexProgram.h index 9b01045dd1..44e4a5e097 100644 --- a/rpcs3/Emu/RSX/GL/GLVertexProgram.h +++ b/rpcs3/Emu/RSX/GL/GLVertexProgram.h @@ -9,6 +9,7 @@ struct GLVertexDecompilerThread : public VertexProgramDecompiler std::string &m_shader; protected: virtual std::string getFloatTypeName(size_t elementCount) override; + std::string getIntTypeName(size_t elementCount) override; virtual std::string getFunction(FUNCTION) override; virtual std::string compareFunction(COMPARE, const std::string&, const std::string&) override;