SDL_Flip in directx

Hi,

In SDL v 1.2 using the directx video driver and a hardware surface, SDL_Flip
saturates the CPU while waiting for the vertical retrace. The culprit is the
following line of code in DX5_FlipHWSurface:

/* to prevent big slowdown on fast computers, wait here instead of

driver ring 0 code /
/
Dmitry Yakimov (ftech at tula.net) */
while(IDirectDrawSurface3_GetFlipStatus(dd_surface, DDGBS_ISBLTDONE) ==
DDERR_WASSTILLDRAWING);

If I comment out that line of code, CPU use of my test app goes from 100% to
50% on both a slow and fast computer. Perhaps this line is a bug.

If I put SDL_Delay( 16) in my main loop, then CPU use goes to nearly zero.
16 ms is my display’s refresh period, so SDL_Delay blocks more efficiently
than IDirectDrawSurface3_Flip.

I conclude that, in oder to operate efficiently, applications must use the
refresh rate to estimate when flipping is ready, since SDL and DirectX do
not seem to do this for you. I can start a timer when SDL_Flip returns, and
work or sleep until the timer exceeds the refresh period. Of course I must
estimate the refresh period first, since I do not see a way to ask the
sytem.

Would appreciate any info about something I might have missed.

Best Regards,

A.J.