HLE: implement mfplat.dll!MFResetDXGIDeviceManagerX with system fallback #21

Merged
raylitebull merged 1 commit from upstream-pr/22 into main 2026-11-21 22:54:06 +00:00
raylitebull commented 2026-11-21 21:57:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-21T21:57:13Z.


Summary

Implements the Xbox GDK Media Foundation helper mfplat.dll!MFResetDXGIDeviceManagerX with transparent system fallback for all standard Media Foundation exports.

Changes

  • crates/xcl/src/hle/mfplat.rs:
    • Implements MFResetDXGIDeviceManagerX(pDeviceManager, pDevice, resetToken) -> HRESULT using the typed windows::Win32::Media::MediaFoundation::IMFDXGIDeviceManager COM interface (borrowing caller-owned pointers with ManuallyDrop).
    • Validates null pointers (E_POINTER) and attempts IMFDXGIDeviceManager::ResetDevice directly first (which succeeds natively for ID3D12Device on Windows 11 and preserves E_INVALIDARG for invalid reset tokens).
    • When direct ResetDevice fails for an ID3D12Device, creates a companion D3D11 device (dynamically loaded from d3d11.dll) on the matching adapter LUID with VIDEO_SUPPORT | BGRA_SUPPORT and ID3D10Multithread::SetMultithreadProtected(TRUE), then passes it to ResetDevice with the caller's resetToken.
    • Adds unit tests covering import routing/fallback, LoadLibrary + GetProcAddress, null pointer handling, invalid token rejection, real ID3D12Device reset + OpenDeviceHandle/TestDevice/CloseDeviceHandle, and the companion D3D11 bridge path.
  • crates/xcl/src/hle/mod.rs:
    • Registers MFPLAT (mfplat.dll) with system fallback &[mfplat.dll] (aliases_are_system() == false), so standard exports (MFStartup, MFCreateDXGIDeviceManager, MFCreateMediaType, etc.) resolve to Windows' mfplat.dll while MFResetDXGIDeviceManagerX resolves to XCL's HLE export and hle::opus dynamic loading remains unchanged.
  • tests/testtitle/src/gpu.rs & tests/testtitle/src/main.rs:
    • Adds an end-to-end check importing MFStartup, MFCreateDXGIDeviceManager, MFShutdown, and MFResetDXGIDeviceManagerX from mfplat.dll against the console d3d12_xs device.

Verification

  • cargo build --workspace: 0 new warnings
  • cargo test --workspace -- --test-threads=4: all tests passed (243 lib unit tests, 12 console_dlls_e2e, 1 console_shaders, 1 e2e including the new testtitle check, 6 gpu_pso_e2e, 3 xg_oracle).
<!-- greyfinch-sync:ivall/xcl:issue:6534913190 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/22). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-11-21T21:57:13Z. --- ## Summary Implements the Xbox GDK Media Foundation helper `mfplat.dll!MFResetDXGIDeviceManagerX` with transparent system fallback for all standard Media Foundation exports. ### Changes - **`crates/xcl/src/hle/mfplat.rs`**: - Implements `MFResetDXGIDeviceManagerX(pDeviceManager, pDevice, resetToken) -> HRESULT` using the typed `windows::Win32::Media::MediaFoundation::IMFDXGIDeviceManager` COM interface (borrowing caller-owned pointers with `ManuallyDrop`). - Validates null pointers (`E_POINTER`) and attempts `IMFDXGIDeviceManager::ResetDevice` directly first (which succeeds natively for `ID3D12Device` on Windows 11 and preserves `E_INVALIDARG` for invalid reset tokens). - When direct `ResetDevice` fails for an `ID3D12Device`, creates a companion D3D11 device (dynamically loaded from `d3d11.dll`) on the matching adapter LUID with `VIDEO_SUPPORT | BGRA_SUPPORT` and `ID3D10Multithread::SetMultithreadProtected(TRUE)`, then passes it to `ResetDevice` with the caller's `resetToken`. - Adds unit tests covering import routing/fallback, `LoadLibrary` + `GetProcAddress`, null pointer handling, invalid token rejection, real `ID3D12Device` reset + `OpenDeviceHandle`/`TestDevice`/`CloseDeviceHandle`, and the companion D3D11 bridge path. - **`crates/xcl/src/hle/mod.rs`**: - Registers `MFPLAT` (`mfplat.dll`) with system fallback `&[mfplat.dll]` (`aliases_are_system() == false`), so standard exports (`MFStartup`, `MFCreateDXGIDeviceManager`, `MFCreateMediaType`, etc.) resolve to Windows' `mfplat.dll` while `MFResetDXGIDeviceManagerX` resolves to XCL's HLE export and `hle::opus` dynamic loading remains unchanged. - **`tests/testtitle/src/gpu.rs` & `tests/testtitle/src/main.rs`**: - Adds an end-to-end check importing `MFStartup`, `MFCreateDXGIDeviceManager`, `MFShutdown`, and `MFResetDXGIDeviceManagerX` from `mfplat.dll` against the console `d3d12_xs` device. ### Verification - `cargo build --workspace`: 0 new warnings - `cargo test --workspace -- --test-threads=4`: all tests passed (243 lib unit tests, 12 `console_dlls_e2e`, 1 `console_shaders`, 1 `e2e` including the new `testtitle` check, 6 `gpu_pso_e2e`, 3 `xg_oracle`).
upstream-sync closed this pull request 2026-11-24 06:56:47 +00:00
ivall commented 2026-11-24 07:00:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ivall on 2026-11-21T22:54:08Z.


Reviewed and merged, thanks. It conflicted with #20 in tests/testtitle/src/main.rs (both added a check line); I merged it on main keeping both lines (your MFPlat check and the XMA2 + Opus XAudio2 line). Checked together with #21, #22 and #25 on top of current main: full workspace tests pass (277 lib tests, e2e, console_dlls_e2e, gpu_pso_e2e, rpf_e2e), no new build warnings.

<!-- greyfinch-sync:ivall/xcl:comment:7070506289 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/22#issuecomment-7070506289). Originally posted by [ivall](https://github.com/ivall) on 2026-11-21T22:54:08Z. --- Reviewed and merged, thanks. It conflicted with #20 in `tests/testtitle/src/main.rs` (both added a check line); I merged it on main keeping both lines (your MFPlat check and the XMA2 + Opus XAudio2 line). Checked together with #21, #22 and #25 on top of current main: full workspace tests pass (277 lib tests, e2e, console_dlls_e2e, gpu_pso_e2e, rpf_e2e), no new build warnings.
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
xcl-dev/xcl!21
No description provided.