summaryrefslogtreecommitdiff
path: root/src/video_core/macro/macro.cpp
diff options
context:
space:
mode:
authorGravatar David2020-06-30 15:32:24 +1000
committerGravatar GitHub2020-06-30 02:32:24 -0300
commit7c970132b5dd6eaa40f114355e0125091ceb8142 (patch)
tree01a9b3f65f6a93d6bc6866ef09300020344f1496 /src/video_core/macro/macro.cpp
parentMerge pull request #4182 from Kewlan/fullscreen-hotkey-fix (diff)
downloadyuzu-7c970132b5dd6eaa40f114355e0125091ceb8142.tar.gz
yuzu-7c970132b5dd6eaa40f114355e0125091ceb8142.tar.xz
yuzu-7c970132b5dd6eaa40f114355e0125091ceb8142.zip
macro: Add support for "middle methods" on the code cache (#4112)
Macro code is just uploaded sequentially from a starting address, however that does not mean the entry point for the macro is at that address. This PR adds preliminary support for executing macros in the middle of our cached code.
Diffstat (limited to 'src/video_core/macro/macro.cpp')
-rw-r--r--src/video_core/macro/macro.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/video_core/macro/macro.cpp b/src/video_core/macro/macro.cpp
index ef7dad349..a50e7b4e0 100644
--- a/src/video_core/macro/macro.cpp
+++ b/src/video_core/macro/macro.cpp
@@ -2,6 +2,7 @@
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>
5#include <boost/container_hash/hash.hpp> 6#include <boost/container_hash/hash.hpp>
6#include "common/assert.h" 7#include "common/assert.h"
7#include "common/logging/log.h" 8#include "common/logging/log.h"
@@ -35,22 +36,40 @@ void MacroEngine::Execute(Engines::Maxwell3D& maxwell3d, u32 method,
35 } 36 }
36 } else { 37 } else {
37 // 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
38 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);
39 if (macro_code == uploaded_macro_code.end()) { 41 if (macro_code == uploaded_macro_code.end()) {
40 UNREACHABLE_MSG("Macro 0x{0:x} was not uploaded", method); 42 for (const auto& [method_base, code] : uploaded_macro_code) {
41 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 }
42 } 52 }
43 auto& cache_info = macro_cache[method]; 53 auto& cache_info = macro_cache[method];
44 cache_info.hash = boost::hash_value(macro_code->second); 54
45 cache_info.lle_program = Compile(macro_code->second); 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 }
46 68
47 auto hle_program = hle_macros->GetHLEProgram(cache_info.hash); 69 auto hle_program = hle_macros->GetHLEProgram(cache_info.hash);
48 if (hle_program.has_value()) { 70 if (hle_program.has_value()) {
49 cache_info.has_hle_program = true; 71 cache_info.has_hle_program = true;
50 cache_info.hle_program = std::move(hle_program.value()); 72 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); 73 cache_info.hle_program->Execute(parameters, method);
55 } else { 74 } else {
56 cache_info.lle_program->Execute(parameters, method); 75 cache_info.lle_program->Execute(parameters, method);