summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/video_core/shader/shader.cpp16
-rw-r--r--src/video_core/shader/shader_jit_x64.cpp13
-rw-r--r--src/video_core/shader/shader_jit_x64.h5
3 files changed, 27 insertions, 7 deletions
diff --git a/src/video_core/shader/shader.cpp b/src/video_core/shader/shader.cpp
index 5e8930476..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
@@ -135,7 +147,7 @@ OutputVertex Run(UnitState<false>& state, const InputVertex& input, int num_attr
135 std::fmin(std::fabs(ret.color[i].ToFloat32()), 1.0f)); 147 std::fmin(std::fabs(ret.color[i].ToFloat32()), 1.0f));
136 } 148 }
137 149
138 LOG_TRACE(Render_Software, "Output vertex: pos(%.2f, %.2f, %.2f, %.2f), quat(%.2f, %.2f, %.2f, %.2f), " 150 LOG_TRACE(HW_GPU, "Output vertex: pos(%.2f, %.2f, %.2f, %.2f), quat(%.2f, %.2f, %.2f, %.2f), "
139 "col(%.2f, %.2f, %.2f, %.2f), tc0(%.2f, %.2f), view(%.2f, %.2f, %.2f)", 151 "col(%.2f, %.2f, %.2f, %.2f), tc0(%.2f, %.2f), view(%.2f, %.2f, %.2f)",
140 ret.pos.x.ToFloat32(), ret.pos.y.ToFloat32(), ret.pos.z.ToFloat32(), ret.pos.w.ToFloat32(), 152 ret.pos.x.ToFloat32(), ret.pos.y.ToFloat32(), ret.pos.z.ToFloat32(), ret.pos.w.ToFloat32(),
141 ret.quat.x.ToFloat32(), ret.quat.y.ToFloat32(), ret.quat.z.ToFloat32(), ret.quat.w.ToFloat32(), 153 ret.quat.x.ToFloat32(), ret.quat.y.ToFloat32(), ret.quat.z.ToFloat32(), ret.quat.w.ToFloat32(),
diff --git a/src/video_core/shader/shader_jit_x64.cpp b/src/video_core/shader/shader_jit_x64.cpp
index 443bcbbef..dffe051ef 100644
--- a/src/video_core/shader/shader_jit_x64.cpp
+++ b/src/video_core/shader/shader_jit_x64.cpp
@@ -645,7 +645,8 @@ void JitCompiler::Compile_MAD(Instruction instr) {
645} 645}
646 646
647void JitCompiler::Compile_IF(Instruction instr) { 647void JitCompiler::Compile_IF(Instruction instr) {
648 ASSERT_MSG(instr.flow_control.dest_offset > *offset_ptr, "Backwards if-statements not supported"); 648 ASSERT_MSG(instr.flow_control.dest_offset > *offset_ptr, "Backwards if-statements (%d -> %d) not supported",
649 *offset_ptr, instr.flow_control.dest_offset.Value());
649 650
650 // Evaluate the "IF" condition 651 // Evaluate the "IF" condition
651 if (instr.opcode.Value() == OpCode::Id::IFU) { 652 if (instr.opcode.Value() == OpCode::Id::IFU) {
@@ -676,7 +677,8 @@ void JitCompiler::Compile_IF(Instruction instr) {
676} 677}
677 678
678void JitCompiler::Compile_LOOP(Instruction instr) { 679void JitCompiler::Compile_LOOP(Instruction instr) {
679 ASSERT_MSG(instr.flow_control.dest_offset > *offset_ptr, "Backwards loops not supported"); 680 ASSERT_MSG(instr.flow_control.dest_offset > *offset_ptr, "Backwards loops (%d -> %d) not supported",
681 *offset_ptr, instr.flow_control.dest_offset.Value());
680 ASSERT_MSG(!looping, "Nested loops not supported"); 682 ASSERT_MSG(!looping, "Nested loops not supported");
681 683
682 looping = true; 684 looping = true;
@@ -704,7 +706,8 @@ void JitCompiler::Compile_LOOP(Instruction instr) {
704} 706}
705 707
706void JitCompiler::Compile_JMP(Instruction instr) { 708void JitCompiler::Compile_JMP(Instruction instr) {
707 ASSERT_MSG(instr.flow_control.dest_offset > *offset_ptr, "Backwards jumps not supported"); 709 ASSERT_MSG(instr.flow_control.dest_offset > *offset_ptr, "Backwards jumps (%d -> %d) not supported",
710 *offset_ptr, instr.flow_control.dest_offset.Value());
708 711
709 if (instr.opcode.Value() == OpCode::Id::JMPC) 712 if (instr.opcode.Value() == OpCode::Id::JMPC)
710 Compile_EvaluateCondition(instr); 713 Compile_EvaluateCondition(instr);
@@ -748,7 +751,7 @@ void JitCompiler::Compile_NextInstr(unsigned* offset) {
748 } else { 751 } else {
749 // Unhandled instruction 752 // Unhandled instruction
750 LOG_CRITICAL(HW_GPU, "Unhandled instruction: 0x%02x (0x%08x)", 753 LOG_CRITICAL(HW_GPU, "Unhandled instruction: 0x%02x (0x%08x)",
751 instr.opcode.Value().EffectiveOpCode(), instr.hex); 754 instr.opcode.Value().EffectiveOpCode(), instr.hex);
752 } 755 }
753} 756}
754 757
@@ -787,7 +790,7 @@ CompiledShader* JitCompiler::Compile() {
787} 790}
788 791
789JitCompiler::JitCompiler() { 792JitCompiler::JitCompiler() {
790 AllocCodeSpace(1024 * 1024 * 4); 793 AllocCodeSpace(jit_cache_size);
791} 794}
792 795
793void JitCompiler::Clear() { 796void 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/**