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/main.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/main.cpp')
| -rw-r--r-- | runtime/src/main.cpp | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index 094aaa321..76b180475 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp | |||
| @@ -9,6 +9,13 @@ | |||
| 9 | // gta6rt --init <image> [--game-dir DIR] [--overlay DIR] | 9 | // gta6rt --init <image> [--game-dir DIR] [--overlay DIR] |
| 10 | // The same mapping, then each loaded DLL's TLS callbacks and DllMain(DLL_PROCESS_ATTACH) are run. | 10 | // The same mapping, then each loaded DLL's TLS callbacks and DllMain(DLL_PROCESS_ATTACH) are run. |
| 11 | // | 11 | // |
| 12 | // gta6rt --precompile-pipelines [--threads N] [--big-threads N] [--big-bytes N] [--all] [--smallest-first] | ||
| 13 | // [--limit N] [--min-bytes N] [--max-bytes N] [--filter PART]... [--list] | ||
| 14 | // No game: creates the Vulkan device as --run does and builds every compute pipeline of the shader library | ||
| 15 | // (LEONIDA_SHADERS) into the pipeline journal and the driver's cache, so a title's first dispatch of a large one | ||
| 16 | // does not stall it. Resumable: entries already journaled are skipped (--all: built anyway). See | ||
| 17 | // shims/d3d12_precompile.h. | ||
| 18 | // | ||
| 12 | // gta6rt --run <exe> [--game-dir DIR] [--overlay DIR] [--trace-d3d12] [--trace FILE] [-- game arguments...] | 19 | // gta6rt --run <exe> [--game-dir DIR] [--overlay DIR] [--trace-d3d12] [--trace FILE] [-- game arguments...] |
| 13 | // The same, then the EXE's own TLS callbacks and its entry point, on a game thread. The game's argv and | 20 | // The same, then the EXE's own TLS callbacks and its entry point, on a game thread. The game's argv and |
| 14 | // command line are <exe name> plus the arguments after "--"; exit/ExitProcess from the game end the run | 21 | // command line are <exe name> plus the arguments after "--"; exit/ExitProcess from the game end the run |
| @@ -156,7 +163,9 @@ void start_title_peek(std::uint8_t* base) { | |||
| 156 | #include "../shims/d3d12_xs_device.h" | 163 | #include "../shims/d3d12_xs_device.h" |
| 157 | #include "../shims/file_system.h" | 164 | #include "../shims/file_system.h" |
| 158 | #ifdef LEONIDA_VULKAN_DEVICE | 165 | #ifdef LEONIDA_VULKAN_DEVICE |
| 166 | #include "vulkan_device_fault.h" | ||
| 159 | #include "../shims/d3d12_compile_exit.h" | 167 | #include "../shims/d3d12_compile_exit.h" |
| 168 | #include "../shims/d3d12_precompile.h" | ||
| 160 | #include "../shims/package_splash.h" | 169 | #include "../shims/package_splash.h" |
| 161 | #endif | 170 | #endif |
| 162 | #include "../shims/process_shim.h" | 171 | #include "../shims/process_shim.h" |
| @@ -224,10 +233,66 @@ int usage() { | |||
| 224 | "usage: gta6rt --dry-run <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace FILE]\n" | 233 | "usage: gta6rt --dry-run <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace FILE]\n" |
| 225 | " gta6rt --init <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE]\n" | 234 | " gta6rt --init <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE]\n" |
| 226 | " gta6rt --first-run-ui <exe> [--game-dir DIR] [--overlay DIR] [--trace FILE]\n" | 235 | " gta6rt --first-run-ui <exe> [--game-dir DIR] [--overlay DIR] [--trace FILE]\n" |
| 227 | " gta6rt --run <exe> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE] [-- game arguments...]\n"); | 236 | " gta6rt --run <exe> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE] [-- game arguments...]\n" |
| 237 | " gta6rt --precompile-pipelines [--threads N] [--big-threads N] [--big-bytes N] [--all] [--smallest-first] [--limit N] [--min-bytes N] [--max-bytes N] [--filter PART]... [--list] [--via-helper]\n" | ||
| 238 | " gta6rt --compile-server [--parent PID] [--threads N] [--idle-threads N] [--idle-exit SECONDS]\n"); | ||
| 228 | return 2; | 239 | return 2; |
| 229 | } | 240 | } |
| 230 | 241 | ||
| 242 | #ifdef LEONIDA_VULKAN_DEVICE | ||
| 243 | // gta6rt --precompile-pipelines ...: argv[1] is the mode. | ||
| 244 | int precompile_main(int argc, wchar_t** argv) { | ||
| 245 | rt::d3d12::PrecompileOptions options; | ||
| 246 | const auto number = [&](int& i, auto& out) { | ||
| 247 | if (i + 1 >= argc) return false; | ||
| 248 | wchar_t* end = nullptr; | ||
| 249 | const unsigned long long v = std::wcstoull(argv[++i], &end, 10); | ||
| 250 | if (!end || *end) return false; | ||
| 251 | out = static_cast<std::remove_reference_t<decltype(out)>>(v); | ||
| 252 | return true; | ||
| 253 | }; | ||
| 254 | for (int i = 2; i < argc; ++i) { | ||
| 255 | const std::wstring a = argv[i]; | ||
| 256 | bool ok = true; | ||
| 257 | if (a == L"--threads") ok = number(i, options.threads); | ||
| 258 | else if (a == L"--big-threads") ok = number(i, options.big_threads); | ||
| 259 | else if (a == L"--big-bytes") ok = number(i, options.big_bytes); | ||
| 260 | else if (a == L"--limit") ok = number(i, options.limit); | ||
| 261 | else if (a == L"--min-bytes") ok = number(i, options.min_bytes); | ||
| 262 | else if (a == L"--max-bytes") ok = number(i, options.max_bytes); | ||
| 263 | else if (a == L"--all") options.rebuild = true; | ||
| 264 | else if (a == L"--smallest-first") options.smallest_first = true; | ||
| 265 | else if (a == L"--list") options.dry_run = true; | ||
| 266 | else if (a == L"--via-helper") options.via_helper = true; | ||
| 267 | else if (a == L"--filter" && i + 1 < argc) { | ||
| 268 | const std::wstring part = argv[++i]; | ||
| 269 | options.filters.emplace_back(part.begin(), part.end()); // library names are ASCII | ||
| 270 | } else ok = false; | ||
| 271 | if (!ok) return usage(); | ||
| 272 | } | ||
| 273 | return rt::d3d12::precompile_compute_pipelines(options); | ||
| 274 | } | ||
| 275 | |||
| 276 | // gta6rt --compile-server [--parent PID] [--threads N] [--idle-threads N] [--idle-exit SECONDS] | ||
| 277 | // (shims/d3d12_compile_helper.h). | ||
| 278 | int compile_server_main(int argc, wchar_t** argv) { | ||
| 279 | rt::d3d12::CompileServerOptions options; | ||
| 280 | for (int i = 2; i < argc; ++i) { | ||
| 281 | const std::wstring a = argv[i]; | ||
| 282 | if (i + 1 >= argc) return usage(); | ||
| 283 | wchar_t* end = nullptr; | ||
| 284 | const unsigned long long v = std::wcstoull(argv[++i], &end, 10); | ||
| 285 | if (!end || *end) return usage(); | ||
| 286 | if (a == L"--parent") options.parent_pid = static_cast<unsigned long>(v); | ||
| 287 | else if (a == L"--threads") options.threads = static_cast<unsigned>(v); | ||
| 288 | else if (a == L"--idle-threads") options.idle_threads = static_cast<unsigned>(v); | ||
| 289 | else if (a == L"--idle-exit") options.idle_exit_s = static_cast<unsigned>(v); | ||
| 290 | else return usage(); | ||
| 291 | } | ||
| 292 | return rt::d3d12::compile_server(options); | ||
| 293 | } | ||
| 294 | #endif | ||
| 295 | |||
| 231 | } // namespace | 296 | } // namespace |
| 232 | 297 | ||
| 233 | #ifdef LEONIDA_VULKAN_DEVICE | 298 | #ifdef LEONIDA_VULKAN_DEVICE |
| @@ -292,6 +357,10 @@ static BOOL WINAPI show_package_window(HWND window, int command) { | |||
| 292 | #endif | 357 | #endif |
| 293 | 358 | ||
| 294 | int wmain(int argc, wchar_t** argv) { | 359 | int wmain(int argc, wchar_t** argv) { |
| 360 | #ifdef LEONIDA_VULKAN_DEVICE | ||
| 361 | if (argc > 1 && std::wstring(argv[1]) == L"--precompile-pipelines") return precompile_main(argc, argv); | ||
| 362 | if (argc > 1 && std::wstring(argv[1]) == L"--compile-server") return compile_server_main(argc, argv); | ||
| 363 | #endif | ||
| 295 | std::filesystem::path image, game_dir, overlay_dir, mods_dir; | 364 | std::filesystem::path image, game_dir, overlay_dir, mods_dir; |
| 296 | uint32_t archetype_lookup_rva = 0; // --archetype-lookup RVA[,ARG]: the game's archetype lookup by hash | 365 | uint32_t archetype_lookup_rva = 0; // --archetype-lookup RVA[,ARG]: the game's archetype lookup by hash |
| 297 | int archetype_lookup_arg = 0; | 366 | int archetype_lookup_arg = 0; |
| @@ -436,6 +505,8 @@ int wmain(int argc, wchar_t** argv) { | |||
| 436 | rt::d3d12_trace::set_enabled(trace_d3d12); | 505 | rt::d3d12_trace::set_enabled(trace_d3d12); |
| 437 | // Slot 133 imports the title's pages; xmem commits them on first touch, so they are committed first. | 506 | // Slot 133 imports the title's pages; xmem commits them on first touch, so they are committed first. |
| 438 | rt::d3d12_xs::set_placed_at_va_pages_hook(&rt::xmem::commit_physical_range); | 507 | rt::d3d12_xs::set_placed_at_va_pages_hook(&rt::xmem::commit_physical_range); |
| 508 | if (rt::xmem::slot31_runs() && rt::xmem::queue_page_mappings_enabled()) | ||
| 509 | rt::d3d12_xs::set_copy_page_mappings_hook(&rt::xmem::copy_page_mappings); | ||
| 439 | // So do the file shims' reads, whose kernel writes do not fault them in: on ERROR_NOACCESS (title_page_watch.h). | 510 | // So do the file shims' reads, whose kernel writes do not fault them in: on ERROR_NOACCESS (title_page_watch.h). |
| 440 | leonida::geometry_writes::aliases.store(&rt::xmem::geometry_aliases); | 511 | leonida::geometry_writes::aliases.store(&rt::xmem::geometry_aliases); |
| 441 | leonida::kernel_writes::set_committer(&rt::xmem::commit_physical_range); | 512 | leonida::kernel_writes::set_committer(&rt::xmem::commit_physical_range); |
| @@ -567,6 +638,9 @@ int wmain(int argc, wchar_t** argv) { | |||
| 567 | previous_fatal_filter = SetUnhandledExceptionFilter(&save_caches_on_fatal_exception); | 638 | previous_fatal_filter = SetUnhandledExceptionFilter(&save_caches_on_fatal_exception); |
| 568 | #endif | 639 | #endif |
| 569 | int code; | 640 | int code; |
| 641 | #ifdef LEONIDA_VULKAN_DEVICE | ||
| 642 | leonida::thread_stack_hook.store(&rt::print_thread_stacks_now, std::memory_order_release); | ||
| 643 | #endif | ||
| 570 | { | 644 | { |
| 571 | auto stacks = rt::start_thread_stacks(); | 645 | auto stacks = rt::start_thread_stacks(); |
| 572 | code = rt::process::run_entry(main_module.base + main_module.entry_rva); | 646 | code = rt::process::run_entry(main_module.base + main_module.entry_rva); |