GameInput: answer IUnknown and own-IID queries on the COM objects #1640

Closed
Calvix2k wants to merge 1 commit from upstream-pr/1641 into main
Calvix2k commented 2026-11-24 20:18:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T20:18:25Z.


Addresses VIC-BT-020 from audit #1242.

Summary

  • Replace the single no_interface slot shared by all three GameInput vtables with per-object QueryInterface handlers.

  • Each handler accepts IID_IUnknown and the object's own GUID from GameInput.h:

    Object IID
    IGameInput 11BE2A7E-4254-445A-9C09-FFC40F006918
    IGameInputDevice 31DD86FB-4C1B-408A-868F-439B3CD47125
    IGameInputReading 2156947A-E1FA-4DE0-A30B-D812931DBD8D
  • On success AddRef through the object's own slot 1, so readings stay reference counted; on failure *out is cleared and the call returns E_NOINTERFACE.

  • Null required pointers and a null *out return E_POINTER.

  • A query for another object's IID is refused (IGameInputDevice does not answer IID_IGameInput).

Tests

New test query_interface_answers_identity_and_the_objects_own_iid walks the input object, a device and a reading, checking:

  • IID_IUnknown and the object's own IID return S_OK with identity.
  • An unknown IID returns E_NOINTERFACE and nulls a sentinel out.
  • Null out / null IID return E_POINTER.
  • Reading reference counts survive the QueryInterface AddRef.

