summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/video_core/shader/shader.cpp14
-rw-r--r--src/video_core/shader/shader_jit_x64.cpp2
-rw-r--r--src/video_core/shader/shader_jit_x64.h5
3 files changed, 19 insertions, 2 deletions
diff --git a/src/video_core/shader/shader.cpp b/src/video_core/shader/shader.cpp
index babb124fe..509558fc0 100644
--- a/src/video_core/shader/shader.cpp
+++ b/src/video_core/shader/shader.cpp
@@ -32,6 +32,12 @@ namespace Shader {
32static std::unordered_map<u64, CompiledShader*> shader_map; 32static std::unordered_map<u64, CompiledShader*> shader_map;
33static JitCompiler jit; 33static JitCompiler jit;
34static CompiledShader* jit_shader; 34static CompiledShader* jit_shader;
35
36static void ClearCache() {
37 shader_map.clear();
38 jit.Clear();
39 LOG_INFO(HW_GPU, "Shader JIT cache cleared");
40}
35#endif // ARCHITECTURE_x86_64 41#endif // ARCHITECTURE_x86_64
36 42
37void Setup(UnitState<false>& state) { 43void Setup(UnitState<false>& state) {
@@ -45,6 +51,12 @@ void Setup(UnitState<false>& state) {
45 if (iter != shader_map.end()) { 51 if (iter != shader_map.end()) {
46 jit_shader = iter->second; 52 jit_shader = iter->second;
47 } else { 53 } else {
54 // Check if remaining JIT code space is enough for at least one more (massive) shader
55 if (jit.GetSpaceLeft() < jit_shader_size) {
56 // If not, clear the cache of all previously compiled shaders
57 ClearCache();
58 }
59
48 jit_shader = jit.Compile(); 60 jit_shader = jit.Compile();
49 shader_map.emplace(cache_key, jit_shader); 61 shader_map.emplace(cache_key, jit_shader);
50 } 62 }
@@ -54,7 +66,7 @@ void Setup(UnitState<false>& state) {
54 66
55void Shutdown() { 67void Shutdown() {
56#ifdef ARCHITECTURE_x86_64 68#ifdef ARCHITECTURE_x86_64
57 shader_map.clear(); 69 ClearCache();
58#endif // ARCHITECTURE_x86_64 70#endif // ARCHITECTURE_x86_64
59} 71}
60 72
diff --git a/src/video_core/shader/shader_jit_x64.cpp b/src/video_core/shader/shader_jit_x64.cpp
index 1c700fca7..e6cdfe9c5 100644
--- a/src/video_core/shader/shader_jit_x64.cpp
+++ b/src/video_core/shader/shader_jit_x64.cpp
@@ -789,7 +789,7 @@ CompiledShader* JitCompiler::Compile() {
789} 789}
790 790
791JitCompiler::JitCompiler() { 791JitCompiler::JitCompiler() {
792 AllocCodeSpace(1024 * 1024 * 4); 792 AllocCodeSpace(jit_cache_size);
793} 793}
794 794
795void JitCompiler::Clear() { 795void JitCompiler::Clear() {
diff --git a/src/video_core/shader/shader_jit_x64.h b/src/video_core/shader/shader_jit_x64.h
index 5ad2d9606..5357c964b 100644
--- a/src/video_core/shader/shader_jit_x64.h
+++ b/src/video_core/shader/shader_jit_x64.h
@@ -19,6 +19,11 @@ namespace Pica {
19 19
20namespace Shader { 20namespace Shader {
21 21
22/// Memory needed to be available to compile the next shader (otherwise, clear the cache)
23constexpr size_t jit_shader_size = 1024 * 512;
24/// Memory allocated for the JIT code space cache
25constexpr size_t jit_cache_size = 1024 * 1024 * 8;
26
22using CompiledShader = void(void* registers); 27using CompiledShader = void(void* registers);
23 28
24/** 29/**