]> git.sesse.net Git - nageru/commitdiff
Yield instead of busy-waiting on fences for NVIDIA cards.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 28 Jun 2017 19:34:58 +0000 (21:34 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 28 Jun 2017 19:34:58 +0000 (21:34 +0200)
decklink_output.cpp
quicksync_encoder.cpp

index a19d0a5e2e44440c9f79ad07f860ec629e194c37..d68467703103966942ce730076ab25875008ad5b 100644 (file)
@@ -2,6 +2,7 @@
 #include <movit/util.h>
 #include <movit/resource_pool.h>  // Must be above the Xlib includes.
 #include <pthread.h>
+#include <unistd.h>
 
 #include <mutex>
 
@@ -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();
 
index 1b36aa5246fbda3b19b5e65a5abc48365ab23840..6cab461a98fe37bbb87a5c0e301829fa31162fb2 100644 (file)
@@ -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);