diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-24 20:26:00 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-24 20:26:00 -0500 |
| commit | 154e4ec034902deffa4b89b2cbca9a949f38baec (patch) | |
| tree | 1b2ef5656de42c172291bc6009efa4c510650815 /runtime/shims/gameinput.cpp | |
| parent | eb6a08cd359d98b5777e70d54d0ae8a75879495a (diff) | |
| parent | 8a242efebf823aeb23c72d17c3d666daf0bbd3e2 (diff) | |
Merge the #984 result (main + RT-PROTON-STORY-LOAD) into #939
The base is 8a242efeb, the merge of main and #984. 68 files conflicted; they were resolved in seven groups by
one rule: the same change in two forms keeps the base's form, everything only #939 has is kept, and where the
two solve one problem in two ways the base's is the frame and #939's plugs into it.
A, the Xbox proxy (d3d12_xs_device.cpp/.h, d3d12_xs.cpp, d3d12_xs_pso_stream.cpp/.h, d3d12_xs_alloc_size.h,
d3d12_xs_desc_clean.h, device_proxy_test.cpp, queue_proxy_test.cpp): the base's files with #939's additions
ported in. Device slot 57 asks #939's NativeGraphicsFactory first and falls back to the base's
proxy_create_graphics_pipeline_from_native_code on E_NOTIMPL. Kept from #939: the providers (texture lease,
raw texture view, resource by address, constant view, descriptor mapping, depth-stencil UAV, texture pages),
the title-backed descriptor mirror, slot 13's feature answers, GPU labels on list slots 71/72. Dropped: #939's
duplicates of the boot ladder routes, its fallback window, its slot 133 stand-in.
A2 (xs_proxy_mock_test.cpp): the base's test with #939's slot 70 raw-buffer case; presentation cases follow
#939's rule that a device which ever had a handler has no queue fallback.
B1, the Vulkan device (d3d12_vulkan_device.cpp, d3d12_com.cpp/.h, shader_library.h, queue_families.h,
pipeline_cache_file.h, startup_trace.h): one lazy-pipeline mechanism, the base's; #939's pending_base_compile
and first_use_backend_pipelines dropped, prepare_on_bind and cold_graphics_compile kept. create_texture keeps
the base's signature; #939's deferred backing is folded into the base's placed-memory binder. #939's quad
lists as triangle indices.
B2, the D3D12 tests (d3d12_existing_heap, a8_dimensions, pipeline_cache_seed, title_va, rect_list,
shader_library, loader_tls_index0, draw, compute, xmem_placed, shader_library_corpus): the base's tests where
both carry the same case, #939's cases added (rebound tables, linear texture map, large vertex batch,
executable shaders, default A8 views).
C, the backend (vulkan_replay.h, vulkan_backend.h, vulkan_bindless.h, vulkan_scratch.h, vulkan_present.h,
rect_list_geometry.h, vk_test_device.h, vk_pipeline_check.cpp, vk_store_test.cpp, bindless_sizing_test.cpp,
replay_texture_barrier_test.cpp): the base's prepare_draw and lazy compute, its #1055 release rule and its
rectangle generator; #939's rectangle variants, GPU quad index expansion, 1D/3D and depth-stencil UAVs, the
label fence on the base's submit.
D, memory, services, presentation (xmem.cpp/.h, xg_xs.cpp, xg_xs_test.cpp, title_va_alias.h and its test,
main.cpp, frame_pacer.h, xbox_present.cpp/.h; xgameruntime_offline.cpp for one comment): the base's xmem with
#939's label hooks, file-backed sections and pin_mapped_data; both texture computers in xg_xs.cpp, the base's
answering first; --first-run-ui kept without host speech in its profile.
E, build, tools, docs (runtime/CMakeLists.txt, make_game.py, tools/rdna2spirv.py, tools/shader_disasm.py,
scripts, tests, docs; docs/README.md and tests/test_exe_shaders_stage.py beyond the conflicts): the base's
v_dot4 decode, #281's disassembler form and tests/semantic/test_fspx_dot4_op_sel_disasm.py dropped; the
base's executable-shader step with #939's cache fix; 366 registered tests.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/gameinput.cpp')
| -rw-r--r-- | runtime/shims/gameinput.cpp | 123 |
1 files changed, 116 insertions, 7 deletions
diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp index 402179cde..db685e71f 100644 --- a/runtime/shims/gameinput.cpp +++ b/runtime/shims/gameinput.cpp | |||
| @@ -47,6 +47,7 @@ | |||
| 47 | #include <mutex> | 47 | #include <mutex> |
| 48 | #include <string> | 48 | #include <string> |
| 49 | #include <thread> | 49 | #include <thread> |
| 50 | #include <utility> | ||
| 50 | #include <vector> | 51 | #include <vector> |
| 51 | 52 | ||
| 52 | #include "gameinput.h" | 53 | #include "gameinput.h" |
| @@ -132,10 +133,14 @@ const rt::gameinput::HapticApi& haptics() { return *g_haptic_api.load(); } | |||
| 132 | // ---- configuration ---------------------------------------------------------------------------------------------- | 133 | // ---- configuration ---------------------------------------------------------------------------------------------- |
| 133 | 134 | ||
| 134 | std::string env(const char* name) { | 135 | std::string env(const char* name) { |
| 135 | char buf[64]; | 136 | // Any length: an input script (LEONIDA_INPUT_SCRIPT) is easily longer than a fixed buffer, and a value that did |
| 136 | const DWORD n = GetEnvironmentVariableA(name, buf, sizeof buf); | 137 | // not fit used to read as unset. |
| 137 | if (n == 0 || n >= sizeof buf) return {}; | 138 | const DWORD need = GetEnvironmentVariableA(name, nullptr, 0); // with the terminator |
| 138 | std::string s(buf, n); | 139 | if (need == 0) return {}; |
| 140 | std::string s(need, '\0'); | ||
| 141 | const DWORD n = GetEnvironmentVariableA(name, s.data(), need); | ||
| 142 | if (n == 0 || n >= need) return {}; | ||
| 143 | s.resize(n); | ||
| 139 | for (auto& c : s) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c))); | 144 | for (auto& c : s) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c))); |
| 140 | return s; | 145 | return s; |
| 141 | } | 146 | } |
| @@ -1861,8 +1866,8 @@ void update_keyboard_pad() { | |||
| 1861 | bool down[SDL_GAMEPAD_BUTTON_COUNT] = {}; | 1866 | bool down[SDL_GAMEPAD_BUTTON_COUNT] = {}; |
| 1862 | int lx = 0, ly = 0; | 1867 | int lx = 0, ly = 0; |
| 1863 | bool aim = false, fire = false; | 1868 | bool aim = false, fire = false; |
| 1864 | // Out of focus every button, stick and trigger is released, so a key held while switching windows does not stay | 1869 | // Focus gates physical keyboard and mouse input. Read the cursor afresh on return to avoid a jump. |
| 1865 | // pressed, and the cursor is read afresh on return, so moving it in another window does not swing the stick. | 1870 | // Scripted presses still run while the window is unfocused. |
| 1866 | const bool active = mode == rt::gameinput::KeyboardPadMode::Always || g_has_focus.load()(); | 1871 | const bool active = mode == rt::gameinput::KeyboardPadMode::Always || g_has_focus.load()(); |
| 1867 | if (active) { | 1872 | if (active) { |
| 1868 | const rt::gameinput::KeyDownFn key_down = g_key_down.load(); | 1873 | const rt::gameinput::KeyDownFn key_down = g_key_down.load(); |
| @@ -1890,11 +1895,88 @@ void update_keyboard_pad() { | |||
| 1890 | } | 1895 | } |
| 1891 | clip_cursor(active && g_raw_ready && g_cursor_pos.load() == system_cursor_pos && foreground_is_ours()); | 1896 | clip_cursor(active && g_raw_ready && g_cursor_pos.load() == system_cursor_pos && foreground_is_ours()); |
| 1892 | for (const auto& b : kKeyBindings) SDL_SetJoystickVirtualButton(g_keyboard.js, b.sdl_button, down[b.sdl_button]); | 1897 | for (const auto& b : kKeyBindings) SDL_SetJoystickVirtualButton(g_keyboard.js, b.sdl_button, down[b.sdl_button]); |
| 1898 | // LEONIDA_INPUT_SCRIPT="a@70,a@85,start@120" (with LEONIDA_KEYBOARD_PAD=always): timed presses on the keyboard | ||
| 1899 | // pad, in seconds since the pad's first update, each held 300 ms. For unattended boots: the title's first prompt | ||
| 1900 | // waits for a button with no timeout (docs/re/notes/firstframe.md, step 5). Buttons: a b x y start back lb rb | ||
| 1901 | // up down left right. The rsup and rsdown entries replay the right-stick throws logged below. | ||
| 1902 | int right_y = g_keyboard.right_y; | ||
| 1903 | struct ScriptedPress { | ||
| 1904 | SDL_GamepadButton button; | ||
| 1905 | double at; | ||
| 1906 | int right_y = 0; | ||
| 1907 | }; | ||
| 1908 | static const std::vector<ScriptedPress> script = [] { | ||
| 1909 | std::vector<ScriptedPress> out; | ||
| 1910 | static const std::pair<const char*, SDL_GamepadButton> names[] = { | ||
| 1911 | {"a", SDL_GAMEPAD_BUTTON_SOUTH}, {"b", SDL_GAMEPAD_BUTTON_EAST}, | ||
| 1912 | {"x", SDL_GAMEPAD_BUTTON_WEST}, {"y", SDL_GAMEPAD_BUTTON_NORTH}, | ||
| 1913 | {"start", SDL_GAMEPAD_BUTTON_START}, {"back", SDL_GAMEPAD_BUTTON_BACK}, | ||
| 1914 | {"lb", SDL_GAMEPAD_BUTTON_LEFT_SHOULDER}, {"rb", SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER}, | ||
| 1915 | {"up", SDL_GAMEPAD_BUTTON_DPAD_UP}, {"down", SDL_GAMEPAD_BUTTON_DPAD_DOWN}, | ||
| 1916 | {"left", SDL_GAMEPAD_BUTTON_DPAD_LEFT}, {"right", SDL_GAMEPAD_BUTTON_DPAD_RIGHT}}; | ||
| 1917 | const std::string text = env("LEONIDA_INPUT_SCRIPT"); | ||
| 1918 | if (text.empty()) return out; | ||
| 1919 | constexpr char whitespace[] = " \t\r\n\f\v"; | ||
| 1920 | size_t items = 0; | ||
| 1921 | for (size_t at = 0, end; at <= text.size(); at = end + 1) { | ||
| 1922 | ++items; | ||
| 1923 | end = std::min(text.find(',', at), text.size()); | ||
| 1924 | const std::string item = text.substr(at, end - at); | ||
| 1925 | const size_t first = item.find_first_not_of(whitespace); | ||
| 1926 | const size_t sep = item.find('@'); | ||
| 1927 | if (sep == std::string::npos || first >= sep) continue; | ||
| 1928 | const char* time = item.c_str() + sep + 1; | ||
| 1929 | char* tail; | ||
| 1930 | const double seconds = std::strtod(time, &tail); | ||
| 1931 | if (tail == time || !std::isfinite(seconds) || seconds < 0 || | ||
| 1932 | item.find_first_not_of(whitespace, tail - item.c_str()) != std::string::npos) continue; | ||
| 1933 | if (item.compare(first, sep - first, "rsup") == 0 || item.compare(first, sep - first, "rsdown") == 0) { | ||
| 1934 | const bool up = item.compare(first, sep - first, "rsup") == 0; | ||
| 1935 | out.push_back({SDL_GAMEPAD_BUTTON_INVALID, seconds, up ? -kStickFull : kStickFull}); | ||
| 1936 | continue; | ||
| 1937 | } | ||
| 1938 | for (const auto& [name, button] : names) { | ||
| 1939 | if (item.compare(first, sep - first, name) == 0) { | ||
| 1940 | out.push_back({button, seconds}); | ||
| 1941 | break; | ||
| 1942 | } | ||
| 1943 | } | ||
| 1944 | } | ||
| 1945 | std::fprintf(stderr, "[rt] gameinput: LEONIDA_INPUT_SCRIPT: %zu scripted press(es), %zu rejected\n", | ||
| 1946 | out.size(), items - out.size()); | ||
| 1947 | return out; | ||
| 1948 | }(); | ||
| 1949 | if (!script.empty()) { | ||
| 1950 | static const ULONGLONG origin = GetTickCount64(); | ||
| 1951 | const double now = (GetTickCount64() - origin) / 1000.0; | ||
| 1952 | // One decision per button: a later entry for the same button must not release what an earlier entry holds | ||
| 1953 | // (it did: with several entries only the last one ever reached the title). | ||
| 1954 | bool scripted[SDL_GAMEPAD_BUTTON_COUNT] = {}; | ||
| 1955 | bool named[SDL_GAMEPAD_BUTTON_COUNT] = {}; | ||
| 1956 | for (const auto& press : script) { | ||
| 1957 | const bool held = now >= press.at && now < press.at + 0.3; | ||
| 1958 | if (press.right_y) { | ||
| 1959 | if (held) right_y = press.right_y; | ||
| 1960 | } else { | ||
| 1961 | named[press.button] = true; | ||
| 1962 | scripted[press.button] |= held; | ||
| 1963 | } | ||
| 1964 | } | ||
| 1965 | for (int button = 0; button < SDL_GAMEPAD_BUTTON_COUNT; ++button) { | ||
| 1966 | if (!named[button]) continue; | ||
| 1967 | SDL_SetJoystickVirtualButton(g_keyboard.js, static_cast<SDL_GamepadButton>(button), | ||
| 1968 | scripted[button] || down[button]); | ||
| 1969 | static bool was[SDL_GAMEPAD_BUTTON_COUNT] = {}; | ||
| 1970 | if (scripted[button] && !was[button]) | ||
| 1971 | std::fprintf(stderr, "[rt] gameinput: scripted press of button %d at %.1f s\n", button, now); | ||
| 1972 | was[button] = scripted[button]; | ||
| 1973 | } | ||
| 1974 | } | ||
| 1893 | const int reach = lx && ly ? kStickDiagonal : kStickFull; | 1975 | const int reach = lx && ly ? kStickDiagonal : kStickFull; |
| 1894 | SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFTX, static_cast<Sint16>(lx * reach)); | 1976 | SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFTX, static_cast<Sint16>(lx * reach)); |
| 1895 | SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFTY, static_cast<Sint16>(ly * reach)); | 1977 | SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFTY, static_cast<Sint16>(ly * reach)); |
| 1896 | SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHTX, static_cast<Sint16>(g_keyboard.right_x)); | 1978 | SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHTX, static_cast<Sint16>(g_keyboard.right_x)); |
| 1897 | SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHTY, static_cast<Sint16>(g_keyboard.right_y)); | 1979 | SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHTY, static_cast<Sint16>(right_y)); |
| 1898 | // SDL maps a full-range virtual axis to the trigger, so -32768 is released, 0 half pulled, 32767 full. | 1980 | // SDL maps a full-range virtual axis to the trigger, so -32768 is released, 0 half pulled, 32767 full. |
| 1899 | SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, aim ? 32767 : -32768); | 1981 | SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_LEFT_TRIGGER, aim ? 32767 : -32768); |
| 1900 | SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, fire ? 32767 : -32768); | 1982 | SDL_SetJoystickVirtualAxis(g_keyboard.js, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER, fire ? 32767 : -32768); |
| @@ -1965,6 +2047,33 @@ void poll_once() { | |||
| 1965 | read_raw(d, &snap); | 2047 | read_raw(d, &snap); |
| 1966 | const bool guide_changed = d->last_snap.guide != snap.guide; | 2048 | const bool guide_changed = d->last_snap.guide != snap.guide; |
| 1967 | const bool changed = !(d->last_snap == snap); | 2049 | const bool changed = !(d->last_snap == snap); |
| 2050 | // Every press is logged in LEONIDA_INPUT_SCRIPT's own form (name@seconds), so a session played by hand can | ||
| 2051 | // be replayed unattended: join the logged items with commas. The right stick's vertical throws (what scrolls | ||
| 2052 | // a page) are logged as rsup/rsdown. LEONIDA_INPUT_LOG=0 turns the lines off. | ||
| 2053 | { | ||
| 2054 | static const bool log_presses = env("LEONIDA_INPUT_LOG") != "0"; | ||
| 2055 | static const ULONGLONG log_origin = GetTickCount64(); | ||
| 2056 | if (log_presses) { | ||
| 2057 | static const std::pair<uint32_t, const char*> kNames[] = { | ||
| 2058 | {GameInputGamepadA, "a"}, {GameInputGamepadB, "b"}, | ||
| 2059 | {GameInputGamepadX, "x"}, {GameInputGamepadY, "y"}, | ||
| 2060 | {GameInputGamepadMenu, "start"}, {GameInputGamepadView, "back"}, | ||
| 2061 | {GameInputGamepadLeftShoulder, "lb"}, {GameInputGamepadRightShoulder, "rb"}, | ||
| 2062 | {GameInputGamepadDPadUp, "up"}, {GameInputGamepadDPadDown, "down"}, | ||
| 2063 | {GameInputGamepadDPadLeft, "left"}, {GameInputGamepadDPadRight, "right"}}; | ||
| 2064 | const double at = (GetTickCount64() - log_origin) / 1000.0; | ||
| 2065 | const uint32_t pressed = snap.gamepad.buttons & ~d->last_snap.gamepad.buttons; | ||
| 2066 | for (const auto& n : kNames) | ||
| 2067 | if (pressed & n.first) | ||
| 2068 | std::fprintf(stderr, "[rt] gameinput: press %s@%.1f (%s)\n", n.second, at, d->name.c_str()); | ||
| 2069 | const auto throw_of = [](float y) { return y > 0.6f ? 1 : y < -0.6f ? -1 : 0; }; | ||
| 2070 | const int was = throw_of(d->last_snap.gamepad.rightThumbstickY); | ||
| 2071 | const int is = throw_of(snap.gamepad.rightThumbstickY); | ||
| 2072 | if (is != was && is != 0) | ||
| 2073 | std::fprintf(stderr, "[rt] gameinput: press %s@%.1f (%s)\n", is > 0 ? "rsup" : "rsdown", at, | ||
| 2074 | d->name.c_str()); | ||
| 2075 | } | ||
| 2076 | } | ||
| 1968 | d->last_snap = snap; | 2077 | d->last_snap = snap; |
| 1969 | // A newly opened pad's first sample here is its baseline (active_input.h), so connecting a pad with a button | 2078 | // A newly opened pad's first sample here is its baseline (active_input.h), so connecting a pad with a button |
| 1970 | // held changes nothing. | 2079 | // held changes nothing. |