Jump to content

  • Log In with Google      Sign In   
  • Create Account

Direct3D 10 vsync problem in window mode with DWM disabled


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 nicolausYes   Members   -  Reputation: 168

Like
0Likes
Like

Posted 12 November 2012 - 05:14 AM

I've got a problem with vsync on Direct3D 10 in window mode with DWM disabled.

We have an application, that render and present some output. It have to work in window mode and it have to produce stable 60 fps minimum.
One version of application is using Direct3D 9 and another Direct3D 10. When we are working in window mode, sometimes we have fps decrease (it's not "stable" decrease. For most of time we are producing stable 60 fps, sometimes it suddenly decrease for several seconds and then getting back to 60 fps). On both version of application fps decrease is ~10-20 fps. It's unacceptable.

In Windows Vista and Windows 7 there are new graphic system, called "desktop composition", that changed the way applications display pixels on the screen. Desktop composition is performed by the Desktop Window Manager (DWM). You know, when DWM is enabled, applications draw into off-screen surfaces in video memory, than it rendered by DWM and presented onto display in some time. So, we noticed, when dwm.exe in Task manager don't do anything (have ~0% process time), we have fps decrease and when dwm.exe takes 1-3% process time there are stable 60 fps and all is ok.

We can't influence on it. So, we have to turn DWM off in order to have high stable fps. When we turn it off, all is ok. There are stable 60 fps on both versions of application. But DWM do the vsync in window mode, so when we turn it off, we have to do vsync by ourselves.
But when we turn DWM off, there is a problem with vsync in Direct3D 10 in window mode. There are image tearing in top of a monitor. Direc3D 9 keeps working well.

So, we have a monitor with 60 Hz refresh rate.

While creating swapchain, we set such params:
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;

And while presenting we set a flag to turn vsync on:
m_pSwapChain->Present( 1, 0 );

And have the next vsync problem. There are vertical lines, that are moving fast from left side to right. And there is image tearing in the top of a monitor.
http://bit.ly/POQoFq

At first we think, that we are doing something wrong. So I installed Microsoft's sample "Tutorial 07: Texture Mapping and Constant Buffers" with rotating cube. Made cube bigger, placed it higher, made it to rotate faster and got the same problem (see pictures).
http://bit.ly/SevNqw
http://bit.ly/RSoEhc
http://bit.ly/UjaNPu

So, on Direct3D 10 in fullscreen mode all is ok. Vsync works perfectly. On Direct3D 9 it's all ok too, with DWM disabled or enabled, vsync works good. On Direct3D 10 in window mode with DWM disabled there are problems.

It was tested on different computers, different videocards (Nvidia 8600 GT, Nvidia 9500 GT, ATI Radeon HD 5870 Eyefinity 6) and different versions of drivers. Problem stably reproduced. We are using Windows 7.


So, why there is such problem? How to solve it and what to do next?

UPD1. If images above are unavailable, there are some mirrors.

https://dl.dropbox.com/u/20468014/DSC_2287.JPG
https://dl.dropbox.com/u/20468014/DSC_2308.JPG
https://dl.dropbox.com/u/20468014/DSC_2313.JPG
https://dl.dropbox.com/u/20468014/DSC_2319.JPG

UDP2. I want also to notice, that I'm creating window with the flag WS_POPUP in order to hide title bar (it has to be hidden). Image tearing appears in different places. It's always in the top of a screen, but it can be on 20 px, and can be on 50 px. So, while creating window with title bar, image tearing sometimes can be simply not visible with the top part of image.

Edited by nicolausYes, 14 November 2012 - 04:57 AM.


Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 7976

Like
0Likes
Like

Posted 12 November 2012 - 06:11 AM

swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;

Are these values coming from a mode that you actually enumerate (via IDXGIOutput::GetDisplayModeList) or did you just assume that you were going to run on a 60hz monitor? It's quite important that they be the former; see http://msdn.microsoft.com/en-us/library/windows/desktop/ee417025%28v=vs.85%29.aspx

Often, developers choose 60 Hz as the refresh rate, not knowing that the enumerated refresh rate from the monitor is approximately 60,000 / 1,001 Hz from the monitor.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 nicolausYes   Members   -  Reputation: 168

Like
0Likes
Like

Posted 12 November 2012 - 07:23 AM

swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;

Are these values coming from a mode that you actually enumerate (via IDXGIOutput::GetDisplayModeList) or did you just assume that you were going to run on a 60hz monitor? It's quite important that they be the former; see http://msdn.microsof...5(v=vs.85).aspx

Often, developers choose 60 Hz as the refresh rate, not knowing that the enumerated refresh rate from the monitor is approximately 60,000 / 1,001 Hz from the monitor.


I was sure, that I'm going to run on 60hz monitor and manually set Numerator to 60 in order not to choose wrong mode programatically. Also, I run programm it in debug mode first and made sure, that monitor support this mode.

#4 Erik Rufelt   Crossbones+   -  Reputation: 3479

Like
0Likes
Like

Posted 12 November 2012 - 07:43 AM

I've noticed this problem too. VSync simply doesn't seem to work that well in window mode, which is strange. You can try manually waiting for vsync with IDXGIOutput::WaitForVBlank and Present(0, 0), or by using DirectDraw vsync methods, though I'm not sure if it will make a difference.

#5 nicolausYes   Members   -  Reputation: 168

Like
0Likes
Like

Posted 12 November 2012 - 09:32 AM

I've noticed this problem too. VSync simply doesn't seem to work that well in window mode, which is strange. You can try manually waiting for vsync with IDXGIOutput::WaitForVBlank and Present(0, 0), or by using DirectDraw vsync methods, though I'm not sure if it will make a difference.


Thanks for reply! I've just tried:
[source lang="cpp"]m_pOutput->WaitForVBlank();m_pSwapChain->Present( 0, 0 );[/source]
The same problem.

Edited by nicolausYes, 12 November 2012 - 09:33 AM.


#6 Erik Rufelt   Crossbones+   -  Reputation: 3479

Like
0Likes
Like

Posted 12 November 2012 - 11:11 AM

I just tried this myself, and I get the same problem as you with DXGI. However, I get correct behavior using DirectDraw (for vsync only, drawing with D3D11 / DXGISwapChain.

You can try it like this:
#include <ddraw.h>

typedef HRESULT (WINAPI * PFNDIRECTDRAWCREATE)(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnknown FAR* pUnkOuter);

load() {
	HMODULE hDDrawLib = LoadLibrary(TEXT("ddraw.dll"));
	if(hDDrawLib == NULL) {
		// fail
	}

	PFNDIRECTDRAWCREATE pDirectDrawCreate = (PFNDIRECTDRAWCREATE)GetProcAddress(hDDrawLib, "DirectDrawCreate");
	if(pDirectDrawCreate == NULL) {
		// fail
	}

	LPDIRECTDRAW pDDraw;
	HRESULT hResult = pDirectDrawCreate(NULL, &pDDraw, NULL);
	if(FAILED(hResult)) {
		// fail
	}
}

vsync() {
	pDDraw->WaitForVerticalBlank(DDWAITVB_BLOCKEND, NULL);
	pDDraw->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL);
}

vsync_alternative() {
	BOOL vb = TRUE;
	while(vb == TRUE)
		pDDraw->GetVerticalBlankStatus(&vb);
	while(vb == FALSE)
		pDDraw->GetVerticalBlankStatus(&vb);
}

release() {
	pDDraw->Release();
	FreeLibrary(hDDrawLib);
}

loop() {
	vsync();
	pSwapChain->Present(0, 0);
}

Edited by Erik Rufelt, 12 November 2012 - 11:15 AM.


#7 nicolausYes   Members   -  Reputation: 168

Like
0Likes
Like

Posted 14 November 2012 - 04:48 AM

Erik Rufelt, I've just tried on Microsoft's sample, still doesn't work( Vsync is working, but I can steel see image tearing.

[source lang="cpp"]#pragma comment( lib, "ddraw.lib " )#pragma comment( lib, "dxguid.lib" )#include <ddraw.h>// ...HRESULT InitDevice(){ // ... // Create DirectDraw device hr = DirectDrawCreateEx( NULL, (LPVOID*) &amp;amp;amp;g_pDevice7, IID_IDirectDraw7, NULL ); hr = g_pDevice7->SetCooperativeLevel( g_hWnd, DDSCL_NORMAL ); // ...}//...void Render(){ // ... // Do vsync g_pDevice7->WaitForVerticalBlank(DDWAITVB_BLOCKEND, NULL); g_pDevice7->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL); g_pSwapChain->Present( 0, 0 );}[/source]

I want also to notice, that I'm creating a window with flag WS_POPUP in order to hide title bar (it has to be hidden). Image tearing appears in different places. It's always in the top of a screen, but it can be on 20 px, and can be on 50 px. So, while creating window with title bar, image tearing sometimes can be simply not visible with the top part of image. And when I' m creating window without title bar, I can always see image tearing.
[source lang="cpp"]g_hWnd = CreateWindow( L"TutorialWindowClass", L"Direct3D 10 Tutorial 7", WS_POPUP | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance, NULL );[/source]

Edited by nicolausYes, 14 November 2012 - 04:59 AM.


#8 Erik Rufelt   Crossbones+   -  Reputation: 3479

Like
0Likes
Like

Posted 14 November 2012 - 05:46 AM

Try adding ID3D10Device::Flush() before vsyncing.

#9 Erik Rufelt   Crossbones+   -  Reputation: 3479

Like
0Likes
Like

Posted 14 November 2012 - 05:51 AM

Actually, when I test it now.. Flush() solves the problem with DXGI vsync too. I'm surprised, I would have assumed Present did that optimally if called with vsync...
(I test with D3D11, but should work the same).

There's probably a good reason why this happens, as it works well in fullscreen mode without flushing. I would only use Flush and WaitForVBlank() when in window mode, to avoid messing with driver frame buffering.. and Present(1, 0) in fullscreen.. though I'm just guessing at this point.

Edited by Erik Rufelt, 14 November 2012 - 05:59 AM.


#10 Endemoniada   Members   -  Reputation: 312

Like
0Likes
Like

Posted 14 November 2012 - 11:03 PM

I've noticed this problem too. VSync simply doesn't seem to work that well in window mode, which is strange. You can try manually waiting for vsync with IDXGIOutput::WaitForVBlank and Present(0, 0), or by using DirectDraw vsync methods, though I'm not sure if it will make a difference.


Hi, I have the opposite effect. I am getting excellent stability in both windowed and fullscreen with vsync enabled, and jerkiness with it disabled. It's something I really don't understand.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS