GameInput: read a DualSense and a DualShock 4's full reports over Bluetooth #2071

Open
sheazywi wants to merge 1 commit from upstream-pr/2081 into main
sheazywi commented 2026-11-25 03:27:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by sheazywi on 2026-11-25T03:27:19Z.


A DualSense over Bluetooth was not read (known() skipped it), and a DualShock 4's full Bluetooth report (0x11) was ignored. This reads them: the simple 0x01 report a DualSense sends over Bluetooth, its full 0x31 report, and the DualShock 4's 0x11. USB behaviour is unchanged.

What is in it

  • crates/xcl/src/hle/playstation.rs: parse picks the layout by pad and report id (shared state decoder); known() no longer excludes a Bluetooth DualSense; new test that the Bluetooth reports read as the same gamepad state as USB, existing tests updated.
  • README.md: DualSense over Bluetooth.

Tested

  • Windows 11 Pro 10.0.26200, RTX 4070 Ti, Rust 1.98.1, debug build
  • cargo build --workspace then cargo test --workspace -- --test-threads=4: all passed, 0 failed (lib: 1099 passed, 26 ignored)
  • SKIPPED: shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (needs Developer Mode), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)

Regression run

  • not done (see Not tested)

Not tested

  • No real DualSense or DualShock 4 over Bluetooth: the report layouts come from a reader I wrote for another project and are checked only by the unit tests with synthetic reports.
  • scripts/smoke.ps1 on main vs this head was not run; the change only touches how a PlayStation pad's HID reports are decoded.
  • AMD GPUs.

AI use

  • Claude Code with Claude Sonnet 5.5 wrote the code, tests and this description; I reviewed the diff.
