From 094ae6fadb57883e25d412443fcae987ddf240ef Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 22 Jul 2015 23:25:30 -0400 Subject: Shader: Initial implementation of x86_x64 JIT compiler for Pica vertex shaders. - Config: Add an option for selecting to use shader JIT or interpreter. - Qt: Add a menu option for enabling/disabling the shader JIT. --- src/video_core/shader/shader.cpp | 42 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'src/video_core/shader/shader.cpp') 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 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "common/logging/log.h" +#include +#include + +#include "common/hash.h" +#include "common/make_unique.h" #include "common/profiler.h" #include "video_core/debug_utils/debug_utils.h" #include "video_core/pica.h" +#include "video_core/video_core.h" #include "shader.h" #include "shader_interpreter.h" +#include "shader_jit.h" namespace Pica { namespace Shader { +#ifdef ARCHITECTURE_x86_64 + +static std::unordered_map shader_map; +static JitCompiler jit; +static CompiledShader* jit_shader; + +#endif // ARCHITECTURE_x86_64 + void Setup(UnitState& state) { - // TODO(bunnei): This will be used by the JIT in a subsequent patch +#ifdef ARCHITECTURE_x86_64 + if (VideoCore::g_shader_jit_enabled) { + u64 cache_key = (Common::ComputeHash64(&g_state.vs.program_code, sizeof(g_state.vs.program_code)) ^ + Common::ComputeHash64(&g_state.vs.swizzle_data, sizeof(g_state.vs.swizzle_data)) ^ + g_state.regs.vs.main_offset); + + auto iter = shader_map.find(cache_key); + if (iter != shader_map.end()) { + jit_shader = iter->second; + } else { + jit_shader = jit.Compile(); + shader_map.emplace(cache_key, jit_shader); + } + } +} + +void Shutdown() { + shader_map.clear(); } static Common::Profiling::TimingCategory shader_category("Vertex Shader"); @@ -54,7 +85,14 @@ OutputVertex Run(UnitState& state, const InputVertex& input, int num_attributes) state.conditional_code[0] = false; state.conditional_code[1] = false; +#ifdef ARCHITECTURE_x86_64 + if (VideoCore::g_shader_jit_enabled) + jit_shader(&state); + else + RunInterpreter(state); +#else RunInterpreter(state); +#endif #if PICA_DUMP_SHADERS DebugUtils::DumpShader(setup.program_code.data(), state.debug.max_offset, setup.swizzle_data.data(), -- cgit v1.2.3