diff options
| author | Moriz82 <72836413+Moriz82@users.noreply.github.com> | 2026-11-25 14:30:51 -0600 |
|---|---|---|
| committer | Moriz82 <72836413+Moriz82@users.noreply.github.com> | 2026-11-25 14:30:51 -0600 |
| commit | 9f98dcc617df5b21eb66b48a289914b551769029 (patch) | |
| tree | 88f50fe6ba6974d4f7d87ed2cabe7ef68db38626 /runtime/src/thread_stacks.cpp | |
| parent | db1a22d290f5e86fff9282fce3d4e02e788b05b4 (diff) | |
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>
Diffstat (limited to 'runtime/src/thread_stacks.cpp')
| -rw-r--r-- | runtime/src/thread_stacks.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/runtime/src/thread_stacks.cpp b/runtime/src/thread_stacks.cpp index 67188d908..38d7cc2a4 100644 --- a/runtime/src/thread_stacks.cpp +++ b/runtime/src/thread_stacks.cpp | |||
| @@ -121,10 +121,10 @@ struct ThreadTrace { | |||
| 121 | size_t count = 0; | 121 | size_t count = 0; |
| 122 | }; | 122 | }; |
| 123 | 123 | ||
| 124 | void print_traces(unsigned at, const std::vector<ThreadTrace>& traces) { | 124 | void print_traces(const std::string& tag, const std::vector<ThreadTrace>& traces) { |
| 125 | std::string out = "[rt] stacks t=" + std::to_string(at) + ": " + std::to_string(traces.size()) + " threads\n"; | 125 | std::string out = "[rt] stacks " + tag + ": " + std::to_string(traces.size()) + " threads\n"; |
| 126 | for (auto it = traces.begin(); it != traces.end(); ++it) { | 126 | for (auto it = traces.begin(); it != traces.end(); ++it) { |
| 127 | out += "[rt] stacks t=" + std::to_string(at) + " thread " + std::to_string(it->tid) + " (" + it->label + "):\n"; | 127 | out += "[rt] stacks " + tag + " thread " + std::to_string(it->tid) + " (" + it->label + "):\n"; |
| 128 | const auto same = std::find_if(traces.begin(), it, [&](const ThreadTrace& earlier) { | 128 | const auto same = std::find_if(traces.begin(), it, [&](const ThreadTrace& earlier) { |
| 129 | return it->count && it->count == earlier.count && | 129 | return it->count && it->count == earlier.count && |
| 130 | std::equal(it->frames.begin(), it->frames.begin() + it->count, earlier.frames.begin()); | 130 | std::equal(it->frames.begin(), it->frames.begin() + it->count, earlier.frames.begin()); |
| @@ -142,10 +142,11 @@ void print_traces(unsigned at, const std::vector<ThreadTrace>& traces) { | |||
| 142 | std::fflush(stderr); | 142 | std::fflush(stderr); |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | void snapshot_threads(unsigned at, StackSampler& sampler, GetDescription describe, QueryThread query) { | 145 | void snapshot_threads(const std::string& tag, StackSampler& sampler, GetDescription describe, QueryThread query, |
| 146 | DWORD only = 0) { | ||
| 146 | const HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); | 147 | const HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); |
| 147 | if (snapshot == INVALID_HANDLE_VALUE) { | 148 | if (snapshot == INVALID_HANDLE_VALUE) { |
| 148 | std::fprintf(stderr, "[rt] stacks t=%u: thread list failed (error %lu)\n", at, GetLastError()); | 149 | std::fprintf(stderr, "[rt] stacks %s: thread list failed (error %lu)\n", tag.c_str(), GetLastError()); |
| 149 | return; | 150 | return; |
| 150 | } | 151 | } |
| 151 | std::vector<ThreadTrace> traces; | 152 | std::vector<ThreadTrace> traces; |
| @@ -157,6 +158,7 @@ void snapshot_threads(unsigned at, StackSampler& sampler, GetDescription describ | |||
| 157 | for (BOOL ok = Thread32First(snapshot, &entry); ok; ok = Thread32Next(snapshot, &entry)) { | 158 | for (BOOL ok = Thread32First(snapshot, &entry); ok; ok = Thread32Next(snapshot, &entry)) { |
| 158 | entry.dwSize = sizeof(entry); | 159 | entry.dwSize = sizeof(entry); |
| 159 | if (entry.th32OwnerProcessID != pid || entry.th32ThreadID == self) continue; | 160 | if (entry.th32OwnerProcessID != pid || entry.th32ThreadID == self) continue; |
| 161 | if (only && entry.th32ThreadID != only) continue; | ||
| 160 | const HANDLE thread = OpenThread(THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION, | 162 | const HANDLE thread = OpenThread(THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION, |
| 161 | FALSE, entry.th32ThreadID); | 163 | FALSE, entry.th32ThreadID); |
| 162 | if (!thread) continue; | 164 | if (!thread) continue; |
| @@ -169,7 +171,7 @@ void snapshot_threads(unsigned at, StackSampler& sampler, GetDescription describ | |||
| 169 | CloseHandle(thread); | 171 | CloseHandle(thread); |
| 170 | } | 172 | } |
| 171 | CloseHandle(snapshot); | 173 | CloseHandle(snapshot); |
| 172 | print_traces(at, traces); | 174 | print_traces(tag, traces); |
| 173 | } | 175 | } |
| 174 | 176 | ||
| 175 | } // namespace | 177 | } // namespace |
| @@ -207,6 +209,20 @@ bool parse_stack_times(std::string_view text, std::vector<unsigned>& seconds) { | |||
| 207 | return true; | 209 | return true; |
| 208 | } | 210 | } |
| 209 | 211 | ||
| 212 | void print_thread_stacks_now(std::uint32_t tid, const char* why) noexcept { | ||
| 213 | static std::mutex mutex; | ||
| 214 | try { | ||
| 215 | std::lock_guard lock(mutex); | ||
| 216 | static StackSampler sampler; | ||
| 217 | const auto describe = reinterpret_cast<GetDescription>(reinterpret_cast<void*>( | ||
| 218 | GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "GetThreadDescription"))); | ||
| 219 | const auto query = reinterpret_cast<QueryThread>(reinterpret_cast<void*>( | ||
| 220 | GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "NtQueryInformationThread"))); | ||
| 221 | snapshot_threads(why ? why : "now", sampler, describe, query, tid); | ||
| 222 | } catch (...) { | ||
| 223 | } | ||
| 224 | } | ||
| 225 | |||
| 210 | std::jthread start_thread_stacks() { | 226 | std::jthread start_thread_stacks() { |
| 211 | const auto start = Clock::now(); | 227 | const auto start = Clock::now(); |
| 212 | char spec[1024]; | 228 | char spec[1024]; |
| @@ -229,7 +245,7 @@ std::jthread start_thread_stacks() { | |||
| 229 | for (const unsigned at : times) { | 245 | for (const unsigned at : times) { |
| 230 | wake.wait_until(lock, stop, start + std::chrono::seconds(at), [] { return false; }); | 246 | wake.wait_until(lock, stop, start + std::chrono::seconds(at), [] { return false; }); |
| 231 | if (stop.stop_requested()) break; | 247 | if (stop.stop_requested()) break; |
| 232 | snapshot_threads(at, sampler, describe, query); | 248 | snapshot_threads("t=" + std::to_string(at), sampler, describe, query); |
| 233 | } | 249 | } |
| 234 | }); | 250 | }); |
| 235 | } | 251 | } |