2016-12-17 10:21:16 +01:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "common/hash.h"
|
|
|
|
#include "common/microprofile.h"
|
|
|
|
#include "video_core/shader/shader.h"
|
|
|
|
#include "video_core/shader/shader_jit_x64.h"
|
|
|
|
#include "video_core/shader/shader_jit_x64_compiler.h"
|
|
|
|
|
|
|
|
namespace Pica {
|
|
|
|
namespace Shader {
|
|
|
|
|
|
|
|
JitX64Engine::JitX64Engine() = default;
|
|
|
|
JitX64Engine::~JitX64Engine() = default;
|
|
|
|
|
2016-12-18 01:06:04 +01:00
|
|
|
void JitX64Engine::SetupBatch(ShaderSetup& setup) {
|
|
|
|
u64 code_hash = Common::ComputeHash64(&setup.program_code, sizeof(setup.program_code));
|
|
|
|
u64 swizzle_hash = Common::ComputeHash64(&setup.swizzle_data, sizeof(setup.swizzle_data));
|
2016-12-17 10:21:16 +01:00
|
|
|
|
|
|
|
u64 cache_key = code_hash ^ swizzle_hash;
|
|
|
|
auto iter = cache.find(cache_key);
|
|
|
|
if (iter != cache.end()) {
|
2016-12-18 01:06:04 +01:00
|
|
|
setup.engine_data.cached_shader = iter->second.get();
|
2016-12-17 10:21:16 +01:00
|
|
|
} else {
|
|
|
|
auto shader = std::make_unique<JitShader>();
|
2016-12-18 01:06:04 +01:00
|
|
|
shader->Compile(&setup.program_code, &setup.swizzle_data);
|
|
|
|
setup.engine_data.cached_shader = shader.get();
|
2016-12-17 10:21:16 +01:00
|
|
|
cache.emplace_hint(iter, cache_key, std::move(shader));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MICROPROFILE_DECLARE(GPU_Shader);
|
|
|
|
|
2016-12-18 01:06:04 +01:00
|
|
|
void JitX64Engine::Run(const ShaderSetup& setup, UnitState& state, unsigned int entry_point) const {
|
|
|
|
ASSERT(setup.engine_data.cached_shader != nullptr);
|
2016-12-17 10:21:16 +01:00
|
|
|
ASSERT(entry_point < 1024);
|
|
|
|
|
|
|
|
MICROPROFILE_SCOPE(GPU_Shader);
|
|
|
|
|
2016-12-18 01:06:04 +01:00
|
|
|
const JitShader* shader = static_cast<const JitShader*>(setup.engine_data.cached_shader);
|
|
|
|
shader->Run(setup, state, entry_point);
|
2016-12-17 10:21:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Shader
|
|
|
|
} // namespace Pica
|