GameInput: a tap between two current-state reads is not lost (input at low frame rates) #2230
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2230
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2230"
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?
@desplmfao on GitHub · 2026-11-25 08:24 UTC · original
desplmfao:fix/input-latch→main· +453 −23 · 1 files · 5 commits · openProblem
At the frame rates Grand Theft Auto VI runs at today (one frame every 300 ms or more), a short key or button press is usually lost. You have to mash a key until it registers.
GTA VI reads the pad and keyboard with
GetCurrentReadingonce per frame (confirmed with the diagnostics log below:GetCurrentReading,GetNextReading,IGameInputReading::GetGamepadState/GetKeyState). VIctory polls the host every 8 ms and hands out the newest reading. A tap that goes down and comes back up between two of the title's reads is never seen. Keeping more history (#2218) doesn't help a title that only asks for the current state.Change
Presses are latched per device slot: host pads, the keyboard, and the keyboard stand-in pad.
GetCurrentReadinghands that device out.GetPreviousReadingof the latched reading returns the state before the press, so an edge check sees the press too.GetCurrentReadingin the last 2 s. A title that only walks the history is unaffected, and nothing can stay held for good.VICTORY_INPUT_LATCH=1turns it on; it is off by default, since it departs from what the realGetCurrentReadingreturns.Diagnostics builds log, once each, which GameInput functions the title calls. They also log every tap the latch kept for a read, meaning a press that was released before the read and would have been missed without the latch.
Measured
Grand Theft Auto VI (Series X 1.0.2.1) in the world, RTX 5080, Linux/Proton, about 306 ms per frame. I tapped keys for about 40 s, and the latch kept 39 taps for the title's reads that it would otherwise have missed: W ×9, J ×8, L ×5, Space ×5, K ×3, E ×3, three pad-button taps through the stand-in pad, and others. Each line in the log looks like
a key tap kept for the title's read (released before it) virtual_key=87.Risks
GetCurrentReading) shows a tap only to the first read after it. No read sees a tap twice.Tested
cargo test -p victory-hle gameinput(Windows x64, under Proton here): 15 passed, of which 6 are new:a_tap_between_current_reads_is_pressed_in_one_read_and_released_in_the_nexta_held_button_stays_pressed_and_its_release_is_not_delayedsticks_and_triggers_stay_the_latest_valuea_host_pad_tap_is_latched_tooa_key_tap_between_current_reads_is_latched_on_the_keyboardwithout_current_reads_or_with_the_latch_off_the_history_is_as_recordedcargo clippy -p victory-hle --all-targets -- -D warnings, with and without--features diagnostics: clean.AI-assisted (Claude Code).
🤖 Generated with Claude Code
@desplmfao on GitHub · 2026-11-25 08:25 UTC · original
A note on intent: this isn't console behaviour. On hardware,
GetCurrentReadingreturns the device's state at that moment, and at 30/60 fps a tap isn't lost anyway. The latch only makes up for the low frame rates VIctory runs at today. If exact parity with the console API is preferred, I'm fine with flipping the default to off (one line,VICTORY_INPUT_LATCH=1to opt in), or with leaving this out. The two side effects are listed under Risks above.@Dathinel on GitHub · 2026-11-25 08:37 UTC · original
One concrete tradeoff for the default-on decision: different buttons tapped in sequence can be reported as a chord. I checked
84da49aon Windows with a synthetic connected pad, an active current-state reader, and four host polls between reads: A only → released → B only → released.With the latch enabled, the next GetCurrentReading returned A+B, and an immediate second read returned neither. With it disabled both reads returned neither. The same sequence with Q and E on the keyboard produced the same distinction. No host poll contained both inputs. This matters to consumers that interpret simultaneous buttons as a separate command; whether the title does so is untested. I'd mention this alongside the existing repeated-tap caveat. AI-assisted synthetic validation.
@desplmfao on GitHub · 2026-11-25 08:40 UTC · original
@Dathinel good catch, thanks for checking it. You're right: presses from separate polls are OR'd together, so A-then-B between two reads arrives as the chord A+B. I'll change the latch to keep presses in order instead: each current-state read takes the oldest held press (together with whatever is really down at that moment), and the next press goes to the next read. A then B then reads as A, then B. The second one comes a read later, but it's never a chord that wasn't pressed. Presses that really were down together in one poll stay together. I'll add your sequence (pad A→B and keyboard Q→E) as tests.
@desplmfao on GitHub · 2026-11-25 08:49 UTC · original
@Dathinel fixed in
d3d9cd1. The latch keeps presses in order now. Each entry is the buttons or keys that went down in one host poll; a current-state read takes the oldest, and the next press goes to the next read. Your sequence (A, release, B, release between two reads) now reads A, then B alone, then nothing. Buttons that went down in the same poll still arrive together. New tests:taps_in_sequence_are_not_reported_as_a_chord(pad A→B, plus the same-poll chord case) andkey_taps_in_sequence_are_not_reported_together(keyboard Q→E).cargo test -p victory-hle gameinputgives 17 passed under Proton here, and clippy is clean with and without--features diagnostics.@Dathinel on GitHub · 2026-11-25 08:51 UTC · original
Confirmed on native Windows/MSVC at
d3d9cd1. I reran the same synthetic probe that failed on84da49a. With both taps released before the reader polls, the pad now returns A, B, then empty, and the keyboard returns Q, E, then empty. Inputs pressed together in one host poll still arrive together in the first read on both devices. All 17 cases selected by the gameinput::tests filter passed, including the independent probe. That resolves my reported sequence. Thanks for the fix! AI-assisted verification.@desplmfao on GitHub · 2026-11-25 08:58 UTC · original
@catminou4 thanks. On the HISTORY overlap: I merged the two branches to check, and #2218 and #2230 merge with no conflict. The result keeps
HISTORY = 256; #2230 doesn't touch the constant (details on #2218). Dathinel has also run the latch tests and their own probe on native Windows/MSVC atd3d9cd1, all passing.@Marvisak on GitHub · 2026-11-25 13:31 UTC · original · edited 2026-11-26 01:25 UTC
Automated triage for the maintainers.
Merge candidate (re-checked on
7288f45). The new head mergesmaininto the opt-in version (f66f86d) and merges cleanly. The resolution incrates/victory-hle/src/modules/gameinput.rskeepsmain's #1430 change:State::seen_inputand the all-zero-pad filter inState::poll. The latch sits on top of it, unchanged. Presses are held per slot until aGetCurrentReadinghands them out, only while that device had a current read in the last 2 s, and only withVICTORY_INPUT_LATCH=1(latch_enabled/latch_asked). Without the variable,GetCurrentReadingbehaves as onmain.On the suggestion to turn it on by default: that departs from the real API and is the maintainer's call. This PR doesn't need it to merge.
CI: passing (
check).Generated by Claude Code
@desplmfao on GitHub · 2026-11-25 13:45 UTC · original
Following the triage, the latch is opt-in as of
f66f86d.VICTORY_INPUT_LATCH=1turns it on, and without itGetCurrentReadingbehaves exactly as onmain. The behaviour with the latch on is unchanged, including the in-order fix Dathinel confirmed atd3d9cd1.the_latch_is_off_unless_asked_for, checks that only1enables it.cargo test -p victory-hle --lib gameinputgives 18 passed under Proton, and clippy is clean with and without--features diagnostics. The PR description says opt-in now.@desplmfao on GitHub · 2026-11-25 13:45 UTC · original
A recommendation for the maintainer's decision, nothing more: we'd suggest considering it on by default (
VICTORY_INPUT_LATCH=0to turn it off) once you're comfortable with the departure from the real API.Why: at today's frame rates (one frame every 200 to 1,000 ms in the world), a tap shorter than a frame is lost without the latch, so menus and prompts feel unresponsive or miss presses. The measured effect is in the PR description. With the latch, every press arrives, at most one read later. Most people who'd benefit won't know the variable exists.
Why it doesn't break anything: it differs from how the console handles input, but not from what a title sees on the console. At its normal 30 to 60 fps, an Xbox reads often enough that these taps are never lost, so the latch only restores that at low frame rates. #2218's 256-entry history is the same kind of change (more history than the console needs, for the same reason), and it's already a merge candidate.
The PR stays opt-in as it is now, so merging it doesn't depend on this.
@catminou4 on GitHub · 2026-11-25 08:48 UTC · original · reviewed
GameInput: presses latched only on devices whose current state was read within 2 ms; diagnostics call tracing. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Substantial rework (+363); overlaps #2218 on HISTORY — see note there.
@fuzeofficlal on GitHub · 2026-11-26 17:01 UTC · original · requested changes
Verified
7288f452241717df7803c5b51bc7547efb44b1f1merged cleanly onto63bcca43on Windows 11 (cargo xtask policy:191 files ok;cargo clippy --locked -p victory-hle --all-targets -- -D warningsclean with default and--all-features;cargo test --locked -p victory-hle --lib gameinput:::19/19passed in both default and--features diagnosticsbuilds).Blocking issue: consecutive presses of the same button/key stick held across N reads and delay release (
crates/victory-hle/src/modules/gameinput.rs:423-437)When
Latchwas switched to aVecDequeto preventA -> Bfrom merging into a chord,Latch::hold(gameinput.rs:423-437) began pushing every rising edge unconditionally, even when the exact same button mask or key set is already at the back of the queue:When a user taps the same button/key multiple times during a slow frame (e.g., mashing
AorQ4 times between twoGetCurrentReadingcalls),buttonsbecomes[A, A, A, A](up toLATCH_QUEUE = 16). On eachGetCurrentReading,Latch::seen(gameinput.rs:473-497) pops oneA, sees the nextAat the front, computesapply(raw) == A == recorded, and records no release — leaving the button stuck down with the exact same reading/sequence for 4 consecutive frames (up to 16 frames if mashed).It also delays the release of a held button after an earlier tap in the same frame: if the user taps
A, releasesA, then presses and holdsAbefore read 1 (which seesA), and then releasesAbefore read 2, read 2 still seesApressed because the second queuedAhas not been popped yet.Reproduced directly with a synthetic probe on
7288f452:Atap ([A, 0] * 4) between read 0 and read 1 -> reads 1..5 return[(0x4, ts=153), (0x4, ts=153), (0x4, ts=153), (0x4, ts=153), (0x0, ts=184)](stuck pressed on the same reading for 4 consecutive reads).Qtap ([Q, empty] * 4) -> reads 1..5 return[[81], [81], [81], [81], []].A-> releaseA-> press & holdA-> read 1 (0x4) -> releaseA-> read 2 returns0x4(release delayed until read 30x0).This breaks both stated invariants ("Two taps between reads become one press" and "A release of a press the title has already seen is recorded at once") and can falsely trigger hold-button actions when mashing a key at low frame rates.
Suggested fix
Skip pushing consecutive duplicate entries onto the latch queues in
Latch::hold(gameinput.rs:424andgameinput.rs:435):if pressed != 0 && self.buttons.back() != Some(&pressed) && self.buttons.len() < LATCH_QUEUEself.keys.back()does not already hold the exact same key set (bysame_keyand length) before pushingpressed.Verified locally with that change on
7288f452: all 19 existinggameinput::tests plus the new probes pass (20/20) — 4x mashedAorQproduces one press then immediate release, tap-then-hold releases immediately on read 2, and alternatingA -> B -> Astill deliversA,B,A,0in order.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.