Skip to content

kbm: calculate mouse velocity over real dt to prevent camera whip (#963) - #1066

Open
mahfuzinam0045-spec wants to merge 1 commit into
xcl-dev:mainfrom
mahfuzinam0045-spec:fix/kbm-camera-whip-dt
Open

mahfuzinam0045-spec wants to merge 1 commit into
xcl-dev:mainfrom
mahfuzinam0045-spec:fix/kbm-camera-whip-dt

Conversation

@mahfuzinam0045-spec

@mahfuzinam0045-spec mahfuzinam0045-spec commented Nov 24, 2026 •

Copy link
Copy Markdown

When a title paused polling the gamepad for over 100 ms (such as during loading screens, level transitions, or hitching), mouse counts continued gathering in DX and DY. In Velocity::update, dt was clamped to 0.1 before dividing (dx as f32 / dt), which artificially multiplied the apparent mouse rate by up to 20x. This caused the stick deflection to peg at 100% and violently whip the camera around upon returning to gameplay.

Fixes #963.

What is in it

  • crates/xcl/src/hle/kbm.rs: compute the mouse velocity rate over the real dt (with dt.max(0.001) to avoid division by zero). The smoothing factor (1 - exp(-dt / SMOOTHING)) naturally bounds the exponential decay in [0, 1).
  • crates/xcl/src/hle/kbm.rs: add frame_hitch_does_not_artificially_accelerate_velocity unit test covering 300 ms and 2 s hitch scenarios, asserting that stick deflection remains moderate.

Tested

  • Windows 11 x64, Rust 1.98.1
  • Synthetic unit tests for Velocity::update and stick_from_mouse under 300 ms and 2 s pauses; confirms deflection stays proportional (< 0.5) instead of pegging at 1.0.

Regression run

  • Retail title smoke run was not performed (no game title dump on this system). The change is narrow and confined to keyboard/mouse velocity calculation, verified with unit tests. Awaiting maintainer review / test-only label or community smoke run.

Not tested

  • Physical gamepad or retail title run (the change is purely to keyboard/mouse velocity rate calculation).

AI use

  • Antigravity with Gemini 3.8 Flash investigated the issue, wrote the fix and unit test, and drafted this PR.

…l-dev#963)

When a title paused polling the gamepad for over 100 ms (during loading
screens or frame hitches), mouse counts accumulated over the entire
pause window. In Velocity::update, dt was clamped to 0.1 s before
dividing, which artificially multiplied the apparent mouse rate by up to
20x and caused stick deflection to peg at 100%, violently whipping the
camera.

Compute the velocity rate using the actual elapsed time (with dt.max(0.001)
to prevent division by zero). The exponential smoothing factor
(1 - exp(-dt / SMOOTHING)) naturally decays without overshooting.

Fixes xcl-dev#963.
Assisted-by: Antigravity (Gemini 3.8 Flash)
@futurepro62

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 53cd523 (on its base 67a3735).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 736 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: frame_hitch_does_not_artificially_accelerate_velocity.

Not tested

  • AMD, 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.

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #1059 #1522 solves the same problem (for #963) in a different way: #1607, group D66. 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.

@JJAutoCompare

Copy link
Copy Markdown

PR #1066 empirical test report

The KBM velocity calculation now uses the elapsed frame time for hitches longer than 100 ms. The added regression test checks 300 ms and two-second hitches. Fixes #963.

What is in it

  • crates/xcl/src/hle/kbm.rs updates mouse velocity and adds frame_hitch_does_not_artificially_accelerate_velocity.

Tested

  • PR head 53cd523c3ac1fec39b8aa209b284251987668ffe fetched with git fetch origin main refs/pull/1066/head and checked out detached from the PR entry in FETCH_HEAD. Fetched origin/main was 2bdf0477f84377d1b08e29424100c9bace4e530f. git merge-tree --write-tree origin/main HEAD exited 0 and produced tree 1076aace942dfd209083dd6fbfc1c666ecdf10c3. The same check against the two pinned SHAs produced the same tree.
  • STOR-WINLAB, Intel Arc A770 16 GiB on driver 32.0.101.9175, AMD Ryzen 7 3800X, Windows 11 Enterprise Evaluation build 26200.9974. Adapter wave range 8–32 and DoublePrecisionFloatShaderOps=0. DXC/DXIL 1.9.2609.5 (DXC revision 01b62ad4) from %LOCALAPPDATA%\XclTooling\dxc-1.9.2609\bin\x64. rustc -V returned rustc 1.100.0 (0ef1bc386 2026-11-09).
  • Unoptimized dev/test profiles with CARGO_INCREMENTAL=0, CARGO_PROFILE_DEV_DEBUG=0, CARGO_PROFILE_TEST_DEBUG=0, and XCL_ADAPTER=A770.
  • cargo test --workspace --no-run compiled successfully outside the GPU lock.
  • cargo test -p xcl --lib hle::kbm::tests:: -- --show-output ran outside the GPU lock. 7 passed, 0 failed, 0 ignored, including the new frame-hitch test.
  • & 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { cargo test --workspace --no-fail-fast -- --test-threads=4 --show-output } ran once under the shared GPU lock. Cargo exited 101. Across 18 test binaries and one doctest target, libtest reported 720 passed, 16 failed, 41 ignored. Five of the 720 reported passes emitted SKIPPED and are excluded from coverage. The other 715 reported passes had no SKIPPED marker, including tests gated on sample-data environment variables.
  • Fifteen failures were GPU recompiler tests. The end-to-end title test failed because the title executable and game DLL were absent after cargo test --workspace --no-run. cargo build --workspace succeeded and produced both artifacts. & 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { cargo test -p xcl --test e2e -- test_title_runs_and_game_folder_is_untouched --exact --show-output } reran only that test under the GPU lock. Cargo exited 101 with 0 passed, 1 failed, 0 ignored. The title launched and failed its dynamic depth-bias check. The log also recorded XAudio2 CreateMasteringVoice error 0x80070490.
  • PowerShell initially rejected the lock wrapper before the suite started. The successful wrapper invocation used a process-only execution policy setting. The wrapper logged lock acquisition and release.

GPU skips (5)

SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
SKIPPED placed_title_textures_share_vram_and_preserve_pixels: tiled tier < 2
SKIPPED test_title_draws_with_a_root_signature_under_the_debug_layer: no d3d12SDKLayers.dll
SKIPPED uploads_start_from_each_subresources_state: no D3D12 debug layer (The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D))