<!-- greyfinch-sync:ivall/xcl:issue:5484585941 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2081). Originally posted by [sheazywi](https://github.com/sheazywi) on 2026-11-25T03:27:19Z. --- A DualSense over Bluetooth was not read (`known()` skipped it), and a DualShock 4's full Bluetooth report (0x11) was ignored. This reads them: the simple 0x01 report a DualSense sends over Bluetooth, its full 0x31 report, and the DualShock 4's 0x11. USB behaviour is unchanged. **What is in it** - `crates/xcl/src/hle/playstation.rs`: `parse` picks the layout by pad and report id (shared `state` decoder); `known()` no longer excludes a Bluetooth DualSense; new test that the Bluetooth reports read as the same gamepad state as USB, existing tests updated. - `README.md`: DualSense over Bluetooth. **Tested** - Windows 11 Pro 10.0.26200, RTX 4070 Ti, Rust 1.98.1, debug build - `cargo build --workspace` then `cargo test --workspace -- --test-threads=4`: all passed, 0 failed (lib: 1099 passed, 26 ignored) - SKIPPED: `shaders::tests::pso_measurement_compiles_an_exact_synthetic_record` (needs Developer Mode), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows) **Regression run** - not done (see Not tested) **Not tested** - No real DualSense or DualShock 4 over Bluetooth: the report layouts come from a reader I wrote for another project and are checked only by the unit tests with synthetic reports. - `scripts/smoke.ps1` on `main` vs this head was not run; the change only touches how a PlayStation pad's HID reports are decoded. - AMD GPUs. **AI use** - Claude Code with Claude Sonnet 5.5 wrote the code, tests and this description; I reviewed the diff.
DavidM1911 commented 2026-11-25 06:05:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T05:26:51Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7153782872 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2081#issuecomment-7153782872). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T05:26:51Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
github-actions[bot] commented 2026-11-28 20:18:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T20:18:15Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7245187417 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2081#issuecomment-7245187417). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T20:18:15Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Grimkaaah commented 2026-11-30 12:05:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Grimkaaah on 2026-11-30T12:05:21Z.


I compared this with the same parser in my project, which reads DualSense, DualSense Edge and DualShock 4 over USB and Bluetooth, and with Linux hid-playstation and SDL's PS4/PS5 HIDAPI drivers.

What I checked, all fine:

  • The offsets match hid-playstation and SDL:
    • DualSense over USB: 0x01, 64 bytes, data from byte 1.
    • DualSense over Bluetooth: 0x31, 78 bytes, data from byte 2.
    • DualShock 4 over Bluetooth: 0x11, 78 bytes, data from byte 3.
    • The simple 0x01 layout (sticks, three button bytes, L2, R2) is the same on a DS4 and on a DualSense over Bluetooth.
  • The length rule (64 bytes is the full layout, anything else the simple one) matches SDL's PS5 driver, which takes a 0x01 report of 10 or 78 bytes as the simple layout.
  • A DualSense's Bluetooth collection has InputReportByteLength 78, so it reads with today's 128-byte buffer.
  • No output reports are written, so OutputReportByteLength padding and the Bluetooth output CRC32 don't apply yet. Double input is unchanged: the HID pad is used only when XInput has no pad.

Findings:

  1. A DS4's 0x11 report can't be reached on Windows with this PR alone. read_until_gone still reads into 128 bytes (playstation.rs:110). A DS4's Bluetooth collection has InputReportByteLength 547, so ReadFile fails with ERROR_INVALID_USER_BUFFER before parse runs (#2465). Fix: rebase on #2546 (or #2525) and say so in the PR. The read also arrives padded to 547 bytes, so the 0x11 test should use a 547-byte buffer, not 78. GitHub also shows the branch as conflicting with main, so it needs a rebase anyway.

  2. No CRC or data check on the Bluetooth full reports (playstation.rs:136 and :141). Here 12 bytes are enough for a 0x31 and 14 for a 0x11.

    • Linux hid-playstation drops a 0x31 or 0x11 report whose CRC32 fails. The CRC covers seed byte 0xA1, then bytes 0 to 73, and is stored little-endian in bytes 74 to 77.
    • SDL drops a PS5 0x31 with a bad CRC. It takes a PS4 0x11 only when byte 1 bit 7 ("HID data present") is set.

    Fix: require at least 78 bytes, check the CRC over the first 78 bytes only (a DS4's read is padded to 547), and for 0x11 also require r[1] & 0x80. We check the CRC the same way in our project.

  3. Optional: SDL reads a DS4's 0x12 to 0x19 as the same state report as 0x11, with the CRC over the first 78 bytes. Here they are dropped.

Not checked: we haven't run this PR, on a pad or otherwise. I didn't check the DualSense Edge's extra buttons, which stay unmapped as before.

AI use: Claude Code (Claude Opus 5.5) reviewed this by comparing it with the same mechanism in my project, Victory Grimkaaah.

<!-- greyfinch-sync:ivall/xcl:comment:7277928194 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2081#issuecomment-7277928194). Originally posted by [Grimkaaah](https://github.com/Grimkaaah) on 2026-11-30T12:05:21Z. --- I compared this with the same parser in my project, which reads DualSense, DualSense Edge and DualShock 4 over USB and Bluetooth, and with Linux hid-playstation and SDL's PS4/PS5 HIDAPI drivers. What I checked, all fine: - The offsets match hid-playstation and SDL: - DualSense over USB: 0x01, 64 bytes, data from byte 1. - DualSense over Bluetooth: 0x31, 78 bytes, data from byte 2. - DualShock 4 over Bluetooth: 0x11, 78 bytes, data from byte 3. - The simple 0x01 layout (sticks, three button bytes, L2, R2) is the same on a DS4 and on a DualSense over Bluetooth. - The length rule (64 bytes is the full layout, anything else the simple one) matches SDL's PS5 driver, which takes a 0x01 report of 10 or 78 bytes as the simple layout. - A DualSense's Bluetooth collection has `InputReportByteLength` 78, so it reads with today's 128-byte buffer. - No output reports are written, so OutputReportByteLength padding and the Bluetooth output CRC32 don't apply yet. Double input is unchanged: the HID pad is used only when XInput has no pad. Findings: 1. A DS4's 0x11 report can't be reached on Windows with this PR alone. `read_until_gone` still reads into 128 bytes (playstation.rs:110). A DS4's Bluetooth collection has `InputReportByteLength` 547, so ReadFile fails with ERROR_INVALID_USER_BUFFER before `parse` runs (#2465). Fix: rebase on #2546 (or #2525) and say so in the PR. The read also arrives padded to 547 bytes, so the 0x11 test should use a 547-byte buffer, not 78. GitHub also shows the branch as conflicting with main, so it needs a rebase anyway. 2. No CRC or data check on the Bluetooth full reports (playstation.rs:136 and :141). Here 12 bytes are enough for a 0x31 and 14 for a 0x11. - Linux hid-playstation drops a 0x31 or 0x11 report whose CRC32 fails. The CRC covers seed byte 0xA1, then bytes 0 to 73, and is stored little-endian in bytes 74 to 77. - SDL drops a PS5 0x31 with a bad CRC. It takes a PS4 0x11 only when byte 1 bit 7 ("HID data present") is set. Fix: require at least 78 bytes, check the CRC over the first 78 bytes only (a DS4's read is padded to 547), and for 0x11 also require `r[1] & 0x80`. We check the CRC the same way in our project. 3. Optional: SDL reads a DS4's 0x12 to 0x19 as the same state report as 0x11, with the CRC over the first 78 bytes. Here they are dropped. Not checked: we haven't run this PR, on a pad or otherwise. I didn't check the DualSense Edge's extra buttons, which stay unmapped as before. AI use: Claude Code (Claude Opus 5.5) reviewed this by comparing it with the same mechanism in my project, Victory Grimkaaah.
Foniass commented 2026-12-01 07:18:53 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:18:53Z.


Triage (#1607) – head de1798f

No open or merged PR reads the DualSense's Bluetooth reports or the DualShock 4's 0x11 report. #2546 is related but different: it sizes the HID read buffer from HIDP_CAPS, and says a DualShock 4 over Bluetooth needs more than the current 128-byte buffer. If that is true, the 0x11 path added here is never reached until a fix like #2546 lands.
In parse, a DualSense report 0x01 is read as the full USB layout only when it is exactly 64 bytes; any other length is read as the simple layout. This depends on the read returning the device's full report length.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7303906898 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2081#issuecomment-7303906898). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:18:53Z. --- **Triage (#1607)** – head de1798f No open or merged PR reads the DualSense's Bluetooth reports or the DualShock 4's 0x11 report. #2546 is related but different: it sizes the HID read buffer from `HIDP_CAPS`, and says a DualShock 4 over Bluetooth needs more than the current 128-byte buffer. If that is true, the 0x11 path added here is never reached until a fix like #2546 lands. In `parse`, a DualSense report 0x01 is read as the full USB layout only when it is exactly 64 bytes; any other length is read as the simple layout. This depends on the read returning the device's full report length. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2081:upstream-pr/2081'
git switch 'upstream-pr/2081'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2081'
git switch 'upstream-pr/2081'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2081'
git switch 'upstream-pr/2081'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2081'
git switch 'main'
git merge --squash 'upstream-pr/2081'
git switch 'main'
git merge --ff-only 'upstream-pr/2081'
git switch 'main'
git merge 'upstream-pr/2081'
git push origin 'main'
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
xcl-dev/xcl!2071
No description provided.