diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-25 21:49:53 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-25 21:49:53 -0500 |
| commit | 8d686309b0617e1a561c0404b8b79e6176385664 (patch) | |
| tree | 439d4a796034028a0951e6d469dbd695eacf69bb /runtime/src/main.cpp | |
| parent | 6c8a89dea7e0521714834383a847e36dcf437036 (diff) | |
| parent | 7f3d0095a2d51892bc7048f24505c37168f25c34 (diff) | |
Merge main into integration/boot-combined (RT-BOOT-COMBINED)
Conflict in runtime/shims/d3d12_xs_device.cpp, proxy_copy_descriptors_simple:
keep this branch's copy_null_rtv_marks call and main's fsdraw::enabled()
gate for the descriptor-copy diagnostic.
tools/rdna2spirv.py merged without a textual conflict, but #1662 on main
calls restore_dot4_inline_sel in the exact re-anchoring path, which this
branch had deleted. The merge puts main's function back so that call
resolves; the next commits reconcile it with the dot4 op_sel rule.
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 94e128d2a..1550039f4 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 |
| @@ -170,6 +177,7 @@ void start_title_peek(std::uint8_t* base) { | |||
| 170 | #include "mods.h" | 177 | #include "mods.h" |
| 171 | #include "pe_loader.h" | 178 | #include "pe_loader.h" |
| 172 | #include "thread_stacks.h" | 179 | #include "thread_stacks.h" |
| 180 | #include "dev_overlay.h" | ||
| 173 | #include "thread_sampler.h" | 181 | #include "thread_sampler.h" |
| 174 | #include "title_page_watch.h" | 182 | #include "title_page_watch.h" |
| 175 | #include "title_geometry_watch.h" | 183 | #include "title_geometry_watch.h" |
| @@ -177,7 +185,9 @@ void start_title_peek(std::uint8_t* base) { | |||
| 177 | #include "../shims/d3d12_xs_device.h" | 185 | #include "../shims/d3d12_xs_device.h" |
| 178 | #include "../shims/file_system.h" | 186 | #include "../shims/file_system.h" |
| 179 | #ifdef LEONIDA_VULKAN_DEVICE | 187 | #ifdef LEONIDA_VULKAN_DEVICE |
| 188 | #include "vulkan_device_fault.h" | ||
| 180 | #include "../shims/d3d12_compile_exit.h" | 189 | #include "../shims/d3d12_compile_exit.h" |
| 190 | #include "../shims/d3d12_precompile.h" | ||
| 181 | #include "../shims/package_splash.h" | 191 | #include "../shims/package_splash.h" |
| 182 | #endif | 192 | #endif |
| 183 | #include "../shims/process_shim.h" | 193 | #include "../shims/process_shim.h" |
| @@ -245,10 +255,66 @@ int usage() { | |||
| 245 | "usage: gta6rt --dry-run <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace FILE]\n" | 255 | "usage: gta6rt --dry-run <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace FILE]\n" |
| 246 | " gta6rt --init <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE]\n" | 256 | " gta6rt --init <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE]\n" |
| 247 | " gta6rt --first-run-ui <exe> [--game-dir DIR] [--overlay DIR] [--trace FILE]\n" | 257 | " gta6rt --first-run-ui <exe> [--game-dir DIR] [--overlay DIR] [--trace FILE]\n" |
| 248 | " 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"); | 258 | " 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" |
| 259 | " 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" | ||
| 260 | " gta6rt --compile-server [--parent PID] [--threads N] [--idle-threads N] [--idle-exit SECONDS]\n"); | ||
| 249 | return 2; | 261 | return 2; |
| 250 | } | 262 | } |
| 251 | 263 | ||
| 264 | #ifdef LEONIDA_VULKAN_DEVICE | ||
| 265 | // gta6rt --precompile-pipelines ...: argv[1] is the mode. | ||
| 266 | int precompile_main(int argc, wchar_t** argv) { | ||
| 267 | rt::d3d12::PrecompileOptions options; | ||
| 268 | const auto number = [&](int& i, auto& out) { | ||
| 269 | if (i + 1 >= argc) return false; | ||
| 270 | wchar_t* end = nullptr; | ||
| 271 | const unsigned long long v = std::wcstoull(argv[++i], &end, 10); | ||
| 272 | if (!end || *end) return false; | ||
| 273 | out = static_cast<std::remove_reference_t<decltype(out)>>(v); | ||
| 274 | return true; | ||
| 275 | }; | ||
| 276 | for (int i = 2; i < argc; ++i) { | ||
| 277 | const std::wstring a = argv[i]; | ||
| 278 | bool ok = true; | ||
| 279 | if (a == L"--threads") ok = number(i, options.threads); | ||
| 280 | else if (a == L"--big-threads") ok = number(i, options.big_threads); | ||
| 281 | else if (a == L"--big-bytes") ok = number(i, options.big_bytes); | ||
| 282 | else if (a == L"--limit") ok = number(i, options.limit); | ||
| 283 | else if (a == L"--min-bytes") ok = number(i, options.min_bytes); | ||
| 284 | else if (a == L"--max-bytes") ok = number(i, options.max_bytes); | ||
| 285 | else if (a == L"--all") options.rebuild = true; | ||
| 286 | else if (a == L"--smallest-first") options.smallest_first = true; | ||
| 287 | else if (a == L"--list") options.dry_run = true; | ||
| 288 | else if (a == L"--via-helper") options.via_helper = true; | ||
| 289 | else if (a == L"--filter" && i + 1 < argc) { | ||
| 290 | const std::wstring part = argv[++i]; | ||
| 291 | options.filters.emplace_back(part.begin(), part.end()); // library names are ASCII | ||
| 292 | } else ok = false; | ||
| 293 | if (!ok) return usage(); | ||
| 294 | } | ||
| 295 | return rt::d3d12::precompile_compute_pipelines(options); | ||
| 296 | } | ||
| 297 | |||
| 298 | // gta6rt --compile-server [--parent PID] [--threads N] [--idle-threads N] [--idle-exit SECONDS] | ||
| 299 | // (shims/d3d12_compile_helper.h). | ||
| 300 | int compile_server_main(int argc, wchar_t** argv) { | ||
| 301 | rt::d3d12::CompileServerOptions options; | ||
| 302 | for (int i = 2; i < argc; ++i) { | ||
| 303 | const std::wstring a = argv[i]; | ||
| 304 | if (i + 1 >= argc) return usage(); | ||
| 305 | wchar_t* end = nullptr; | ||
| 306 | const unsigned long long v = std::wcstoull(argv[++i], &end, 10); | ||
| 307 | if (!end || *end) return usage(); | ||
| 308 | if (a == L"--parent") options.parent_pid = static_cast<unsigned long>(v); | ||
| 309 | else if (a == L"--threads") options.threads = static_cast<unsigned>(v); | ||
| 310 | else if (a == L"--idle-threads") options.idle_threads = static_cast<unsigned>(v); | ||
| 311 | else if (a == L"--idle-exit") options.idle_exit_s = static_cast<unsigned>(v); | ||
| 312 | else return usage(); | ||
| 313 | } | ||
| 314 | return rt::d3d12::compile_server(options); | ||
| 315 | } | ||
| 316 | #endif | ||
| 317 | |||
| 252 | } // namespace | 318 | } // namespace |
| 253 | 319 | ||
| 254 | #ifdef LEONIDA_VULKAN_DEVICE | 320 | #ifdef LEONIDA_VULKAN_DEVICE |
| @@ -313,6 +379,10 @@ static BOOL WINAPI show_package_window(HWND window, int command) { | |||
| 313 | #endif | 379 | #endif |
| 314 | 380 | ||
| 315 | int wmain(int argc, wchar_t** argv) { | 381 | int wmain(int argc, wchar_t** argv) { |
| 382 | #ifdef LEONIDA_VULKAN_DEVICE | ||
| 383 | if (argc > 1 && std::wstring(argv[1]) == L"--precompile-pipelines") return precompile_main(argc, argv); | ||
| 384 | if (argc > 1 && std::wstring(argv[1]) == L"--compile-server") return compile_server_main(argc, argv); | ||
| 385 | #endif | ||
| 316 | std::filesystem::path image, game_dir, overlay_dir, mods_dir; | 386 | std::filesystem::path image, game_dir, overlay_dir, mods_dir; |
| 317 | uint32_t archetype_lookup_rva = 0; // --archetype-lookup RVA[,ARG]: the game's archetype lookup by hash | 387 | uint32_t archetype_lookup_rva = 0; // --archetype-lookup RVA[,ARG]: the game's archetype lookup by hash |
| 318 | int archetype_lookup_arg = 0; | 388 | int archetype_lookup_arg = 0; |
| @@ -457,6 +527,8 @@ int wmain(int argc, wchar_t** argv) { | |||
| 457 | rt::d3d12_trace::set_enabled(trace_d3d12); | 527 | rt::d3d12_trace::set_enabled(trace_d3d12); |
| 458 | // Slot 133 imports the title's pages; xmem commits them on first touch, so they are committed first. | 528 | // Slot 133 imports the title's pages; xmem commits them on first touch, so they are committed first. |
| 459 | rt::d3d12_xs::set_placed_at_va_pages_hook(&rt::xmem::commit_physical_range); | 529 | rt::d3d12_xs::set_placed_at_va_pages_hook(&rt::xmem::commit_physical_range); |
| 530 | if (rt::xmem::slot31_runs() && rt::xmem::queue_page_mappings_enabled()) | ||
| 531 | rt::d3d12_xs::set_copy_page_mappings_hook(&rt::xmem::copy_page_mappings); | ||
| 460 | // So do the file shims' reads, whose kernel writes do not fault them in: on ERROR_NOACCESS (title_page_watch.h). | 532 | // So do the file shims' reads, whose kernel writes do not fault them in: on ERROR_NOACCESS (title_page_watch.h). |
| 461 | leonida::geometry_writes::aliases.store(&rt::xmem::geometry_aliases); | 533 | leonida::geometry_writes::aliases.store(&rt::xmem::geometry_aliases); |
| 462 | leonida::kernel_writes::set_committer(&rt::xmem::commit_physical_range); | 534 | leonida::kernel_writes::set_committer(&rt::xmem::commit_physical_range); |
| @@ -562,7 +634,9 @@ int wmain(int argc, wchar_t** argv) { | |||
| 562 | std::fprintf(stderr, "error: %s has no entry point\n", main_module.name.c_str()); | 634 | std::fprintf(stderr, "error: %s has no entry point\n", main_module.name.c_str()); |
| 563 | return 1; | 635 | return 1; |
| 564 | } | 636 | } |
| 565 | const std::wstring paths = L"console paths: GAME: -> " + game_dir.native() + L", writes -> " + overlay_dir.native(); | 637 | const std::filesystem::path scratch_dir = rt::fs::scratch_dir(); |
| 638 | const std::wstring paths = L"console paths: GAME: -> " + game_dir.native() + L", writes -> " + | ||
| 639 | overlay_dir.native() + L", T: -> " + scratch_dir.native(); | ||
| 566 | const HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); | 640 | const HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); |
| 567 | DWORD mode; | 641 | DWORD mode; |
| 568 | bool printed = false; | 642 | bool printed = false; |
| @@ -575,19 +649,25 @@ int wmain(int argc, wchar_t** argv) { | |||
| 575 | if (!printed) { | 649 | if (!printed) { |
| 576 | const auto game = game_dir.u8string(); | 650 | const auto game = game_dir.u8string(); |
| 577 | const auto overlay = overlay_dir.u8string(); | 651 | const auto overlay = overlay_dir.u8string(); |
| 578 | std::printf("console paths: GAME: -> %s, writes -> %s\n", | 652 | const auto scratch = scratch_dir.u8string(); |
| 579 | reinterpret_cast<const char*>(game.c_str()), reinterpret_cast<const char*>(overlay.c_str())); | 653 | std::printf("console paths: GAME: -> %s, writes -> %s, T: -> %s\n", |
| 654 | reinterpret_cast<const char*>(game.c_str()), reinterpret_cast<const char*>(overlay.c_str()), | ||
| 655 | reinterpret_cast<const char*>(scratch.c_str())); | ||
| 580 | } | 656 | } |
| 581 | std::printf("running %s\n", main_module.name.c_str()); | 657 | std::printf("running %s\n", main_module.name.c_str()); |
| 582 | std::fflush(stdout); | 658 | std::fflush(stdout); |
| 583 | keep_title_watchdog_kicked(main_module.base); | 659 | keep_title_watchdog_kicked(main_module.base); |
| 584 | start_title_peek(main_module.base); | 660 | start_title_peek(main_module.base); |
| 661 | leonida::dev_overlay::start(); // LEONIDA_DEV_OVERLAY=1 | ||
| 585 | leonida::thread_sampler::start(main_module.base, main_module.size); // LEONIDA_SAMPLE_MS (diagnostic) | 662 | leonida::thread_sampler::start(main_module.base, main_module.size); // LEONIDA_SAMPLE_MS (diagnostic) |
| 586 | #ifdef LEONIDA_VULKAN_DEVICE | 663 | #ifdef LEONIDA_VULKAN_DEVICE |
| 587 | SetConsoleCtrlHandler(&stop_compiles_on_console_exit, TRUE); | 664 | SetConsoleCtrlHandler(&stop_compiles_on_console_exit, TRUE); |
| 588 | previous_fatal_filter = SetUnhandledExceptionFilter(&save_caches_on_fatal_exception); | 665 | previous_fatal_filter = SetUnhandledExceptionFilter(&save_caches_on_fatal_exception); |
| 589 | #endif | 666 | #endif |
| 590 | int code; | 667 | int code; |
| 668 | #ifdef LEONIDA_VULKAN_DEVICE | ||
| 669 | leonida::thread_stack_hook.store(&rt::print_thread_stacks_now, std::memory_order_release); | ||
| 670 | #endif | ||
| 591 | { | 671 | { |
| 592 | auto stacks = rt::start_thread_stacks(); | 672 | auto stacks = rt::start_thread_stacks(); |
| 593 | code = rt::process::run_entry(main_module.base + main_module.entry_rva); | 673 | code = rt::process::run_entry(main_module.base + main_module.entry_rva); |