fix(hid): the sticks' direction pseudo-buttons (StickLLeft .. StickRDown) #1684
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1684
Loading…
Reference in a new issue
No description provided.
Delete branch "rainy/Longshot:fix/hid-stick-pseudo-buttons"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type: fix · Risk: low · Tested on: Linux (Omarchy, kernel 7.2.15; Intel Core Ultra 7 270K Plus; RTX 4090, driver 615.78.08) · Needs: a run on Windows, any GPU, a controller
TL;DR
On a console, pushing a stick past halfway also counts as a direction button, and programs can read those buttons. Longshot never set them, so anything that reads a stick direction as a button saw nothing. This PR sets them from the stick positions. A new game-free test fails on main and passes here. The full check suite on this branch has the same 40 failures as main, and one more pass. It also ran in the game on Linux.
Breakdown
python -I -B tests/run_all.py --jobs 8, which has the same 40 failures as main and one more pass.Why
A code mod, sloperinaGZ 0.0.8, on snaildev99's mods/module-gaps branch is what showed this. The console's controller service sets the stick direction buttons from the stick axes. libnx names them
HidNpadButton_StickLLeft = BITL(16)toHidNpadButton_StickRDown = BITL(23)innx/include/switch/services/hid.h. Longshot set none of them, so a button combo that uses a stick direction never fires. yuzu sets them past half the travel, inTransformToStickininput_converter.cpp, with the threshold's default 0.5 ininput_poller.cpp. This PR uses the same threshold. The tracker has no issue or PR for stick or npad.How to reproduce
Seen on: Linux (Omarchy, kernel 7.2.15; Intel Core Ultra 7 270K Plus; RTX 4090, driver 615.78.08), any controller. The bits themselves do not depend on the GPU or driver.
Settings and switches: defaults
Steps: read the Npad state's buttons while the right stick is pushed all the way down, from mod code or from the game-free test below run against main.
Expected: bit 23, StickRDown, set.
Actual: bits 16 to 23 are never set.
What changed
npad_statesadds the stick direction bits to the buttons of every state it writes.stick_buttonsinhost/nn_hid.cturns the final stick axes into bits 16 to 23. The threshold is half the travel, 16384, and y is up.npad_statesORs the result intobuttons.tests/test_stick_buttons.pycutsstick_buttonsout of the source withtests/srccut.pyand compiles it. It checks each direction of each stick, the threshold, diagonals, that no bit outside 16 to 23 is set, and thatnpad_statesuses it.Measurements
Nothing to measure. Four comparisons per controller read, with no effect a timing could show.
Flags and settings
None
Testing
Tested:
python -I -B tests/run_all.py --jobs 8on Linux (Omarchy, kernel 7.2.15; Intel Core Ultra 7 270K Plus; RTX 4090, driver 615.78.08). main @2f1c0c9c: 685 passed, 40 failed, 97 skipped. this branch @e670ad6c: 686 passed, 40 failed, 97 skipped, 0 new failures compared by test name. The 40 failures also fail on main. They are:Tests that also fail on main @
2f1c0c9cin this environmenttests/test_bug_report_defaults.pytests/test_bug_report.pytests/test_capture_read_once.pytests/test_crash_groups.pytests/test_crash_record.pytests/test_crt_options.pytests/test_damage_debug_menu.pytests/test_dev_packs.pytests/test_display_startup_failure.pytests/test_dlss_feature_size.pytests/test_failed_compile_keeps_objects.pytests/test_guest_imported.pytests/test_hardware_report.pytests/test_high_fps_fixes.pytests/test_host_guest_writes.pytests/test_hud_layout_row.pytests/test_invalidate_quick.pytests/test_libc_hooks.pytests/test_link_path_comma.pytests/test_linux_preflight.pytests/test_linux_pressure.pytests/test_linux_update.pytests/test_log_open_failure.pytests/test_missing_nup.pytests/test_mods_size_table.pytests/test_pending_guest_import.pytests/test_pipeline_play_cache.pytests/test_prepare_cache_save.pytests/test_present_thread.pytests/test_profiling_mode.pytests/test_psychov35_fsr3_fg.pytests/test_readback_timeout_source.pytests/test_run_all_changed.pytests/test_slow_frames.pytests/test_song_note_cue.pytests/test_switch_table.pytests/test_upscaler_rows.pytests/test_vcore_escape.pytests/test_walk_key.pytests/test_vbytes.py(timed out at 600 s)With the fix's source file reverted to main,
python -I -B tests/test_stick_buttons.pyfails (stick_buttons()is not inhost/nn_hid.c). It passes on this branch. In the game, built from this branch on Linux with an RTX 4090: the sticks move Link and the menus as on main.Not testable by hand: the console case can only be reached by a code mod. The game reads the stick axes, not these bits, so a run of the unmodified game cannot show the fix. The game-free test stands in for it. The in-game run shows that the menus and Link still move as on main.
Not tested: Windows (no build or run there) and other GPUs. The same change also ran in the game on snaildev99's mods/module-gaps branch, where a mod's menu opened with R and the right stick down.
Must be tested:
Risks
What could break: code that reads bits 16 to 23 and expected them to stay 0. The game reads the axes, and a console sets these bits too.
Turning it off: revert the commit
Compatibility: Nothing changes
Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks.
main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here.tests/that reads changed source updated in this PR, not weakened.Tested in game: Linux (Omarchy, kernel 7.2.15), Intel Core Ultra 7 270K Plus, RTX 4090 driver 615.78.08, a build of this branch on v3.0.0-rc.8: the sticks move Link and the menus as on main.
From the code and the evidence this looks ready to merge. There are a few nits and a note on merge order below. Nothing blocks it.
What I checked
TransformToStickwith its default threshold of 0.5, with no hysteresis, the same as yuzu. The bit order 16-19 (L: left, up, right, down) and 20-23 (R) matches libnx'sHidNpadButton_StickLLeft..StickRDown. Horizon's exact threshold isn't documented, and following yuzu is the sensible choice.host/nn_hid.c:1228runs afterread_inputand after the free-camera and flight branches, which zerostick. So the bits follow the axes the game actually gets: no StickL bits while flying, and none while the free camera holds the sticks. The other things that changebuttons(hold toggles,oc_pad_word's note remap, the title and frame-step filters) only touch bits 0-15, so nothing overwrites or clears 16-23. When the pad is not connectedstickis zero, so no bits are set.hos_filter_stick, a radial cut with no rescale whose largest cut is 9830, thenstick_maxinto the samestick. The dead zone can never hide a push past half, and both paths get the same bits. The keyboard's move and camera keys (32767), the mouse as stick and the right-stick invert rows all feed the same final values, so they set the bits the way a pad would. The Walk key tilts the stick to 45% by default, which sets no bit. Walk speed 55-90% sets one, as a real stick at that tilt would. The change is plain integer code, so there's no Windows/Linux difference to worry about. A Windows run is still welcome, but the code itself doesn't need one.Merge order with #1349
tests/test_input_background.py: theblock(hid, "static int flight_jump_shortcut("), read, block(hid, "static void npad_states(")))list. Whichever merges second has a small text conflict. To resolve it, keep both new blocks beforenpad_states, in this order:read, then 1349's"#include <math.h>\nstatic volatile LONG pad_left_raw[2];"andstick_witnessblock, then this PR'sblock(hid, "static uint64_t stick_buttons("), thenblock(hid, "static void npad_states(").host/nn_hid.chunks don't touch each other.npad_states, so with it merged the direction bits fire at half of the scaled travel. That is also how yuzu applies its threshold, so it's the right interaction.Nits (also as line comments)
tests/input_background_test.c:146computes the expected bits with the function under test. Every existing case there passes ±32767 or 0, so this is right. A literal for the non-zero cases would keep this check independent ofstick_buttons.Measurements: none, and none needed. The change adds four comparisons per stick on each controller read, and the default is the console's own behaviour. The evidence is a game-free test that fails on main and passes here, the full suite with no new failures by name (40 failures that also fail on main), and an in-game run on Linux with an RTX 4090.
Testing still missing: Windows with a controller, through XInput and through SDL. It's asked of the Test Farm in the description. It is low value for this code.
@ -1211,6 +1225,7 @@ static void npad_states(Ctx *c) {if (connected) buttons = hos_title_input(buttons);uint64_t hos_frame_step_buttons(uint64_t buttons); /* nn_vi.c: the frame step of the wheel and quick menus */if (connected) buttons = hos_frame_step_buttons(buttons);buttons |= stick_buttons(stick);Good placement: after the free-camera and flight branches zero
stick, so the bits follow the axes the game actually gets, and nothing after this line touches bits 16-23.@ -143,6 +143,8 @@ static void packet(uint64_t buttons, int32_t lx, int32_t ly, int32_t rx) {npad_states(&context);CHECK(context.x[0] == 2);expected_sampling++;const int32_t sticks[4] = {lx, ly, rx, 0};Nit: this computes the expected bits with
stick_buttonsitself, so this check can't catch a regression in it (test_stick_buttons.pydoes). Every packet here is 0 or ±32767, so a literal mask for the non-zero cases would keep the check independent. Fine as it is.