diff options
| author | Aslan2142 <jan.trencansky@protonmail.com> | 2026-11-26 01:01:15 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-26 01:01:15 +0100 |
| commit | c50ed94b35b37b697ab9c5fd176f3738480b4db5 (patch) | |
| tree | fbc257236021f3e4e41b3a7e7bf062aac898a1bf /runtime/src/main.cpp | |
| parent | 33bd07cf86bb42236635c27341359b3fe841d1d5 (diff) | |
| parent | fc71534883424112a7ea08fefe5b820fc4ee58aa (diff) | |
Merge pull request #2098 from Moriz82/pr/upstream-1125
Improve post-load GPU memory and pipeline handling (RT-POST-LOAD-GPU-MEMORY)
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 1b55264fb..4d483ed59 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 |
| @@ -157,7 +164,9 @@ void start_title_peek(std::uint8_t* base) { | |||
| 157 | #include "../shims/d3d12_xs_device.h" | 164 | #include "../shims/d3d12_xs_device.h" |
| 158 | #include "../shims/file_system.h" | 165 | #include "../shims/file_system.h" |
| 159 | #ifdef LEONIDA_VULKAN_DEVICE | 166 | #ifdef LEONIDA_VULKAN_DEVICE |
| 167 | #include "vulkan_device_fault.h" | ||
| 160 | #include "../shims/d3d12_compile_exit.h" | 168 | #include "../shims/d3d12_compile_exit.h" |
| 169 | #include "../shims/d3d12_precompile.h" | ||
| 161 | #include "../shims/package_splash.h" | 170 | #include "../shims/package_splash.h" |
| 162 | #endif | 171 | #endif |
| 163 | #include "../shims/process_shim.h" | 172 | #include "../shims/process_shim.h" |
| @@ -225,10 +234,66 @@ int usage() { | |||
| 225 | "usage: gta6rt --dry-run <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace FILE]\n" | 234 | "usage: gta6rt --dry-run <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace FILE]\n" |
| 226 | " gta6rt --init <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE]\n" | 235 | " gta6rt --init <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE]\n" |
| 227 | " gta6rt --first-run-ui <exe> [--game-dir DIR] [--overlay DIR] [--trace FILE]\n" | 236 | " gta6rt --first-run-ui <exe> [--game-dir DIR] [--overlay DIR] [--trace FILE]\n" |
| 228 | " 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 --run <exe> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE] [-- game arguments...]\n" |
| 238 | " 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" | ||
| 239 | " gta6rt --compile-server [--parent PID] [--threads N] [--idle-threads N] [--idle-exit SECONDS]\n"); | ||
| 229 | return 2; | 240 | return 2; |
| 230 | } | 241 | } |
| 231 | 242 | ||
| 243 | #ifdef LEONIDA_VULKAN_DEVICE | ||
| 244 | // gta6rt --precompile-pipelines ...: argv[1] is the mode. | ||
| 245 | int precompile_main(int argc, wchar_t** argv) { | ||
| 246 | rt::d3d12::PrecompileOptions options; | ||
| 247 | const auto number = [&](int& i, auto& out) { | ||
| 248 | if (i + 1 >= argc) return false; | ||
| 249 | wchar_t* end = nullptr; | ||
| 250 | const unsigned long long v = std::wcstoull(argv[++i], &end, 10); | ||
| 251 | if (!end || *end) return false; | ||
| 252 | out = static_cast<std::remove_reference_t<decltype(out)>>(v); | ||
| 253 | return true; | ||
| 254 | }; | ||
| 255 | for (int i = 2; i < argc; ++i) { | ||
| 256 | const std::wstring a = argv[i]; | ||
| 257 | bool ok = true; | ||
| 258 | if (a == L"--threads") ok = number(i, options.threads); | ||
| 259 | else if (a == L"--big-threads") ok = number(i, options.big_threads); | ||
| 260 | else if (a == L"--big-bytes") ok = number(i, options.big_bytes); | ||
| 261 | else if (a == L"--limit") ok = number(i, options.limit); | ||
| 262 | else if (a == L"--min-bytes") ok = number(i, options.min_bytes); | ||
| 263 | else if (a == L"--max-bytes") ok = number(i, options.max_bytes); | ||
| 264 | else if (a == L"--all") options.rebuild = true; | ||
| 265 | else if (a == L"--smallest-first") options.smallest_first = true; | ||
| 266 | else if (a == L"--list") options.dry_run = true; | ||
| 267 | else if (a == L"--via-helper") options.via_helper = true; | ||
| 268 | else if (a == L"--filter" && i + 1 < argc) { | ||
| 269 | const std::wstring part = argv[++i]; | ||
| 270 | options.filters.emplace_back(part.begin(), part.end()); // library names are ASCII | ||
| 271 | } else ok = false; | ||
| 272 | if (!ok) return usage(); | ||
| 273 | } | ||
| 274 | return rt::d3d12::precompile_compute_pipelines(options); | ||
| 275 | } | ||
| 276 | |||
| 277 | // gta6rt --compile-server [--parent PID] [--threads N] [--idle-threads N] [--idle-exit SECONDS] | ||
| 278 | // (shims/d3d12_compile_helper.h). | ||
| 279 | int compile_server_main(int argc, wchar_t** argv) { | ||
| 280 | rt::d3d12::CompileServerOptions options; | ||
| 281 | for (int i = 2; i < argc; ++i) { | ||
| 282 | const std::wstring a = argv[i]; | ||
| 283 | if (i + 1 >= argc) return usage(); | ||
| 284 | wchar_t* end = nullptr; | ||
| 285 | const unsigned long long v = std::wcstoull(argv[++i], &end, 10); | ||
| 286 | if (!end || *end) return usage(); | ||
| 287 | if (a == L"--parent") options.parent_pid = static_cast<unsigned long>(v); | ||
| 288 | else if (a == L"--threads") options.threads = static_cast<unsigned>(v); | ||
| 289 | else if (a == L"--idle-threads") options.idle_threads = static_cast<unsigned>(v); | ||
| 290 | else if (a == L"--idle-exit") options.idle_exit_s = static_cast<unsigned>(v); | ||
| 291 | else return usage(); | ||
| 292 | } | ||
| 293 | return rt::d3d12::compile_server(options); | ||
| 294 | } | ||
| 295 | #endif | ||
| 296 | |||
| 232 | } // namespace | 297 | } // namespace |
| 233 | 298 | ||
| 234 | #ifdef LEONIDA_VULKAN_DEVICE | 299 | #ifdef LEONIDA_VULKAN_DEVICE |
| @@ -293,6 +358,10 @@ static BOOL WINAPI show_package_window(HWND window, int command) { | |||
| 293 | #endif | 358 | #endif |
| 294 | 359 | ||
| 295 | int wmain(int argc, wchar_t** argv) { | 360 | int wmain(int argc, wchar_t** argv) { |
| 361 | #ifdef LEONIDA_VULKAN_DEVICE | ||
| 362 | if (argc > 1 && std::wstring(argv[1]) == L"--precompile-pipelines") return precompile_main(argc, argv); | ||
| 363 | if (argc > 1 && std::wstring(argv[1]) == L"--compile-server") return compile_server_main(argc, argv); | ||
| 364 | #endif | ||
| 296 | std::filesystem::path image, game_dir, overlay_dir, mods_dir; | 365 | std::filesystem::path image, game_dir, overlay_dir, mods_dir; |
| 297 | uint32_t archetype_lookup_rva = 0; // --archetype-lookup RVA[,ARG]: the game's archetype lookup by hash | 366 | uint32_t archetype_lookup_rva = 0; // --archetype-lookup RVA[,ARG]: the game's archetype lookup by hash |
| 298 | int archetype_lookup_arg = 0; | 367 | int archetype_lookup_arg = 0; |
| @@ -437,6 +506,8 @@ int wmain(int argc, wchar_t** argv) { | |||
| 437 | rt::d3d12_trace::set_enabled(trace_d3d12); | 506 | rt::d3d12_trace::set_enabled(trace_d3d12); |
| 438 | // Slot 133 imports the title's pages; xmem commits them on first touch, so they are committed first. | 507 | // Slot 133 imports the title's pages; xmem commits them on first touch, so they are committed first. |
| 439 | rt::d3d12_xs::set_placed_at_va_pages_hook(&rt::xmem::commit_physical_range); | 508 | rt::d3d12_xs::set_placed_at_va_pages_hook(&rt::xmem::commit_physical_range); |
| 509 | if (rt::xmem::slot31_runs() && rt::xmem::queue_page_mappings_enabled()) | ||
| 510 | rt::d3d12_xs::set_copy_page_mappings_hook(&rt::xmem::copy_page_mappings); | ||
| 440 | // So do the file shims' reads, whose kernel writes do not fault them in: on ERROR_NOACCESS (title_page_watch.h). | 511 | // So do the file shims' reads, whose kernel writes do not fault them in: on ERROR_NOACCESS (title_page_watch.h). |
| 441 | leonida::geometry_writes::aliases.store(&rt::xmem::geometry_aliases); | 512 | leonida::geometry_writes::aliases.store(&rt::xmem::geometry_aliases); |
| 442 | leonida::kernel_writes::set_committer(&rt::xmem::commit_physical_range); | 513 | leonida::kernel_writes::set_committer(&rt::xmem::commit_physical_range); |
| @@ -573,6 +644,9 @@ int wmain(int argc, wchar_t** argv) { | |||
| 573 | previous_fatal_filter = SetUnhandledExceptionFilter(&save_caches_on_fatal_exception); | 644 | previous_fatal_filter = SetUnhandledExceptionFilter(&save_caches_on_fatal_exception); |
| 574 | #endif | 645 | #endif |
| 575 | int code; | 646 | int code; |
| 647 | #ifdef LEONIDA_VULKAN_DEVICE | ||
| 648 | leonida::thread_stack_hook.store(&rt::print_thread_stacks_now, std::memory_order_release); | ||
| 649 | #endif | ||
| 576 | { | 650 | { |
| 577 | auto stacks = rt::start_thread_stacks(); | 651 | auto stacks = rt::start_thread_stacks(); |
| 578 | code = rt::process::run_entry(main_module.base + main_module.entry_rva); | 652 | code = rt::process::run_entry(main_module.base + main_module.entry_rva); |