Windows timer resolution change from SDL 1.2

Hi,
I noticed SDL2 leaves the Windows timer resolution alone, so SDL_Delay(1)
will sleep for ~15ms (on recent windows versions, afaik), whereas SDL 1.2
set the resolution to 1ms at startup (in SDL_StartTicks).

This is different from both OS X 10.10 and Ubuntu 14.04, where I’m seeing
~1ms resolution for SDL_Delay(1) with SDL2 from hg.

Just wondering if it’s planned to leave SDL2/Windows with the default 15ms
resolution?

I’m aware that timeBeginPeriod(1) is frowned upon due to the increased
power usage (e.g. in this blog post


), but even that article points out that timeBeginPeriod(1) + Sleep(1) are
useful for throttling games to 30 FPS. In my case, I help maintain some
legacy code that uses SDL_Delay(1) to throttle a mainloop to 72fps
(Quakespasm).

I think it might be nice to bring the default resolution up to 1ms on
SDL2/Windows, matching the other platforms, and maybe have a hint to
request not to do that for low-power games.
Thoughts? I could put together a patch for that if there’s interest.

Cheers,
Eric

PS. I came across the 1ms->15ms change when investigating this buffer
underrun issue with directsound (
https://bugzilla.libsdl.org/show_bug.cgi?id=2944 ).

I was going to point out that SDL 2 does use timeBeginPeriod to set the timer resolution to 1ms (and there?s a SDL hint to change that as well - SDL_HINT_TIMER_RESOLUTION) but I double-checked the source code and apparently timeBeginPeriod is only ever used if Windows? QueryPerformanceFrequency function doesn?t return successfully… https://hg.libsdl.org/SDL/file/tip/src/timer/windows/SDL_systimer.c#l83 https://hg.libsdl.org/SDL/file/tip/src/timer/windows/SDL_systimer.c#l83

That codepath also means that SDL_HINT_TIMER_RESOLUTION doesn?t actually do anything at all unless QueryPerformanceCounter fails, which isn?t what I expected (since the timer resolution also affects SDL_Delay, not just SDL_GetTicks.)> On Apr 14, 2015, at 8:29 PM, Eric Wasylishen wrote:

Hi,
I noticed SDL2 leaves the Windows timer resolution alone, so SDL_Delay(1) will sleep for ~15ms (on recent windows versions, afaik), whereas SDL 1.2 set the resolution to 1ms at startup (in SDL_StartTicks).

2015-04-14 20:40 GMT-03:00, Alex Szpakowski :

I was going to point out that SDL 2 does use timeBeginPeriod to set the
timer resolution to 1ms (and there?s a SDL hint to change that as well -
SDL_HINT_TIMER_RESOLUTION) but I double-checked the source code and
apparently timeBeginPeriod is only ever used if Windows?
QueryPerformanceFrequency function doesn?t return successfully…
https://hg.libsdl.org/SDL/file/tip/src/timer/windows/SDL_systimer.c#l83
https://hg.libsdl.org/SDL/file/tip/src/timer/windows/SDL_systimer.c#l83

That codepath also means that SDL_HINT_TIMER_RESOLUTION doesn?t actually do
anything at all unless QueryPerformanceCounter fails, which isn?t what I
expected (since the timer resolution also affects SDL_Delay, not just
SDL_GetTicks.)

That’d mean that either the scheduler is way more accurate than I
thought or something else is calling it, because when I messed with it
SDL_Delay(1) would not cause my game to miss frames no matter what
(and we know how SDL_Delay can easily wreck timing, since the value
passed is the minimum wait).

Ryan Gordon has pushed some commits to SDL today which fix this, I think.> On Apr 14, 2015, at 8:40 PM, Alex Szpakowski <@Alex_Szpakowski> wrote:

I was going to point out that SDL 2 does use timeBeginPeriod to set the timer resolution to 1ms (and there?s a SDL hint to change that as well - SDL_HINT_TIMER_RESOLUTION) but I double-checked the source code and apparently timeBeginPeriod is only ever used if Windows? QueryPerformanceFrequency function doesn?t return successfully… https://hg.libsdl.org/SDL/file/tip/src/timer/windows/SDL_systimer.c#l83 https://hg.libsdl.org/SDL/file/tip/src/timer/windows/SDL_systimer.c#l83

That codepath also means that SDL_HINT_TIMER_RESOLUTION doesn?t actually do anything at all unless QueryPerformanceCounter fails, which isn?t what I expected (since the timer resolution also affects SDL_Delay, not just SDL_GetTicks.)

On Apr 14, 2015, at 8:29 PM, Eric Wasylishen <ewasylishen at gmail.com <mailto:ewasylishen at gmail.com>> wrote:

Hi,
I noticed SDL2 leaves the Windows timer resolution alone, so SDL_Delay(1) will sleep for ~15ms (on recent windows versions, afaik), whereas SDL 1.2 set the resolution to 1ms at startup (in SDL_StartTicks).

Ryan Gordon has pushed some commits to SDL today which fix this, I think.

Thanks, the resolution on Windows now defaults to 1ms, and SDL_HINT_TIMER_RESOLUTION
can be used to raise that, so that addresses my concerns :-)On Mon, Apr 20, 2015 at 1:17 PM, Alex Szpakowski wrote: