GameInput: size PlayStation HID reads for the collection #2515

Closed
loyodea wants to merge 1 commit from upstream-pr/2525 into main
loyodea commented 2026-11-25 21:35:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by loyodea on 2026-11-25T21:35:14Z.


Fixes #2465. XCL used a fixed 128-byte buffer for Windows HID reads. A DualShock 4 Bluetooth HID collection can advertise a 547-byte maximum. Size the read buffer from the collection capabilities and keep the previous fallback when the capability is unavailable.

What is in it

  • playstation.rs queries the existing HID handle, releases the preparsed data, and uses the advertised input report length. A synthetic regression covers Bluetooth, USB, fallback sizing, and parsing.
  • Cargo.toml enables the required bindings in the existing windows-sys dependency. The README describes the input behavior.

Tested

  • Windows 11 Pro build 26300, Ryzen 7 5700X3D, RX 9060 XT driver 32.0.32029.2010, Rust 1.100.0 GNU x64, DXC 1.9.2609.5, debug.
  • cargo +stable-x86_64-pc-windows-gnu test -j 4 -p xcl --lib hle::playstation::tests: 3 passed, 0 failed, 0 ignored. The regression failed before the fix with a 128-byte buffer where it expected 547 bytes.
  • Workspace build passed. cargo +stable-x86_64-pc-windows-gnu test -j 4 --workspace --no-fail-fast -- --test-threads=4: 1,420 passed, 4 failed, 46 ignored. The four GPU failures also appeared on an independent checkout of the same base and earlier clean upstream. Eight SKIPPED notices covered six unsupported per-lane paths, driver-cache measurement without Developer Mode, and the opt-in heap-window path.
  • Verified all three HID imports in the built executable. The synthetic end-to-end title passed.

Regression run

Paired real-title smoke runs are pending. This draft remains blocked on those runs.

Not tested

Physical DualShock 4 Bluetooth, retail titles, MSVC, release, and other GPU vendors.

AI use

OpenAI Codex with GPT-6.2 Sol (extra-high reasoning for the implementation and final checks) updated the code and regression and ran the tests.

