Optimize RSX Debugger

This commit is contained in:
Eladash 2023-07-31 10:24:16 +03:00 committed by Elad Ashkenazi
parent 53c1da8f94
commit b12edf70bb
7 changed files with 622 additions and 592 deletions

View file

@ -109,6 +109,8 @@ u32 RSXDisAsm::disasm(u32 pc)
pc += 4; pc += 4;
std::string str;
for (u32 i = 0; i < count; i++, pc += 4) for (u32 i = 0; i < count; i++, pc += 4)
{ {
if (!try_read_op(pc)) if (!try_read_op(pc))
@ -137,7 +139,9 @@ u32 RSXDisAsm::disasm(u32 pc)
continue; continue;
} }
std::string str = rsx::get_pretty_printing_function(id)(id, m_op); str.clear();
rsx::get_pretty_printing_function(id)(str, id, m_op);
Write(str, m_mode == cpu_disasm_mode::list ? i : count, non_inc, id); Write(str, m_mode == cpu_disasm_mode::list ? i : count, non_inc, id);
} }

View file

@ -3198,7 +3198,9 @@ namespace rsx
} }
} }
fmt::append(result, "[%04x] %s\n", i, ensure(rsx::get_pretty_printing_function(i))(i, method_registers.registers[i])); fmt::append(result, "[%04x] ", i);
ensure(rsx::get_pretty_printing_function(i))(result, i, method_registers.registers[i]);
result += '\n';
} }
} }

View file

@ -612,8 +612,21 @@ void fmt_class_string<texture_max_anisotropy>::format(std::string& out, u64 arg)
namespace rsx namespace rsx
{ {
std::string print_boolean(bool b) enum class boolean_to_string_t : u8;
{ }
return b ? "enabled" : "disabled";
template <>
void fmt_class_string<boolean_to_string_t>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](boolean_to_string_t value)
{
switch (value)
{
case boolean_to_string_t{+true}: return "true";
case boolean_to_string_t{+false}: return "false";
default: break; // TODO: This is technically unreachable but need needs to be reachable when value is not 1 or 0
}
return unknown;
});
} }
} // end namespace rsx

View file

@ -902,18 +902,20 @@ namespace
#undef KEY_STR #undef KEY_STR
} }
std::string rsx::get_method_name(const u32 id) std::pair<std::string_view, std::string_view> rsx::get_method_name(u32 id, std::string& string_name)
{ {
const auto found = methods_name.find(id); const auto found = methods_name.find(id);
if (found != methods_name.end()) if (found != methods_name.end())
{ {
std::string prefix("CELL_GCM_"sv); constexpr std::string_view prefix = "CELL_GCM_";
prefix.append(found->second.data(), found->second.size());
return prefix; return {prefix, found->second};
} }
return fmt::format("Unnamed method 0x%04x", id); string_name.clear();
fmt::append(string_name, "Unnamed method 0x%04x", id);
return {};
} }
// Various parameter pretty printing function // Various parameter pretty printing function
@ -984,15 +986,15 @@ namespace
namespace namespace
{ {
template <u32 Opcode> template <u32 Opcode>
std::string register_pretty_function(u32 /*id*/, u32 arg) void register_pretty_function(std::string& out, u32 /*id*/, u32 arg)
{ {
return rsx::registers_decoder<Opcode>::dump(arg); rsx::registers_decoder<Opcode>::dump(out, arg);
} }
template <typename T, T... Index> template <typename T, T... Index>
std::array<std::string(*)(u32, u32), 1 << 14> create_printing_table(std::integer_sequence<T, Index...>) std::array<void(*)(std::string&, u32, u32), 1 << 14> create_printing_table(std::integer_sequence<T, Index...>)
{ {
std::array<std::string(*)(u32, u32), 1 << 14> result{}; std::array<void(*)(std::string&, u32, u32), 1 << 14> result{};
((result[opcode_list[Index * 5 + 0]] = &register_pretty_function<opcode_list[Index * 5 + 0]>, ((result[opcode_list[Index * 5 + 0]] = &register_pretty_function<opcode_list[Index * 5 + 0]>,
result[opcode_list[Index * 5 + 1]] = &register_pretty_function<opcode_list[Index * 5 + 1]>, result[opcode_list[Index * 5 + 1]] = &register_pretty_function<opcode_list[Index * 5 + 1]>,
@ -1022,7 +1024,7 @@ namespace
};*/ };*/
} }
std::add_pointer_t<std::string(u32, u32)> rsx::get_pretty_printing_function(u32 id) std::add_pointer_t<void(std::string&, u32, u32)> rsx::get_pretty_printing_function(u32 id)
{ {
const auto found = id < printing_functions.size() ? printing_functions[id] : nullptr; const auto found = id < printing_functions.size() ? printing_functions[id] : nullptr;
@ -1031,11 +1033,17 @@ std::add_pointer_t<std::string(u32, u32)> rsx::get_pretty_printing_function(u32
return found; return found;
} }
return [](u32 id, u32 v) return [](std::string& result, u32 id, u32 v)
{ {
const std::string name = rsx::get_method_name(id); std::string string_name;
const std::string_view view = name, prefix = "CELL_GCM_"sv; const auto [name_prefix, name] = rsx::get_method_name(id, string_name);
return fmt::format("%s: 0x%08x", name.starts_with("CELL_GCM_"sv) ? view.substr(prefix.size()) : view, v); if (!string_name.empty())
{
fmt::append(result, "%s: 0x%08x", string_name, v);
return;
}
fmt::append(result, "%s: 0x%08x", name, v);
}; };
} }

View file

@ -6,7 +6,7 @@
namespace rsx namespace rsx
{ {
std::string get_method_name(u32 id); std::pair<std::string_view, std::string_view> get_method_name(u32 id, std::string& result_str);
std::add_pointer_t<std::string(u32, u32)> get_pretty_printing_function(u32 id); std::add_pointer_t<void(std::string&, u32, u32)> get_pretty_printing_function(u32 id);
} }

File diff suppressed because it is too large Load diff

View file

@ -629,18 +629,21 @@ void rsx_debugger::GetMemory() const
std::string dump; std::string dump;
u32 cmd_i = 0; u32 cmd_i = 0;
std::string str;
for (const auto& command : frame_debug.command_queue) for (const auto& command : frame_debug.command_queue)
{ {
const std::string str = rsx::get_pretty_printing_function(command.first)(command.first, command.second); str.clear();
rsx::get_pretty_printing_function(command.first)(str, command.first, command.second);
m_list_captured_frame->setItem(cmd_i++, 0, new QTableWidgetItem(qstr(str))); m_list_captured_frame->setItem(cmd_i++, 0, new QTableWidgetItem(qstr(str)));
dump += str; dump += str;
dump += '\n'; dump += '\n';
} }
if (fs::file file = fs::file(fs::get_cache_dir() + "command_dump.log", fs::rewrite)) if (!dump.empty())
{ {
file.write(dump); fs::write_file(fs::get_cache_dir() + "command_dump.log", fs::rewrite, dump);
} }
for (u32 i = 0; i < frame_debug.draw_calls.size(); i++) for (u32 i = 0; i < frame_debug.draw_calls.size(); i++)