[DX9] Vsync Lag

Started by
12 comments, last by Armion 13 years, 8 months ago
Quote:Original post by Armion
@Matias Goldberg: Hmm... I will test if there is any error in my arguments when creating the fullscreen. Could this be related to the Ex version of interfaces and calls(IDirect3DDevice9Ex, PresentEx())?

I don't think so.
The problem is basically when the device doesn't like the arguments for the backbuffer format you passed for the actual resolution you end up using (i.e. wrong refresh rate or bpp colour).

Quote:Original post by Armion
I don't think low fps is the problem - getting more than 4000 with D3DPRESENT_INTERVAL_IMMEDIATE - my app is just rendering its own cursor below the real one.(Unreal Tournament, Battlefield 2 Bad Company)

Oh I see, I thought this problem appeared when you were low on fps with VSync enabled.

Quote:Original post by Armion
- limiting your fps to one or two below the refresh rate - let's say 58fps for 60Hz refresh rate... And it works like a charm. Can someone explain to me this STRANGE behavior?

Well, I'm not sure if I get what exactly you're doing, but seems you're clamping the FPS through the CPU. I can only guess with +60fps present() takes time inside the driver, while having 58-59fps makes present() returns almost immediately except for occasional nano- or milliseconds delay to synchronize with the monitor's refresh; which makes your timing response somehow more accurate. I'm only guessing

There's something I don't understand though about how you're rendering the cursor.
If I understand correctly, you're letting the window's default cursor to show on top of the in window, and at the same time you're drawing a quad with your own cursor. Then use a function like GetCursorPos() to draw it in the same position the hardware cursor should be?
How exactly are you doing this?
Advertisement
Hi Matias :)

As you can see in the source code above i fill my D3DPRESENT_PARAMETERS structure with the following code:

D3DPRESENT_PARAMETERS d3dpp;	d3dpp.BackBufferWidth            = width;	d3dpp.BackBufferHeight           = height;	d3dpp.BackBufferFormat           = D3DFMT_A8R8G8B8;	d3dpp.BackBufferCount            = 1;	d3dpp.MultiSampleType            = D3DMULTISAMPLE_NONE;	d3dpp.MultiSampleQuality         = 0;	d3dpp.SwapEffect                 = D3DSWAPEFFECT_DISCARD; 	d3dpp.hDeviceWindow              = hwnd;	d3dpp.Windowed                   = windowed;	d3dpp.EnableAutoDepthStencil     = true; 	d3dpp.AutoDepthStencilFormat     = D3DFMT_D24S8;	d3dpp.Flags                      = 0;	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;	d3dpp.PresentationInterval       = D3DPRESENT_INTERVAL_ONE;


What part of it could be the problem? Checking the created device with PIX the only strange thing i see is that Windowed is set to true if we have specified fullscreen. Still i guess this interesting thing is happening because of the internal workings of PIX - even if i force Windowed to false Pix still tells me that Windowed is false. So i can't really see what could be messing with my application for i-don't-know-how-much-time. I tried playing with the settings and the once that gave me problems didn't return S_OK when creating the device so even if i wanted i couldn't use them.

For your next assumption - yes, clamping the FPS through CPU remedies the problem in fullscreen. Windowed mode still lags but it's not as bad as before.

As for how i'm rendering the cursor:
The windows cursor is on. Additionally that's what i'm doing in my render procedure:
// This source is almost the same as the in the book of Frank Luna,// called Introduction to 3D Game Programming With DirectX 9.0// For complete source code see my first post - 3rd code fileDevice->Clear(some parameters);Device->BeginScene();//Get the current cursor position according to screen coordinates//Render a texture representing a second cursor in that exact placeDevice->EndScene();Device->Present(0, 0, 0, 0);


No matter how i think about it in the worst case scenario the difference in the position should be at most 1/60 of the second. I don't see how the difference in time between moment 2 and 3 can be more that.
moment 1: Present() at retrace period
moment 2: Render cursor
moment 3: Present() at retrace period

And still the drawn cursor is lagging behind...
About the fullscreen <-> Win7 issue, seems we can discard that as a problem.

But regarding my questions with mouse cursor, you haven't answered anything meaningful.
For example you say:
Quote:It's only polling the cursor position

You said you're not using WM_CURSOR, ok, then HOW are you polling the cursor? What function? GetMouseCursorPos? Are you using DirectInput?
I'm sorry i've misunderstood you :) Here is the code you asked for:

		POINT coords;	::GetCursorPos(&coords);	::ScreenToClient(handle, &coords);	RECT client;	GetClientRect(handle, &client); 	// This works correctly for windowed	D3DXVECTOR3 pos(coords.x, coords.y, 0);	sprite->Begin(D3DXSPRITE_ALPHABLEND);	HRESULT test = sprite->Draw(texture, 0, 0, &pos, 0xFFFFFFFF);	sprite->End();


[Edited by - Armion on August 21, 2010 5:10:59 PM]

This topic is closed to new replies.

Advertisement