fix(libSceMouse): sum consecutive motion into the newest unread report #9982
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9982"
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?
Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-23T02:11:18Z.
What
High on Life (PPSA15388) reads the mouse through
sceMouseRead. At its in-game frame rates (2–9 FPS here), the view follows the mouse 2–4 s late. It keeps turning after the hand stops, and new movement is ignored for 1–2 s until the backlog drains.Cause:
Mouse::Publishenqueues oneMouseDataper host motion event, into the 64-entry queue. The title callssceMouseRead(handle, data, 8)once per frame. A gaming mouse sends hundreds of reports a second, so between two frames the queue fills, andenqueuedrops the oldest entry for every new one. The title therefore always reads the eight oldest reports still queued, about eight frames behind. Local logging of one session onmain(not part of this PR): 83 reads found the queue full at 64 entries, and 3,862 of 8,179 motion reports were dropped.Fix: when a report carries motion only (no button change, wheel, tilt or connection change) and the newest unread entry is also motion only with the same buttons and connection state,
Publishadds the deltas to that entry, saturating at theint32limits, and moves its timestamp forward. Every other report starts an entry as before. The queue then grows only when the state changes, and the title reads current motion. Total motion is unchanged. Per-report granularity is not reproduced, and that is noted under Functional indocs/dev/debt/libSceMouse.md.Tested
Linux (CachyOS), GCC 16.2.1, Release. Written and tested in game on
main895f47f4e, then rebased ontomainb7a451d62, wheremouse_inputand both convention checks were rerun.mouse_input(tests/Mouse.cpp), new cases:INT32_MAXreports saturate instead of wrapping;35ee90267, from review).3bfc1c11d, from review).The earlier case that expected 70 motion reports to keep the newest 64 now expects one summed entry.
Negative check: with
mouse_impl.cpprestored tomain,mouse_inputaborts.The 47 tests matching
mouse|pad|keyboard|video_outpass.video_out_hdr_presentfailed once in the parallel run and passes on its own; this change does not touch it.tools/check_conventions.pyandtools/check_test_registration.pypass.PPSA15388 in Blim City, mouse look while panning and stopping, with the same local logging:
main895f47f4eBoth runs come from the same session on the same machine, the same save and the same spot. Each build had a local commit (not in this PR) that only logs motion events, queue depth at each read, and drops. An earlier session on
mainshowed the same pattern: 106 reads at a full queue and 5,426 reports dropped.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-23T03:19:08Z.
Review: COMMENTED
Checked against main
3875f8c8ffand shadPS4 a6025d3 (src/core/libraries/mouse/sdl_mouse.cpp):int32axes, and everything runs undermouseMutex, asReaddoes. Thanks for the clear A/B numbers.MouseInput::scaledcan emit motion reports with x=y=0 when the guest is presented larger than its source size (scale < 1, e.g. 1080p shown at 4K, wherexrel=1alternates 0,1,0,1). A 0,0 report isn'tmotionOnly(mouse_impl.cpp:28-30), so it gets its own entry and also stops the next report from merging (:39). Simulating the merge logic with 300 such events, the queue still ends full at 64 entries and 32 of 150 units arrive, the same as main. Could zero-delta reports with no state change be dropped or merged too, with a test for that case?Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T04:12:59Z.
Review: CHANGES_REQUESTED
I reviewed exact head
014d9de4b6. Blocking edge case:motionOnlyrequires at least one nonzero axis. When host-to-guest scaling rounds a motion event to(0, 0),mergeMotionrejects it andPublishenqueues it as a separate entry. That zero entry then sits between two otherwise mergeable motion reports, so the next report cannot merge with the earlier tail; repeated scaled events can still fill the 64-entry queue and drop the oldest motion. This defeats the fix for common fractional scale factors.Please handle zero-delta reports that carry no button/wheel/tilt/connection change without consuming a queue slot or breaking adjacent motion coalescing, and add a regression that alternates zero and nonzero scaled deltas (for example
0, 1, 0, 1) while checking the accumulated total and queue depth. Preserve ordering around actual state-change events.Hosted eligibility, conventions, intake, labels and report checks pass; product builds are skipped by policy. The PR reports Linux
mouse_inputand input-family tests plus an in-game A/B. I could not run the local test binary because this workspace has no configured AnyPS5 build. I have not approved this head because the zero-delta path can still reproduce the reported backlog/drop behavior.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T10:17:08Z.
Review: APPROVED
Re-reviewed exact head
3bfc1c11d0af53b202032aa2929be6c59b0a4cf5against currentmainf99d7fece316e31878f0195f8bbc2ad2fbe635e4.The earlier zero-delta blocker is resolved.
Publishnow drops a report with no motion or state change before it can occupy a queue slot, and the new tests cover alternating zero/nonzero scaled motion, accumulated totals, queue depth, ordering across button/wheel changes, and saturation. Connection changes and button resets remain separate entries; the debt entry discloses that per-report granularity is an emulator heuristic.Current-main merge preview is clean. The only current-main change in the PR's paths is the test's consolidation onto
Api.hpp; the merged preview contains the header and removes the duplicate local declarations.git diff --checkandtools/check_conventions.pypass. The author reports the focused Linux test and 47 input-family tests passing on the rebased head; independent Windows reports cover the focused test and its negative control. Hosted product test jobs are skipped, and I did not run a local build or physical-console test.No remaining actionable finding in this review.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T10:29:59Z.
Review: APPROVED
Reviewed — approved
The coalescing of consecutive motion-only reports is correct, it merges cleanly into current
main, the input-family tests pass, and the newmouse_inputcases fail without the production change.What I ran
3bfc1c11d0af53b202032aa2929be6c59b0a4cf5main:f48ef6a076b68c07c6c22bad6f609080a36e10edBUILD_TESTING=ON, in a clean worktree.Results
mainf48ef6a07tests/Mouse.cpp)git diff --checktools/check_conventions.py --base origin/maintools/check_test_registration.pylibsand full tree)mouse_input,video_out_mouse,pad_keyboard_mouseand the other 15 tests matchingmouse|keyboard|pad_mouse_impl.cppfrommain)mouse_inputabortsctest, merged tree
ctest, negative control
Negative control
I restored only
core/libs/prx/libSceMouse/src/mouse_impl.cppfrommain, kept the newtests/Mouse.cpp, rebuiltmouse_testsand ranmouse_input: it aborts. With the PR's file restored it passes again. This matches the author's Linux result and the Windows results posted in the comments.Findings
Blocking
None.
Non-blocking
None.
Notes from reading the code, for the record:
014d9de4bis closed. A report with no motion and no button, wheel, tilt, reset or connection change returns before it reaches the queue (mouse_impl.cpp:122). The test that alternates x = 0 and 1 (tests/Mouse.cpp:118-125) covers it. No motion is lost by dropping these reports, becauseMouseInput::scaledkeeps the fractional remainder inremainderX/remainderY.mergeMotion(mouse_impl.cpp:36-44) only touches the newest unread entry, undermouseMutex, the same lockReadtakes.Readadvancesheadand decrementscount, so the tail can never be an entry the title has already consumed. The initial entry fromOpenhas zero motion, so motion never merges into it. Button, wheel, tilt, reset and connection entries also have zero motion or a non-zero wheel/tilt, so motion never merges across them. The ordering test (tests/Mouse.cpp:137-142) covers this.int64clamp insaturatedSumis correct for theint32axes. The debt entry indocs/dev/debt/libSceMouse.mddiscloses that per-report granularity is an AnyPS5 heuristic and not measured console behaviour, which is the right place for it.Not verified
sceMouseReadwith a fast mouse. As the earlier reviews note, nobody has measured this.