Pavor

Hello!

How should one to determine lost devices in D3D10

Documentation says that we should use

Code Snippet
Present( 0, DXGI_PRESENT_TEST );

But a few lines below we can read the following:

DXGI_PRESENT_TEST is only intended for use when switching from the idle state; do not use it to determine when to switch to the idle state as doing so can leave the swapchain unable to exit fullscreen mode.

Well, the question is -- how to detect that our program must stop rendering and wait until the device is available (to switch to the idle state) keeping in mind the above quote



Re: Direct3D 10 TestCooperativeLevel in D3D10

Ralf Kornmann

The lost of a D3D10 device is an unlikely event but you are right that a good app should even handle this.

As you lost the device and not the swap chain the method you are looking for is in the ID3D10Device interface. If GetDeviceRemovedReason returns something else that S_OK your device is gone.






Re: Direct3D 10 TestCooperativeLevel in D3D10

Pavor

Thanks for the hint ... But what should the application do, when it comes back to rendering, in previous versions we would use the code like this:

Code Snippet

HRESULT hr;
hr=p_d3d_Device->TestCooperativeLevel()))
if(hr==D3DERR_DEVICELOST) return;
if(hr==D3DERR_DEVICENOTRESET) p_d3d_Device->Reset(&d3dpp);

\\ if we get here, everything is OK. Performing rendering.

Is it necessary to reset the device in D3D10

ID3D10Device Interface does not have method called Reset, so the situation in D3D10 is different

Please check my code, and tell me wether will it fly or not

Code Snippet

// Direct3D 10 version

void Render3D ()

{

HRESULT hr;

if FAILED ( p_gD3D10Device->GetDeviceRemovedReason )

g_bDeviceLost = TRUE;

if ( g_bDeviceLost )

// Idle state, checking if

// the device is avaliable

{

if FAILED ( g_pSwapChain->Present (0, DXGI_PRESENT_TEST ) )

return

else

g_bDeviceLost = FALSE;

}

else

// The device is available

{

//Rendering 3D geometry.

g_pSwapChain->Present (0, 0);

}

}

Add:

I tested the above code. It works, but in a strange way: when you switch to another application (Alt+Tab) and back the D3D10 full-screen application becomes windowed. Any suggestions

Additional question: The lost of a D3D10 device is an unlikely event

Why so





Re: Direct3D 10 TestCooperativeLevel in D3D10

Ralf Kornmann

DXGI_STATUS_OCCLUDED and the results of GetDeviceRemovedReason are two different things.

DXGI_STATUS_OCCLUDED tells you only that whatever you draw would not be visible because your window is hidden. The device is still ready and you can ignore DXGI_STATUS_OCCLUDED. ItĄ¯s only a hint to save CPU and GPU work.

The error messages from GetDeviceRemovedReason are more critical as a D3D9 device lost. After such an event the device is in a highly undefined state. The only thing you could do is to shut everything down and create a new device and all resources. But such events require a massive problem in your system. It would only happen after a hardware or driver failure.






Re: Direct3D 10 TestCooperativeLevel in D3D10

Pavor

So, does it mean the device in D3D10 eventually cannot be lost, as it was in D3D9

Again, how to detect the window (the screen) is occluded in case do not use it to determine when to switch to the idle state as doing so can leave the swapchain unable to exit fullscreen mode.

OK. Just give me a hint, how to set fullscreen mode when switching back (Alt+Tab) to my application.

Thanks in advance





Re: Direct3D 10 TestCooperativeLevel in D3D10

Ralf Kornmann

Right the D3D9 lost state doesnĄ¯t longer exist in D3D10.

The occlusion test of present is meant in a way that you should not use to detect that your window is fully hidden. You should only use it to test if your window is visible again after a call to present without the flag have reported that the window is occluded.

Have you tried IDXGISwapChain:Tongue TiedetFullscreenState to toggle between window and full screen mode






Re: Direct3D 10 TestCooperativeLevel in D3D10

Brian Klamik

The basic reason to have D3D10 'device removed' is that some bus types support hot-docking. So, you could conceptually have the adapter card ripped from its socket. In production this will probably be more popular when DX10 laptops/ docking stations arrive. There's a hot-swap scenario that isn't hard to imagine. We advocate apps attempt to save a temporary game before exit and re-spawn; and to try to prevent infinite re-spawn.

D3D9 has it also; but D3D9 overlaps 'device removed' with 'device lost', where Reset will continually fail.

D3D10 converted the typical D3D9 aspect of 'lost device' into 'losing fullscreen', which is a DXGI full-screen swap chain concept. You can lose full-screen in many rare scenarios that will barely be remembered to test for (ie. undock a monitor from multi-mon system, connect to the PC that is running a full-screen app with remote desktop, or another app resizes your display out from underneath you, etc.). After it occurs, you can rely on your user to try to re-claim full-screen (with Alt-Enter, if you invoked IDXGIFactory::MakeWindowAssociation correctly); or attempt to do it manually, like Ralf says. Requesting full-screen does not mean you'll get it. There are some rare scenarios where you'll never be able to acquire full-screen. If I remember correctly, you can't acquire full-screen in a remote desktop session with 8bpp pixel modes. Super rare stuff like that.






Re: Direct3D 10 TestCooperativeLevel in D3D10

Pavor

Thank you for your comprehensive answer..

It seems I need to learn more about IDXGIFactory::MakeWindowAssociation.

In my application setting the fullscreen mode is the same as for windowed app, with one exception:

Code Snippet

// Setting fullscreen property

SwapChainDesc.Windowed = FALSE;

Now I think I should add after the Device and SwapChain are created something like this:

Code Snippet

IDXGIFactory * pFactory;
HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)(&pFactory) );

pFactory->MakeWindowAssociation( hOurWindowHandle, 0);

Please add some comments to this code, if you'll have some time and..

thank you again.


PS:

By the way, the surface format is:

SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;

And display settings are 32bpp