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

Open
VlREX wants to merge 1 commit from upstream-pr/2715 into main
VlREX commented 2026-11-25 18:41:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by VlREX on 2026-11-25T18:41:42Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6611271485 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2715). Originally posted by [VlREX](https://github.com/VlREX) on 2026-11-25T18:41:42Z. --- 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).
kotekompotek commented 2026-11-25 19:06:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T18:51:39Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171502097 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2715#issuecomment-7171502097). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T18:51:39Z. --- 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.
oni-swr commented 2026-11-25 20:06:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T19:41:08Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7172631770 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2715#issuecomment-7172631770). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T19:41:08Z. --- 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).
fuzeofficlal commented 2026-11-25 20:06:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T19:43:53Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7172691547 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2715#issuecomment-7172691547). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T19:43:53Z. --- 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.
Marvisak commented 2026-11-26 00:03:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:18:12Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177381823 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2715#issuecomment-7177381823). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:18:12Z. --- <!-- 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)_
Dukestar69 commented 2026-11-26 06:02:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T05:11:05Z.

Review: APPROVED


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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6068859807 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2715#pullrequestreview-6068859807). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T05:11:05Z. **Review:** APPROVED --- 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).
futurepro62 commented 2026-11-26 13:04:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T12:24:19Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7191957909 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2715#issuecomment-7191957909). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T12:24:19Z. --- 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.
fuzeofficlal commented 2026-11-26 14:01:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T13:24:49Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6074901922 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2715#pullrequestreview-6074901922). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T13:24:49Z. **Review:** COMMENTED --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2715:upstream-pr/2715'
git switch 'upstream-pr/2715'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2715'
git switch 'upstream-pr/2715'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2715'
git switch 'upstream-pr/2715'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2715'
git switch 'main'
git merge --squash 'upstream-pr/2715'
git switch 'main'
git merge --ff-only 'upstream-pr/2715'
git switch 'main'
git merge 'upstream-pr/2715'
git push origin 'main'
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
Marvisak/VIctory!2713
No description provided.