• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
nicolausYes

Direct3D 10 vsync problem in window mode with DWM disabled

9 posts in this topic

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.
[url="http://bit.ly/POQoFq"]http://bit.ly/POQoFq[/url]

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).
[url="http://bit.ly/SevNqw"]http://bit.ly/SevNqw[/url]
[url="http://bit.ly/RSoEhc"]http://bit.ly/RSoEhc[/url]
[url="http://bit.ly/UjaNPu"]http://bit.ly/UjaNPu[/url]

[b]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.[/b]

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
0

Share this post


Link to post
Share on other sites
[CODE]
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
[/CODE]

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

[quote]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.[/quote]
0

Share this post


Link to post
Share on other sites
[quote name='mhagain' timestamp='1352722265' post='5000205']
[CODE]
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
[/CODE]

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 [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ee417025%28v=vs.85%29.aspx"]http://msdn.microsof...5(v=vs.85).aspx[/url]

[quote]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.[/quote]
[/quote]

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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
[quote name='Erik Rufelt' timestamp='1352727790' post='5000229']
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.
[/quote]

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
0

Share this post


Link to post
Share on other sites
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:
[CODE]
#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);
}
[/CODE] Edited by Erik Rufelt
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
[quote name='Erik Rufelt' timestamp='1352727790' post='5000229']
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.
[/quote]

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.
0

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  
Followers 0