New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glfwSwapInterval() different behavior on win 8 and centos 7 #603

Open
giordi91 opened this Issue Sep 12, 2015 · 7 comments

Comments

Projects
None yet
3 participants
@giordi91

giordi91 commented Sep 12, 2015

Hi there, I notice and odd behavior during cross compiling my project, I implemented two game loop one that runs as fast as it can one that i lock the thread until is not time to render the next frame, fixed frame rate (60fps).
//lets compute how much we need sleep
long long offset = next_game_tick + Constants::TICKS_PER_FRAME;
long long sleep_time = offset - m_clock->get_ticks();
if (sleep_time >= 0)
{
m_clock->sleep(sleep_time);
}
return;

On centos it works all good and nice with both swap interval set to 0 and 1, on windows instead of reaching 60 fps i reach 30 fps if i have the setIntervalTo 1. I don't think is a glfw bug but I was curious to know if you guys had any Idea of what is going on, Might it be that my call comes right after the lock of glfw of the swap frame so I get twice the lock and so get 30 fps rather then 60? If that the case, any clue why this doesn't happen on Linux?

Cheers

@tombsar

This comment has been minimized.

Show comment
Hide comment
@tombsar

tombsar Sep 12, 2015

Contributor

By default Windows schedules threads in intervals of 15.6ms, so any call to sleep will usually round up to that. If this is the issue, you can try calling a Windows API function to increase the timer resolution: https://msdn.microsoft.com/en-us/library/windows/desktop/dd757624(v=vs.85).aspx

Contributor

tombsar commented Sep 12, 2015

By default Windows schedules threads in intervals of 15.6ms, so any call to sleep will usually round up to that. If this is the issue, you can try calling a Windows API function to increase the timer resolution: https://msdn.microsoft.com/en-us/library/windows/desktop/dd757624(v=vs.85).aspx

@giordi91

This comment has been minimized.

Show comment
Hide comment
@giordi91

giordi91 Sep 12, 2015

Hi since I am cross compiling I am not calling anything OS specific so far, I am using the high resolution clock in nanoscecond introduced in the std library with c++ 11, in the sleep function i just do a dumb while loop until I have not waited enough. (it is more of a lock then a sleep)

template
void Clock::sleep(const long long amount) const
{
const high_res_time_point t = now();
while (get_delta(t) < amount);
{ }
}
So I am not sure if the problem is related to the windows thread scheduling?

giordi91 commented Sep 12, 2015

Hi since I am cross compiling I am not calling anything OS specific so far, I am using the high resolution clock in nanoscecond introduced in the std library with c++ 11, in the sleep function i just do a dumb while loop until I have not waited enough. (it is more of a lock then a sleep)

template
void Clock::sleep(const long long amount) const
{
const high_res_time_point t = now();
while (get_delta(t) < amount);
{ }
}
So I am not sure if the problem is related to the windows thread scheduling?

@tombsar

This comment has been minimized.

Show comment
Hide comment
@tombsar

tombsar Sep 12, 2015

Contributor

Well that does make it less likely, but I wouldn't rule it out without testing.

Only other thing I can suggest is adding debug code to record timestamps at key parts of your program, e.g. frame_begin, input_processed, rendering_finished, etc. That should narrow down which function calls are taking longer than they should.

Contributor

tombsar commented Sep 12, 2015

Well that does make it less likely, but I wouldn't rule it out without testing.

Only other thing I can suggest is adding debug code to record timestamps at key parts of your program, e.g. frame_begin, input_processed, rendering_finished, etc. That should narrow down which function calls are taking longer than they should.

@giordi91

This comment has been minimized.

Show comment
Hide comment
@giordi91

giordi91 Sep 12, 2015

well, I have an "empty" game loop, I am draing a single triangle and that s it, no fancy processing , not even processing inputs etc. if i remove the fps caps run on at 8000 and more FPS, also the computation of the sleep time looks correct since it works fine if I don't have the glfw frame lock.
I mean that s not a problem overall, I am just curious to see if I can find the source of the different behavior. As you might suggest might very well be an OS related thing rather the glfw

giordi91 commented Sep 12, 2015

well, I have an "empty" game loop, I am draing a single triangle and that s it, no fancy processing , not even processing inputs etc. if i remove the fps caps run on at 8000 and more FPS, also the computation of the sleep time looks correct since it works fine if I don't have the glfw frame lock.
I mean that s not a problem overall, I am just curious to see if I can find the source of the different behavior. As you might suggest might very well be an OS related thing rather the glfw

@giordi91

This comment has been minimized.

Show comment
Hide comment
@giordi91

giordi91 Sep 13, 2015

might be useful if I try to create a stripped down example? just the window and the event loop nothing else?

giordi91 commented Sep 13, 2015

might be useful if I try to create a stripped down example? just the window and the event loop nothing else?

@elmindreda

This comment has been minimized.

Show comment
Hide comment
@elmindreda

elmindreda Sep 13, 2015

Member

@giordi91 It might, yes. Also, do you have Aero enabled?

Member

elmindreda commented Sep 13, 2015

@giordi91 It might, yes. Also, do you have Aero enabled?

@elmindreda elmindreda self-assigned this Sep 13, 2015

@giordi91

This comment has been minimized.

Show comment
Hide comment
@giordi91

giordi91 Sep 13, 2015

@elmindreda nope I got solid window borders. I am gonna make a test sample and upload it.
M.

giordi91 commented Sep 13, 2015

@elmindreda nope I got solid window borders. I am gonna make a test sample and upload it.
M.

@elmindreda elmindreda added the waiting label Aug 2, 2016

@elmindreda elmindreda removed their assignment Aug 2, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment