From 9f98dcc617df5b21eb66b48a289914b551769029 Mon Sep 17 00:00:00 2001 From: Moriz82 <72836413+Moriz82@users.noreply.github.com> Date: Wed, 25 Nov 2026 14:30:51 -0600 Subject: Improve post-load GPU memory and pipeline handling (RT-POST-LOAD-GPU-MEMORY) Fall back to a dedicated buffer allocation when the shared arena fills. Update console descriptors and resource backing, preserve pipeline cache entries, and replay mesh records using bounded indirect arguments. Keep scripted input available until read and cover the runtime and translator paths with synthetic tests. Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com> Co-authored-by: ivanepsilondelta <264061546+ivanepsilondelta@users.noreply.github.com> --- runtime/src/thread_sampler.h | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'runtime/src/thread_sampler.h') diff --git a/runtime/src/thread_sampler.h b/runtime/src/thread_sampler.h index 282eb20dd..0c18949ce 100644 --- a/runtime/src/thread_sampler.h +++ b/runtime/src/thread_sampler.h @@ -44,6 +44,9 @@ struct Sampler { // LEONIDA_SAMPLE_DETAIL=[,...]: for these threads, the 10 most frequent chains, 16 frames deep, each as a // share of that thread's samples (thread ids are stable from boot to boot: the title's main, render and submit). std::vector detail; + // LEONIDA_SAMPLE_FIND=[,...] (title function starts): which threads have the function on their stack + // (48 frames deep), how often, and their most frequent chain under it, every report. + std::vector find; }; // Per title thread (one with a title frame in its chain): how many samples were inside our runtime, and through which @@ -151,6 +154,7 @@ inline DWORD WINAPI run(LPVOID parameter) { constexpr int kDetailFrames = 16; using DetailChain = std::array; std::map, std::uint64_t> detail_chains; + std::map, std::map> found; // (rva, thread) -> chains std::uint64_t total = 0; ULONGLONG listed = 0, reported = GetTickCount64(); const auto cpu_of = [](HANDLE h) { @@ -205,11 +209,20 @@ inline DWORD WINAPI run(LPVOID parameter) { unwind(context, deep); ++detail_chains[{it->first, deep}]; } - if (s.shims) { + if (s.shims || !s.find.empty()) { DeepChain deep{}; const int n = unwind(context, deep); std::copy_n(deep.begin(), kFrames, chain.begin()); - count_shims(s, deep, n, moved, shim_counts[it->first]); + if (s.shims) count_shims(s, deep, n, moved, shim_counts[it->first]); + const auto title = reinterpret_cast(s.title); + for (const std::uint64_t rva : s.find) + for (int f = 0; f < n; ++f) + if (deep[f] == title + rva) { + DetailChain inner{}; + std::copy_n(deep.begin(), (std::min)(kDetailFrames, n), inner.begin()); + ++found[{rva, it->first}][inner]; + break; + } } else { unwind(context, chain); } @@ -299,6 +312,23 @@ inline DWORD WINAPI run(LPVOID parameter) { } } detail_chains.clear(); + for (const auto& [key, chains_of] : found) { + std::uint64_t all = 0; + const DetailChain* top = nullptr; + std::uint64_t top_n = 0; + for (const auto& [c, n] : chains_of) { + all += n; + if (n > top_n) top_n = n, top = &c; + } + std::string frames; + for (int f = 0; top && f < kDetailFrames && (*top)[f]; ++f) frames += (f ? " < " : "") + name_of(s, (*top)[f]); + const auto t = threads.find(key.second); + std::fprintf(stderr, "[rt] sampler: find t+%llx: thread %lu %llu samples of %llu; top chain (%llu): %s\n", + static_cast(key.first), key.second, static_cast(all), + static_cast(t == threads.end() ? 0 : t->second.samples), + static_cast(top_n), frames.c_str()); + } + found.clear(); if (s.shims) { // Title threads by their samples inside our runtime: where the title's own threads (its main, render and // Subrender workers, streaming) spend time in our shims, waiting or running. @@ -386,6 +416,15 @@ inline void start(std::uint8_t* title, std::uint64_t title_size) { if (id) s.detail.push_back(DWORD(id)); at = *end == ',' ? end + 1 : end; } + char finds[256] = {}; + if (const DWORD n = GetEnvironmentVariableA("LEONIDA_SAMPLE_FIND", finds, sizeof(finds)); n && n < sizeof(finds)) + for (char* at = finds; *at;) { + char* end = nullptr; + const std::uint64_t rva = std::strtoull(at, &end, 16); + if (end == at) break; + if (rva) s.find.push_back(rva); + at = *end == ',' ? end + 1 : end; + } char shims[4] = {}; s.shims = GetEnvironmentVariableA("LEONIDA_SAMPLE_SHIMS", shims, sizeof(shims)) == 1 && shims[0] == '1'; if (const auto self = reinterpret_cast(GetModuleHandleW(nullptr))) { -- cgit v1.2.3