From 619a76fadda466e02ff89e18a12411d420f148be Mon Sep 17 00:00:00 2001 From: Andreas Edlund Date: Fri, 20 Nov 2026 19:04:45 +0100 Subject: [PATCH] fix(linux): allow NvFBC direct capture to attach after startup Remove the startup probe in cuda::nvfbc::display_t::reinit() that ran three immediate NOWAIT grabs and disabled bAllowDirectCapture and bPushModel whenever bDirectCapture was false. That probe failed both when no fullscreen application was active at session startup and when consecutive NOWAIT grabs completed before a new frame arrived, permanently preventing direct capture for the rest of the session. Per NvFBC.h, NvFBC automatically attaches and detaches from suitable fullscreen applications while direct capture remains enabled and falls back to X driver desktop frames in between. --- src/platform/linux/cuda.cpp | 45 ------------------------------------- 1 file changed, 45 deletions(-) diff --git a/src/platform/linux/cuda.cpp b/src/platform/linux/cuda.cpp index 8f3613d2f03..684b6d38523 100644 --- a/src/platform/linux/cuda.cpp +++ b/src/platform/linux/cuda.cpp @@ -1803,51 +1803,6 @@ namespace cuda { return platf::capture_e::capture_error; } - // If trying to capture directly, test if it actually does. - if (capture_params.bAllowDirectCapture) { - CUdeviceptr device_ptr; - NVFBC_FRAME_GRAB_INFO grab_info; - - NVFBC_TOCUDA_GRAB_FRAME_PARAMS grab { - NVFBC_TOCUDA_GRAB_FRAME_PARAMS_VER, - NVFBC_TOCUDA_GRAB_FLAGS_NOWAIT, - &device_ptr, - &grab_info, - 0, - }; - - // Direct Capture may fail the first few times, even if it's possible - for (int x = 0; x < 3; ++x) { - if (auto status = func.nvFBCToCudaGrabFrame(handle.handle, &grab)) { - if (status == NVFBC_ERR_MUST_RECREATE) { - return platf::capture_e::reinit; - } - - BOOST_LOG(error) << "Couldn't capture nvFramebuffer: "sv << handle.last_error(); - - return platf::capture_e::capture_error; - } - - if (grab_info.bDirectCapture) { - break; - } - - BOOST_LOG(debug) << "Direct capture failed attempt ["sv << x << ']'; - } - - if (!grab_info.bDirectCapture) { - BOOST_LOG(debug) << "Direct capture failed, trying the extra copy method"sv; - // Direct capture failed - capture_params.bPushModel = nv_bool(false); - capture_params.bWithCursor = nv_bool(false); - capture_params.bAllowDirectCapture = nv_bool(false); - - if (handle.stop() || handle.capture(capture_params)) { - return platf::capture_e::capture_error; - } - } - } - return platf::capture_e::ok; }