Sign in to follow this  
Trillian

Consequences of losing a device?

Recommended Posts

Hello! I am programming with Direct3D 9 and I know that I should include something to handle a device lost. But I don't think I've actually ever lost a device! And don't say I didn't try, I've played with minimizing and alt-tabbing. Anyways, I'd like to know the following: 1- Under which circonstances may a direct3D device be lost? 2- What are the direct consequences of losing a device (textures, vertex buffers)? Thanks! EDIT: I think I've actually just lost my device! When A messagebox pops in my game while playing fullscreen, I don't seem to be able to continue playing...

Share this post


Link to post
Share on other sites
Games to which I played, when minimized and maximized back, had no problem continuing to work. If the textures and buffers were lost, it should normally take some time before the game loads back every model and so. How do they manage to do this? Do they keep a copy of the data in CPU memory?

Share this post


Link to post
Share on other sites
I don't think they actually lose the device when minimised. I am able to minimise my renderer with no consequences.

Dave

Share this post


Link to post
Share on other sites
hi,

how far I know (I'm working with OGL)
you loose everything not created MANAGED,

btw: have you ever minimized half-life 2 and then returned to
the game, it takes a long time....


Marc

Share this post


Link to post
Share on other sites
If the device was lost when minimised then my textures wouldn't show, but they do. I have no preventative measures in place to reload the textures if a device is lost.

Dave

Share this post


Link to post
Share on other sites
Thanks for all the info, I think I'm going to do like Dave : No preventive measures. This is my first game with direct3D, it's okay if there are some flaws like this, as long as it is playable!

Share this post


Link to post
Share on other sites
You lose a device when:
  • You're fullscreen and another application (including Windows [message boxes]) takes the focus
  • You're in windowed mode and the screen bit depth changes (It's useful to do this to test your resetting code in windowed mode, since debugging is so much easier)

    When you lose a device, all resources stored in D3DPOOL_DEFAULT are trashed, and the device is set back to the same state as when you created it (All render states are reset, all lights, materials, transform matrices are reset, etc).
    Most games will use D3DPOOL_MANAGED for most resources, and the D3D runtime takes care of restoring those resources for you (They keep a copy of the data in system memory). Pre-DX8 applications will need to do that themselfs, and store their own copy of the data in system memory (Managed pools didn't exist pre-DX8).

    The reason some games take a long time to reset after you alt+tab, is that they probably use the default pool, and have to read all the resources from disk. Even if they use the managed pool, they still need to recreate all dynamic resources (Dynamic resources can't be managed), and reset all render states, lights, etc etc.

    If you use a scene graph (Or even just a light wrapper around your D3D device), then you can respond nicely to a reset device, since you'll have a cached copy of all states, lights, materials, etc. Plus, you can create a pure device without any drawbacks, which can give you slightly better performance, and you can avoid redundant SetRenderState()s, etc.

    HTH,
    Steve

    Share this post


    Link to post
    Share on other sites
    WindowsKey+L locks your windows desktop (you need to input your password to unlock it again). It's another quick way to test your lost-device handling code.

    Share this post


    Link to post
    Share on other sites
    Others might say make things managed pool because it will handle the reloading of resources, but I will say that you should create everything with the default pool and handle the reloading yourself.

    Managed pool has limitations*, so if you want to use the feature you have to make the pool default anyways and handle reloading for that one object, so you're gonna need the code anyways. Might as well do it all.

    (*its been a few years but I believe the limitations were dynamic vertex buffers, where the contents of the vertex buffers change every frame, you could not use the managed pool when creating a dynamic vertex buffer.)

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by JoeyBlow2
    Others might say make things managed pool because it will handle the reloading of resources, but I will say that you should create everything with the default pool and handle the reloading yourself.

    Managed pool has limitations*, so if you want to use the feature you have to make the pool default anyways and handle reloading for that one object, so you're gonna need the code anyways. Might as well do it all.

    (*its been a few years but I believe the limitations were dynamic vertex buffers, where the contents of the vertex buffers change every frame, you could not use the managed pool when creating a dynamic vertex buffer.)
    The managed pool does more than just handle restoring lost resources. It also manages swapping resources in and out of video memory. If you use the drfault pool for everything, you have to watch for D3DERR_OUTOFVIDEOMEMORY errors when you create resources, and release some resources to make room, then try to recreate the resource.

    Yes, you can't create dynamic resources in the managed pool, but why would you want to? Dynamic resources are almost always in AGP memory, so both the CPU and GPU can access them, and the data in them isn't persistant, so there's nothing to load into them after you recreate them.

    Share this post


    Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    Sign in to follow this