upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/shims/gameinput.cpp
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 22:09:38 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 22:09:38 -0500
commit5115f0887940595aa0f46fed7fc9db28b64151ff (patch)
tree98b4df97d3b97af290331ea9893587e250c0fac0 /runtime/shims/gameinput.cpp
parentc8f7515e2e6fb2a2a61eb1e986ee8c6fd4431399 (diff)
parentb07b9ecb09b47fa6496f01ad9d8fe87d205bd5d8 (diff)
Merge main into RT-DIRECT-HEAP-COMPUTE (#1064)
main already supplies the directly indexed heaps to compute dispatches (integration #984, the tree this pull request was split from): with_direct_heaps()/compute_user_data() on Dispatch and the ExecuteIndirect dispatch path, RootArgumentLayout::compute_arguments_end (kNoSgpr for a spilled signature), LEONIDA_COMPUTE_DIRECT_HEAPS=0, and the first form of this test (direct dispatch, indirect after a resource-only rebind, the GPU read through the heap). That form stays. What this pull request adds beyond it is carried onto it: the review-round reports, the extra recorded-argument checks, the census tool and its evidence. Conflicts: - runtime/shims/d3d12_com.cpp: main's with_direct_heaps()/compute_user_data() and its one-argument note_direct_heap_indexing(). Carried: compute_user_data() makes the note itself, so an ExecuteIndirect dispatch with no heap bound is reported too (record_dispatch's own call removed), and a heap with no inline dword left is reported once per heap kind ("compute root arguments leave no inline SGPR for the resource/sampler heap"); a spilled signature (main: kNoSgpr) gets one note of its own. Dropped: the PR's GetEnvironmentVariableA switch (main's direct_heaps_enabled) and its "graphics heap-base SGPR is not supplied" notes (main supplies the graphics heaps). - runtime/shims/d3d12_com.h, runtime/shims/d3d12_vulkan_device.cpp: main's (compute_arguments_end and graphics_arguments_end with their comment; compute_arguments_end only when the compute arguments do not spill). - runtime/test/glsl/cs_user_data.comp: main's; its direct-indexing mode (s5 = 0xFFFFFFFC, heap at s9) is this pull request's, byte for byte. - runtime/test/d3d12_compute_test.cpp: the PR's block replaces main's earlier form of it (a superset: adds the bundle dispatch that inherits the parent's heaps, an indirect dispatch with only the sampler heap, signatures ending at s30 and s31, and the LEONIDA_COMPUTE_DIRECT_HEAPS=0 expectations). - docs/d3d12_vulkan.md: main's section 3.4 (the BatchCull s7 and PreSkin s9 evidence), with the PR's census paragraph (tools/compute_heap_layout_census.py, the seven paired layouts, the heap order as a hypothesis) and the no-room and spill reports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/gameinput.cpp')
-rw-r--r--runtime/shims/gameinput.cpp50
1 files changed, 46 insertions, 4 deletions
diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp
index 7650b361f..db685e71f 100644
--- a/runtime/shims/gameinput.cpp
+++ b/runtime/shims/gameinput.cpp
@@ -1895,10 +1895,15 @@ void update_keyboard_pad() {
1895 } 1895 }
1896 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());
1897 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 // Timed presses on the keyboard pad, in seconds since its first update. Each press lasts 300 ms. 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;
1899 struct ScriptedPress { 1903 struct ScriptedPress {
1900 SDL_GamepadButton button; 1904 SDL_GamepadButton button;
1901 double at; 1905 double at;
1906 int right_y = 0;
1902 }; 1907 };
1903 static const std::vector<ScriptedPress> script = [] { 1908 static const std::vector<ScriptedPress> script = [] {
1904 std::vector<ScriptedPress> out; 1909 std::vector<ScriptedPress> out;
@@ -1925,6 +1930,11 @@ void update_keyboard_pad() {
1925 const double seconds = std::strtod(time, &tail); 1930 const double seconds = std::strtod(time, &tail);
1926 if (tail == time || !std::isfinite(seconds) || seconds < 0 || 1931 if (tail == time || !std::isfinite(seconds) || seconds < 0 ||
1927 item.find_first_not_of(whitespace, tail - item.c_str()) != std::string::npos) continue; 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 }
1928 for (const auto& [name, button] : names) { 1938 for (const auto& [name, button] : names) {
1929 if (item.compare(first, sep - first, name) == 0) { 1939 if (item.compare(first, sep - first, name) == 0) {
1930 out.push_back({button, seconds}); 1940 out.push_back({button, seconds});
@@ -1944,8 +1954,13 @@ void update_keyboard_pad() {
1944 bool scripted[SDL_GAMEPAD_BUTTON_COUNT] = {}; 1954 bool scripted[SDL_GAMEPAD_BUTTON_COUNT] = {};
1945 bool named[SDL_GAMEPAD_BUTTON_COUNT] = {}; 1955 bool named[SDL_GAMEPAD_BUTTON_COUNT] = {};
1946 for (const auto& press : script) { 1956 for (const auto& press : script) {
1947 named[press.button] = true; 1957 const bool held = now >= press.at && now < press.at + 0.3;
1948 if (now >= press.at && now < press.at + 0.3) scripted[press.button] = true; 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 }
1949 } 1964 }
1950 for (int button = 0; button < SDL_GAMEPAD_BUTTON_COUNT; ++button) { 1965 for (int button = 0; button < SDL_GAMEPAD_BUTTON_COUNT; ++button) {
1951 if (!named[button]) continue; 1966 if (!named[button]) continue;
@@ -1961,7 +1976,7 @@ void update_keyboard_pad() {
1961 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));
1962 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));
1963 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));
1964 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));
1965 // 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.
1966 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);
1967 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);
@@ -2032,6 +2047,33 @@ void poll_once() {
2032 read_raw(d, &snap); 2047 read_raw(d, &snap);
2033 const bool guide_changed = d->last_snap.guide != snap.guide; 2048 const bool guide_changed = d->last_snap.guide != snap.guide;
2034 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 }
2035 d->last_snap = snap; 2077 d->last_snap = snap;
2036 // 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
2037 // held changes nothing. 2079 // held changes nothing.