Understanding VSync and Mouse lag

Holyfish

Newcomer
Hi,

Today I've been looking into a problem I have for some time now and which seems to be a pretty general problem if I google about it: serious mouselag when enabling VSync. I did some reading about it and I think I finally understand what is going wrong, although I still fail to fix the problem.

The cullprit is the Directx command buffer, which is sometimes filled a lot faster by the CPU than the GPU can follow. The frames the GPU outputs are thus lagging behind the CPU.
Looking into the Directx helpfiles it should be possible to flush the command buffers (I realise this is not something you should do in practice) by using a DirectX Event query, issue a D3DISSUE_END just before EndScene() and "while-looping" until the needed data for the current frame is available right after Present(). Though, this doesn't seem to work for me.

I created a very simple test program which creates a fullscreen app with D3DPRESENT_INTERVAL_FOUR as presentationinterval (the problem is very noticable here), it renders the hardware cursor and an "X" symbol which is rendered by the GPU ( and which should be on the same spot as the mousecursor). Moving the mouse around clearly shows the problem (the "X" lags behind the mouse).

A link to the the code (VS2008 solution) and executable are hosted here: http://docs.google.com/uc?id=0B0ndu...WFjN2QtYTJlNjAwMjFkYzdm&export=download&hl=nl

Perhaps someone here knows another way of purging the command buffer? Does anyone have experience with this problem and perhaps knows has a solution?


Thanks a lot in advance!
Bert.
 
I don't know but in games where I get mouse lag with vsync I use a framerate cap of say 55fps and the lag is gone as long as my framerate doesn't drop below that.
 
DirectX buffers up to three frames. If you need to eliminate mouse lag you can indeed use the event query method. I have used that in the past with great success. I don't know how it works with a present interval of four, never tried to use anything else than 0 and 1, and quite frankly don't know why anyone would use anything else.

These days you could also use these methods:
IDirect3DDevice9Ex::SetMaximumFrameLatency()
IDXGIDevice1::SetMaximumFrameLatency()

I haven't tried them, so YMMV.
 
Hi, thanks for your reply.

I tried creating a IDirect3DDevice9Ex (wasn't even aware that existed), but even with SetMaximumFrameLatency(1) I have the mouse latency.
So you say that you managed to completely eliminate the mouselag with the event query method? I'm really curious about what I'm doing wrong then...

I also have the mouselag using other present intervals, but with present interval four the lag is more obvious hence the choice.
 
Back
Top