diff options
Diffstat (limited to 'src/video_core/macro/macro.cpp')
| -rw-r--r-- | src/video_core/macro/macro.cpp | 60 |
1 files changed, 53 insertions, 7 deletions
diff --git a/src/video_core/macro/macro.cpp b/src/video_core/macro/macro.cpp index 89077a2d8..a50e7b4e0 100644 --- a/src/video_core/macro/macro.cpp +++ b/src/video_core/macro/macro.cpp | |||
| @@ -2,32 +2,78 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <optional> | ||
| 6 | #include <boost/container_hash/hash.hpp> | ||
| 5 | #include "common/assert.h" | 7 | #include "common/assert.h" |
| 6 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 7 | #include "core/settings.h" | 9 | #include "core/settings.h" |
| 10 | #include "video_core/engines/maxwell_3d.h" | ||
| 8 | #include "video_core/macro/macro.h" | 11 | #include "video_core/macro/macro.h" |
| 12 | #include "video_core/macro/macro_hle.h" | ||
| 9 | #include "video_core/macro/macro_interpreter.h" | 13 | #include "video_core/macro/macro_interpreter.h" |
| 10 | #include "video_core/macro/macro_jit_x64.h" | 14 | #include "video_core/macro/macro_jit_x64.h" |
| 11 | 15 | ||
| 12 | namespace Tegra { | 16 | namespace Tegra { |
| 13 | 17 | ||
| 18 | MacroEngine::MacroEngine(Engines::Maxwell3D& maxwell3d) | ||
| 19 | : hle_macros{std::make_unique<Tegra::HLEMacro>(maxwell3d)} {} | ||
| 20 | |||
| 21 | MacroEngine::~MacroEngine() = default; | ||
| 22 | |||
| 14 | void MacroEngine::AddCode(u32 method, u32 data) { | 23 | void MacroEngine::AddCode(u32 method, u32 data) { |
| 15 | uploaded_macro_code[method].push_back(data); | 24 | uploaded_macro_code[method].push_back(data); |
| 16 | } | 25 | } |
| 17 | 26 | ||
| 18 | void MacroEngine::Execute(u32 method, const std::vector<u32>& parameters) { | 27 | void MacroEngine::Execute(Engines::Maxwell3D& maxwell3d, u32 method, |
| 28 | const std::vector<u32>& parameters) { | ||
| 19 | auto compiled_macro = macro_cache.find(method); | 29 | auto compiled_macro = macro_cache.find(method); |
| 20 | if (compiled_macro != macro_cache.end()) { | 30 | if (compiled_macro != macro_cache.end()) { |
| 21 | compiled_macro->second->Execute(parameters, method); | 31 | const auto& cache_info = compiled_macro->second; |
| 32 | if (cache_info.has_hle_program) { | ||
| 33 | cache_info.hle_program->Execute(parameters, method); | ||
| 34 | } else { | ||
| 35 | cache_info.lle_program->Execute(parameters, method); | ||
| 36 | } | ||
| 22 | } else { | 37 | } else { |
| 23 | // Macro not compiled, check if it's uploaded and if so, compile it | 38 | // Macro not compiled, check if it's uploaded and if so, compile it |
| 24 | auto macro_code = uploaded_macro_code.find(method); | 39 | std::optional<u32> mid_method = std::nullopt; |
| 40 | const auto macro_code = uploaded_macro_code.find(method); | ||
| 25 | if (macro_code == uploaded_macro_code.end()) { | 41 | if (macro_code == uploaded_macro_code.end()) { |
| 26 | UNREACHABLE_MSG("Macro 0x{0:x} was not uploaded", method); | 42 | for (const auto& [method_base, code] : uploaded_macro_code) { |
| 27 | return; | 43 | if (method >= method_base && (method - method_base) < code.size()) { |
| 44 | mid_method = method_base; | ||
| 45 | break; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | if (!mid_method.has_value()) { | ||
| 49 | UNREACHABLE_MSG("Macro 0x{0:x} was not uploaded", method); | ||
| 50 | return; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | auto& cache_info = macro_cache[method]; | ||
| 54 | |||
| 55 | if (!mid_method.has_value()) { | ||
| 56 | cache_info.lle_program = Compile(macro_code->second); | ||
| 57 | cache_info.hash = boost::hash_value(macro_code->second); | ||
| 58 | } else { | ||
| 59 | const auto& macro_cached = uploaded_macro_code[mid_method.value()]; | ||
| 60 | const auto rebased_method = method - mid_method.value(); | ||
| 61 | auto& code = uploaded_macro_code[method]; | ||
| 62 | code.resize(macro_cached.size() - rebased_method); | ||
| 63 | std::memcpy(code.data(), macro_cached.data() + rebased_method, | ||
| 64 | code.size() * sizeof(u32)); | ||
| 65 | cache_info.hash = boost::hash_value(code); | ||
| 66 | cache_info.lle_program = Compile(code); | ||
| 67 | } | ||
| 68 | |||
| 69 | auto hle_program = hle_macros->GetHLEProgram(cache_info.hash); | ||
| 70 | if (hle_program.has_value()) { | ||
| 71 | cache_info.has_hle_program = true; | ||
| 72 | cache_info.hle_program = std::move(hle_program.value()); | ||
| 73 | cache_info.hle_program->Execute(parameters, method); | ||
| 74 | } else { | ||
| 75 | cache_info.lle_program->Execute(parameters, method); | ||
| 28 | } | 76 | } |
| 29 | macro_cache[method] = Compile(macro_code->second); | ||
| 30 | macro_cache[method]->Execute(parameters, method); | ||
| 31 | } | 77 | } |
| 32 | } | 78 | } |
| 33 | 79 | ||