Change pair to optional

This commit is contained in:
David Marcec
2020-06-24 13:11:25 +10:00
parent 61c89aed2e
commit 746adc8885

View File

@@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <boost/container_hash/hash.hpp>
#include <optional>
#include "common/assert.h"
#include "common/logging/log.h"
#include "core/settings.h"
@@ -35,16 +36,16 @@ void MacroEngine::Execute(Engines::Maxwell3D& maxwell3d, u32 method,
}
} else {
// Macro not compiled, check if it's uploaded and if so, compile it
std::pair<bool, u32> mid_method;
std::optional<u32> mid_method = std::nullopt;
auto macro_code = uploaded_macro_code.find(method);
if (macro_code == uploaded_macro_code.end()) {
for (const auto& [method_base, code] : uploaded_macro_code) {
if (method >= method_base && (method - method_base) < code.size()) {
mid_method = {true, method_base};
mid_method = method_base;
break;
}
}
if (!mid_method.first) {
if (!mid_method.has_value()) {
UNREACHABLE_MSG("Macro 0x{0:x} was not uploaded", method);
return;
}
@@ -58,6 +59,22 @@ void MacroEngine::Execute(Engines::Maxwell3D& maxwell3d, u32 method,
cache_info.has_hle_program = true;
cache_info.hle_program = std::move(hle_program.value());
}
if (cache_info.has_hle_program) {
cache_info.hle_program->Execute(parameters, method);
} else {
cache_info.lle_program->Execute(parameters, method);
}
if (mid_method.has_value()) {
const auto& macro_cached = uploaded_macro_code[mid_method.value()];
const auto rebased_method = method - mid_method.value();
auto& code = uploaded_macro_code[method];
code.resize(macro_cached.size() - rebased_method);
std::memcpy(code.data(), macro_cached.data() + rebased_method,
code.size() * sizeof(u32));
macro_cache[method] = Compile(code);
} else {
macro_cache[method] = Compile(macro_code->second);
}
if (cache_info.has_hle_program) {
cache_info.hle_program->Execute(parameters, method);