summaryrefslogtreecommitdiff
path: root/src/video_core/macro/macro.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/macro/macro.cpp')
-rw-r--r--src/video_core/macro/macro.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/video_core/macro/macro.cpp b/src/video_core/macro/macro.cpp
new file mode 100644
index 000000000..ef7dad349
--- /dev/null
+++ b/src/video_core/macro/macro.cpp
@@ -0,0 +1,72 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <boost/container_hash/hash.hpp>
6#include "common/assert.h"
7#include "common/logging/log.h"
8#include "core/settings.h"
9#include "video_core/engines/maxwell_3d.h"
10#include "video_core/macro/macro.h"
11#include "video_core/macro/macro_hle.h"
12#include "video_core/macro/macro_interpreter.h"
13#include "video_core/macro/macro_jit_x64.h"
14
15namespace Tegra {
16
17MacroEngine::MacroEngine(Engines::Maxwell3D& maxwell3d)
18 : hle_macros{std::make_unique<Tegra::HLEMacro>(maxwell3d)} {}
19
20MacroEngine::~MacroEngine() = default;
21
22void MacroEngine::AddCode(u32 method, u32 data) {
23 uploaded_macro_code[method].push_back(data);
24}
25
26void MacroEngine::Execute(Engines::Maxwell3D& maxwell3d, u32 method,
27 const std::vector<u32>& parameters) {
28 auto compiled_macro = macro_cache.find(method);
29 if (compiled_macro != macro_cache.end()) {
30 const auto& cache_info = compiled_macro->second;
31 if (cache_info.has_hle_program) {
32 cache_info.hle_program->Execute(parameters, method);
33 } else {
34 cache_info.lle_program->Execute(parameters, method);
35 }
36 } else {
37 // Macro not compiled, check if it's uploaded and if so, compile it
38 auto macro_code = uploaded_macro_code.find(method);
39 if (macro_code == uploaded_macro_code.end()) {
40 UNREACHABLE_MSG("Macro 0x{0:x} was not uploaded", method);
41 return;
42 }
43 auto& cache_info = macro_cache[method];
44 cache_info.hash = boost::hash_value(macro_code->second);
45 cache_info.lle_program = Compile(macro_code->second);
46
47 auto hle_program = hle_macros->GetHLEProgram(cache_info.hash);
48 if (hle_program.has_value()) {
49 cache_info.has_hle_program = true;
50 cache_info.hle_program = std::move(hle_program.value());
51 }
52
53 if (cache_info.has_hle_program) {
54 cache_info.hle_program->Execute(parameters, method);
55 } else {
56 cache_info.lle_program->Execute(parameters, method);
57 }
58 }
59}
60
61std::unique_ptr<MacroEngine> GetMacroEngine(Engines::Maxwell3D& maxwell3d) {
62 if (Settings::values.disable_macro_jit) {
63 return std::make_unique<MacroInterpreter>(maxwell3d);
64 }
65#ifdef ARCHITECTURE_x86_64
66 return std::make_unique<MacroJITx64>(maxwell3d);
67#else
68 return std::make_unique<MacroInterpreter>(maxwell3d);
69#endif
70}
71
72} // namespace Tegra