diff --git a/CMakeLists.txt b/CMakeLists.txt index 95ea1066..f69b5d85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,7 @@ endif() # Check for arm64 if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") set(HOST_ARM64 TRUE) + add_compile_definitions(PANDA3DS_ARM64_HOST) else() set(HOST_ARM64 FALSE) endif() diff --git a/include/PICA/dynapica/shader_rec.hpp b/include/PICA/dynapica/shader_rec.hpp index 2dbb8300..09ff5664 100644 --- a/include/PICA/dynapica/shader_rec.hpp +++ b/include/PICA/dynapica/shader_rec.hpp @@ -3,13 +3,19 @@ #if defined(PANDA3DS_DYNAPICA_SUPPORTED) && defined(PANDA3DS_X64_HOST) #define PANDA3DS_SHADER_JIT_SUPPORTED +#include #include + +#ifdef PANDA3DS_X64_HOST +#include "xbyak/xbyak.h" +using ShaderEmitter = Xbyak::CodeGenerator; +#endif #endif class ShaderJIT { #ifdef PANDA3DS_SHADER_JIT_SUPPORTED using Hash = PICAShader::Hash; - using ShaderCache = std::unordered_map; + using ShaderCache = std::unordered_map>; ShaderCache cache; void compileShader(PICAShader& shaderUnit); diff --git a/src/core/PICA/dynapica/shader_rec.cpp b/src/core/PICA/dynapica/shader_rec.cpp index 63ea504b..e5a08caa 100644 --- a/src/core/PICA/dynapica/shader_rec.cpp +++ b/src/core/PICA/dynapica/shader_rec.cpp @@ -9,6 +9,17 @@ void ShaderJIT::reset() { void ShaderJIT::prepare(PICAShader& shaderUnit) { // We construct a shader hash from both the code and operand descriptor hashes // This is so that if only one of them changes, we still properly recompile the shader + // This code is inspired from how Citra solves this problem Hash hash = shaderUnit.getCodeHash() ^ shaderUnit.getOpdescHash(); + auto it = cache.find(hash); + + if (it == cache.end()) { // Block has not been compiled yet + auto emitter = std::make_unique(); + cache.emplace_hint(it, hash, std::move(emitter)); + } else { // Block has been compiled and found, use it + + } + + shaderUnit.pc = shaderUnit.entrypoint; } #endif // PANDA3DS_SHADER_JIT_SUPPORTED \ No newline at end of file