[video_core] Avoid stale macro upload references

This commit is contained in:
xbzk 2026-08-01 16:02:40 -03:00
parent e5b247db35
commit a0bc8bfde4

View file

@ -1391,29 +1391,26 @@ void MacroEngine::Execute(Core::System& system, Engines::Maxwell3D& maxwell3d, u
std::span<const u32> code; std::span<const u32> code;
auto macro_code = uploaded_macro_code.find(method); auto macro_code = uploaded_macro_code.find(method);
if (macro_code == uploaded_macro_code.end()) { if (macro_code == uploaded_macro_code.end()) {
std::optional<u32> mid_method; for (auto it = uploaded_macro_code.begin(); it != uploaded_macro_code.end(); ++it) {
for (const auto& [method_base, uploaded_code] : uploaded_macro_code) { const auto& [method_base, uploaded_code] = *it;
if (method >= method_base && (method - method_base) < uploaded_code.size()) { if (method >= method_base && (method - method_base) < uploaded_code.size()) {
mid_method = method_base; macro_code = it;
break; break;
} }
} }
if (!mid_method) { if (macro_code == uploaded_macro_code.end()) {
ASSERT_MSG(false, "Macro 0x{0:x} was not uploaded", method); ASSERT_MSG(false, "Macro 0x{0:x} was not uploaded", method);
return; return;
} }
const auto source = uploaded_macro_code.find(*mid_method); const auto rebased_method = method - macro_code->first;
ASSERT(source != uploaded_macro_code.end()); std::vector<u32> rebased_code(macro_code->second.begin() + rebased_method,
const auto rebased_method = method - *mid_method; macro_code->second.end());
std::vector<u32> rebased_code(source->second.begin() + rebased_method,
source->second.end());
const auto [it, inserted] = uploaded_macro_code.emplace(method, std::move(rebased_code)); const auto [it, inserted] = uploaded_macro_code.emplace(method, std::move(rebased_code));
ASSERT(inserted); ASSERT(inserted);
code = it->second; macro_code = it;
} else {
code = macro_code->second;
} }
code = macro_code->second;
auto& ci = macro_cache[method]; auto& ci = macro_cache[method];
ci.hash = Common::HashRange(code.begin(), code.end()); ci.hash = Common::HashRange(code.begin(), code.end());