4

I have a CanvasControl in a UWP app and I've noticed when I leave my Surface alone for a while and it goes to sleep automatically, the CanvasControl no longer works after resuming. The previously drawn bitmap is now blank.

I tried to simulate Suspend/Resume in Visual Studio 2015, but that doesn't seem to cause a problem. It resumes fine.

I have a feeling it has to do with the CanvasDevice.DeviceLost event, and although I manage that with the CanvasControl.CreateResources event, I can't find a way to easily test it.

I tried the following:

// 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();

Is there a way to programmatically invoke a CanvasDevice.DeviceLost event? How can I fake it?

Laith
  • 6,071
  • 1
  • 33
  • 60

2 Answers2

11

It's not possible to trigger a device lost event with an API, but there is a command line tool you can use:

DXCap.exe -forcetdr

The version of DXCap you need is part of the Graphics Tools for Windows 10 package, for Win10 build 10586 or later: https://msdn.microsoft.com/en-us/library/mt125501.aspx#InstallGraphicsTools

After installing the VSGD, you can find DXCap in the windows\system32 directory.

Unfortunately it looks like this option is not (yet) documented, but from the command line:

  -forcetdr          Don't capture or replay, but simply force a GPU Timeout
                     Detection and Recovery event, then exit.
Simon
  • 126
  • 1
  • 2
  • Excellent! I found the bug instantly! This is probably an important suggestion, maybe you should attach it to the Win2D documentation. Thank you, Simon. – Laith Feb 25 '16 at 05:02
  • [One way to force a TDR programmatically](https://gamedev.stackexchange.com/questions/108141/how-can-i-test-dxgi-error-device-removed-error-handling) – diapir Dec 31 '17 at 03:08
0

What the @Simon described is documented here at the bottom of the page:

Handle device removed scenarios in Direct3D 11

Direct quote from the link above:

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.

Zingam
  • 4,498
  • 6
  • 28
  • 48