shader_jit_x64: Clear cache after code space fills up.

This commit is contained in:
bunnei 2016-03-12 12:15:49 -05:00
parent c103759cdc
commit 6efb710b28
3 changed files with 19 additions and 2 deletions

View File

@ -32,6 +32,12 @@ namespace Shader {
static std::unordered_map<u64, CompiledShader*> shader_map; static std::unordered_map<u64, CompiledShader*> shader_map;
static JitCompiler jit; static JitCompiler jit;
static CompiledShader* jit_shader; static CompiledShader* jit_shader;
static void ClearCache() {
shader_map.clear();
jit.Clear();
LOG_INFO(HW_GPU, "Shader JIT cache cleared");
}
#endif // ARCHITECTURE_x86_64 #endif // ARCHITECTURE_x86_64
void Setup(UnitState<false>& state) { void Setup(UnitState<false>& state) {
@ -45,6 +51,12 @@ void Setup(UnitState<false>& state) {
if (iter != shader_map.end()) { if (iter != shader_map.end()) {
jit_shader = iter->second; jit_shader = iter->second;
} else { } else {
// Check if remaining JIT code space is enough for at least one more (massive) shader
if (jit.GetSpaceLeft() < jit_shader_size) {
// If not, clear the cache of all previously compiled shaders
ClearCache();
}
jit_shader = jit.Compile(); jit_shader = jit.Compile();
shader_map.emplace(cache_key, jit_shader); shader_map.emplace(cache_key, jit_shader);
} }
@ -54,7 +66,7 @@ void Setup(UnitState<false>& state) {
void Shutdown() { void Shutdown() {
#ifdef ARCHITECTURE_x86_64 #ifdef ARCHITECTURE_x86_64
shader_map.clear(); ClearCache();
#endif // ARCHITECTURE_x86_64 #endif // ARCHITECTURE_x86_64
} }

View File

@ -789,7 +789,7 @@ CompiledShader* JitCompiler::Compile() {
} }
JitCompiler::JitCompiler() { JitCompiler::JitCompiler() {
AllocCodeSpace(1024 * 1024 * 4); AllocCodeSpace(jit_cache_size);
} }
void JitCompiler::Clear() { void JitCompiler::Clear() {

View File

@ -19,6 +19,11 @@ namespace Pica {
namespace Shader { namespace Shader {
/// Memory needed to be available to compile the next shader (otherwise, clear the cache)
constexpr size_t jit_shader_size = 1024 * 512;
/// Memory allocated for the JIT code space cache
constexpr size_t jit_cache_size = 1024 * 1024 * 8;
using CompiledShader = void(void* registers); using CompiledShader = void(void* registers);
/** /**