HLE: SDL3 gamepad backend for the gameinput shim #312

Open
DaviTostes wants to merge 1 commit from upstream-pr/312 into main
DaviTostes commented 2026-11-24 02:14:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T02:14:35Z.


Part of #187: this is the SDL3 gamepad backend and the trigger rumble. Sensors/gyro and glyph profiles are follow-ups.

What

  • host::sdl loads SDL3.dll at run time and reads up to four pads through SDL's gamepad API: buttons (positional A/B/X/Y), sticks (Y flipped to XInput's up-positive convention), both triggers, and hotplug (the list is rescanned every second).
  • Rumble goes through SDL_RumbleGamepad and SDL_RumbleGamepadTriggers; the shim now passes all four motor levels to the backend instead of dropping the trigger pair. XInput keeps the two body motors.
  • XInput remains the fallback: SDL3 is selected only when its DLL loads and SDL_Init(SDL_INIT_GAMEPAD) succeeds. VICTORY_INPUT=xinput|sdl3 forces a backend.
  • The keyboard path is shared by both backends.
  • No build dependency: the DLL is optional, and nothing changes for a build or run without it.

Tested

  • Windows release build under Wine 11.22 with SDL3 3.4.20 (SDL3.dll next to the exe) and a GameSir G7 Pro: pad found, and A/B, bumpers, dpad, both sticks and both triggers were read live (values moved as expected; Y axis correctly inverted).
  • cargo test -p victory-hle under the same setup: 85 passed, 1 failed. The failure is modules::net::tests::only_loopback_is_reachable (Wine lacks WSAConnectByList; #195/#217 territory), not this change.
  • Without SDL3.dll, host::source() selects XInput and the suite is unchanged.

Not in this PR

  • Gyro/accelerometer (SDL_OpenSensor / SDL_GetSensorData).
  • SDL_GetGamepadType detection and the glyph-profile work.
  • Trigger rumble was exercised through the API, but the physical feel was not verified on hardware.

No game data used.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6573067004 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/312). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T02:14:35Z. --- Part of #187: this is the SDL3 gamepad backend and the trigger rumble. Sensors/gyro and glyph profiles are follow-ups. ## What - `host::sdl` loads `SDL3.dll` at run time and reads up to four pads through SDL's gamepad API: buttons (positional A/B/X/Y), sticks (Y flipped to XInput's up-positive convention), both triggers, and hotplug (the list is rescanned every second). - Rumble goes through `SDL_RumbleGamepad` and `SDL_RumbleGamepadTriggers`; the shim now passes all four motor levels to the backend instead of dropping the trigger pair. XInput keeps the two body motors. - **XInput remains the fallback**: SDL3 is selected only when its DLL loads and `SDL_Init(SDL_INIT_GAMEPAD)` succeeds. `VICTORY_INPUT=xinput|sdl3` forces a backend. - The keyboard path is shared by both backends. - No build dependency: the DLL is optional, and nothing changes for a build or run without it. ## Tested - Windows release build under **Wine 11.22** with SDL3 3.4.20 (`SDL3.dll` next to the exe) and a **GameSir G7 Pro**: pad found, and A/B, bumpers, dpad, both sticks and both triggers were read live (values moved as expected; Y axis correctly inverted). - `cargo test -p victory-hle` under the same setup: **85 passed, 1 failed**. The failure is `modules::net::tests::only_loopback_is_reachable` (Wine lacks `WSAConnectByList`; #195/#217 territory), not this change. - Without `SDL3.dll`, `host::source()` selects XInput and the suite is unchanged. ## Not in this PR - Gyro/accelerometer (`SDL_OpenSensor` / `SDL_GetSensorData`). - `SDL_GetGamepadType` detection and the glyph-profile work. - Trigger rumble was exercised through the API, but the physical feel was not verified on hardware. No game data used.
DaviTostes commented 2026-11-24 06:55:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T03:48:15Z.


