GameInput: size PlayStation HID read buffer from HIDP_CAPS #2546

Open
github-bot wants to merge 1 commit from github-bot/gh-2546 into main AGit
Owner

@⁠ramon-victor on GitHub · 2026-11-25 22:34 UTC · original
ramon-victor:fix/playstation-hid-read-buffer → main · +88 −2 · 1 files · 1 commits · open

Fixes #2465.

Problem

crates/xcl/src/hle/playstation.rs matches DualShock 4 controllers over Bluetooth (vid&0002054c, service 00001124-0000-1000-8000-00805f9b34fb), opens their HID handle, and reads reports into a hardcoded 128-byte buffer (let mut buf = [0u8; 128];).

On Windows, hidclass.sys rejects every ReadFile call whose buffer is smaller than HIDP_CAPS.InputReportByteLength with ERROR_INVALID_USER_BUFFER (1784). A DualShock 4 over Bluetooth advertises InputReportByteLength = 547 (input report 0x19), so ReadFile fails immediately on the first call, causing reader() to close the handle, sleep 1 s, and reconnect in a loop without reading input.

Fix

  • Query HIDP_CAPS.InputReportByteLength on the opened HID handle via HidD_GetPreparsedData, HidP_GetCaps, and HidD_FreePreparsedData (hid.dll, raw-dylib), always freeing preparsed data before returning.
  • Allocate the ReadFile buffer dynamically to read_buffer_len(input_report_byte_length(h)), clamping nonzero cap lengths to at least 64 bytes and falling back to 1024 bytes (>= 547) if HIDP_CAPS cannot be queried or reports zero.
  • Guard the unreadable-report log (buf[0]) against zero-length reads so it does not log a stale report ID.
  • Leave known() and parse() untouched so this change stays independent of Bluetooth DualSense report-parsing work (#2081).
  • Add unit tests in playstation::read_buffer_tests covering HidpCaps ABI size/offset against Windows SDK hidpi.h, buffer sizing across USB/Bluetooth/fallback lengths, and invalid-handle handling through hid.dll.

Tested

  • Targeted unit tests (cargo test --lib -p xcl playstation): 4 passed, 0 failed (hidp_caps_layout_and_read_buffer_sizing, input_report_byte_length_handles_invalid_handle, plus the 2 existing PlayStation tests).
  • Full workspace (.\scripts\test.ps1, NVIDIA GeForce RTX 3070, Windows 11): 1425 passed, 0 failed, 46 ignored.
  • Release build (cargo build --release -p xcl) and 60 s retail smoke run (see below).

Not tested

  • Live input delivery on a physical DualShock 4 controller connected over Bluetooth (no DualShock 4 hardware is attached on this test machine; HIDP_CAPS layout and HidD_GetPreparsedData/HidP_GetCaps/HidD_FreePreparsedData signatures were verified against Windows SDK hidpi.h/hidsdi.h, and hid.dll raw-dylib invocation was verified on INVALID_HANDLE_VALUE).

Regression run

Main (f087b99):

xcl-smoke v1
commit: f087b998d0d51a9f11bbfa0761967a63e778edd9
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14467 MB

This PR (20b18f7):

xcl-smoke v1
commit: 20b18f742afb2f2cfa0670d132cc78329757780d
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1622 (PresentX 1622)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14003 MB

AI use

  • Antigravity (Gemini 4 Neon): implementation, ABI verification against Windows SDK headers, tests, and PR drafting.
**@⁠ramon-victor** on GitHub · 2026-11-25 22:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/2546) `ramon-victor:fix/playstation-hid-read-buffer` → `main` · +88 −2 · 1 files · 1 commits · open Fixes #2465. **Problem** `crates/xcl/src/hle/playstation.rs` matches DualShock 4 controllers over Bluetooth (`vid&0002054c`, service `00001124-0000-1000-8000-00805f9b34fb`), opens their HID handle, and reads reports into a hardcoded 128-byte buffer (`let mut buf = [0u8; 128];`). On Windows, `hidclass.sys` rejects every `ReadFile` call whose buffer is smaller than `HIDP_CAPS.InputReportByteLength` with `ERROR_INVALID_USER_BUFFER` (1784). A DualShock 4 over Bluetooth advertises `InputReportByteLength = 547` (input report `0x19`), so `ReadFile` fails immediately on the first call, causing `reader()` to close the handle, sleep 1 s, and reconnect in a loop without reading input. **Fix** - Query `HIDP_CAPS.InputReportByteLength` on the opened HID handle via `HidD_GetPreparsedData`, `HidP_GetCaps`, and `HidD_FreePreparsedData` (`hid.dll`, `raw-dylib`), always freeing preparsed data before returning. - Allocate the `ReadFile` buffer dynamically to `read_buffer_len(input_report_byte_length(h))`, clamping nonzero cap lengths to at least 64 bytes and falling back to 1024 bytes (`>= 547`) if `HIDP_CAPS` cannot be queried or reports zero. - Guard the unreadable-report log (`buf[0]`) against zero-length reads so it does not log a stale report ID. - Leave `known()` and `parse()` untouched so this change stays independent of Bluetooth DualSense report-parsing work (#2081). - Add unit tests in `playstation::read_buffer_tests` covering `HidpCaps` ABI size/offset against Windows SDK `hidpi.h`, buffer sizing across USB/Bluetooth/fallback lengths, and invalid-handle handling through `hid.dll`. **Tested** - Targeted unit tests (`cargo test --lib -p xcl playstation`): 4 passed, 0 failed (`hidp_caps_layout_and_read_buffer_sizing`, `input_report_byte_length_handles_invalid_handle`, plus the 2 existing PlayStation tests). - Full workspace (`.\scripts\test.ps1`, NVIDIA GeForce RTX 3070, Windows 11): `1425 passed, 0 failed, 46 ignored`. - Release build (`cargo build --release -p xcl`) and 60 s retail smoke run (see below). **Not tested** - Live input delivery on a physical DualShock 4 controller connected over Bluetooth (no DualShock 4 hardware is attached on this test machine; `HIDP_CAPS` layout and `HidD_GetPreparsedData`/`HidP_GetCaps`/`HidD_FreePreparsedData` signatures were verified against Windows SDK `hidpi.h`/`hidsdi.h`, and `hid.dll` `raw-dylib` invocation was verified on `INVALID_HANDLE_VALUE`). **Regression run** Main (`f087b99`): ``` xcl-smoke v1 commit: f087b998d0d51a9f11bbfa0761967a63e778edd9 gpu: NVIDIA GeForce RTX 3070 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14467 MB ``` This PR (`20b18f7`): ``` xcl-smoke v1 commit: 20b18f742afb2f2cfa0670d132cc78329757780d gpu: NVIDIA GeForce RTX 3070 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1622 (PresentX 1622) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14003 MB ``` **AI use** - Antigravity (Gemini 4 Neon): implementation, ABI verification against Windows SDK headers, tests, and PR drafting.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:33:27 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 22:46 UTC · original

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!

