From c493825cba8945284561b3d4a934e9a534ead3b8 Mon Sep 17 00:00:00 2001 From: simply0001 Date: Fri, 5 Jun 2026 16:38:51 +0200 Subject: [PATCH] video_core: compute macro param address on demand MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GetMacroAddress only reads a couple of indices per macro, but ProcessMacro was building a full std::vector with one push_back per parameter word every submission. macro_segments already holds (base, count) per chunk, so GetMacroAddress can just walk it instead — dropping the per-word loop, a .clear(), and a vector member. Also returns on the first match in the macro dispatch instead of running every std::get_if check. No behaviour change, just removes redundant per-submission work. Signed-off-by: simply0001 --- src/video_core/engines/maxwell_3d.cpp | 4 ---- src/video_core/engines/maxwell_3d.h | 10 ++++++++-- src/video_core/macro.cpp | 28 +++++++++++++-------------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index 7cf351e458..36898fe7d8 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp @@ -210,9 +210,6 @@ void Maxwell3D::ProcessMacro(u32 method, const u32* base_start, u32 amount, bool } macro_params.insert(macro_params.end(), base_start, base_start + amount); - for (size_t i = 0; i < amount; i++) { - macro_addresses.push_back(current_dma_segment + i * sizeof(u32)); - } macro_segments.emplace_back(current_dma_segment, amount); current_macro_dirty |= current_dirty; current_dirty = false; @@ -222,7 +219,6 @@ void Maxwell3D::ProcessMacro(u32 method, const u32* base_start, u32 amount, bool ConsumeSink(); CallMacroMethod(executing_macro, macro_params); macro_params.clear(); - macro_addresses.clear(); macro_segments.clear(); current_macro_dirty = false; } diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h index 864ee27fb6..14f768c478 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h @@ -3159,7 +3159,14 @@ public: DrawManager draw_manager; GPUVAddr GetMacroAddress(size_t index) const { - return macro_addresses[index]; + size_t base = 0; + for (const auto& [addr, count] : macro_segments) { + if (index < base + count) { + return addr + (index - base) * sizeof(u32); + } + base += count; + } + return 0; } void RefreshParameters() { @@ -3263,7 +3270,6 @@ private: bool execute_on{true}; std::vector> macro_segments; - std::vector macro_addresses; bool current_macro_dirty{}; }; diff --git a/src/video_core/macro.cpp b/src/video_core/macro.cpp index dbf011860e..e347839cbe 100644 --- a/src/video_core/macro.cpp +++ b/src/video_core/macro.cpp @@ -1357,33 +1357,33 @@ static void Dump(u64 hash, std::span code, bool decompiled = false) { void MacroEngine::Execute(Engines::Maxwell3D& maxwell3d, u32 method, std::span parameters) { auto const execute_variant = [&maxwell3d, ¶meters, method](AnyCachedMacro& acm) { if (auto a = std::get_if(&acm)) - a->Execute(maxwell3d, parameters, method); + return a->Execute(maxwell3d, parameters, method); if (auto a = std::get_if(&acm)) - a->Execute(maxwell3d, parameters, method); + return a->Execute(maxwell3d, parameters, method); if (auto a = std::get_if(&acm)) - a->Execute(maxwell3d, parameters, method); + return a->Execute(maxwell3d, parameters, method); if (auto a = std::get_if(&acm)) - a->Execute(maxwell3d, parameters, method); + return a->Execute(maxwell3d, parameters, method); if (auto a = std::get_if(&acm)) - a->Execute(maxwell3d, parameters, method); + return a->Execute(maxwell3d, parameters, method); if (auto a = std::get_if(&acm)) - a->Execute(maxwell3d, parameters, method); + return a->Execute(maxwell3d, parameters, method); if (auto a = std::get_if(&acm)) - a->Execute(maxwell3d, parameters, method); + return a->Execute(maxwell3d, parameters, method); if (auto a = std::get_if(&acm)) - a->Execute(maxwell3d, parameters, method); + return a->Execute(maxwell3d, parameters, method); if (auto a = std::get_if(&acm)) - a->Execute(maxwell3d, parameters, method); + return a->Execute(maxwell3d, parameters, method); if (auto a = std::get_if(&acm)) - a->Execute(maxwell3d, parameters, method); + return a->Execute(maxwell3d, parameters, method); if (auto a = std::get_if(&acm)) - a->Execute(maxwell3d, parameters, method); + return a->Execute(maxwell3d, parameters, method); if (auto a = std::get_if(&acm)) - a->Execute(maxwell3d, parameters, method); + return a->Execute(maxwell3d, parameters, method); if (auto a = std::get_if(&acm)) - a->Execute(maxwell3d, parameters, method); + return a->Execute(maxwell3d, parameters, method); if (auto a = std::get_if>(&acm)) - a->get()->Execute(maxwell3d, parameters, method); + return a->get()->Execute(maxwell3d, parameters, method); }; if (auto const it = macro_cache.find(method); it != macro_cache.end()) { auto& ci = it->second;