fix(pad): report a press that ends before the next pad read #7059

Merged
Aryansh1520 merged 3 commits from upstream-pr/7059 into main 2026-10-19 20:52:24 +00:00
Aryansh1520 commented 2026-10-17 09:32:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-17T09:32:15Z.


What

Report a press that starts and ends between two scePadReadState calls. The pad state is sampled only on read, so a tap shorter than the read interval was never seen by the guest, which made menus miss a press. The press is latched when input is published and folded into the next read. Adds CheckTapBetweenReads to GuestPad.

Tested

Linux (x86-64, gcc, Release): ctest -R guest_pad passes. Hardware: AMD Ryzen 7 260 host, NVIDIA GeForce RTX 5060 Laptop GPU (Wayland). Game check: not run separately for this change alone.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (no AGC, shader recompiler or VideoOut change); game run on NVIDIA GeForce RTX 5060 Laptop GPU, driver 615.78.08, Linux (Wayland)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4898973192 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7059). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-17T09:32:15Z. --- ### What Report a press that starts and ends between two `scePadReadState` calls. The pad state is sampled only on read, so a tap shorter than the read interval was never seen by the guest, which made menus miss a press. The press is latched when input is published and folded into the next read. Adds `CheckTapBetweenReads` to `GuestPad`. ### Tested Linux (x86-64, gcc, Release): `ctest -R guest_pad` passes. Hardware: AMD Ryzen 7 260 host, NVIDIA GeForce RTX 5060 Laptop GPU (Wayland). Game check: not run separately for this change alone. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a (no AGC, shader recompiler or VideoOut change); game run on NVIDIA GeForce RTX 5060 Laptop GPU, driver 615.78.08, Linux (Wayland) - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-17 09:46:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T09:46:15Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6337 core/libs/prx/libScePad/src/PadState.cpp L232

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6044 core/libs/tests/GuestPad.cpp
PR 6879 core/libs/prx/libScePad/src/PadState.cpp
PR 7881 core/libs/prx/libScePad/src/PadState.cpp
core/libs/tests/GuestPad.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6232446506 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7059#issuecomment-6232446506). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T09:46:15Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 6337](https://www.github.com/boykopovar/AnyPS5/pull/6337) | `core/libs/prx/libScePad/src/PadState.cpp` [L232](https://github.com/boykopovar/AnyPS5/blob/9b34cba9efe421d247562d9228404597e41f3eea/core/libs/prx/libScePad/src/PadState.cpp#L232) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestPad.cpp` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libScePad/src/PadState.cpp` | | [PR 7881](https://www.github.com/boykopovar/AnyPS5/pull/7881) | `core/libs/prx/libScePad/src/PadState.cpp`<br>`core/libs/tests/GuestPad.cpp` |
oneandonlydean commented 2026-10-17 10:23:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T10:23:16Z.


Thanks for this. The locking is fine (every access is under stateMutex), and CheckTapBetweenReads covers the cases it names. One fix is needed before merge:

The latch is only cleared by a ReadState, so a stale press can replay later as a phantom press.

  • Initialize clears the queue but not pressedSinceRead (PadState.cpp:105-113), and PadPublishInput doesn't check initialized. A press made before the title initializes the pad is reported on its first read.
  • The latch also keeps a press for as long as the title doesn't call scePadReadState: during a load, while it only reads through scePadRead, or while paused. When it does read, the old press arrives as a fresh one and can confirm a dialog. Main never does this.

Fix: clear the latch in Initialize and when the title reads through scePadRead, and drop latched presses older than about one read interval (or keep a timestamp with the latched bits).

Minor: a latched L2/R2 tap sets the button bit, but analog_buttons_l2/r2 comes from the current state (0), so the bit and the analog value disagree for one read.

Question: do you have hardware evidence that scePadReadState latches short taps on a PS5? Real taps usually last 50-100 ms, longer than a 16 ms read interval, so a missed tap may come from the host publishing press and release in the same input poll. If so, the fix might belong in the publisher instead.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6232773318 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7059#issuecomment-6232773318). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T10:23:16Z. --- Thanks for this. The locking is fine (every access is under `stateMutex`), and `CheckTapBetweenReads` covers the cases it names. One fix is needed before merge: **The latch is only cleared by a `ReadState`, so a stale press can replay later as a phantom press.** - `Initialize` clears the queue but not `pressedSinceRead` (`PadState.cpp:105-113`), and `PadPublishInput` doesn't check `initialized`. A press made before the title initializes the pad is reported on its first read. - The latch also keeps a press for as long as the title doesn't call `scePadReadState`: during a load, while it only reads through `scePadRead`, or while paused. When it does read, the old press arrives as a fresh one and can confirm a dialog. Main never does this. Fix: clear the latch in `Initialize` and when the title reads through `scePadRead`, and drop latched presses older than about one read interval (or keep a timestamp with the latched bits). Minor: a latched L2/R2 tap sets the button bit, but `analog_buttons_l2/r2` comes from the current state (0), so the bit and the analog value disagree for one read. Question: do you have hardware evidence that `scePadReadState` latches short taps on a PS5? Real taps usually last 50-100 ms, longer than a 16 ms read interval, so a missed tap may come from the host publishing press and release in the same input poll. If so, the fix might belong in the publisher instead.
Aryansh1520 commented 2026-10-17 10:38:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-17T10:38:23Z.


