From: Steinar H. Gunderson Date: Wed, 28 Jun 2017 19:34:58 +0000 (+0200) Subject: Yield instead of busy-waiting on fences for NVIDIA cards. X-Git-Tag: 1.6.1~22 X-Git-Url: https://git.sesse.net/?p=nageru;a=commitdiff_plain;h=fdf765b229349a1d1a30414341957a4d10a0b6c9 Yield instead of busy-waiting on fences for NVIDIA cards. --- diff --git a/decklink_output.cpp b/decklink_output.cpp index a19d0a5..d684677 100644 --- a/decklink_output.cpp +++ b/decklink_output.cpp @@ -2,6 +2,7 @@ #include #include // Must be above the Xlib includes. #include +#include #include @@ -543,7 +544,15 @@ void DeckLinkOutput::present_thread_func() ++metric_decklink_output_inflight_frames; } - glClientWaitSync(frame->fence.get(), /*flags=*/0, GL_TIMEOUT_IGNORED); + for ( ;; ) { + int err = glClientWaitSync(frame->fence.get(), /*flags=*/0, 0); + if (err == GL_TIMEOUT_EXPIRED) { + // NVIDIA likes to busy-wait; yield instead. + this_thread::sleep_for(milliseconds(1)); + } else { + break; + } + } check_error(); frame->fence.reset(); diff --git a/quicksync_encoder.cpp b/quicksync_encoder.cpp index 1b36aa5..6cab461 100644 --- a/quicksync_encoder.cpp +++ b/quicksync_encoder.cpp @@ -1981,8 +1981,12 @@ void QuickSyncEncoderImpl::pass_frame(QuickSyncEncoderImpl::PendingFrame frame, // Wait for the GPU to be done with the frame. GLenum sync_status; do { - sync_status = glClientWaitSync(frame.fence.get(), 0, 1000000000); + sync_status = glClientWaitSync(frame.fence.get(), 0, 0); check_error(); + if (sync_status == GL_TIMEOUT_EXPIRED) { + // NVIDIA likes to busy-wait; yield instead. + this_thread::sleep_for(milliseconds(1)); + } } while (sync_status == GL_TIMEOUT_EXPIRED); assert(sync_status != GL_WAIT_FAILED);