<!-- greyfinch-sync:ivall/xcl:issue:5499563857 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2525). Originally posted by [loyodea](https://github.com/loyodea) on 2026-11-25T21:35:14Z. --- Fixes #2465. XCL used a fixed 128-byte buffer for Windows HID reads. A DualShock 4 Bluetooth HID collection can advertise a 547-byte maximum. Size the read buffer from the collection capabilities and keep the previous fallback when the capability is unavailable. **What is in it** - `playstation.rs` queries the existing HID handle, releases the preparsed data, and uses the advertised input report length. A synthetic regression covers Bluetooth, USB, fallback sizing, and parsing. - `Cargo.toml` enables the required bindings in the existing `windows-sys` dependency. The README describes the input behavior. **Tested** - Windows 11 Pro build 26300, Ryzen 7 5700X3D, RX 9060 XT driver 32.0.32029.2010, Rust 1.100.0 GNU x64, DXC 1.9.2609.5, debug. - `cargo +stable-x86_64-pc-windows-gnu test -j 4 -p xcl --lib hle::playstation::tests`: 3 passed, 0 failed, 0 ignored. The regression failed before the fix with a 128-byte buffer where it expected 547 bytes. - Workspace build passed. `cargo +stable-x86_64-pc-windows-gnu test -j 4 --workspace --no-fail-fast -- --test-threads=4`: 1,420 passed, 4 failed, 46 ignored. The four GPU failures also appeared on an independent checkout of the same base and earlier clean upstream. Eight SKIPPED notices covered six unsupported per-lane paths, driver-cache measurement without Developer Mode, and the opt-in heap-window path. - Verified all three HID imports in the built executable. The synthetic end-to-end title passed. **Regression run** Paired real-title smoke runs are pending. This draft remains blocked on those runs. **Not tested** Physical DualShock 4 Bluetooth, retail titles, MSVC, release, and other GPU vendors. **AI use** OpenAI Codex with GPT-6.2 Sol (extra-high reasoning for the implementation and final checks) updated the code and regression and ran the tests.
DavidM1911 commented 2026-11-25 22:06:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T21:54:08Z.


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:7175685033 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2525#issuecomment-7175685033). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T21:54:08Z. --- 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!
xpatfussy69x commented 2026-11-25 23:09:07 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by xpatfussy69x on 2026-11-25T22:21:46Z.


Test run on exact head 09dda60 (09dda60869b741c6193277fe7f5d7dc4ab12d428, on its base 6d12f58), clean tree.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (driver 32.0.16.2124, 32-lane waves only), AMD Ryzen 5 7500F, Windows 11, Rust 1.100.0; debug build for the tests, release for the smoke runs
  • cargo test --workspace -- --test-threads=4: 1424 passed, 0 failed, 46 ignored
  • SKIPPED (25): 21 × no wave64; 1 × no heap windows; 3 × per-lane form refused V_MUL_F16 / V_PK_MUL_F16 / V_CVT_F16_F32 (on main too)
  • cargo test -p xcl --lib read_buffer_matches_the_hid: 1 passed, 0 failed
  • This PR's new tests in the workspace run:
    • read_buffer_matches_the_hid_collection_input_report_length: ok

Regression run (60 s, default settings, a retail title)

main:

xcl-smoke v1
commit: e1d84b7d9153f86a97d2ec5d209d196046fc0bea
gpu: NVIDIA GeForce RTX 3060
title: c3f791f3
seconds: 60
exit: 0x0
frames shown: 1091 (PresentX 1091)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14814 MB

this PR:

xcl-smoke v1
commit: 09dda60869b741c6193277fe7f5d7dc4ab12d428
gpu: NVIDIA GeForce RTX 3060
title: c3f791f3
seconds: 60
exit: 0x0
frames shown: 1098 (PresentX 1098)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14790 MB

No crash or device removal; frames 101 % of main's, peak commit 100 %.

Not tested

  • No PlayStation controller was connected (the smoke run has no controller input), so the HID read path did not run: a regression check only
  • The PR merged into current main (tested on its own base; it merges into e1d84b7 without conflicts)
  • AMD / native wave64

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and both smoke runs on the machine above and wrote this report.
<!-- greyfinch-sync:ivall/xcl:comment:7176267425 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2525#issuecomment-7176267425). Originally posted by [xpatfussy69x](https://github.com/xpatfussy69x) on 2026-11-25T22:21:46Z. --- Test run on exact head `09dda60` (`09dda60869b741c6193277fe7f5d7dc4ab12d428`, on its base `6d12f58`), clean tree. **Tested** - NVIDIA GeForce RTX 3060 12 GB (driver 32.0.16.2124, 32-lane waves only), AMD Ryzen 5 7500F, Windows 11, Rust 1.100.0; debug build for the tests, release for the smoke runs - `cargo test --workspace -- --test-threads=4`: 1424 passed, 0 failed, 46 ignored - SKIPPED (25): 21 × no wave64; 1 × no heap windows; 3 × per-lane form refused `V_MUL_F16` / `V_PK_MUL_F16` / `V_CVT_F16_F32` (on `main` too) - `cargo test -p xcl --lib read_buffer_matches_the_hid`: 1 passed, 0 failed - This PR's new tests in the workspace run: - `read_buffer_matches_the_hid_collection_input_report_length`: ok **Regression run** (60 s, default settings, a retail title) main: ``` xcl-smoke v1 commit: e1d84b7d9153f86a97d2ec5d209d196046fc0bea gpu: NVIDIA GeForce RTX 3060 title: c3f791f3 seconds: 60 exit: 0x0 frames shown: 1091 (PresentX 1091) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14814 MB ``` this PR: ``` xcl-smoke v1 commit: 09dda60869b741c6193277fe7f5d7dc4ab12d428 gpu: NVIDIA GeForce RTX 3060 title: c3f791f3 seconds: 60 exit: 0x0 frames shown: 1098 (PresentX 1098) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14790 MB ``` No crash or device removal; frames 101 % of `main`'s, peak commit 100 %. **Not tested** - No PlayStation controller was connected (the smoke run has no controller input), so the HID read path did not run: a regression check only - The PR merged into current `main` (tested on its own base; it merges into `e1d84b7` without conflicts) - AMD / native wave64 **AI use** - Claude Code (Claude Opus 5.5) ran the tests and both smoke runs on the machine above and wrote this report.
SlopTart commented 2026-11-25 23:09:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-25T22:49:55Z.


Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).

