video_core/shader: Refactor JIT-Engines into JitEngine type (#7210)
This commit is contained in:
56
src/video_core/shader/shader_jit.cpp
Normal file
56
src/video_core/shader/shader_jit.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright 2016 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "common/arch.h"
|
||||
#if CITRA_ARCH(x86_64) || CITRA_ARCH(arm64)
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/microprofile.h"
|
||||
#include "video_core/shader/shader.h"
|
||||
#include "video_core/shader/shader_jit.h"
|
||||
#if CITRA_ARCH(arm64)
|
||||
#include "video_core/shader/shader_jit_a64_compiler.h"
|
||||
#endif
|
||||
#if CITRA_ARCH(x86_64)
|
||||
#include "video_core/shader/shader_jit_x64_compiler.h"
|
||||
#endif
|
||||
|
||||
namespace Pica::Shader {
|
||||
|
||||
JitEngine::JitEngine() = default;
|
||||
JitEngine::~JitEngine() = default;
|
||||
|
||||
void JitEngine::SetupBatch(ShaderSetup& setup, u32 entry_point) {
|
||||
ASSERT(entry_point < MAX_PROGRAM_CODE_LENGTH);
|
||||
setup.engine_data.entry_point = entry_point;
|
||||
|
||||
const u64 code_hash = setup.GetProgramCodeHash();
|
||||
const u64 swizzle_hash = setup.GetSwizzleDataHash();
|
||||
|
||||
const u64 cache_key = Common::HashCombine(code_hash, swizzle_hash);
|
||||
auto iter = cache.find(cache_key);
|
||||
if (iter != cache.end()) {
|
||||
setup.engine_data.cached_shader = iter->second.get();
|
||||
} else {
|
||||
auto shader = std::make_unique<JitShader>();
|
||||
shader->Compile(&setup.program_code, &setup.swizzle_data);
|
||||
setup.engine_data.cached_shader = shader.get();
|
||||
cache.emplace_hint(iter, cache_key, std::move(shader));
|
||||
}
|
||||
}
|
||||
|
||||
MICROPROFILE_DECLARE(GPU_Shader);
|
||||
|
||||
void JitEngine::Run(const ShaderSetup& setup, UnitState& state) const {
|
||||
ASSERT(setup.engine_data.cached_shader != nullptr);
|
||||
|
||||
MICROPROFILE_SCOPE(GPU_Shader);
|
||||
|
||||
const JitShader* shader = static_cast<const JitShader*>(setup.engine_data.cached_shader);
|
||||
shader->Run(setup, state, setup.engine_data.entry_point);
|
||||
}
|
||||
|
||||
} // namespace Pica::Shader
|
||||
|
||||
#endif // CITRA_ARCH(x86_64) || CITRA_ARCH(arm64)
|
||||
Reference in New Issue
Block a user