Clear stale button and key state in GameInput output buffers #2715

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

@⁠VlREX on GitHub · 2026-11-25 18:41 UTC · original
VlREX:fix/gameinput-stale-state → main · +46 −11 · 1 files · 1 commits · open

GetGamepadState must return an at-rest state and false for readings without gamepad input. GetKeyState uses a zero scan code and virtual key to mark the end of valid keys when the output has room. Implement both for reused output buffers. Regression tests start with a pressed button/trigger or a nonzero key in the output and cover a full buffer, spare space, and an empty list. Both tests failed before the fix. Nine input tests passed locally using the fake host, excluding the native host and export resolver. References: GetGamepadState and GetKeyState.

**@⁠VlREX** on GitHub · 2026-11-25 18:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2715) `VlREX:fix/gameinput-stale-state` → `main` · +46 −11 · 1 files · 1 commits · open GetGamepadState must return an at-rest state and false for readings without gamepad input. GetKeyState uses a zero scan code and virtual key to mark the end of valid keys when the output has room. Implement both for reused output buffers. Regression tests start with a pressed button/trigger or a nonzero key in the output and cover a full buffer, spare space, and an empty list. Both tests failed before the fix. Nine input tests passed locally using the fake host, excluding the native host and export resolver. References: [GetGamepadState](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getgamepadstate) and [GetKeyState](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinputreading/methods/igameinputreading_getkeystate).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:12:38 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 18:51 UTC · original

Matches the documented contract on both sides: GetKeyState writes a zeroed entry after the last valid key when the buffer has room (the terminator titles scan for), and GetGamepadState returns false but still writes an at-rest state for non-gamepad readings. The reused-buffer regression is the right way to catch stale-state bugs.

**@⁠kotekompotek** on GitHub · 2026-11-25 18:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2715#issuecomment-7171502097) Matches the documented contract on both sides: GetKeyState writes a zeroed entry after the last valid key when the buffer has room (the terminator titles scan for), and GetGamepadState returns false but still writes an at-rest state for non-gamepad readings. The reused-buffer regression is the right way to catch stale-state bugs.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 19:41 UTC · original

Independent WARP/CPU verification

Head: 88d7c75f72e4020536d36d77b85bd65b36918c7c
Base: origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca
Status: open, non-draft; clean merge tree; no oni-swr comment on this head.

Environment: Windows x64, WARP selected (VICTORY_WARP=1, VICTORY_D3D12_WARP=1), dxil.dll 1.8.2502.11 from Windows SDK 10.0.26100.0; rustc 1.98.1.

Commands (each with CARGO_TARGET_DIR=D:\victory-warp-2690-target and the WARP variables above):

  • Baseline and PR: cargo test --locked -p victory-hle
  • PR targeted: cargo test --locked -p victory-hle keyboard_reading_clears_previous_gamepad_state; cargo test --locked -p victory-hle key_state_terminates_a_reused_buffer
  • PR lint: cargo clippy --locked -p victory-hle --all-targets -- -D warnings

Results: baseline 148 passed, 0 failed (146 unit + 2 integration); PR 150 passed, 0 failed (148 unit + 2 integration). Targeted regressions 2/2 passed. Clippy passed.

Negative control: reverted both production handlers; each targeted regression failed (exit 101), as expected. No implementation bug found.

Not tested: physical GPU, retail title, release build. AI-assisted: Codex (gpt-6-luna).

**@⁠oni-swr** on GitHub · 2026-11-25 19:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2715#issuecomment-7172631770) Independent WARP/CPU verification Head: `88d7c75f72e4020536d36d77b85bd65b36918c7c` Base: `origin/main` `13f91caee25f2fdf2c062be5f7a27f058e51cbca` Status: open, non-draft; clean merge tree; no `oni-swr` comment on this head. Environment: Windows x64, WARP selected (`VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`), `dxil.dll` 1.8.2502.11 from Windows SDK 10.0.26100.0; rustc 1.98.1. Commands (each with `CARGO_TARGET_DIR=D:\victory-warp-2690-target` and the WARP variables above): - Baseline and PR: `cargo test --locked -p victory-hle` - PR targeted: `cargo test --locked -p victory-hle keyboard_reading_clears_previous_gamepad_state`; `cargo test --locked -p victory-hle key_state_terminates_a_reused_buffer` - PR lint: `cargo clippy --locked -p victory-hle --all-targets -- -D warnings` Results: baseline 148 passed, 0 failed (146 unit + 2 integration); PR 150 passed, 0 failed (148 unit + 2 integration). Targeted regressions 2/2 passed. Clippy passed. Negative control: reverted both production handlers; each targeted regression failed (exit 101), as expected. No implementation bug found. Not tested: physical GPU, retail title, release build. AI-assisted: Codex (gpt-6-luna).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 19:43 UTC · original

