mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-09 07:35:41 +12:00
[Shader JIT[ Cache harder
This commit is contained in:
parent
4064abfdeb
commit
6a70edca7e
3 changed files with 19 additions and 1 deletions
|
@ -58,6 +58,7 @@ endif()
|
||||||
# Check for arm64
|
# Check for arm64
|
||||||
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
|
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
|
||||||
set(HOST_ARM64 TRUE)
|
set(HOST_ARM64 TRUE)
|
||||||
|
add_compile_definitions(PANDA3DS_ARM64_HOST)
|
||||||
else()
|
else()
|
||||||
set(HOST_ARM64 FALSE)
|
set(HOST_ARM64 FALSE)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -3,13 +3,19 @@
|
||||||
|
|
||||||
#if defined(PANDA3DS_DYNAPICA_SUPPORTED) && defined(PANDA3DS_X64_HOST)
|
#if defined(PANDA3DS_DYNAPICA_SUPPORTED) && defined(PANDA3DS_X64_HOST)
|
||||||
#define PANDA3DS_SHADER_JIT_SUPPORTED
|
#define PANDA3DS_SHADER_JIT_SUPPORTED
|
||||||
|
#include <memory>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#ifdef PANDA3DS_X64_HOST
|
||||||
|
#include "xbyak/xbyak.h"
|
||||||
|
using ShaderEmitter = Xbyak::CodeGenerator;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class ShaderJIT {
|
class ShaderJIT {
|
||||||
#ifdef PANDA3DS_SHADER_JIT_SUPPORTED
|
#ifdef PANDA3DS_SHADER_JIT_SUPPORTED
|
||||||
using Hash = PICAShader::Hash;
|
using Hash = PICAShader::Hash;
|
||||||
using ShaderCache = std::unordered_map<Hash, int>;
|
using ShaderCache = std::unordered_map<Hash, std::unique_ptr<ShaderEmitter>>;
|
||||||
|
|
||||||
ShaderCache cache;
|
ShaderCache cache;
|
||||||
void compileShader(PICAShader& shaderUnit);
|
void compileShader(PICAShader& shaderUnit);
|
||||||
|
|
|
@ -9,6 +9,17 @@ void ShaderJIT::reset() {
|
||||||
void ShaderJIT::prepare(PICAShader& shaderUnit) {
|
void ShaderJIT::prepare(PICAShader& shaderUnit) {
|
||||||
// We construct a shader hash from both the code and operand descriptor hashes
|
// 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 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();
|
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<ShaderEmitter>();
|
||||||
|
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
|
#endif // PANDA3DS_SHADER_JIT_SUPPORTED
|
Loading…
Add table
Reference in a new issue