diff options
Diffstat (limited to 'src/video_core/shader/shader.cpp')
| -rw-r--r-- | src/video_core/shader/shader.cpp | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/video_core/shader/shader.cpp b/src/video_core/shader/shader.cpp index 13e22cb53..fa1f7cafe 100644 --- a/src/video_core/shader/shader.cpp +++ b/src/video_core/shader/shader.cpp | |||
| @@ -2,21 +2,52 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/logging/log.h" | 5 | #include <memory> |
| 6 | #include <unordered_map> | ||
| 7 | |||
| 8 | #include "common/hash.h" | ||
| 9 | #include "common/make_unique.h" | ||
| 6 | #include "common/profiler.h" | 10 | #include "common/profiler.h" |
| 7 | 11 | ||
| 8 | #include "video_core/debug_utils/debug_utils.h" | 12 | #include "video_core/debug_utils/debug_utils.h" |
| 9 | #include "video_core/pica.h" | 13 | #include "video_core/pica.h" |
| 14 | #include "video_core/video_core.h" | ||
| 10 | 15 | ||
| 11 | #include "shader.h" | 16 | #include "shader.h" |
| 12 | #include "shader_interpreter.h" | 17 | #include "shader_interpreter.h" |
| 18 | #include "shader_jit.h" | ||
| 13 | 19 | ||
| 14 | namespace Pica { | 20 | namespace Pica { |
| 15 | 21 | ||
| 16 | namespace Shader { | 22 | namespace Shader { |
| 17 | 23 | ||
| 24 | #ifdef ARCHITECTURE_x86_64 | ||
| 25 | |||
| 26 | static std::unordered_map<u64, CompiledShader*> shader_map; | ||
| 27 | static JitCompiler jit; | ||
| 28 | static CompiledShader* jit_shader; | ||
| 29 | |||
| 30 | #endif // ARCHITECTURE_x86_64 | ||
| 31 | |||
| 18 | void Setup(UnitState& state) { | 32 | void Setup(UnitState& state) { |
| 19 | // TODO(bunnei): This will be used by the JIT in a subsequent patch | 33 | #ifdef ARCHITECTURE_x86_64 |
| 34 | if (VideoCore::g_shader_jit_enabled) { | ||
| 35 | u64 cache_key = (Common::ComputeHash64(&g_state.vs.program_code, sizeof(g_state.vs.program_code)) ^ | ||
| 36 | Common::ComputeHash64(&g_state.vs.swizzle_data, sizeof(g_state.vs.swizzle_data)) ^ | ||
| 37 | g_state.regs.vs.main_offset); | ||
| 38 | |||
| 39 | auto iter = shader_map.find(cache_key); | ||
| 40 | if (iter != shader_map.end()) { | ||
| 41 | jit_shader = iter->second; | ||
| 42 | } else { | ||
| 43 | jit_shader = jit.Compile(); | ||
| 44 | shader_map.emplace(cache_key, jit_shader); | ||
| 45 | } | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | void Shutdown() { | ||
| 50 | shader_map.clear(); | ||
| 20 | } | 51 | } |
| 21 | 52 | ||
| 22 | static Common::Profiling::TimingCategory shader_category("Vertex Shader"); | 53 | static Common::Profiling::TimingCategory shader_category("Vertex Shader"); |
| @@ -54,7 +85,14 @@ OutputVertex Run(UnitState& state, const InputVertex& input, int num_attributes) | |||
| 54 | state.conditional_code[0] = false; | 85 | state.conditional_code[0] = false; |
| 55 | state.conditional_code[1] = false; | 86 | state.conditional_code[1] = false; |
| 56 | 87 | ||
| 88 | #ifdef ARCHITECTURE_x86_64 | ||
| 89 | if (VideoCore::g_shader_jit_enabled) | ||
| 90 | jit_shader(&state); | ||
| 91 | else | ||
| 92 | RunInterpreter(state); | ||
| 93 | #else | ||
| 57 | RunInterpreter(state); | 94 | RunInterpreter(state); |
| 95 | #endif | ||
| 58 | 96 | ||
| 59 | #if PICA_DUMP_SHADERS | 97 | #if PICA_DUMP_SHADERS |
| 60 | DebugUtils::DumpShader(setup.program_code.data(), state.debug.max_offset, setup.swizzle_data.data(), | 98 | DebugUtils::DumpShader(setup.program_code.data(), state.debug.max_offset, setup.swizzle_data.data(), |