Independent Windows 11 verification and review of 88d7c75 (on 13f91ca, plus combined test with #2717 + #2718):

Verification (rustc 1.98.1 MSVC)

  • cargo xtask policy: 184 files ok.
  • cargo clippy --locked -p victory-hle --all-targets -- -D warnings and --features diagnostics: 0 warnings.
  • cargo test --locked -p victory-hle --lib modules::gameinput: 11 passed, 0 failed; full victory-hle --lib: 148 passed, 0 failed.
  • Combined 3-way merge with #2717 + #2718: clean zero-conflict git merge-tree; --features diagnostics modules::gameinput 13 passed, full victory-hle --lib 150 passed, 0 failed.

Review Notes

  • Null-pointer and count == 0 guards run before any pointer arithmetic, out.add(n) stays strictly inside [0..count) when n < count, and non-keyboard/non-gamepad readings clear out[0] / *out cleanly. (Minor optional note: clearing out[n..count] rather than only the single null terminator out[n] would also clear stale tail entries if a caller scans past the terminator, though writing the terminator at out[n] already matches the documented GameInput contract.) Clean and ready to merge.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 19:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/2715#issuecomment-7172691547) Independent Windows 11 verification and review of `88d7c75` (on `13f91ca`, plus combined test with #2717 + #2718): ### Verification (`rustc 1.98.1` MSVC) - `cargo xtask policy`: **184 files ok**. - `cargo clippy --locked -p victory-hle --all-targets -- -D warnings` and `--features diagnostics`: **0 warnings**. - `cargo test --locked -p victory-hle --lib modules::gameinput`: **11 passed, 0 failed**; full `victory-hle --lib`: **148 passed, 0 failed**. - **Combined 3-way merge with #2717 + #2718:** clean zero-conflict `git merge-tree`; `--features diagnostics` `modules::gameinput` **13 passed**, full `victory-hle --lib` **150 passed, 0 failed**. ### Review Notes - Null-pointer and `count == 0` guards run before any pointer arithmetic, `out.add(n)` stays strictly inside `[0..count)` when `n < count`, and non-keyboard/non-gamepad readings clear `out[0]` / `*out` cleanly. (Minor optional note: clearing `out[n..count]` rather than only the single null terminator `out[n]` would also clear stale tail entries if a caller scans past the terminator, though writing the terminator at `out[n]` already matches the documented GameInput contract.) Clean and ready to merge.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:18 UTC · original

Automated triage for the maintainers.

In crates/victory-hle/src/modules/gameinput.rs, gamepad_state now writes an at-rest PadState and returns false for a keyboard reading, and key_state writes one zeroed KeyState after the last key when the caller's array has room. key_state also returns 0 early for count == 0 and for gamepad readings. The return values are unchanged, so callers that use the returned count behave the same. The PR cites the public reference pages for GetGamepadState and GetKeyState. I could not open them from here, so a maintainer may want to confirm the terminator wording. The writes stay inside [0, count) and both new tests cover reused buffers. CI (check) passes.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 23:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2715#issuecomment-7177381823) <!-- victory-triage v1 head=88d7c75f72e4020536d36d77b85bd65b36918c7c verdict=merge-candidate at=2026-11-25T23:18:02Z --> Automated triage for the maintainers. In `crates/victory-hle/src/modules/gameinput.rs`, `gamepad_state` now writes an at-rest `PadState` and returns false for a keyboard reading, and `key_state` writes one zeroed `KeyState` after the last key when the caller's array has room. `key_state` also returns 0 early for `count == 0` and for gamepad readings. The return values are unchanged, so callers that use the returned count behave the same. The PR cites the public reference pages for GetGamepadState and GetKeyState. I could not open them from here, so a maintainer may want to confirm the terminator wording. The writes stay inside `[0, count)` and both new tests cover reused buffers. CI (`check`) passes. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 05:11 UTC · original · approved these changes

Tested merged onto origin/main (63bcca4) on Windows 11 x64:

  • cargo test -p victory-hle --lib modules::gameinput::: 12 passed, 0 failed (including new keyboard_reading_clears_previous_gamepad_state and key_state_terminates_a_reused_buffer).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 05:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/2715#pullrequestreview-6068859807) · **approved these changes** Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - `cargo test -p victory-hle --lib modules::gameinput::`: **12 passed, 0 failed** (including new `keyboard_reading_clears_previous_gamepad_state` and `key_state_terminates_a_reused_buffer`). - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 12:24 UTC · original

NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, oni-swr, since none of them names a GPU run. Tested exact head 88d7c75 (on its base 13f91ca).

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.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 775 passed, 0 failed, 9 ignored.
  • The new tests ran and passed: keyboard_reading_clears_previous_gamepad_state, key_state_terminates_a_reused_buffer.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (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-26 12:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2715#issuecomment-7191957909) NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, oni-swr, since none of them names a GPU run. Tested exact head `88d7c75` (on its base `13f91ca`). **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.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **775 passed, 0 failed, 9 ignored**. - The new tests ran and passed: `keyboard_reading_clears_previous_gamepad_state`, `key_state_terminates_a_reused_buffer`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (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

@⁠fuzeofficlal on GitHub · 2026-11-26 13:24 UTC · original · reviewed

The gamepad_state change (crates/victory-hle/src/modules/gameinput.rs:1068-1079) matches the documented at-rest output for a reading without the gamepad kind. For key_state (gameinput.rs:1051-1067), writing KeyState::default() at out[n] satisfies callers that consume either out[..returned] or stop at the first zeroed {scanCode: 0, virtualKey: 0} terminator, while the GDK keyboard guide leaves spare tail entries unspecified.

A few polish suggestions:

  • Document in a short comment why only the single terminator slot out[n] is cleared (as opposed to zeroing all of out[n..count]), in case a caller scans the full count skipping zero entries.
  • key_state_terminates_a_reused_buffer uses a 2-slot buffer with 1 key, leaving only 1 spare slot so it doesn't distinguish single-slot termination from full-tail clearing; extending it to >= 3 prefilled slots (plus zero-key, truncated keys.len() > count, count == 0, and null out cases) would lock down the exact contract.
  • rustfmt --edition 2024 --check flags line 1598 in the new test keyboard_reading_clears_previous_gamepad_state (alongside 4 pre-existing lines in gameinput.rs).

Local verification on commit 88d7c75f72e4: xtask policy (184 files ok), cargo clippy -p victory-hle --all-targets (default and --all-features), gameinput:: tests (11 passed), and the full victory-hle suite (148 unit + 2 integration = 150 passed, 0 failed) all pass.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 13:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2715#pullrequestreview-6074901922) · **reviewed** The `gamepad_state` change (`crates/victory-hle/src/modules/gameinput.rs:1068-1079`) matches the documented at-rest output for a reading without the gamepad kind. For `key_state` (`gameinput.rs:1051-1067`), writing `KeyState::default()` at `out[n]` satisfies callers that consume either `out[..returned]` or stop at the first zeroed `{scanCode: 0, virtualKey: 0}` terminator, while the GDK keyboard guide leaves spare tail entries unspecified. A few polish suggestions: - Document in a short comment why only the single terminator slot `out[n]` is cleared (as opposed to zeroing all of `out[n..count]`), in case a caller scans the full `count` skipping zero entries. - `key_state_terminates_a_reused_buffer` uses a 2-slot buffer with 1 key, leaving only 1 spare slot so it doesn't distinguish single-slot termination from full-tail clearing; extending it to >= 3 prefilled slots (plus zero-key, truncated `keys.len() > count`, `count == 0`, and null `out` cases) would lock down the exact contract. - `rustfmt --edition 2024 --check` flags line `1598` in the new test `keyboard_reading_clears_previous_gamepad_state` (alongside 4 pre-existing lines in `gameinput.rs`). Local verification on commit `88d7c75f72e4`: `xtask policy` (`184 files ok`), `cargo clippy -p victory-hle --all-targets` (`default` and `--all-features`), `gameinput::` tests (`11 passed`), and the full `victory-hle` suite (`148 unit + 2 integration = 150 passed, 0 failed`) all pass.
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/2715/head:github-bot/gh-2715'
git switch 'github-bot/gh-2715'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2715'
git switch 'github-bot/gh-2715'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2715'
git switch 'github-bot/gh-2715'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2715'
git switch 'main'
git merge --squash 'github-bot/gh-2715'
git switch 'main'
git merge --ff-only 'github-bot/gh-2715'
git switch 'main'
git merge 'github-bot/gh-2715'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2715
No description provided.