Validation

  • cargo test -p victory-hle --locked -- --test-threads=1 — passed (95 unit tests and 1 integration test).
  • cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings — passed.
  • cargo xtask policy — passed (154 files).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6590602917 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1641). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T20:18:25Z. --- Addresses `VIC-BT-020` from [audit #1242](https://github.com/Marvisak/VIctory/issues/1242). ## Summary - Replace the single `no_interface` slot shared by all three GameInput vtables with per-object `QueryInterface` handlers. - Each handler accepts `IID_IUnknown` and the object's own GUID from `GameInput.h`: | Object | IID | | --- | --- | | `IGameInput` | `11BE2A7E-4254-445A-9C09-FFC40F006918` | | `IGameInputDevice` | `31DD86FB-4C1B-408A-868F-439B3CD47125` | | `IGameInputReading` | `2156947A-E1FA-4DE0-A30B-D812931DBD8D` | - On success AddRef through the object's own slot 1, so readings stay reference counted; on failure `*out` is cleared and the call returns `E_NOINTERFACE`. - Null required pointers and a null `*out` return `E_POINTER`. - A query for another object's IID is refused (`IGameInputDevice` does not answer `IID_IGameInput`). ## Tests New test `query_interface_answers_identity_and_the_objects_own_iid` walks the input object, a device and a reading, checking: - `IID_IUnknown` and the object's own IID return `S_OK` with identity. - An unknown IID returns `E_NOINTERFACE` and nulls a sentinel `out`. - Null `out` / null IID return `E_POINTER`. - Reading reference counts survive the `QueryInterface` AddRef. ## Validation - `cargo test -p victory-hle --locked -- --test-threads=1` — passed (95 unit tests and 1 integration test). - `cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings` — passed. - `cargo xtask policy` — passed (154 files).
DenRakEiw commented 2026-11-24 21:02:57 +00:00 (Migrated from github.com)

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

Review: APPROVED


Verified locally merged onto origin/main (Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-hle --lib gameinput:: — 8 passed, 0 failed (including query_interface_answers_identity_and_the_objects_own_iid)
  • cargo clippy -p victory-hle --all-targets — 0 warnings
  • cargo xtask policy — ok

Clean QueryInterface implementation for IUnknown and each GameInput COM object's own IID. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6046816907 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1641#pullrequestreview-6046816907). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T20:26:19Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-hle --lib gameinput::` — 8 passed, 0 failed (including `query_interface_answers_identity_and_the_objects_own_iid`) - `cargo clippy -p victory-hle --all-targets` — 0 warnings - `cargo xtask policy` — ok Clean `QueryInterface` implementation for `IUnknown` and each GameInput COM object's own IID. Looks good. AI-assisted (Gemini 4 Neon).
pfhandler commented 2026-11-24 21:03:44 +00:00 (Migrated from github.com)

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


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:7144210993 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1641#issuecomment-7144210993). Originally posted by [pfhandler](https://github.com/pfhandler) on 2026-11-24T20:54:15Z. --- 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; } ```
Calvix2k commented 2026-11-24 21:03:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T20:59:27Z.


Thanks — these are unrelated to this PR, so I upstreamed them separately with you credited: VICTORY_MODE is now #1701 (validated WxH, falls back to 3840x2160) and VICTORY_NO_HOST_PAD is #1702 (read once, logs that pads are ignored).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144327572 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1641#issuecomment-7144327572). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T20:59:27Z. --- Thanks — these are unrelated to this PR, so I upstreamed them separately with you credited: `VICTORY_MODE` is now #1701 (validated `WxH`, falls back to 3840x2160) and `VICTORY_NO_HOST_PAD` is #1702 (read once, logs that pads are ignored).
BaggyALPHA commented 2026-11-24 21:28:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by BaggyALPHA on 2026-11-24T21:23:10Z.

Review: COMMENTED


I checked the accepted interface IDs against the Windows SDK GameInput v0 header and ran the seven GameInput tests on Windows. All passed, including the new QueryInterface test.

One ABI gap matters when this starts accepting the device IID. The SDK's IGameInputDevice has 22 slots, including IUnknown. VIctory's device table has 21, so it is missing the final void ReleaseExclusiveRawDeviceAccess method. The preceding AcquireExclusiveRawDeviceAccess entry also uses the generic HRESULT stub, while the SDK header declares a bool return. Could we make acquire return false and add a void release stub before advertising the device IID? That would match the existing lack of raw exclusive access and give callers the complete method table.

AI-assisted (Codex).

<!-- greyfinch-sync:Marvisak/VIctory:review:6047636358 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1641#pullrequestreview-6047636358). Originally posted by [BaggyALPHA](https://github.com/BaggyALPHA) on 2026-11-24T21:23:10Z. **Review:** COMMENTED --- I checked the accepted interface IDs against the Windows SDK GameInput v0 header and ran the seven GameInput tests on Windows. All passed, including the new QueryInterface test. One ABI gap matters when this starts accepting the device IID. The SDK's IGameInputDevice has 22 slots, including IUnknown. VIctory's device table has 21, so it is missing the final void ReleaseExclusiveRawDeviceAccess method. The preceding AcquireExclusiveRawDeviceAccess entry also uses the generic HRESULT stub, while the SDK header declares a bool return. Could we make acquire return false and add a void release stub before advertising the device IID? That would match the existing lack of raw exclusive access and give callers the complete method table. AI-assisted (Codex).
catminou4 commented 2026-11-24 22:01:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:42:10Z.

Review: COMMENTED


Static review only: Windows-only code (D3D12/windows_sys/Win32) — nothing compiles or runs on macOS; source review of the diff.

GameInput COM objects now answer IUnknown and own-IID queries: query_interface validates the IID against an expected GUID, returns the object itself with an AddRef via the vtable (transmute of the fn pointer is contained), and nulls 'out' first. The three interface entry points (input/device/reading) share it, and query_interface_answers_identity_and_the_objects_own_iid tests it. COM identity rules look right; GameInput is HLE-side but this file lives in the Windows-only tree.

<!-- greyfinch-sync:Marvisak/VIctory:review:6047874436 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1641#pullrequestreview-6047874436). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T21:42:10Z. **Review:** COMMENTED --- Static review only: Windows-only code (D3D12/windows_sys/Win32) — nothing compiles or runs on macOS; source review of the diff. GameInput COM objects now answer IUnknown and own-IID queries: query_interface validates the IID against an expected GUID, returns the object itself with an AddRef via the vtable (transmute of the fn pointer is contained), and nulls 'out' first. The three interface entry points (input/device/reading) share it, and query_interface_answers_identity_and_the_objects_own_iid tests it. COM identity rules look right; GameInput is HLE-side but this file lives in the Windows-only tree.
BaggyALPHA commented 2026-11-24 23:06:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by BaggyALPHA on 2026-11-24T22:42:11Z.


I followed up on the v0 device table review. A Windows regression test failed on the current PR because the SDK interface has 22 slots and the device table has 21. A local correction passed all 8 GameInput tests and HLE Clippy with all targets and features.

The correction makes both the table and Device's table reference 22 entries, uses typed false-returning stubs for IsForceFeedbackMotorPoweredOn at slot 7 and AcquireExclusiveRawDeviceAccess at slot 20, and adds a typed void no-op for ReleaseExclusiveRawDeviceAccess at slot 21. The test queries the device IID first, then calls those slots with the signatures from the Windows SDK header. It uses a synthetic device.

AI-assisted (Codex).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146544404 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1641#issuecomment-7146544404). Originally posted by [BaggyALPHA](https://github.com/BaggyALPHA) on 2026-11-24T22:42:11Z. --- I followed up on the [v0 device table review](https://github.com/Marvisak/VIctory/pull/1641#pullrequestreview-6047636358). A Windows regression test failed on the current PR because the SDK interface has 22 slots and the device table has 21. A local correction passed all 8 GameInput tests and HLE Clippy with all targets and features. The correction makes both the table and Device's table reference 22 entries, uses typed false-returning stubs for IsForceFeedbackMotorPoweredOn at slot 7 and AcquireExclusiveRawDeviceAccess at slot 20, and adds a typed void no-op for ReleaseExclusiveRawDeviceAccess at slot 21. The test queries the device IID first, then calls those slots with the signatures from the Windows SDK header. It uses a synthetic device. AI-assisted (Codex).
upstream-sync closed this pull request 2026-11-25 02:04:42 +00:00
Marvisak commented 2026-11-25 02:05:56 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers. Closing because it breaks a repository rule (see docs/asset-policy.md and the project rules): nothing taken from the console SDK or the game, no weakening of the asset policy, and the title stays offline.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149480127 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1641#issuecomment-7149480127). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:22:30Z. --- Automated triage for the maintainers. Closing because it breaks a repository rule (see `docs/asset-policy.md` and the project rules): nothing taken from the console SDK or the game, no weakening of the asset policy, and the title stays offline. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Calvix2k commented 2026-11-25 02:06:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T01:26:06Z.


Re-landed as #1942 (this PR cannot be reopened). It carries BaggyALPHA's 22-slot device-table correction: IsForceFeedbackMotorPoweredOn (0x38) and AcquireExclusiveRawDeviceAccess (0xa0) return false, ReleaseExclusiveRawDeviceAccess (0xa8) is a void no-op. Tests 10/10, clippy/policy pass. The triage closure looks like a false positive: the IIDs are public Windows SDK GameInput.h constants, only gameinput.rs changes.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149542270 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1641#issuecomment-7149542270). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-25T01:26:06Z. --- Re-landed as #1942 (this PR cannot be reopened). It carries BaggyALPHA's 22-slot device-table correction: IsForceFeedbackMotorPoweredOn (0x38) and AcquireExclusiveRawDeviceAccess (0xa0) return false, ReleaseExclusiveRawDeviceAccess (0xa8) is a void no-op. Tests 10/10, clippy/policy pass. The triage closure looks like a false positive: the IIDs are public Windows SDK GameInput.h constants, only gameinput.rs changes.

Pull request closed

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!1640
No description provided.