Thanks for the review. Pushed a follow-up (baf107a58, rebased onto current main):

  • Stale presses: the latch is cleared in Initialize and when the title reads through scePadRead, and a latched press is dropped if ReadState doesn't pick it up within 100 ms (pressedAt timestamp).
  • L2/R2: a latched L2 or R2 press keeps the analog value it was published with, so the bit and the analog value agree.

Question: we don't have hardware evidence that a PS5 pad latches short taps, so I can't confirm this from a console. Your point stands that a short press within one host poll may be better fixed in the publisher. I'd like to keep the reader-side fix (it's what a title can observe) unless you think the publisher fix is needed too. I'm open to changing the approach if you'd rather move it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6232907472 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7059#issuecomment-6232907472). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-17T10:38:23Z. --- Thanks for the review. Pushed a follow-up (baf107a58, rebased onto current main): - **Stale presses:** the latch is cleared in `Initialize` and when the title reads through `scePadRead`, and a latched press is dropped if `ReadState` doesn't pick it up within 100 ms (`pressedAt` timestamp). - **L2/R2:** a latched L2 or R2 press keeps the analog value it was published with, so the bit and the analog value agree. Question: we don't have hardware evidence that a PS5 pad latches short taps, so I can't confirm this from a console. Your point stands that a short press within one host poll may be better fixed in the publisher. I'd like to keep the reader-side fix (it's what a title can observe) unless you think the publisher fix is needed too. I'm open to changing the approach if you'd rather move it.
oneandonlydean commented 2026-10-17 14:58:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T14:58:56Z.


Thanks @Aryansh1520. We re-reviewed baf107a58: the earlier points are fixed. Initialize and scePadRead now clear the latch, ReadState expires it after kLatchExpiry, and a latched L2/R2 press keeps its analog value.

There's one small issue left from the same phantom-press class. PadPublishInput keeps a single pressedAt for every latched bit and refreshes it on each new press. If a title doesn't call scePadReadState for a while (a load screen, say) and the player presses X at t=0 and O at t=900 ms, a read at t=950 ms reports both X and O, although X is 950 ms old. The expiry only holds when no other press follows, and mashing through a load screen is exactly that pattern.

A one-line fix in PadPublishInput, before OR-ing in the new bits:

if (pressedSinceRead != 0 && timestamp - pressedAt > kLatchExpiry) pressedSinceRead = 0;

(Per-bit timestamps would work too.)

Could you also add tests for the new behaviour to GuestPad.cpp? They're all CPU-only and short:

  • a press, then scePadRead, then scePadReadState doesn't report it;
  • a press, a ~150 ms sleep, then scePadReadState doesn't report it;
  • press A, sleep ~150 ms, press and release B, then one read reports B only.

Once that's on a new head we'll run full CI and re-review.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235406311 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7059#issuecomment-6235406311). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T14:58:56Z. --- Thanks @Aryansh1520. We re-reviewed baf107a58: the earlier points are fixed. `Initialize` and `scePadRead` now clear the latch, `ReadState` expires it after `kLatchExpiry`, and a latched L2/R2 press keeps its analog value. There's one small issue left from the same phantom-press class. `PadPublishInput` keeps a single `pressedAt` for every latched bit and refreshes it on each new press. If a title doesn't call `scePadReadState` for a while (a load screen, say) and the player presses X at t=0 and O at t=900 ms, a read at t=950 ms reports **both** X and O, although X is 950 ms old. The expiry only holds when no other press follows, and mashing through a load screen is exactly that pattern. A one-line fix in `PadPublishInput`, before OR-ing in the new bits: ```cpp if (pressedSinceRead != 0 && timestamp - pressedAt > kLatchExpiry) pressedSinceRead = 0; ``` (Per-bit timestamps would work too.) Could you also add tests for the new behaviour to `GuestPad.cpp`? They're all CPU-only and short: - a press, then `scePadRead`, then `scePadReadState` doesn't report it; - a press, a ~150 ms sleep, then `scePadReadState` doesn't report it; - press A, sleep ~150 ms, press and release B, then one read reports B only. Once that's on a new head we'll run full CI and re-review.
Aryansh1520 commented 2026-10-17 15:00:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-17T15:00:34Z.


Thanks for the detailed review. Pushed baf107a58 on top of current main:

  • Stale presses: the latch is cleared in Initialize and whenever the title reads through scePadRead. A latched press is also dropped if ReadState doesn't pick it up within 100 ms, so it can't show up later as a fresh press.
  • L2/R2: a latched L2 or R2 press keeps the analog value it was published with, so the bit and the analog value agree.

