GameInput: size PlayStation HID read buffer from HIDP_CAPS #2536
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2546"
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 ivall/xcl. Originally posted by ramon-victor on 2026-11-25T22:34:08Z.
Fixes #2465.
Problem
crates/xcl/src/hle/playstation.rsmatches DualShock 4 controllers over Bluetooth (vid&0002054c, service00001124-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.sysrejects everyReadFilecall whose buffer is smaller thanHIDP_CAPS.InputReportByteLengthwithERROR_INVALID_USER_BUFFER(1784). A DualShock 4 over Bluetooth advertisesInputReportByteLength = 547(input report0x19), soReadFilefails immediately on the first call, causingreader()to close the handle, sleep 1 s, and reconnect in a loop without reading input.Fix
HIDP_CAPS.InputReportByteLengthon the opened HID handle viaHidD_GetPreparsedData,HidP_GetCaps, andHidD_FreePreparsedData(hid.dll,raw-dylib), always freeing preparsed data before returning.ReadFilebuffer dynamically toread_buffer_len(input_report_byte_length(h)), clamping nonzero cap lengths to at least 64 bytes and falling back to 1024 bytes (>= 547) ifHIDP_CAPScannot be queried or reports zero.buf[0]) against zero-length reads so it does not log a stale report ID.known()andparse()untouched so this change stays independent of Bluetooth DualSense report-parsing work (#2081).playstation::read_buffer_testscoveringHidpCapsABI size/offset against Windows SDKhidpi.h, buffer sizing across USB/Bluetooth/fallback lengths, and invalid-handle handling throughhid.dll.Tested
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)..\scripts\test.ps1, NVIDIA GeForce RTX 3070, Windows 11):1425 passed, 0 failed, 46 ignored.cargo build --release -p xcl) and 60 s retail smoke run (see below).Not tested
HIDP_CAPSlayout andHidD_GetPreparsedData/HidP_GetCaps/HidD_FreePreparsedDatasignatures were verified against Windows SDKhidpi.h/hidsdi.h, andhid.dllraw-dylibinvocation was verified onINVALID_HANDLE_VALUE).Regression run
Main (
f087b99):This PR (
20b18f7):AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T22:46:53Z.
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!
Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-25T22:53:21Z.
Full-suite run, since this PR has no test report yet. Tested exact head
20b18f7(on its basee1d84b7).Tested
cargo build --workspace, thenXCL_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.hidp_caps_layout_and_read_buffer_sizing,input_report_byte_length_handles_invalid_handle.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).--skipleaves out tests that fail on maine1d84b7too, not because of this PR. On NVIDIA:heap_window_out_of_memory_falls_back_to_the_switch_form(#1651), the fourgpu::recomp::lower_dxil::tests::*_programs_on_the_gputests,const_and_null_mask_operands_agree_with_hlsl_on_the_gpuandmask_ff0_and_flbit_agree_with_hlsl_on_the_gpu(follow-up on #1651) fail becauserunner::skip_testturns their skips into failures underXCL_REQUIRE_GPU=mesh, andgpu::dxil::fuzz_testsseeds 70, 545, 1019 and 1507 failCreateComputePipelineStatewithE_OUTOFMEMORYon this card (drivers 616.64 and 621.40). On AMD:fuzz_validate_and_gpu_1fails on seed 540 (res[833]0x7 vs CPU 0x6). The AMD run does not setXCL_REQUIRE_GPU.Not tested
AI use
Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-25T23:33:29Z.
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 targetx86_64-pc-windows-gnurun 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_sizingandinput_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.
Imported from ivall/xcl. Originally posted by throny on 2026-11-26T01:10:12Z.
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.
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-26T23:22:53Z.
Tested head
20b18f742afb2f2cfa0670d132cc78329757780d, merge-basee1d84b7d9153f86a97d2ec5d209d196046fc0bea, RTX 3070 (Ampere) driver 616.56, Windows 11, rustc 1.100.0Head
20b18f7(on its merge-basee1d84b7withmain), debug, NVIDIA GeForce RTX 3070 8 GB, native Windows.cargo test -p xcl --lib -- read_buffer_tests playstation --test-threads=1, 3 runs on20b18f7: 4 passed, 0 failed, 0 ignored each time (hidp_caps_layout_and_read_buffer_sizing,input_report_byte_length_handles_invalid_handleand the 2 existing PlayStation tests).read_buffer_testsmodule appended to the merge-basee1d84b7'splaystation.rs: it does not compile, 11 errors, all E0425 (HidpCaps,read_buffer_len,input_report_byte_length,MIN_INPUT_REPORT_LENnot found), so the tests need the PR's code.cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4(thehle::xaudio2tests hang on this machine, onmaintoo; 9 filtered out):20b18f7: 1291 passed, 0 failed, 26 ignorede1d84b7: 1289 passed, 0 failed, 26 ignoredNot tested: retail title. A physical DualShock 4 over Bluetooth (no pad here); this only checks the HIDP_CAPS layout, the buffer sizing and the invalid-handle path.
AI-assisted (Claude Code, Claude Sonnet 5.5 ran the tests; Claude Opus 5.5 checked and posted).
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-27T02:45:03Z.
Independent desktop NVIDIA / Windows 11 verification of PR #2546 at head
20b18f742afb2f2cfa0670d132cc78329757780d(1commit; exact parent & merge-base:e1d84b7d9153f86a97d2ec5d209d196046fc0bea, pre-#2555ancestor ofmain).Environment
7956 MiBreported by D3D12), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200(Developer Mode off)rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC1.9.2609.5,--releaseTargeted release tests & build (
20b18f74)cargo test --release -p xcl --lib hidp_caps_layout_and_read_buffer_sizing -- --nocapture(3 consecutive runs)1 passed; 0 failed; 0 ignored; 1325 filtered out× 3 (0.00s× 3,0skipped)cargo test --release -p xcl --lib input_report_byte_length_handles_invalid_handle -- --nocapture(3 consecutive runs)1 passed; 0 failed; 0 ignored; 1325 filtered out× 3 (0.00s× 3,0skipped)cargo test --release -p xcl --lib hle::playstation::(3 consecutive runs)4 passed; 0 failed; 0 ignored; 1322 filtered out× 3 (0.00s× 3,0skipped)cargo build --release -p xcl1m 07s, exit0,0new warnings)Paired quiet 60 s retail smoke (
title: 29640639)Exact parent & merge-base (
e1d84b7d9153f86a97d2ec5d209d196046fc0bea, cached baseline on the same machine):PR #2546 (
20b18f742afb2f2cfa0670d132cc78329757780d):Runtime log observations (
xcl.log)9221log lines,0[ERROR]/ device-removal / panic lines.19513 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample14005 MB committed by the process; video memory 6115 MB local, 4683 MB non-local.Limits of coverage
HIDP_CAPSstruct layout,read_buffer_lensizing, and invalid-handleHidD_GetPreparsedDatasafety were verified via both new unit tests (3/3each) andhle::playstation::(4/4× 3), and the 60 s retail smoke confirms clean build and runtime non-regression on Windows 11.AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by throny on 2026-11-28T03:01:31Z.
merge-check claim
head:
20b18f742aImported from ivall/xcl. Originally posted by throny on 2026-11-28T03:16:10Z.
merge-check
base:
753e8b1ahead:
20b18f742amerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1514 passed, 0 failed, 47 ignored (no PlayStation controller attached here, so the device path did not run) (26 SKIPPED lines); base alone: 1512 passed, 0 failed, 47 ignored
review: none. The capability struct's size and the status constant are right; the buffer is the larger of the device's report length and 64 bytes, at most 65535, and 1024 if the query fails; the read is bounded by the buffer and the parser checks the report's length and id, so short and long reports are safe. For the maintainer: triage marked #2525 as a duplicate (still open).
performance: one heap buffer per controller thread; not a hot path.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-28T12:05:33Z.
merge-check claim
head:
20b18f742aImported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-28T13:39:12Z.
merge-check
base:
e429936c10head:
20b18f742amerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4, run at the same time as 2 other PRs' suites in one queued job: the lib unit-test target (unittests src\lib.rs) exited with STATUS_ACCESS_VIOLATION (0xc0000005) partway, during the vfs tests, after this PR's two new tests had passed; the other 38 targets -> 131 passed, 3 failed, 20 ignored. The lib target rerun alone through the queue on the same merge commit (cargo test -p xcl --lib --no-fail-fast -- --test-threads=4) -> 1997 passed, 6 failed, 28 ignored, 24 SKIPPED, no crash. Together: 2128 passed, 9 failed, 48 ignored (the base's 2126 passed plus this PR's 2 new tests); failing: the 9 tests that fail on the base
e429936ctoo (its suite, run alone on this PC with the same command: 2126 passed, 9 failed, 48 ignored, 25 SKIPPED, these same 9): 6 lib GPU tests (gpu::dxil::module::split dispatch_chain_oversized_loop_matches_whole / dispatch_chain_wave32_live_loops / dispatch_chain_wave64_live_loops_and_exchange, gpu_heap_flat_reads_match_guarded_and_root_output, gpu_compute_mode_dispatch_abi, gpu_float_cas_uses_ieee_equality) and 3 e2e tests (test_title_runs_and_game_folder_is_untouched, test_title_draws_with_a_root_signature_under_the_debug_layer, test_title_runs_under_the_debug_layer_with_dred); not caused by this PR. The access violation did not recur alone and was not traced.review: none. Whole diff read (playstation.rs: the HID read buffer is sized from HIDP_CAPS.InputReportByteLength (at least 64), 1024 when the caps cannot be read, instead of a fixed 128 bytes; the "report this does not read" log reads the id only when bytes came; HIDP_CAPS declared (64 bytes, InputReportByteLength at +4, as in hidpi.h), hid.dll linked; 2 tests). A Bluetooth controller with 547-byte reports no longer fails ReadFile.
performance: no runtime cost of note (one caps query and one allocation per opened controller).
verdict: safe to merge
hardware / tool and model: Windows 11 build 26300.9974, NVIDIA GeForce RTX 2070 SUPER 8 GB (driver 621.40, wave32 only), AMD Ryzen 5 3600XT; rustc 1.100.1 (20ddd0171 2026-11-25) x86_64-pc-windows-msvc, debug test profile; trial merge 10136a7b6791b81d90898ff7a4dca8aa2150b1e1 (local, not pushed). Claude Code: Claude Opus 5.5 (coordination, full-diff review, draft).
correction (2026-11-28): the base counts above were first given as 2128 passed: that base run reused this PC's merge test binary (one cargo target dir for both sides). The base was rerun with its own target dir; the same 9 tests fail on it, so the classification and the verdict stand.
Imported from ivall/xcl. Originally posted by Grimkaaah on 2026-11-30T12:05:18Z.
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, SDL's PS4/PS5 HIDAPI drivers and Linux hid-playstation.
What I checked, all fine:
HidpCapsis 64 bytes,InputReportByteLengthis at +4, andHIDP_STATUS_SUCCESSis 0x00110000 (hidpi.h). The preparsed data is freed on every path.caps.InputReportByteLengthand reads exactly that. We read with max(caps length, 78), or 1024 when the caps are unknown, so your 1024 fallback matches ours.InputReportByteLength. That is why SDL's PS5 driver accepts the Bluetooth 0x01 report at 10 or 78 bytes. So a DS4's 10-byte 0x01 report arrives as 547 bytes, andparseonly needs 10 or more.One gap, not a bug in this diff: with this PR ReadFile succeeds, but a DualShock 4 over Bluetooth gives input only while it sends the basic 0x01 report. After anything reads its calibration feature report (Steam Input's PlayStation support, DS4Windows, an SDL game), it sends 0x11 until it reconnects.
parsedrops 0x11 (playstation.rs:198,r[0] != 0x01), so the log says "sent a report this does not read (id 0x11, 547 bytes)" once and the pad stays silent. #2081 parses 0x11. Landing both closes #2465 fully. Otherwise #2465 is fixed only for pads still in basic mode.Duplicate: #2525 fixes the same thing. This PR is the more complete one, for two reasons:
buf[0]on a 0-byte read.#2525's one advantage is that it uses the windows-sys
HidD_*/HidP_GetCaps/HIDP_CAPSbindings instead of a hand-declared struct and araw-dylibblock. Switching to those here is optional.Not checked: we haven't run this PR, on a pad or otherwise. No DS4 over Bluetooth was read with it.
AI use: Claude Code (Claude Opus 5.5) reviewed this by comparing it with the same mechanism in my project, Victory Grimkaaah.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:20:43Z.
Triage (#1607) – head
20b18f7#2525 fixes the same problem in the same way: both size the
playstation.rsReadFile buffer fromHidP_GetCaps(...).InputReportByteLength. #2525 uses thewindows-sysHID bindings and falls back to 128 bytes. This PR declaresHIDP_CAPSand the hid imports by hand (raw-dylib), with a 64-byte minimum and a 1024-byte fallback. No problems found in the diff: the hand-writtenHIDP_CAPSlayout (64 bytes,InputReportByteLengthat offset 4) matches the SDK. Only one of the two should be merged.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.