upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/main.cpp')
-rw-r--r--runtime/src/main.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp
index 11da727b8..7d0dbfd88 100644
--- a/runtime/src/main.cpp
+++ b/runtime/src/main.cpp
@@ -30,13 +30,16 @@
30#include "base_reservation.h" 30#include "base_reservation.h"
31#include "code_hooks.h" 31#include "code_hooks.h"
32#include "cpu_emulation.h" 32#include "cpu_emulation.h"
33#include "host_cpu.h"
33#include "mods.h" 34#include "mods.h"
34#include "pe_loader.h" 35#include "pe_loader.h"
35#include "../shims/d3d12_trace.h" 36#include "../shims/d3d12_trace.h"
37#include "../shims/d3d12_xs_device.h"
36#include "../shims/file_system.h" 38#include "../shims/file_system.h"
37#include "../shims/process_shim.h" 39#include "../shims/process_shim.h"
38#include "../shims/shims.h" 40#include "../shims/shims.h"
39#include "../shims/startup_trace.h" 41#include "../shims/startup_trace.h"
42#include "../shims/xmem.h"
40 43
41namespace { 44namespace {
42 45
@@ -112,6 +115,12 @@ int wmain(int argc, wchar_t** argv) {
112 if (image.empty()) return usage(); 115 if (image.empty()) return usage();
113 // Exactly one mode: --dry-run --run would otherwise initialise the modules and call the entry point. 116 // Exactly one mode: --dry-run --run would otherwise initialise the modules and call the entry point.
114 if (dry_run + init + run != 1) return usage(); 117 if (dry_run + init + run != 1) return usage();
118 // 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())
120 if (const auto missing = rt::host_cpu::missing_host_features(); !missing.empty()) {
121 std::fprintf(stderr, "%s\n", rt::host_cpu::message(missing).c_str());
122 return rt::host_cpu::kExitCode;
123 }
115 // The console folders are fixed once, as absolute paths. A bare image name (`gta6rt --run game.exe` from the 124 // The console folders are fixed once, as absolute paths. A bare image name (`gta6rt --run game.exe` from the
116 // game folder) has an empty parent path, which left GAME: with no root; and a relative --game-dir or --overlay 125 // game folder) has an empty parent path, which left GAME: with no root; and a relative --game-dir or --overlay
117 // would follow the title's later SetCurrentDirectory. If absolute() fails the path stays as given. 126 // would follow the title's later SetCurrentDirectory. If absolute() fails the path stays as given.
@@ -122,6 +131,15 @@ int wmain(int argc, wchar_t** argv) {
122 }; 131 };
123 game_dir = game_dir.empty() ? absolute_or_same(image).parent_path() : absolute_or_same(game_dir); 132 game_dir = game_dir.empty() ? absolute_or_same(image).parent_path() : absolute_or_same(game_dir);
124 if (!overlay_dir.empty()) overlay_dir = absolute_or_same(overlay_dir); 133 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.
135 if (const DWORD size = GetEnvironmentVariableW(L"LEONIDA_SHADERS", nullptr, 0)) {
136 std::wstring shaders(size, L'\0');
137 const DWORD n = GetEnvironmentVariableW(L"LEONIDA_SHADERS", shaders.data(), size);
138 if (n && n < size) {
139 shaders.resize(n);
140 SetEnvironmentVariableW(L"LEONIDA_SHADERS", absolute_or_same(shaders).c_str());
141 }
142 }
125 // An image without relocations whose range this process already uses (arm64 Wine on macOS) runs in a new 143 // An image without relocations whose range this process already uses (arm64 Wine on macOS) runs in a new
126 // process that has the range reserved from the start (base_reservation.h); that process does not do this again. 144 // process that has the range reserved from the start (base_reservation.h); that process does not do this again.
127 if (!rt::base_reservation::inherited()) 145 if (!rt::base_reservation::inherited())
@@ -158,6 +176,9 @@ int wmain(int argc, wchar_t** argv) {
158 "this executable (docs/modding.md)\n", leonida::mods::active().size()); 176 "this executable (docs/modding.md)\n", leonida::mods::active().size());
159 } 177 }
160 rt::d3d12_trace::set_enabled(trace_d3d12); 178 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.
180 // MERGE NOTE: main registers rt::xmem::commit_physical_range here for its commit-on-touch xmem. This branch keeps
181 // the run-mapped xmem (pages are committed when allocated), so there is nothing to commit before slot 133.
161 if (int trace_error = 0; !trace_file.empty() && !rt::startup_trace::open(trace_file.c_str(), &trace_error)) { 182 if (int trace_error = 0; !trace_file.empty() && !rt::startup_trace::open(trace_file.c_str(), &trace_error)) {
162 std::fprintf(stderr, trace_error == EEXIST ? "error: the trace file already exists; --trace only creates a new file\n" 183 std::fprintf(stderr, trace_error == EEXIST ? "error: the trace file already exists; --trace only creates a new file\n"
163 : "error: cannot create the trace file\n"); 184 : "error: cannot create the trace file\n");