diff options
| author | Rain156 <77776581+Rain156@users.noreply.github.com> | 2026-11-24 21:19:30 +0800 |
|---|---|---|
| committer | Rain156 <77776581+Rain156@users.noreply.github.com> | 2026-11-24 21:19:30 +0800 |
| commit | db19bbd3455a757c3fe986c6e6db36998f275150 (patch) | |
| tree | fc55054b03582969e5897c73a667cc4c8b44ad5a /runtime/src/main.cpp | |
| parent | e0d4fd2b81e6636b1c6bb2f76be79e910e84d84b (diff) | |
runtime: connect native pipelines and title resources to the offline first-run UI
Build on the public frame-loop integration in #321. Carry the texture-view and depth work from #213 and #261, the layout provider from #461, the responsive window from #526, and the rectangle generator from #682. Integrate the Xbox constant-buffer row addressing measured in #513 and the draw-time rectangle selection in #722. Keep all fixtures synthetic.
The Windows GPU path resolves title-owned shader objects, retires geometry uploads per submission, materializes texture views on use, maps linear surfaces, and delivers completed GPU label writes. A first-run UI launch selects the tested settings for these paths.
Diffstat (limited to 'runtime/src/main.cpp')
| -rw-r--r-- | runtime/src/main.cpp | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index 63bd016e8..8ea202fa0 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp | |||
| @@ -62,10 +62,40 @@ extern "C" __declspec(allocate(".CRT$XCT")) void(__cdecl* const gta6rt_reserve_t | |||
| 62 | reserve_tls_index0_at_start; | 62 | reserve_tls_index0_at_start; |
| 63 | #pragma comment(linker, "/INCLUDE:gta6rt_reserve_tls_index0") | 63 | #pragma comment(linker, "/INCLUDE:gta6rt_reserve_tls_index0") |
| 64 | 64 | ||
| 65 | // Select the settings used to display the offline first-run UI. Keep explicit caller settings. | ||
| 66 | bool configure_first_run_ui(const std::filesystem::path& package, std::filesystem::path& overlay) { | ||
| 67 | const auto set_default = [](const wchar_t* name, const wchar_t* value) { | ||
| 68 | return GetEnvironmentVariableW(name, nullptr, 0) != 0 || _wputenv_s(name, value) == 0; | ||
| 69 | }; | ||
| 70 | const struct { const wchar_t* name; const wchar_t* value; } settings[] = { | ||
| 71 | {L"LEONIDA_D3D12", L"vulkan"}, {L"LEONIDA_ARENA_MB", L"2048"}, | ||
| 72 | {L"LEONIDA_GRAPHICS_STAGE_LAYOUT", L"1"}, {L"LEONIDA_PIPELINE_COMPILE", L"on-demand"}, | ||
| 73 | {L"LEONIDA_GPU_LABELS", L"1"}, {L"LEONIDA_FRAME_PACING", L"1"}, | ||
| 74 | {L"LEONIDA_LOCAL_SPEECH", L"1"}, {L"LEONIDA_KEYBOARD_PAD", L"always"}, | ||
| 75 | }; | ||
| 76 | for (const auto& setting : settings) { | ||
| 77 | if (!set_default(setting.name, setting.value)) return false; | ||
| 78 | } | ||
| 79 | std::wstring executable(32768, L'\0'); | ||
| 80 | const DWORD length = GetModuleFileNameW(nullptr, executable.data(), static_cast<DWORD>(executable.size())); | ||
| 81 | if (!length || length >= executable.size()) return false; | ||
| 82 | executable.resize(length); | ||
| 83 | const auto state = std::filesystem::path(executable).parent_path() / L"first-run-ui"; | ||
| 84 | if (overlay.empty()) overlay = state / L"overlay"; | ||
| 85 | if (!GetEnvironmentVariableW(L"LEONIDA_XMEM_BACKING_DIR", nullptr, 0)) { | ||
| 86 | std::error_code error; | ||
| 87 | const auto backing = state / L"xmem"; | ||
| 88 | std::filesystem::create_directories(backing, error); | ||
| 89 | if (error || !set_default(L"LEONIDA_XMEM_BACKING_DIR", backing.c_str())) return false; | ||
| 90 | } | ||
| 91 | return SetCurrentDirectoryW(package.c_str()) != FALSE; | ||
| 92 | } | ||
| 93 | |||
| 65 | int usage() { | 94 | int usage() { |
| 66 | std::fprintf(stderr, | 95 | std::fprintf(stderr, |
| 67 | "usage: gta6rt --dry-run <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace FILE]\n" | 96 | "usage: gta6rt --dry-run <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace FILE]\n" |
| 68 | " gta6rt --init <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE]\n" | 97 | " gta6rt --init <image> [--game-dir DIR] [--overlay DIR] [--mods DIR] [--archetype-lookup RVA[,ARG]] [--view-mode-getter RVA] [--trace-d3d12] [--trace FILE]\n" |
| 98 | " gta6rt --first-run-ui <exe> [--game-dir DIR] [--overlay DIR] [--trace FILE]\n" | ||
| 69 | " 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"); | 99 | " 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"); |
| 70 | return 2; | 100 | return 2; |
| 71 | } | 101 | } |
| @@ -77,7 +107,7 @@ int wmain(int argc, wchar_t** argv) { | |||
| 77 | uint32_t archetype_lookup_rva = 0; // --archetype-lookup RVA[,ARG]: the game's archetype lookup by hash | 107 | uint32_t archetype_lookup_rva = 0; // --archetype-lookup RVA[,ARG]: the game's archetype lookup by hash |
| 78 | int archetype_lookup_arg = 0; | 108 | int archetype_lookup_arg = 0; |
| 79 | uint32_t view_mode_getter_rva = 0; // --view-mode-getter RVA: the game's view mode of a camera context | 109 | uint32_t view_mode_getter_rva = 0; // --view-mode-getter RVA: the game's view mode of a camera context |
| 80 | bool dry_run = false, init = false, run = false, trace_d3d12 = false; | 110 | bool dry_run = false, init = false, run = false, trace_d3d12 = false, first_run_ui = false; |
| 81 | std::vector<std::wstring> game_args; // wide: path::string() throws on a character the code page lacks (RT-84) | 111 | std::vector<std::wstring> game_args; // wide: path::string() throws on a character the code page lacks (RT-84) |
| 82 | std::wstring trace_file; | 112 | std::wstring trace_file; |
| 83 | for (int i = 1; i < argc; ++i) { | 113 | for (int i = 1; i < argc; ++i) { |
| @@ -88,6 +118,7 @@ int wmain(int argc, wchar_t** argv) { | |||
| 88 | } | 118 | } |
| 89 | if (a == L"--dry-run") dry_run = true; | 119 | if (a == L"--dry-run") dry_run = true; |
| 90 | else if (a == L"--init") init = true; | 120 | else if (a == L"--init") init = true; |
| 121 | else if (a == L"--first-run-ui") first_run_ui = true; | ||
| 91 | else if (a == L"--run") run = true; | 122 | else if (a == L"--run") run = true; |
| 92 | else if (a == L"--trace-d3d12") trace_d3d12 = true; | 123 | else if (a == L"--trace-d3d12") trace_d3d12 = true; |
| 93 | else if (a == L"--trace" && i + 1 < argc) trace_file = argv[++i]; | 124 | else if (a == L"--trace" && i + 1 < argc) trace_file = argv[++i]; |
| @@ -114,7 +145,8 @@ int wmain(int argc, wchar_t** argv) { | |||
| 114 | } | 145 | } |
| 115 | if (image.empty()) return usage(); | 146 | if (image.empty()) return usage(); |
| 116 | // Exactly one mode: --dry-run --run would otherwise initialise the modules and call the entry point. | 147 | // Exactly one mode: --dry-run --run would otherwise initialise the modules and call the entry point. |
| 117 | if (dry_run + init + run != 1) return usage(); | 148 | if (dry_run + init + run + first_run_ui != 1) return usage(); |
| 149 | run = run || first_run_ui; | ||
| 118 | // The game runs AVX code from its TLS callbacks on; without AVX that is a bare 0xC000001D (src/host_cpu.h). | 150 | // The game runs AVX code from its TLS callbacks on; without AVX that is a bare 0xC000001D (src/host_cpu.h). |
| 119 | if ((init || run) && !rt::host_cpu::check_skipped()) | 151 | if ((init || run) && !rt::host_cpu::check_skipped()) |
| 120 | if (const auto missing = rt::host_cpu::missing_host_features(); !missing.empty()) { | 152 | if (const auto missing = rt::host_cpu::missing_host_features(); !missing.empty()) { |
| @@ -129,6 +161,11 @@ int wmain(int argc, wchar_t** argv) { | |||
| 129 | std::filesystem::path a = std::filesystem::absolute(p, ec); | 161 | std::filesystem::path a = std::filesystem::absolute(p, ec); |
| 130 | return ec ? p : a; | 162 | return ec ? p : a; |
| 131 | }; | 163 | }; |
| 164 | if (first_run_ui) { | ||
| 165 | image = absolute_or_same(image); | ||
| 166 | if (!mods_dir.empty()) mods_dir = absolute_or_same(mods_dir); | ||
| 167 | if (!trace_file.empty()) trace_file = absolute_or_same(trace_file).wstring(); | ||
| 168 | } | ||
| 132 | game_dir = game_dir.empty() ? absolute_or_same(image).parent_path() : absolute_or_same(game_dir); | 169 | game_dir = game_dir.empty() ? absolute_or_same(image).parent_path() : absolute_or_same(game_dir); |
| 133 | if (!overlay_dir.empty()) overlay_dir = absolute_or_same(overlay_dir); | 170 | if (!overlay_dir.empty()) overlay_dir = absolute_or_same(overlay_dir); |
| 134 | // LEONIDA_SHADERS too: the D3D12 device reads it at the title's first pipeline state, after it may have moved. | 171 | // LEONIDA_SHADERS too: the D3D12 device reads it at the title's first pipeline state, after it may have moved. |
| @@ -145,6 +182,10 @@ int wmain(int argc, wchar_t** argv) { | |||
| 145 | if (!rt::base_reservation::inherited()) | 182 | if (!rt::base_reservation::inherited()) |
| 146 | if (const auto range = rt::base_reservation::needed(image)) return rt::base_reservation::relaunch(*range); | 183 | if (const auto range = rt::base_reservation::needed(image)) return rt::base_reservation::relaunch(*range); |
| 147 | // GAME: paths read under --game-dir; whatever a title writes lands in the overlay, never in the package. | 184 | // GAME: paths read under --game-dir; whatever a title writes lands in the overlay, never in the package. |
| 185 | if (first_run_ui && !configure_first_run_ui(game_dir, overlay_dir)) { | ||
| 186 | std::fprintf(stderr, "cannot initialize the first-run UI paths or graphics settings\n"); | ||
| 187 | return 1; | ||
| 188 | } | ||
| 148 | if (overlay_dir.empty()) overlay_dir = game_dir / "overlay"; | 189 | if (overlay_dir.empty()) overlay_dir = game_dir / "overlay"; |
| 149 | rt::fs::configure(game_dir, overlay_dir); | 190 | rt::fs::configure(game_dir, overlay_dir); |
| 150 | // Mods (docs/modding.md): <folder of gta6rt.exe>\mods unless --mods names another. Loaded and reported here; | 191 | // Mods (docs/modding.md): <folder of gta6rt.exe>\mods unless --mods names another. Loaded and reported here; |
| @@ -178,6 +219,7 @@ int wmain(int argc, wchar_t** argv) { | |||
| 178 | rt::d3d12_trace::set_enabled(trace_d3d12); | 219 | rt::d3d12_trace::set_enabled(trace_d3d12); |
| 179 | // Slot 133 imports the title's pages; xmem commits them on first touch, so they are committed first. | 220 | // Slot 133 imports the title's pages; xmem commits them on first touch, so they are committed first. |
| 180 | rt::d3d12_xs::set_placed_at_va_pages_hook(&rt::xmem::commit_physical_range); | 221 | rt::d3d12_xs::set_placed_at_va_pages_hook(&rt::xmem::commit_physical_range); |
| 222 | rt::d3d12_xs::set_texture_page_provider(&rt::xmem::pin_mapped_data); | ||
| 181 | if (int trace_error = 0; !trace_file.empty() && !rt::startup_trace::open(trace_file.c_str(), &trace_error)) { | 223 | if (int trace_error = 0; !trace_file.empty() && !rt::startup_trace::open(trace_file.c_str(), &trace_error)) { |
| 182 | std::fprintf(stderr, trace_error == EEXIST ? "error: the trace file already exists; --trace only creates a new file\n" | 224 | std::fprintf(stderr, trace_error == EEXIST ? "error: the trace file already exists; --trace only creates a new file\n" |
| 183 | : "error: cannot create the trace file\n"); | 225 | : "error: cannot create the trace file\n"); |