diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-25 19:04:24 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-25 19:04:24 -0500 |
| commit | 8d832fd10913064e1c8aec74191e3ba8f70211c8 (patch) | |
| tree | e365199d7d86ebf592a5a0dc2f07cda4b74b58a7 /runtime/src/main.cpp | |
| parent | 5da3b6be3cefc1499452ba8c8370a50092674d61 (diff) | |
| parent | c50ed94b35b37b697ab9c5fd176f3738480b4db5 (diff) | |
Merge main into rt-title-every-budget (#2122)
#2098 split the every-pass loop of refresh_title_textures by mode: with
LEONIDA_TEXTURE_REFRESH_ASYNC every persistent mapping is polled each
pass and only stale unmapped textures are visited, without it all mapped
or stale ones are. The async branch is kept as main has it.
LEONIDA_TITLE_EVERY_BUDGET_US applies to the synchronous pass, the one
before a submission on the submitting thread; under async the pass runs
on the refresh worker and the limit does not apply (README says so).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/main.cpp')
| -rw-r--r-- | runtime/src/main.cpp | 88 |
1 files changed, 84 insertions, 4 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index 094aaa321..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 |
| @@ -149,6 +156,7 @@ void start_title_peek(std::uint8_t* base) { | |||
| 149 | #include "mods.h" | 156 | #include "mods.h" |
| 150 | #include "pe_loader.h" | 157 | #include "pe_loader.h" |
| 151 | #include "thread_stacks.h" | 158 | #include "thread_stacks.h" |
| 159 | #include "dev_overlay.h" | ||
| 152 | #include "thread_sampler.h" | 160 | #include "thread_sampler.h" |
| 153 | #include "title_page_watch.h" | 161 | #include "title_page_watch.h" |
| 154 | #include "title_geometry_watch.h" | 162 | #include "title_geometry_watch.h" |
| @@ -156,7 +164,9 @@ void start_title_peek(std::uint8_t* base) { | |||
| 156 | #include "../shims/d3d12_xs_device.h" | 164 | #include "../shims/d3d12_xs_device.h" |
| 157 | #include "../shims/file_system.h" | 165 | #include "../shims/file_system.h" |
| 158 | #ifdef LEONIDA_VULKAN_DEVICE | 166 | #ifdef LEONIDA_VULKAN_DEVICE |
| 167 | #include "vulkan_device_fault.h" | ||
| 159 | #include "../shims/d3d12_compile_exit.h" | 168 | #include "../shims/d3d12_compile_exit.h" |
| 169 | #include "../shims/d3d12_precompile.h" | ||
| 160 | #include "../shims/package_splash.h" | 170 | #include "../shims/package_splash.h" |
| 161 | #endif | 171 | #endif |
| 162 | #include "../shims/process_shim.h" | 172 | #include "../shims/process_shim.h" |
| @@ -224,10 +234,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" | 234 | "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" | 235 | " 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" | 236 | " 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"); | 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"); | ||
| 228 | return 2; | 240 | return 2; |
| 229 | } | 241 | } |
| 230 | 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 | |||
| 231 | } // namespace | 297 | } // namespace |
| 232 | 298 | ||
| 233 | #ifdef LEONIDA_VULKAN_DEVICE | 299 | #ifdef LEONIDA_VULKAN_DEVICE |
| @@ -292,6 +358,10 @@ static BOOL WINAPI show_package_window(HWND window, int command) { | |||
| 292 | #endif | 358 | #endif |
| 293 | 359 | ||
| 294 | 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 | ||
| 295 | std::filesystem::path image, game_dir, overlay_dir, mods_dir; | 365 | 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 | 366 | uint32_t archetype_lookup_rva = 0; // --archetype-lookup RVA[,ARG]: the game's archetype lookup by hash |
| 297 | int archetype_lookup_arg = 0; | 367 | int archetype_lookup_arg = 0; |
| @@ -436,6 +506,8 @@ int wmain(int argc, wchar_t** argv) { | |||
| 436 | rt::d3d12_trace::set_enabled(trace_d3d12); | 506 | 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. | 507 | // 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); | 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); | ||
| 439 | // 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). |
| 440 | leonida::geometry_writes::aliases.store(&rt::xmem::geometry_aliases); | 512 | leonida::geometry_writes::aliases.store(&rt::xmem::geometry_aliases); |
| 441 | leonida::kernel_writes::set_committer(&rt::xmem::commit_physical_range); | 513 | leonida::kernel_writes::set_committer(&rt::xmem::commit_physical_range); |
| @@ -541,7 +613,9 @@ int wmain(int argc, wchar_t** argv) { | |||
| 541 | std::fprintf(stderr, "error: %s has no entry point\n", main_module.name.c_str()); | 613 | std::fprintf(stderr, "error: %s has no entry point\n", main_module.name.c_str()); |
| 542 | return 1; | 614 | return 1; |
| 543 | } | 615 | } |
| 544 | const std::wstring paths = L"console paths: GAME: -> " + game_dir.native() + L", writes -> " + overlay_dir.native(); | 616 | const std::filesystem::path scratch_dir = rt::fs::scratch_dir(); |
| 617 | const std::wstring paths = L"console paths: GAME: -> " + game_dir.native() + L", writes -> " + | ||
| 618 | overlay_dir.native() + L", T: -> " + scratch_dir.native(); | ||
| 545 | const HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); | 619 | const HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); |
| 546 | DWORD mode; | 620 | DWORD mode; |
| 547 | bool printed = false; | 621 | bool printed = false; |
| @@ -554,19 +628,25 @@ int wmain(int argc, wchar_t** argv) { | |||
| 554 | if (!printed) { | 628 | if (!printed) { |
| 555 | const auto game = game_dir.u8string(); | 629 | const auto game = game_dir.u8string(); |
| 556 | const auto overlay = overlay_dir.u8string(); | 630 | const auto overlay = overlay_dir.u8string(); |
| 557 | std::printf("console paths: GAME: -> %s, writes -> %s\n", | 631 | const auto scratch = scratch_dir.u8string(); |
| 558 | reinterpret_cast<const char*>(game.c_str()), reinterpret_cast<const char*>(overlay.c_str())); | 632 | std::printf("console paths: GAME: -> %s, writes -> %s, T: -> %s\n", |
| 633 | reinterpret_cast<const char*>(game.c_str()), reinterpret_cast<const char*>(overlay.c_str()), | ||
| 634 | reinterpret_cast<const char*>(scratch.c_str())); | ||
| 559 | } | 635 | } |
| 560 | std::printf("running %s\n", main_module.name.c_str()); | 636 | std::printf("running %s\n", main_module.name.c_str()); |
| 561 | std::fflush(stdout); | 637 | std::fflush(stdout); |
| 562 | keep_title_watchdog_kicked(main_module.base); | 638 | keep_title_watchdog_kicked(main_module.base); |
| 563 | start_title_peek(main_module.base); | 639 | start_title_peek(main_module.base); |
| 640 | leonida::dev_overlay::start(); // LEONIDA_DEV_OVERLAY=1 | ||
| 564 | leonida::thread_sampler::start(main_module.base, main_module.size); // LEONIDA_SAMPLE_MS (diagnostic) | 641 | leonida::thread_sampler::start(main_module.base, main_module.size); // LEONIDA_SAMPLE_MS (diagnostic) |
| 565 | #ifdef LEONIDA_VULKAN_DEVICE | 642 | #ifdef LEONIDA_VULKAN_DEVICE |
| 566 | SetConsoleCtrlHandler(&stop_compiles_on_console_exit, TRUE); | 643 | SetConsoleCtrlHandler(&stop_compiles_on_console_exit, TRUE); |
| 567 | previous_fatal_filter = SetUnhandledExceptionFilter(&save_caches_on_fatal_exception); | 644 | previous_fatal_filter = SetUnhandledExceptionFilter(&save_caches_on_fatal_exception); |
| 568 | #endif | 645 | #endif |
| 569 | 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 | ||
| 570 | { | 650 | { |
| 571 | auto stacks = rt::start_thread_stacks(); | 651 | auto stacks = rt::start_thread_stacks(); |
| 572 | 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); |