video_core/macro_hle: Return unique_ptr directly from GetHLEProgram()
Same behavior, but less code and header dependencies.
This commit is contained in:
parent
a05d9405b9
commit
cfd9f7d25b
|
@ -65,10 +65,9 @@ void MacroEngine::Execute(u32 method, const std::vector<u32>& parameters) {
|
||||||
cache_info.lle_program = Compile(code);
|
cache_info.lle_program = Compile(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto hle_program = hle_macros->GetHLEProgram(cache_info.hash);
|
if (auto hle_program = hle_macros->GetHLEProgram(cache_info.hash)) {
|
||||||
if (hle_program.has_value()) {
|
|
||||||
cache_info.has_hle_program = true;
|
cache_info.has_hle_program = true;
|
||||||
cache_info.hle_program = std::move(hle_program.value());
|
cache_info.hle_program = std::move(hle_program);
|
||||||
cache_info.hle_program->Execute(parameters, method);
|
cache_info.hle_program->Execute(parameters, method);
|
||||||
} else {
|
} else {
|
||||||
cache_info.lle_program->Execute(parameters, method);
|
cache_info.lle_program->Execute(parameters, method);
|
||||||
|
|
|
@ -105,11 +105,11 @@ private:
|
||||||
HLEMacro::HLEMacro(Engines::Maxwell3D& maxwell3d_) : maxwell3d{maxwell3d_} {}
|
HLEMacro::HLEMacro(Engines::Maxwell3D& maxwell3d_) : maxwell3d{maxwell3d_} {}
|
||||||
HLEMacro::~HLEMacro() = default;
|
HLEMacro::~HLEMacro() = default;
|
||||||
|
|
||||||
std::optional<std::unique_ptr<CachedMacro>> HLEMacro::GetHLEProgram(u64 hash) const {
|
std::unique_ptr<CachedMacro> HLEMacro::GetHLEProgram(u64 hash) const {
|
||||||
const auto it = std::find_if(hle_funcs.cbegin(), hle_funcs.cend(),
|
const auto it = std::find_if(hle_funcs.cbegin(), hle_funcs.cend(),
|
||||||
[hash](const auto& pair) { return pair.first == hash; });
|
[hash](const auto& pair) { return pair.first == hash; });
|
||||||
if (it == hle_funcs.end()) {
|
if (it == hle_funcs.end()) {
|
||||||
return std::nullopt;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return std::make_unique<HLEMacroImpl>(maxwell3d, it->second);
|
return std::make_unique<HLEMacroImpl>(maxwell3d, it->second);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|
||||||
namespace Tegra {
|
namespace Tegra {
|
||||||
|
@ -19,7 +18,9 @@ public:
|
||||||
explicit HLEMacro(Engines::Maxwell3D& maxwell3d_);
|
explicit HLEMacro(Engines::Maxwell3D& maxwell3d_);
|
||||||
~HLEMacro();
|
~HLEMacro();
|
||||||
|
|
||||||
std::optional<std::unique_ptr<CachedMacro>> GetHLEProgram(u64 hash) const;
|
// Allocates and returns a cached macro if the hash matches a known function.
|
||||||
|
// Returns nullptr otherwise.
|
||||||
|
[[nodiscard]] std::unique_ptr<CachedMacro> GetHLEProgram(u64 hash) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Engines::Maxwell3D& maxwell3d;
|
Engines::Maxwell3D& maxwell3d;
|
||||||
|
|
Reference in New Issue