On the publisher question: we don't have hardware evidence that a PS5 latches short taps, so I'd rather keep the fix on the reader side, where a title can observe it, and not change the publisher without that evidence. If you think the publisher fix is needed anyway, tell me what you'd expect to see and I'll look at it. Otherwise, is this ready to approve?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235422214 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7059#issuecomment-6235422214). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-17T15:00:34Z. --- Thanks for the detailed review. Pushed `baf107a58` on top of current main: - **Stale presses:** the latch is cleared in `Initialize` and whenever the title reads through `scePadRead`. A latched press is also dropped if `ReadState` doesn't pick it up within 100 ms, so it can't show up later as a fresh press. - **L2/R2:** a latched L2 or R2 press keeps the analog value it was published with, so the bit and the analog value agree. On the publisher question: we don't have hardware evidence that a PS5 latches short taps, so I'd rather keep the fix on the reader side, where a title can observe it, and not change the publisher without that evidence. If you think the publisher fix is needed anyway, tell me what you'd expect to see and I'll look at it. Otherwise, is this ready to approve?
Aryansh1520 commented 2026-10-17 15:05:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-17T15:05:25Z.


Thanks for the re-review, and sorry for the delay: my previous reply went up before I had read your 14:58 note.

Pushed f3e05559d on top of baf107a58:

  • Older latched press survives a newer press: PadPublishInput now drops the latch before OR-ing in the new bits when it has expired, using your one-line fix. X at t=0, O at t=900 ms, read at t=950 ms reports O only.
  • Tests added to core/libs/tests/GuestPad.cpp (CheckLatchedPressLifetime), covering your three cases:
    • a press, scePadRead, then scePadReadState does not report it;
    • a press, a ~150 ms sleep, then scePadReadState does not report it;
    • press X, sleep ~150 ms, press and release O, then one read reports O only.

guest_pad_tests builds and passes locally in Release on Linux. I haven't run it against the unfixed commit to confirm the new cases fail there, so that check is still open.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235472877 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7059#issuecomment-6235472877). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-17T15:05:25Z. --- Thanks for the re-review, and sorry for the delay: my previous reply went up before I had read your 14:58 note. Pushed `f3e05559d` on top of `baf107a58`: - **Older latched press survives a newer press:** `PadPublishInput` now drops the latch before OR-ing in the new bits when it has expired, using your one-line fix. X at t=0, O at t=900 ms, read at t=950 ms reports O only. - **Tests added to `core/libs/tests/GuestPad.cpp`** (`CheckLatchedPressLifetime`), covering your three cases: - a press, `scePadRead`, then `scePadReadState` does not report it; - a press, a ~150 ms sleep, then `scePadReadState` does not report it; - press X, sleep ~150 ms, press and release O, then one read reports O only. `guest_pad_tests` builds and passes locally in Release on Linux. I haven't run it against the unfixed commit to confirm the new cases fail there, so that check is still open.
jotitadev commented 2026-10-17 23:33:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-17T23:33:36Z.

Review: COMMENTED


The check the last comment leaves open: each new case run against the code without the fix it covers.

Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, full build.
Head f3e05559d merged onto main 5de7a46e0 (clean merge). Require in GuestPad.cpp aborts without a message, so for the runs below I made it print its line.

  • PR: guest_pad passes, as do the other pad tests (ctest -R pad, 9 tests).
  • Test file only, on main: aborts at the first check of CheckTapBetweenReads (the tap between two reads is not reported).
  • PR with PadState.cpp from 5786a9628 (no clear or expiry): aborts in CheckLatchedPressLifetime at the first case, the press is still reported by scePadReadState after scePadRead.
  • PR with PadState.cpp from baf107a58 (before the last fix): aborts at the last case, the older Cross is reported together with Circle.
  • Non-GPU suite (ctest -E "^agc|gpu|vulkan|video_out"): 697/697, same as main.

So each new case fails without the change it covers.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5560634832 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7059#pullrequestreview-5560634832). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-17T23:33:36Z. **Review:** COMMENTED --- The check the last comment leaves open: each new case run against the code without the fix it covers. Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, `BUILD_TESTING=ON`, full build. Head `f3e05559d` merged onto `main` `5de7a46e0` (clean merge). `Require` in `GuestPad.cpp` aborts without a message, so for the runs below I made it print its line. - PR: `guest_pad` passes, as do the other pad tests (`ctest -R pad`, 9 tests). - Test file only, on `main`: aborts at the first check of `CheckTapBetweenReads` (the tap between two reads is not reported). - PR with `PadState.cpp` from `5786a9628` (no clear or expiry): aborts in `CheckLatchedPressLifetime` at the first case, the press is still reported by `scePadReadState` after `scePadRead`. - PR with `PadState.cpp` from `baf107a58` (before the last fix): aborts at the last case, the older Cross is reported together with Circle. - Non-GPU suite (`ctest -E "^agc|gpu|vulkan|video_out"`): 697/697, same as `main`. So each new case fails without the change it covers. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!7059
No description provided.