gpu_ suite (cold cache): 164 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR.
Targeted run of read_buffer_matches_the_hid_collection_input_report_length: passed. GameInput, CPU-side, fine under the Wine lane. Note the test drives the size computation from the HID report descriptor, not a real pad, so it verifies the parsing path rather than device input.

Not tested: retail titles (no title data on this lane, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7176837910 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2525#issuecomment-7176837910). Originally posted by [SlopTart](https://github.com/SlopTart) on 2026-11-25T22:49:55Z. --- **Tested**: current PR head merged onto current `origin/main` (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target `x86_64-pc-windows-gnu` run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29). `gpu_` suite (cold cache): 164 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR. Targeted run of `read_buffer_matches_the_hid_collection_input_report_length`: passed. GameInput, CPU-side, fine under the Wine lane. Note the test drives the size computation from the HID report descriptor, not a real pad, so it verifies the parsing path rather than device input. **Not tested**: retail titles (no title data on this lane, counts only). **AI use**: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.
throny commented 2026-11-26 01:05:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-26T00:58:36Z.


Two contributors checked independently and found that #2546 solves the same problem (for #2465) in a different way: #1607, group D120. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

<!-- greyfinch-sync:ivall/xcl:comment:7179300805 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2525#issuecomment-7179300805). Originally posted by [throny](https://github.com/throny) on 2026-11-26T00:58:36Z. --- <!-- xcl-1607-hint:D120 --> Two contributors checked independently and found that #2546 solves the same problem (for #2465) in a different way: #1607, group D120. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint from the community triage in #1607, not a maintainer decision. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
loyodea commented 2026-11-26 18:53:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by loyodea on 2026-11-26T18:53:30Z.


Thanks for flagging #2546. Both patches query HIDP_CAPS.InputReportByteLength on the open HID handle, so one patch can address #2465. This PR uses the existing windows-sys bindings and tests the 547-byte buffer and standard 0x01 report with synthetic data. #2546 adds a 1,024-byte fallback when the capabilities query fails. Thanks also for the Windows and Wine test reports. The sizing test passed on both, and physical DualShock 4 Bluetooth verification remains open.

<!-- greyfinch-sync:ivall/xcl:comment:7200965049 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2525#issuecomment-7200965049). Originally posted by [loyodea](https://github.com/loyodea) on 2026-11-26T18:53:30Z. --- Thanks for flagging #2546. Both patches query `HIDP_CAPS.InputReportByteLength` on the open HID handle, so one patch can address #2465. This PR uses the existing `windows-sys` bindings and tests the 547-byte buffer and standard `0x01` report with synthetic data. #2546 adds a 1,024-byte fallback when the capabilities query fails. Thanks also for the Windows and Wine test reports. The sizing test passed on both, and physical DualShock 4 Bluetooth verification remains open.
Grimkaaah commented 2026-11-30 12:05:19 +00:00 (Migrated from github.com)

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


I compared this with the same HID read path in my project, which reads DualSense, DualSense Edge and DualShock 4 over USB and Bluetooth with ReadFile. I also checked it against hidapi's Windows backend and SDL's PS4/PS5 HIDAPI drivers.

What I checked, all fine:

  • The caps are read on the handle that is read, so the size is that collection's. The preparsed data is freed on every path. The windows-sys bindings avoid hand-written FFI.
  • Reading exactly InputReportByteLength is what hidapi does. Windows pads each report to that length, so a DS4's 0x01 report over Bluetooth arrives as 547 bytes, and parse only needs 10 or more.
  • 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. playstation.rs:121: when the caps can't be read, the buffer falls back to 128 bytes. That is the size #2465 is about: 128 < 547, and ReadFile fails with ERROR_INVALID_USER_BUFFER on a DS4 over Bluetooth. On that path the PR changes nothing. Fix: fall back to 1024 bytes (at least 547, the largest Sony Bluetooth input report), as #2546 and our code do. Then change the assertion at playstation.rs:210.
  2. Duplicate of #2546. #2546 already has the 1024 fallback and guards buf[0] on a 0-byte read (here playstation.rs:149 still logs buf[0] when n == 0). I'd keep one: #2546 as it is, or this one with finding 1 fixed.

Note for #2465, beyond this diff: once a DS4 over Bluetooth has been switched to its full report 0x11, parse drops it (playstation.rs:166), and the pad gives no input. Steam Input, DS4Windows or an SDL game switch it by reading the calibration report. #2081 reads 0x11.

Not checked: we haven't run this PR, on a pad or otherwise.

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:7277927588 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2525#issuecomment-7277927588). Originally posted by [Grimkaaah](https://github.com/Grimkaaah) on 2026-11-30T12:05:19Z. --- I compared this with the same HID read path in my project, which reads DualSense, DualSense Edge and DualShock 4 over USB and Bluetooth with ReadFile. I also checked it against hidapi's Windows backend and SDL's PS4/PS5 HIDAPI drivers. What I checked, all fine: - The caps are read on the handle that is read, so the size is that collection's. The preparsed data is freed on every path. The windows-sys bindings avoid hand-written FFI. - Reading exactly `InputReportByteLength` is what hidapi does. Windows pads each report to that length, so a DS4's 0x01 report over Bluetooth arrives as 547 bytes, and `parse` only needs 10 or more. - 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. playstation.rs:121: when the caps can't be read, the buffer falls back to 128 bytes. That is the size #2465 is about: 128 < 547, and ReadFile fails with ERROR_INVALID_USER_BUFFER on a DS4 over Bluetooth. On that path the PR changes nothing. Fix: fall back to 1024 bytes (at least 547, the largest Sony Bluetooth input report), as #2546 and our code do. Then change the assertion at playstation.rs:210. 2. Duplicate of #2546. #2546 already has the 1024 fallback and guards `buf[0]` on a 0-byte read (here playstation.rs:149 still logs `buf[0]` when `n == 0`). I'd keep one: #2546 as it is, or this one with finding 1 fixed. Note for #2465, beyond this diff: once a DS4 over Bluetooth has been switched to its full report 0x11, `parse` drops it (playstation.rs:166), and the pad gives no input. Steam Input, DS4Windows or an SDL game switch it by reading the calibration report. #2081 reads 0x11. Not checked: we haven't run this PR, on a pad or otherwise. 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 08:16:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:16:42Z.


Triage (#1607) – head 09dda60

#2546 makes the same change in playstation.rs read_until_gone. Both size the ReadFile buffer from HidD_GetPreparsedData + HidP_GetCaps InputReportByteLength in place of [0u8; 128]. This PR binds them through a new Win32_Devices_HumanInterfaceDevice windows-sys feature, and #2546 through raw-dylib as other modules on main do.
If the caps query fails, report_buffer(0) here falls back to 128 bytes, which is the size that fails for a Bluetooth DualShock 4 (547). #2546 falls back to 1024.
#2546 has a green Build and test check. This PR has no build run yet.
Recommendation: close (duplicate of #2546).

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:7305105937 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2525#issuecomment-7305105937). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T08:16:42Z. --- **Triage (#1607)** – head 09dda60 #2546 makes the same change in `playstation.rs` `read_until_gone`. Both size the `ReadFile` buffer from `HidD_GetPreparsedData` + `HidP_GetCaps` `InputReportByteLength` in place of `[0u8; 128]`. This PR binds them through a new `Win32_Devices_HumanInterfaceDevice` windows-sys feature, and #2546 through `raw-dylib` as other modules on main do. If the caps query fails, `report_buffer(0)` here falls back to 128 bytes, which is the size that fails for a Bluetooth DualShock 4 (547). #2546 falls back to 1024. #2546 has a green `Build and test` check. This PR has no build run yet. Recommendation: close (duplicate of #2546). AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
throny commented 2026-12-01 15:58:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-01T15:58:57Z.


Closing as superseded: the same change is in #2546 (open, mergeable, required checks green). From Foniass's rechecked close list on #1607, checked again by script just now. If something here is still missing, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:ivall/xcl:comment:7316838247 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2525#issuecomment-7316838247). Originally posted by [throny](https://github.com/throny) on 2026-12-01T15:58:57Z. --- Closing as superseded: the same change is in #2546 (open, mergeable, required checks green). From Foniass's rechecked close list on #1607, checked again by script just now. If something here is still missing, say so and reopen it, or ask and I will. AI use: Claude Code (Claude Opus 5.5).

Pull request closed

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!2515
No description provided.