Not tested

  • Interactive retail-title mouse input and the paired scripts/smoke.ps1 regression run on main and the PR head.
  • A workspace suite on main, AMD and NVIDIA GPUs, wave64 hardware, and hardware FP64 shader operations.
  • Sample-data paths gated by unset XCL_SAMPLE_* variables, D3D12 debug-layer coverage, and tiled tier 2 coverage.

AI use

  • T3 Code / Codex (gpt-6.2-sol) ran the build and tests and drafted this report. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified the counts against the saved suite log and published this report.

Verbatim failure output from the full suite and focused retry

Full logs are in L:\XclTooling\neon-slot-2\tmp\pr1066-suite.log and L:\XclTooling\neon-slot-2\tmp\pr1066-e2e.log.

failures:

---- gpu::recomp::tests::gpu_clamp_and_omod_per_instruction stdout ----

thread 'gpu::recomp::tests::gpu_clamp_and_omod_per_instruction' (7352) panicked at crates\xcl\src\gpu\recomp\tests.rs:1070:47:
called `Result::unwrap()` on an `Err` value: "CreateComputePipelineState: The parameter is incorrect. (0x80070057)"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- gpu::recomp::tests::gpu_f64_compares_with_nan stdout ----

thread 'gpu::recomp::tests::gpu_f64_compares_with_nan' (10024) panicked at crates\xcl\src\gpu\recomp\tests.rs:72:35:
called `Result::unwrap()` on an `Err` value: "CreateComputePipelineState: The parameter is incorrect. (0x80070057)"

---- gpu::recomp::tests::gpu_f64_literal_high_word stdout ----

thread 'gpu::recomp::tests::gpu_f64_literal_high_word' (10028) panicked at crates\xcl\src\gpu\recomp\tests.rs:72:35:
called `Result::unwrap()` on an `Err` value: "CreateComputePipelineState: The parameter is incorrect. (0x80070057)"

---- gpu::recomp::tests::gpu_f64_class_compare stdout ----

thread 'gpu::recomp::tests::gpu_f64_class_compare' (9380) panicked at crates\xcl\src\gpu\recomp\tests.rs:519:47:
called `Result::unwrap()` on an `Err` value: "CreateComputePipelineState: The parameter is incorrect. (0x80070057)"

---- gpu::recomp::tests::gpu_f64_roots stdout ----

thread 'gpu::recomp::tests::gpu_f64_roots' (12704) panicked at crates\xcl\src\gpu\recomp\tests.rs:72:35:
called `Result::unwrap()` on an `Err` value: "CreateComputePipelineState: The parameter is incorrect. (0x80070057)"

---- gpu::recomp::tests::gpu_f64_rounding_and_conversions stdout ----

thread 'gpu::recomp::tests::gpu_f64_rounding_and_conversions' (8076) panicked at crates\xcl\src\gpu\recomp\tests.rs:72:35:
called `Result::unwrap()` on an `Err` value: "CreateComputePipelineState: The parameter is incorrect. (0x80070057)"

