From 114d6b2f97eb62c7d8c958ebb391b70b026130f9 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 17 Dec 2016 01:21:16 -0800 Subject: VideoCore/Shader: Split interpreter and JIT into separate ShaderEngines --- src/video_core/shader/shader.cpp | 92 ++++++---------------------------------- 1 file changed, 13 insertions(+), 79 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 97c6519d6..b30dae476 100644 --- a/src/video_core/shader/shader.cpp +++ b/src/video_core/shader/shader.cpp @@ -2,14 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include #include #include -#include -#include -#include -#include "common/bit_field.h" -#include "common/hash.h" #include "common/logging/log.h" #include "common/microprofile.h" #include "video_core/pica.h" @@ -17,7 +11,7 @@ #include "video_core/shader/shader.h" #include "video_core/shader/shader_interpreter.h" #ifdef ARCHITECTURE_x86_64 -#include "video_core/shader/shader_jit_x64_compiler.h" +#include "video_core/shader/shader_jit_x64.h" #endif // ARCHITECTURE_x86_64 #include "video_core/video_core.h" @@ -87,93 +81,33 @@ void UnitState::LoadInputVertex(const InputVertex& input, int num_attributes) { conditional_code[1] = false; } -class MergedShaderEngine : public ShaderEngine { -public: - void SetupBatch(const ShaderSetup* setup) override; - void Run(UnitState& state, unsigned int entry_point) const override; - DebugData ProduceDebugInfo(const InputVertex& input, int num_attributes, - unsigned int entry_point) const override; - -private: - const ShaderSetup* setup = nullptr; -}; - -#ifdef ARCHITECTURE_x86_64 -static std::unordered_map> shader_map; -static const JitShader* jit_shader; -#endif // ARCHITECTURE_x86_64 +MICROPROFILE_DEFINE(GPU_Shader, "GPU", "Shader", MP_RGB(50, 50, 240)); -void ClearCache() { #ifdef ARCHITECTURE_x86_64 - shader_map.clear(); +static std::unique_ptr jit_engine; #endif // ARCHITECTURE_x86_64 -} - -void MergedShaderEngine::SetupBatch(const ShaderSetup* setup_) { - setup = setup_; - if (setup == nullptr) - return; +static InterpreterEngine interpreter_engine; +ShaderEngine* GetEngine() { #ifdef ARCHITECTURE_x86_64 + // TODO(yuriks): Re-initialize on each change rather than being persistent if (VideoCore::g_shader_jit_enabled) { - u64 code_hash = Common::ComputeHash64(&setup->program_code, sizeof(setup->program_code)); - u64 swizzle_hash = Common::ComputeHash64(&setup->swizzle_data, sizeof(setup->swizzle_data)); - - u64 cache_key = code_hash ^ swizzle_hash; - auto iter = shader_map.find(cache_key); - if (iter != shader_map.end()) { - jit_shader = iter->second.get(); - } else { - auto shader = std::make_unique(); - shader->Compile(); - jit_shader = shader.get(); - shader_map[cache_key] = std::move(shader); + if (jit_engine == nullptr) { + jit_engine = std::make_unique(); } + return jit_engine.get(); } #endif // ARCHITECTURE_x86_64 -} - -MICROPROFILE_DEFINE(GPU_Shader, "GPU", "Shader", MP_RGB(50, 50, 240)); - -void MergedShaderEngine::Run(UnitState& state, unsigned int entry_point) const { - ASSERT(setup != nullptr); - ASSERT(entry_point < 1024); - MICROPROFILE_SCOPE(GPU_Shader); + return &interpreter_engine; +} +void Shutdown() { #ifdef ARCHITECTURE_x86_64 - if (VideoCore::g_shader_jit_enabled) { - jit_shader->Run(*setup, state, entry_point); - } else { - DebugData dummy_debug_data; - RunInterpreter(*setup, state, dummy_debug_data, entry_point); - } -#else - DebugData dummy_debug_data; - RunInterpreter(*setup, state, dummy_debug_data, entry_point); + jit_engine = nullptr; #endif // ARCHITECTURE_x86_64 } -DebugData MergedShaderEngine::ProduceDebugInfo(const InputVertex& input, int num_attributes, - unsigned int entry_point) const { - ASSERT(setup != nullptr); - ASSERT(entry_point < 1024); - - UnitState state; - DebugData debug_data; - - // Setup input register table - boost::fill(state.registers.input, Math::Vec4::AssignToAll(float24::Zero())); - state.LoadInputVertex(input, num_attributes); - RunInterpreter(*setup, state, debug_data, entry_point); - return debug_data; -} - -ShaderEngine* GetEngine() { - static MergedShaderEngine merged_engine; - return &merged_engine; -} - } // namespace Shader } // namespace Pica -- cgit v1.2.3