Fix HLE macro code to not hash all of macro memory + update args struct

We incorrectly hashed the entirety of macro memory starting from the macro base address, as opposed to just the macro itself.
This commit is contained in:
Billy Laws 2023-02-04 22:49:33 +00:00
parent b313dcbdca
commit 2444f2e81d

View File

@ -7,16 +7,18 @@
namespace skyline::soc::gm20b { namespace skyline::soc::gm20b {
namespace macro_hle { namespace macro_hle {
void DrawInstanced(size_t offset, span<u32> args, engine::MacroEngineBase *targetEngine) { bool DrawInstanced(size_t offset, span<MacroArgument> args, engine::MacroEngineBase *targetEngine) {
u32 instanceCount{targetEngine->ReadMethodFromMacro(0xD1B) & args[2]}; u32 instanceCount{targetEngine->ReadMethodFromMacro(0xD1B) & *args[2]};
targetEngine->DrawInstanced(true, args[0], args[1], instanceCount, args[3], args[4]); targetEngine->DrawInstanced(true, *args[0], *args[1], instanceCount, *args[3], *args[4]);
return true;
} }
void DrawIndexedInstanced(size_t offset, span<u32> args, engine::MacroEngineBase *targetEngine) { bool DrawIndexedInstanced(size_t offset, span<MacroArgument> args, engine::MacroEngineBase *targetEngine) {
u32 instanceCount{targetEngine->ReadMethodFromMacro(0xD1B) & args[2]}; u32 instanceCount{targetEngine->ReadMethodFromMacro(0xD1B) & *args[2]};
targetEngine->DrawIndexedInstanced(true, args[0], args[1], instanceCount, args[3], args[4], args[5]); targetEngine->DrawIndexedInstanced(true, *args[0], *args[1], instanceCount, *args[3], *args[4], *args[5]);
return true;
} }
void DrawInstancedIndexedWithConstantBuffer(size_t offset, span<u32> args, engine::MacroEngineBase *targetEngine) { void DrawInstancedIndexedWithConstantBuffer(size_t offset, span<u32> args, engine::MacroEngineBase *targetEngine) {
@ -37,10 +39,10 @@ namespace skyline::soc::gm20b {
u32 hash; u32 hash;
}; };
constexpr std::array<HleFunctionInfo, 0x3> functions{{ constexpr std::array<HleFunctionInfo, 0x4> functions{{
{DrawInstanced, 0x12, 0x6F0DD310}, {DrawInstanced, 0x12, 0x2FDD711},
{DrawIndexedInstanced, 0x17, 0x2764C4F}, {DrawIndexedInstanced, 0x17, 0xDBC3B762},
{DrawInstancedIndexedWithConstantBuffer, 0x1F, 0xF2F16988}, {DrawInstancedIndexedIndirectWithConstantBuffer, 0x1F, 0xDA07F4E5}
}}; }};
static Function LookupFunction(span<u32> code) { static Function LookupFunction(span<u32> code) {
@ -49,8 +51,7 @@ namespace skyline::soc::gm20b {
continue; continue;
auto macro{code.subspan(0, function.size)}; auto macro{code.subspan(0, function.size)};
if (XXH32(macro.data(), macro.size_bytes(), 0) == function.hash)
if (XXH32(code.data(), code.size_bytes(), 0) == function.hash)
return function.function; return function.function;
} }
@ -62,7 +63,7 @@ namespace skyline::soc::gm20b {
invalidatePending = true; invalidatePending = true;
} }
void MacroState::Execute(u32 position, span<u32> args, engine::MacroEngineBase *targetEngine) { void MacroState::Execute(u32 position, span<MacroArgument> args, engine::MacroEngineBase *targetEngine) {
size_t offset{macroPositions[position]}; size_t offset{macroPositions[position]};
if (invalidatePending) { if (invalidatePending) {
@ -77,9 +78,11 @@ namespace skyline::soc::gm20b {
hleEntry.valid = true; hleEntry.valid = true;
} }
if (macroHleFunctions[position].function) if (macroHleFunctions[position].function && macroHleFunctions[position].function(offset, args, targetEngine))
macroHleFunctions[position].function(offset, args, targetEngine); return;
else
macroInterpreter.Execute(offset, args, targetEngine); argumentStorage.resize(args.size());
std::transform(args.begin(), args.end(), argumentStorage.begin(), [](MacroArgument arg) { return *arg; });
macroInterpreter.Execute(offset, argumentStorage, targetEngine);
} }
} }