rsx: Relocatable transform constants

This commit is contained in:
kd-11 2022-03-23 22:53:18 +03:00 committed by kd-11
parent e650d11b30
commit 9a2d4fe46b
23 changed files with 222 additions and 67 deletions

View file

@ -126,6 +126,8 @@ std::string VertexProgramDecompiler::GetSRC(const u32 n)
break;
case RSX_VP_REGISTER_TYPE_CONSTANT:
m_parr.AddParam(PF_PARAM_UNIFORM, getFloatTypeName(4), std::string("vc[468]"));
properties.has_indexed_constants |= !!d3.index_const;
m_constant_ids.push_back(d1.const_src);
ret += std::string("vc[") + std::to_string(d1.const_src) + (d3.index_const ? " + " + AddAddrReg() : "") + "]";
break;
@ -391,6 +393,30 @@ std::string VertexProgramDecompiler::BuildCode()
m_parr.AddParam(PF_PARAM_OUT, float4_type, "dst_reg0", float4_type + "(0., 0., 0., 1.)");
}
if (!properties.has_indexed_constants && !m_constant_ids.empty())
{
// Relocate transform constants
std::vector<std::pair<std::string, std::string>> reloc_table;
reloc_table.reserve(m_constant_ids.size());
// First sort the data in ascending order
std::sort(m_constant_ids.begin(), m_constant_ids.end());
// Build the string lookup table
for (const auto& index : m_constant_ids)
{
reloc_table.emplace_back(fmt::format("vc[%d]", index), fmt::format("vc[%llu]", reloc_table.size()));
}
// One-time patch
main_body = fmt::replace_all(main_body, reloc_table);
// Rename the array type
auto type_list = ensure(m_parr.SearchParam(PF_PARAM_CONST, getFloatTypeName(4)));
const auto item = ParamItem(fmt::format("vc[%llu]", m_constant_ids.size()), -1);
type_list->ReplaceOrInsert("vc[468]", item);
}
std::stringstream OS;
insertHeader(OS);