**@⁠DavidM1911** on GitHub · 2026-11-25 22:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/2546#issuecomment-7176779345) 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!
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-25 22:53 UTC · original · edited 2026-11-25 22:57 UTC

Full-suite run, since this PR has no test report yet. Tested exact head 20b18f7 (on its base e1d84b7).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 1413 passed, 0 failed, 44 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, dispatch_chain_native_wave64_builds_whole, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: hidp_caps_layout_and_read_buffer_sizing, input_report_byte_length_handles_invalid_handle.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 1424 passed, 0 failed, 46 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main e1d84b7 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (#1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests, const_and_null_mask_operands_agree_with_hlsl_on_the_gpu and mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-25 22:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/2546#issuecomment-7176903353) · edited 2026-11-25 22:57 UTC Full-suite run, since this PR has no test report yet. Tested exact head `20b18f7` (on its base `e1d84b7`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests`: **1413 passed, 0 failed, 44 ignored**. SKIPPED (no wave64): `a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu`, `a_per_lane_2d_or_3d_group_runs_on_the_gpu`, `coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu`, `cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu`, `dispatch_chain_native_wave64_builds_whole`, `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`, `the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu`. - The new tests ran and passed: `hidp_caps_layout_and_read_buffer_sizing`, `input_report_byte_length_handles_invalid_handle`. - Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1`: **1424 passed, 0 failed, 46 ignored**. SKIPPED: `f16_programs_on_the_gpu` (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), `f16_programs_on_the_gpu` (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), `f16_programs_on_the_gpu` (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), `f16_programs_on_the_gpu` (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), `f32_programs_on_the_gpu` (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), `f32_programs_on_the_gpu` (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - `--skip` leaves out tests that fail on main `e1d84b7` too, not because of this PR. On NVIDIA: `heap_window_out_of_memory_falls_back_to_the_switch_form` (#1651), the four `gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu` tests, `const_and_null_mask_operands_agree_with_hlsl_on_the_gpu` and `mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu` ([follow-up on #1651](https://git.gtahub.st/github/xcl-dev--xcl/issues/1651)) fail because `runner::skip_test` turns their skips into failures under `XCL_REQUIRE_GPU=mesh`, and `gpu::dxil::fuzz_tests` seeds 70, 545, 1019 and 1507 fail `CreateComputePipelineState` with `E_OUTOFMEMORY` on this card (drivers 616.64 and 621.40). On AMD: `fuzz_validate_and_gpu_1` fails on seed 540 (`res[833]` 0x7 vs CPU 0x6). The AMD run does not set `XCL_REQUIRE_GPU`. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠SlopTart on GitHub · 2026-11-25 23:33 UTC · original

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): 165 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 hidp_caps_layout_and_read_buffer_sizing and input_report_byte_length_handles_invalid_handle: 2 passed. No physical pad on this lane; these verify the HID parsing/sizing path, not device I/O.

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.

**@⁠SlopTart** on GitHub · 2026-11-25 23:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/2546#issuecomment-7177728689) **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): 165 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 `hidp_caps_layout_and_read_buffer_sizing` and `input_report_byte_length_handles_invalid_handle`: 2 passed. No physical pad on this lane; these verify the HID parsing/sizing path, not device I/O. **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.
Author
Owner

@⁠throny on GitHub · 2026-11-26 01:10 UTC · original

Two contributors checked independently and found that #2525 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.

**@⁠throny** on GitHub · 2026-11-26 01:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/2546#issuecomment-7179502733) <!-- xcl-1607-hint:D120 --> Two contributors checked independently and found that #2525 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2546/head:github-bot/gh-2546'
git switch 'github-bot/gh-2546'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2546'
git switch 'github-bot/gh-2546'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2546'
git switch 'github-bot/gh-2546'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2546'
git switch 'main'
git merge --squash 'github-bot/gh-2546'
git switch 'main'
git merge --ff-only 'github-bot/gh-2546'
git switch 'main'
git merge 'github-bot/gh-2546'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.