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

Manually merged
github merged 1 commit from gh-pr/22/head into gh-pr/22/base 2026-11-26 04:04:41 +00:00
Owner

@⁠raylitebull on GitHub · 2026-11-21 21:57 UTC · original
raylitebull:mfplat-reset-dxgi → main · +438 −0 · 4 files · 1 commits · merged 2026-11-21 22:54 UTC

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).
**@⁠raylitebull** on GitHub · 2026-11-21 21:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/22) `raylitebull:mfplat-reset-dxgi` → `main` · +438 −0 · 4 files · 1 commits · merged 2026-11-21 22:54 UTC ## 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`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:04:40 +00:00
github manually merged commit 6a27beb714 into gh-pr/22/base 2026-11-26 04:04:41 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-21 22:54 UTC · original

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.

**@⁠ivall** on GitHub · 2026-11-21 22:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/22#issuecomment-7070506289) 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.