---- gpu::recomp::tests::gpu_f64_math_random stdout ----

thread 'gpu::recomp::tests::gpu_f64_math_random' (8720) panicked at crates\xcl\src\gpu\recomp\tests.rs:6386:47:
called `Result::unwrap()` on an `Err` value: "CreateComputePipelineState: The parameter is incorrect. (0x80070057)"

---- gpu::recomp::tests::gpu_frexp_f64_exp_and_mant stdout ----

thread 'gpu::recomp::tests::gpu_frexp_f64_exp_and_mant' (396) panicked at crates\xcl\src\gpu\recomp\tests.rs:752:47:
called `Result::unwrap()` on an `Err` value: "CreateComputePipelineState: The parameter is incorrect. (0x80070057)"

---- gpu::recomp::tests::gpu_ldexp_f64 stdout ----

thread 'gpu::recomp::tests::gpu_ldexp_f64' (11040) panicked at crates\xcl\src\gpu\recomp\tests.rs:72:35:
called `Result::unwrap()` on an `Err` value: "CreateComputePipelineState: The parameter is incorrect. (0x80070057)"

---- gpu::recomp::tests::gpu_float_compares_random stdout ----
wave32 F32: 1600 lanes x 33 compares, 0 distinct failures, 527 results that match only a flush of f32 denormals

thread 'gpu::recomp::tests::gpu_float_compares_random' (10512) panicked at crates\xcl\src\gpu\recomp\tests.rs:6498:51:
called `Result::unwrap()` on an `Err` value: "CreateComputePipelineState: The parameter is incorrect. (0x80070057)"

---- gpu::recomp::tests::gpu_nonfused_mad_and_mac_prevent_fma_contraction stdout ----

thread 'gpu::recomp::tests::gpu_nonfused_mad_and_mac_prevent_fma_contraction' (4352) panicked at crates\xcl\src\gpu\recomp\tests.rs:6703:5:
assertion `left == right` failed: v_fma_f32 overflow control should stay fused
  left: 2139095040
 right: 1946157055

---- gpu::recomp::tests::gpu_ps_image_sample_offset_implicit_lod_between_mips stdout ----

thread 'gpu::recomp::tests::gpu_ps_image_sample_offset_implicit_lod_between_mips' (4400) panicked at crates\xcl\src\gpu\recomp\tests.rs:2060:13:
pixel (0,0) = 25.609375, expected 26

---- gpu::recomp::tests::gpu_rndne_f64 stdout ----

thread 'gpu::recomp::tests::gpu_rndne_f64' (2212) panicked at crates\xcl\src\gpu\recomp\tests.rs:692:47:
called `Result::unwrap()` on an `Err` value: "CreateComputePipelineState: The parameter is incorrect. (0x80070057)"

---- gpu::recomp::tests::gpu_valu_16_and_64_bit stdout ----

thread 'gpu::recomp::tests::gpu_valu_16_and_64_bit' (11764) panicked at crates\xcl\src\gpu\recomp\tests.rs:2707:9:
assertion `left == right` failed: lane 0 v_add_f16 keeps the high half
  left: 0
 right: 3203351424

---- gpu::recomp::tests::gpu_wave64_ps_whole_wave_reductions stdout ----
waves of [16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16] pixels

thread 'gpu::recomp::tests::gpu_wave64_ps_whole_wave_reductions' (9572) panicked at crates\xcl\src\gpu\recomp\tests.rs:2165:13:
assertion `left == right` failed: pixel 0 (lane 0, wave of pixel 0): min / sum over the odd pixels, waterfall read
  left: [2, 217, 2]
 right: [2, 216, 2]

failures:

---- test_title_runs_and_game_folder_is_untouched stdout ----

thread 'test_title_runs_and_game_folder_is_untouched' (5740) panicked at crates\xcl\tests\e2e.rs:93:5:
missing L:\XclTooling\neon-slot-2\target\debug\xcl_testtitle.exe / L:\XclTooling\neon-slot-2\target\debug\testgame_mw.dll – build first: cargo build --workspace
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

xcl: XAudio2: CreateMasteringVoice failed (0x80070490) – no audio device?
thread 'test_title_runs_and_game_folder_is_untouched' (13276) panicked at crates\xcl\tests\e2e.rs:132:5:
failed checks in the test title:
[FAIL] D3D12.X: dynamic depth bias via RSSetDepthBiasX (#94): top-right [0, 0, 255, 255] (expected green: RSSetDepthBiasX(-1000.5) passes depth test)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of 53cd523c on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 53cd523c3ac1fec39b8aa209b284251987668ffe
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1621 (PresentX 1621)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14809 MB

Against the limits in CONTRIBUTING.md: 100 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keyboard/mouse: the camera whips after the title stops reading the gamepad for over 100 ms

6 participants