Status against current main (d2a4bae): CLEAN / MERGEABLE, no reviews and no checks. Re-ran the Windows build under Wine 11.22: victory-hle 85 passed, 1 failed — only modules::net::tests::only_loopback_is_reachable (Wine WSAConnectByList, #217).

Coordination: the rumble plumbing here overlaps #26 (both change Source::rumble to carry the four motor levels). #26 predates this PR and is smaller (+71/−16), while this one also adds the SDL3 backend; git merge-tree --write-tree pr312 pr26 reports CONFLICT (content) in gameinput.rs. If #26 lands first, this branch needs a rebase — or this PR can keep only the SDL3 backend and leave the shared Motors change to #26.

No game data used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121438143 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/312#issuecomment-7121438143). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T03:48:15Z. --- Status against current `main` (`d2a4bae`): **CLEAN / MERGEABLE**, no reviews and no checks. Re-ran the Windows build under Wine 11.22: `victory-hle` **85 passed, 1 failed** — only `modules::net::tests::only_loopback_is_reachable` (Wine `WSAConnectByList`, #217). Coordination: the rumble plumbing here overlaps **#26** (both change `Source::rumble` to carry the four motor levels). #26 predates this PR and is smaller (+71/−16), while this one also adds the SDL3 backend; `git merge-tree --write-tree pr312 pr26` reports `CONFLICT (content)` in `gameinput.rs`. If #26 lands first, this branch needs a rebase — or this PR can keep only the SDL3 backend and leave the shared `Motors` change to #26. No game data used.
jeremygold02 commented 2026-11-24 06:55:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:19:29Z.


Tested PR #312 at head 191e335d784888d37d7c0626a95c377e38ba87e5 (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at 191e335d784888d37d7c0626a95c377e38ba87e5.

  • cargo test --locked -p victory-hle --lib — passed (ok. 86 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.56s ); cases: modules::audio::tests::full_message_queues_count_drops, modules::display::tests::sdr_and_display_deferrals, modules::dsp::tests::convolution_stream_as_the_title_drives_it, modules::dstorage::tests::request_layout_is_the_titles, and 82 more.

Behavior covered: Runs the HLE library unit suite with the new SDL3 gamepad backend compiled; there is no dedicated gameinput test added by this PR.
Code: crates/victory-hle/src/modules/gameinput.rs

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121913590 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/312#issuecomment-7121913590). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:19:29Z. --- Tested PR #312 at head `191e335d784888d37d7c0626a95c377e38ba87e5` (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at `191e335d784888d37d7c0626a95c377e38ba87e5`. - `cargo test --locked -p victory-hle --lib` — passed (ok. 86 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.56s ); cases: modules::audio::tests::full_message_queues_count_drops, modules::display::tests::sdr_and_display_deferrals, modules::dsp::tests::convolution_stream_as_the_title_drives_it, modules::dstorage::tests::request_layout_is_the_titles, and 82 more. Behavior covered: Runs the HLE library unit suite with the new SDL3 gamepad backend compiled; there is no dedicated gameinput test added by this PR. Code: [crates/victory-hle/src/modules/gameinput.rs](https://github.com/Marvisak/VIctory/blob/191e335d784888d37d7c0626a95c377e38ba87e5/crates/victory-hle/src/modules/gameinput.rs)
pluvialmoon commented 2026-11-24 15:04:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pluvialmoon on 2026-11-24T14:30:39Z.


Ran into this with a Stadia Controller (HID, not XInput) on Windows 11 / RTX 5060: Source::rumble is called on the title's thread while Source::pad is on the hub's poll thread. If the backend initialises SDL from rumble too, the first rumble after a poll re-initialises SDL on the title's thread — seen as eight "SDL gamepad" log lines in a row on a world load. Worth guarding in host::sdl: only the poll thread should own SDL.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7134493042 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/312#issuecomment-7134493042). Originally posted by [pluvialmoon](https://github.com/pluvialmoon) on 2026-11-24T14:30:39Z. --- Ran into this with a Stadia Controller (HID, not XInput) on Windows 11 / RTX 5060: Source::rumble is called on the title's thread while Source::pad is on the hub's poll thread. If the backend initialises SDL from rumble too, the first rumble after a poll re-initialises SDL on the title's thread — seen as eight "SDL gamepad" log lines in a row on a world load. Worth guarding in host::sdl: only the poll thread should own SDL.
DaviTostes commented 2026-11-24 18:06:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T18:01:45Z.


Status/coordination: the rumble signature is now contested by several PRs.

  • #1357 implements the four motors as a Rumble struct (WinRT Windows.Gaming.Input + XInput fallback + async worker + zeroing on disconnect/focus), and looks like the more complete Windows path.
  • #26 (Motors struct) and #1104 (XInputSetStateEx ordinal 100) cover the same plumbing.
  • This PR uses [f32; 4] and adds the SDL3 backend.

They conflict in gameinput.rs (merge-tree between this head and #1357 reports a conflict). Suggestion: let the winning Rumble signature land first, then rebase this branch onto it and keep only the SDL3 source (SDL_RumbleGamepad / SDL_RumbleGamepadTriggers), dropping the duplicated XInput signatures. No code change made yet; happy to adjust once the maintainers pick one.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140053140 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/312#issuecomment-7140053140). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T18:01:45Z. --- Status/coordination: the rumble signature is now contested by several PRs. - **#1357** implements the four motors as a `Rumble` struct (WinRT `Windows.Gaming.Input` + XInput fallback + async worker + zeroing on disconnect/focus), and looks like the more complete Windows path. - #26 (Motors struct) and #1104 (XInputSetStateEx ordinal 100) cover the same plumbing. - This PR uses `[f32; 4]` and adds the SDL3 backend. They conflict in `gameinput.rs` (`merge-tree` between this head and #1357 reports a conflict). Suggestion: let the winning `Rumble` signature land first, then rebase this branch onto it and keep only the SDL3 source (`SDL_RumbleGamepad` / `SDL_RumbleGamepadTriggers`), dropping the duplicated XInput signatures. No code change made yet; happy to adjust once the maintainers pick one.
pfhandler commented 2026-11-24 21:03:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pfhandler on 2026-11-24T20:51:44Z.


Local patches for two issues hit while running GTA VI 1.0.2.1 through VIctory on Linux (GE-Proton 11-14, vkd3d-proton 3.2.0, RTX 4060 Ti 8 GB):

  • VICTORY_NO_HOST_PAD=1 — a connected host pad (e.g. DualShock appearing as XInput pad 0) keeps the keyboard stand-in pad from being enumerated. Hiding the host pad lets VICTORY_KEYS drive the title again.
  • VICTORY_MODE=1920x1080 — the DXGI output mode list is fixed at the console's 3840x2160. Reporting 1920x1080 instead keeps the title's render targets and VRAM use down on smaller hosts (Series S profile + 1080p settled around 3.5 GB VRAM here).

Both are local uncommitted diffs, posted here for reuse. Tested only on the configuration above.

diff --git a/crates/victory-gpu/src/dxgi.rs b/crates/victory-gpu/src/dxgi.rs
index c7f7c45..2535b68 100644
--- a/crates/victory-gpu/src/dxgi.rs
+++ b/crates/victory-gpu/src/dxgi.rs
@@ -219,6 +219,19 @@ struct Mode {
 }
 const _: () = assert!(size_of::<Mode>() == 32);
 
+/// The console's fixed output mode, overridable for hosts smaller than the
+/// console's 4K target: `VICTORY_MODE=1920x1080` reports that instead.
+fn mode_size() -> (u32, u32) {
+    const DEFAULT: (u32, u32) = (3840, 2160);
+    let Some(text) = std::env::var_os("VICTORY_MODE") else {
+        return DEFAULT;
+    };
+    let text = text.to_string_lossy();
+    text.split_once('x')
+        .and_then(|(w, h)| Some((w.trim().parse().ok()?, h.trim().parse().ok()?)))
+        .unwrap_or(DEFAULT)
+}
+
 /// The console's mode list: one 4K mode at 60 Hz (Grand Theft Auto VI looks
 /// for a 120 Hz one to allow 120 Hz frame intervals).
 /// shortcut: fixed mode, not the host display's; report the host's rates if
@@ -242,9 +255,10 @@ extern "system" fn modes(
         return MORE_DATA;
     }
     *count = 1;
+    let (width, height) = mode_size();
     let mode = Mode {
-        width: 3840,
-        height: 2160,
+        width,
+        height,
         refresh: [60, 1],
         format: 0,
         scanlines: 1, // progressive
diff --git a/crates/victory-hle/src/modules/gameinput.rs b/crates/victory-hle/src/modules/gameinput.rs
index a411bd0..da8d66c 100644
--- a/crates/victory-hle/src/modules/gameinput.rs
+++ b/crates/victory-hle/src/modules/gameinput.rs
@@ -1134,6 +1134,11 @@ mod host {
 
     impl Source for Host {
         fn pad(&mut self, slot: usize) -> Option<PadState> {
+            // The keyboard stand-in pad only exists while no host pad is
+            // connected; this hides a host pad the title mis-handles.
+            if std::env::var_os("VICTORY_NO_HOST_PAD").is_some() {
+                return None;
+            }
             if self.empty_until[slot].is_some_and(|until| Instant::now() < until) {
                 return None;
             }
<!-- greyfinch-sync:Marvisak/VIctory:comment:7144155258 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/312#issuecomment-7144155258). Originally posted by [pfhandler](https://github.com/pfhandler) on 2026-11-24T20:51:44Z. --- Local patches for two issues hit while running GTA VI 1.0.2.1 through VIctory on Linux (GE-Proton 11-14, vkd3d-proton 3.2.0, RTX 4060 Ti 8 GB): - `VICTORY_NO_HOST_PAD=1` — a connected host pad (e.g. DualShock appearing as XInput pad 0) keeps the keyboard stand-in pad from being enumerated. Hiding the host pad lets `VICTORY_KEYS` drive the title again. - `VICTORY_MODE=1920x1080` — the DXGI output mode list is fixed at the console's 3840x2160. Reporting 1920x1080 instead keeps the title's render targets and VRAM use down on smaller hosts (Series S profile + 1080p settled around 3.5 GB VRAM here). Both are local uncommitted diffs, posted here for reuse. Tested only on the configuration above. ```diff diff --git a/crates/victory-gpu/src/dxgi.rs b/crates/victory-gpu/src/dxgi.rs index c7f7c45..2535b68 100644 --- a/crates/victory-gpu/src/dxgi.rs +++ b/crates/victory-gpu/src/dxgi.rs @@ -219,6 +219,19 @@ struct Mode { } const _: () = assert!(size_of::<Mode>() == 32); +/// The console's fixed output mode, overridable for hosts smaller than the +/// console's 4K target: `VICTORY_MODE=1920x1080` reports that instead. +fn mode_size() -> (u32, u32) { + const DEFAULT: (u32, u32) = (3840, 2160); + let Some(text) = std::env::var_os("VICTORY_MODE") else { + return DEFAULT; + }; + let text = text.to_string_lossy(); + text.split_once('x') + .and_then(|(w, h)| Some((w.trim().parse().ok()?, h.trim().parse().ok()?))) + .unwrap_or(DEFAULT) +} + /// The console's mode list: one 4K mode at 60 Hz (Grand Theft Auto VI looks /// for a 120 Hz one to allow 120 Hz frame intervals). /// shortcut: fixed mode, not the host display's; report the host's rates if @@ -242,9 +255,10 @@ extern "system" fn modes( return MORE_DATA; } *count = 1; + let (width, height) = mode_size(); let mode = Mode { - width: 3840, - height: 2160, + width, + height, refresh: [60, 1], format: 0, scanlines: 1, // progressive diff --git a/crates/victory-hle/src/modules/gameinput.rs b/crates/victory-hle/src/modules/gameinput.rs index a411bd0..da8d66c 100644 --- a/crates/victory-hle/src/modules/gameinput.rs +++ b/crates/victory-hle/src/modules/gameinput.rs @@ -1134,6 +1134,11 @@ mod host { impl Source for Host { fn pad(&mut self, slot: usize) -> Option<PadState> { + // The keyboard stand-in pad only exists while no host pad is + // connected; this hides a host pad the title mis-handles. + if std::env::var_os("VICTORY_NO_HOST_PAD").is_some() { + return None; + } if self.empty_until[slot].is_some_and(|until| Instant::now() < until) { return None; } ```
Marvisak commented 2026-11-25 01:07:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:30:03Z.


Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-hle/src/modules/gameinput.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148573236 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/312#issuecomment-7148573236). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:30:03Z. --- <!-- victory-triage v1 head=191e335d784888d37d7c0626a95c377e38ba87e5 verdict=needs-rebase at=2026-11-25T01:15:46Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-hle/src/modules/gameinput.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
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/312:upstream-pr/312'
git switch 'upstream-pr/312'

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/312'
git switch 'upstream-pr/312'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/312'
git switch 'upstream-pr/312'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/312'
git switch 'main'
git merge --squash 'upstream-pr/312'
git switch 'main'
git merge --ff-only 'upstream-pr/312'
git switch 'main'
git merge 'upstream-pr/312'
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!312
No description provided.