如何使用 Win2D 模拟 DeviceLost 事件?

How can I simulate a DeviceLost event with Win2D?

我在 UWP 应用程序中有一个 CanvasControl,我注意到当我将 Surface 单独放置一段时间后它会自动进入睡眠状态,CanvasControl 在恢复后不再工作。之前绘制的位图现在是空白的。

我尝试在 Visual Studio 2015 年模拟 Suspend/Resume,但这似乎没有引起问题。它恢复正常。

我感觉它与 CanvasDevice.DeviceLost 事件有关,尽管我通过 CanvasControl.CreateResources 事件解决了这个问题,但我找不到轻松测试它的方法。

我尝试了以下方法:

// This throws an exception. Not allowed to do this.
myCanvas.Device.RaiseDeviceLost(); 

// and this doesn't report a device lost, but myCanvas becomes unusable.
myCanvas.Device.Dispose();

有没有办法以编程方式调用 CanvasDevice.DeviceLost 事件?我怎样才能伪造它?

无法使用 API 触发设备丢失事件,但可以使用命令行工具:

DXCap.exe -forcetdr

您需要的 DXCap 版本是 Windows 10 包的图形工具的一部分,适用于 Win10 内部版本 10586 或更高版本: https://msdn.microsoft.com/en-us/library/mt125501.aspx#InstallGraphicsTools

安装好VSGD后,可以在windows\system32目录下找到DXCap

不幸的是,这个选项似乎(还)没有记录,但是来自命令行:

  -forcetdr          Don't capture or replay, but simply force a GPU Timeout
                     Detection and Recovery event, then exit.

@Simon 描述的内容记录在页面底部:

Handle device removed scenarios in Direct3D 11

直接引用上面的link:

Visual Studio's Developer Command Prompt supports a command line tool 'dxcap' for Direct3D event capture and playback related to the Visual Studio Graphics Diagnostics. You can use the command line option "-forcetdr" while your app is running which will force a GPU Timeout Detection and Recovery event, thereby triggering DXGI_ERROR_DEVICE_REMOVED and allowing you to test your error handling code.