26
\$\begingroup\$

This is more of an open ended question, but I hope to get some good insight on how to avoid the issue.

When playing Games on Windows, I might want to ALT-TAB out of it. Some games have no problems, others are not so easy: They may take AGES to switch out and back in. Some are even prone to crashing or to weird behaviour like graphic distortion or stuttering sound.

I just wonder what causes this behavior? Is this more a DirectX or an OpenGL thing? Is it caused by Games being 'clever' and caching/wiping the cache whenever the screen settings change? (I assume they do get some sort of signal when I ALT-TAB?)

I don't have any problem of my own, but I'd like to know what to avoid and which 'clever' trick may cause this type of horrible customer experience?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Great question! Hopefully we get some insightful answers, as usual! \$\endgroup\$
    – Sergio
    Commented Oct 26, 2010 at 12:05

3 Answers 3

17
\$\begingroup\$

In some situations ALT-TAB will cause the DirectX device to be lost. When the device is lost all GPU resources (vertices, textures, shaders and so on) must be considered invalid and cannot be used again. MSDN reference here.

These lost resources must be released, and then recreated when the device is restored. In the case of most games restoring these resources requires a lot of data to be loaded from disk again - often the same loading procedure as done at the start of the game/level.

What can be done to avoid this?

  • You can keep a cache of your data in ram so transferring it back to the GPU will be faster than reloading from HD. I believe there's a way to make DirectX do this automatically.
  • Use a new version of DirectX. This quote (source) is from MSDN on DirectX 9Ex:

Devices are now only lost under two circumstances; when the hardware is reset because it is hanging, and when the device driver is stopped. When hardware hangs, the device can be reset by calling ResetEx. If hardware hangs, texture memory is lost.

\$\endgroup\$
3
  • \$\begingroup\$ Could you provide a link for that quote? We find that the device is lost when you lock the desktop, also. \$\endgroup\$
    – Kylotan
    Commented Oct 26, 2010 at 10:37
  • \$\begingroup\$ I've added the link for the quote. \$\endgroup\$ Commented Oct 26, 2010 at 11:18
  • 1
    \$\begingroup\$ the change in DirectX behavior is a side effect of the change in the driver model. That is, it requires WDDM. SO it's Vista/Win7 only. \$\endgroup\$
    – Bahbar
    Commented Oct 26, 2010 at 11:52
7
\$\begingroup\$

In Direct3D a device can become lost when you ALT-TAB out of the full screen window. If that happens you have to release and restore the resources and reset the device. This can be hard to do properly depending on the complexity of the game or the laziness of developers (hi Valve!). I don't think OpenGL suffers from the same problem because the driver is responsible for keeping the OpenGL context for you, but I'm not sure.

There's a question on StackOverflow about the best practices for ALT-TAB support in a DirectX app which includes useful links from MSDN and other sources.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ You're correct, the reason OpenGL doesn't suffer (as much) from this is because the driver keeps a copy of everything for you on Windows. This can cause GL apps to use more RAM than DX apps, but a well-behaved DX app should be caching everything in case it needs to restore its context data anyway, so it amounts to who's responsibility that caching is. \$\endgroup\$
    – Branan
    Commented Oct 26, 2010 at 15:08
  • \$\begingroup\$ That's true (about OpenGL). \$\endgroup\$
    – topright
    Commented Oct 26, 2010 at 22:13
0
\$\begingroup\$

It can be the available amount of free ram. If it is too low, when your game runs, Windows hides most of its services into the swap area (i.e it takes most of the data loaded in RAM and put it in a special area of your hard drive instead) in order for your game to have as mush available RAM space as possible.

Then, when you alt+tab from the game to windows, it needs these services to be loaded in RAM in order to work, so it will take your game data from the RAM, store it in the swap, and pull the windows data from the swap to the RAM.

And as you know, writing to the hard-drive can take AGES compared to the RAM. The same thing actually also happens when you quit a heavy game. That's why having enough RAM space for both a game and windows can be really more comfortable.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .