Skip to content

Commit

Permalink
Update gfx_sdl2.cpp to fix macOS Metal Slowdown. (#807)
Browse files Browse the repository at this point in the history
Fixes stutter/inability to lock 60 consistently on macOS using Metal. May also provide performance benefits under OpenGL and Linux. This is the weird 57-58 fps issue noticed on Metal graphics on Macs for a long while.

Thanks to @Spodi, @Malkierian, ProxySaw, and Fenrir for their help on Discord getting this figured out! :D
  • Loading branch information
ReddestDream authored Jan 31, 2025
1 parent 50eb906 commit e641b37
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/graphic/Fast3D/gfx_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ static inline void sync_framerate_with_timer() {

const int64_t next = previous_time + 10 * FRAME_INTERVAL_US_NUMERATOR / FRAME_INTERVAL_US_DENOMINATOR;
int64_t left = next - t;
#ifdef _WIN32
#if defined(_WIN32) || defined(__APPLE__)
// We want to exit a bit early, so we can busy-wait the rest to never miss the deadline
left -= 15000UL;
#endif
Expand All @@ -632,10 +632,14 @@ static inline void sync_framerate_with_timer() {
#endif
}

#ifdef _WIN32
#if defined(_WIN32) || defined(__APPLE__)
t = qpc_to_100ns(SDL_GetPerformanceCounter());
while (t < next) {
YieldProcessor(); // TODO: Find a way for other compilers, OSes and architectures
#ifdef _WIN32
YieldProcessor();
#elif defined(__APPLE__)
sched_yield();
#endif
t = qpc_to_100ns(SDL_GetPerformanceCounter());
}
#endif
Expand Down

0 comments on commit e641b37

Please sign in to comment.