Common/GL/D3D12: Fix int vector ctor in vertex shader and a compare opcode.

This commit is contained in:
Vincent Lejeune 2015-10-05 19:30:06 +02:00
parent de97d3a7aa
commit b0f8611f49
6 changed files with 28 additions and 13 deletions

View File

@ -232,16 +232,15 @@ std::string VertexProgramDecompiler::GetCond()
if (d0.cond == 0) return "false"; if (d0.cond == 0) return "false";
if (d0.cond == (lt | gt | eq)) return "true"; 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", COMPARE::FUNCTION_SLT, // "error"
"lessThan", COMPARE::FUNCTION_SLT,
"equal", COMPARE::FUNCTION_SEQ,
"lessThanEqual", COMPARE::FUNCTION_SLE,
"greaterThan", COMPARE::FUNCTION_SGT,
"notEqual", COMPARE::FUNCTION_SNE,
"greaterThanEqual", COMPARE::FUNCTION_SGE,
"error"
}; };
static const char f[4] = { 'x', 'y', 'z', 'w' }; static const char f[4] = { 'x', 'y', 'z', 'w' };
@ -253,8 +252,7 @@ std::string VertexProgramDecompiler::GetCond()
swizzle += f[d0.mask_w]; swizzle += f[d0.mask_w];
swizzle = swizzle == "xyzw" ? "" : "." + swizzle; swizzle = swizzle == "xyzw" ? "" : "." + swizzle;
return "any(" + compareFunction(cond_string_table[d0.cond], "cc" + std::to_string(d0.cond_reg_sel_1), getFloatTypeName(4) + "(0., 0., 0., 0.)" + 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());
} }
void VertexProgramDecompiler::AddCodeCond(const std::string& dst, const std::string& src) void VertexProgramDecompiler::AddCodeCond(const std::string& dst, const std::string& src)
@ -330,7 +328,7 @@ std::string VertexProgramDecompiler::AddAddrMask()
std::string VertexProgramDecompiler::AddAddrReg() std::string VertexProgramDecompiler::AddAddrReg()
{ {
static const char f[] = { 'x', 'y', 'z', 'w' }; 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() 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_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_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_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_FRC: SetDSTVec(getFunction(FUNCTION::FUNCTION_FRACT)); break;
case RSX_VEC_OPCODE_FLR: SetDSTVec("floor($0)"); 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; case RSX_VEC_OPCODE_SEQ: SetDSTVec(getFloatTypeName(4) + "(" + compareFunction(COMPARE::FUNCTION_SEQ, "$0", "$1") + ")"); break;

View File

@ -80,6 +80,10 @@ protected:
*/ */
virtual std::string getFloatTypeName(size_t elementCount) = 0; 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 /** returns string calling function where arguments are passed via
* $0 $1 $2 substring. * $0 $1 $2 substring.
*/ */

View File

@ -11,6 +11,11 @@ std::string D3D12VertexProgramDecompiler::getFloatTypeName(size_t elementCount)
return getFloatTypeNameImp(elementCount); return getFloatTypeNameImp(elementCount);
} }
std::string D3D12VertexProgramDecompiler::getIntTypeName(size_t elementCount)
{
return "int4";
}
std::string D3D12VertexProgramDecompiler::getFunction(enum class FUNCTION f) std::string D3D12VertexProgramDecompiler::getFunction(enum class FUNCTION f)
{ {
return getFunctionImp(f); return getFunctionImp(f);

View File

@ -8,6 +8,7 @@ struct D3D12VertexProgramDecompiler : public VertexProgramDecompiler
{ {
protected: protected:
virtual std::string getFloatTypeName(size_t elementCount) override; 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 getFunction(enum class FUNCTION) override;
virtual std::string compareFunction(enum class COMPARE, const std::string &, const std::string &) override; virtual std::string compareFunction(enum class COMPARE, const std::string &, const std::string &) override;

View File

@ -10,6 +10,12 @@ std::string GLVertexDecompilerThread::getFloatTypeName(size_t elementCount)
return getFloatTypeNameImpl(elementCount); return getFloatTypeNameImpl(elementCount);
} }
std::string GLVertexDecompilerThread::getIntTypeName(size_t elementCount)
{
return "ivec4";
}
std::string GLVertexDecompilerThread::getFunction(FUNCTION f) std::string GLVertexDecompilerThread::getFunction(FUNCTION f)
{ {
return getFunctionImpl(f); return getFunctionImpl(f);

View File

@ -9,6 +9,7 @@ struct GLVertexDecompilerThread : public VertexProgramDecompiler
std::string &m_shader; std::string &m_shader;
protected: protected:
virtual std::string getFloatTypeName(size_t elementCount) override; virtual std::string getFloatTypeName(size_t elementCount) override;
std::string getIntTypeName(size_t elementCount) override;
virtual std::string getFunction(FUNCTION) override; virtual std::string getFunction(FUNCTION) override;
virtual std::string compareFunction(COMPARE, const std::string&, const std::string&) override; virtual std::string compareFunction(COMPARE, const std::string&, const std::string&) override;