Repository navigation
fix(linux): allow NvFBC direct capture to attach after startup - #6199
medialaxis wants to merge 3 commits into
Conversation
|
4d4eadd to
9ca55fd
Compare
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.
9ca55fd to
689e13b
Compare
ReenigneArcher
left a comment
There was a problem hiding this comment.
The change preserves late attachment by keeping direct capture enabled for the cursor-free session. A temporary fake-driver harness reproduced the startup fallback on master and passed on this head. Please add the regression test and update the session documentation.
The patch applies cleanly to current master and ClangFormat passed. GitHub marked CI, common lint, and CodeQL action_required before any jobs ran. I could verify Sunshine’s startup behavior with the fake driver. Live NVIDIA X11 attachment remains covered by the manual test described in the PR.
Review completed by Codex | Model: gpt-6.2-sol | Thinking: xhigh
| } | ||
| } | ||
|
|
||
| return platf::capture_e::ok; |
There was a problem hiding this comment.
[P2] Cover cursor-free NvFBC startup with a regression test
The behavior this patch changes is under Sunshine’s control. When the first desktop frames are indirect, Sunshine must create one cursor-free session, keep direct capture and push mode enabled, and leave the first grab to the capture loop. The hardware run checks that the driver attaches later. A fake function table can catch Sunshine recreating the session and disabling direct capture before that happens.
In tests/unit/platform/linux/test_cuda.cpp, add this case under SUNSHINE_BUILD_CUDA. Wire fake_nvfbc_driver_t::reinit() to the real display_t::reinit() through a small test entry point in cuda.cpp that accepts an NvFBC function table. The fake should record nvFBCCreateCaptureSession parameters, return success from setup and teardown, and return a successful grab with the configured bDirectCapture value.
TEST(NvFbcCaptureSessionTest, KeepsDirectCaptureEnabledWhenStartingOnDesktop) {
fake_nvfbc_driver_t driver;
driver.direct_capture = NVFBC_FALSE;
ASSERT_EQ(driver.reinit(false), platf::capture_e::ok);
ASSERT_EQ(driver.sessions.size(), 1U);
EXPECT_EQ(driver.sessions.front().bAllowDirectCapture, NVFBC_TRUE);
EXPECT_EQ(driver.sessions.front().bPushModel, NVFBC_TRUE);
EXPECT_EQ(driver.sessions.front().bWithCursor, NVFBC_FALSE);
EXPECT_EQ(driver.grab_calls, 0U);
}Run ./cmake-build-linux/tests/test_sunshine --gtest_filter='NvFbcCaptureSessionTest.*' from the repo root with a CUDA-enabled Linux build in cmake-build-linux. I verified the startup assertions in a temporary C++ harness around the exact method body. master made three grabs and created two sessions, while this head made zero grabs and created one session. The proposed GoogleTest fixture still needs to be integrated and run.
Review completed by Codex | Model: gpt-6.2-sol | Thinking: xhigh
There was a problem hiding this comment.
Added cuda::test::reinit_nvfbc_display() and NvFbcCaptureSessionTest.KeepsDirectCaptureEnabledWhenStartingOnDesktop in 241c4e3. Verified locally with a CUDA-enabled Linux build (./cmake-build-linux/tests/test_sunshine --gtest_filter=NvFbcCaptureSessionTest.*, 1/1 passed).
| } | ||
|
|
||
| return platf::capture_e::ok; | ||
| } |
There was a problem hiding this comment.
[P3] Document why the session keeps direct capture enabled
With the probe gone, cursor-free sessions deliberately keep push mode enabled even when the desktop is supplying indirect frames. Update the existing Doxygen block immediately above display_t::reinit() so a future change to this setup preserves late attachment and accounts for the driver’s desktop frame cadence.
/**
* @brief Create the NvFBC session for the current cursor visibility.
*
* With the cursor hidden, keep push mode and direct capture enabled so NvFBC
* can attach to a fullscreen application after startup. The driver supplies
* desktop frames on damage events while direct capture is inactive.
*
* @param cursor Whether to composite the mouse cursor into captured frames.
* @return Capture status for session creation.
*/Review completed by Codex | Model: gpt-6.2-sol | Thinking: xhigh
There was a problem hiding this comment.
Updated the display_t::reinit() Doxygen block in 9b8dd21.
|



Description
Remove the 3-frame
NVFBC_TOCUDA_GRAB_FLAGS_NOWAITstartup probe incuda::nvfbc::display_t::reinit()that disabledbAllowDirectCaptureandbPushModel(and recreated the capture session) whenevergrab_info.bDirectCapturewas not immediately true.That probe prevented NvFBC direct capture in two common cases when cursor capture is disabled:
NOWAITgrabs can execute within the same millisecond—returning one initial non-direct frame followed by twoNo new frameresults before the application presents—triggering an immediate fallback to non-direct desktop capture.bAllowDirectCapturefor the rest of the session and NvFBC can never attach once a fullscreen application starts.Per
third-party/nvfbc/NvFBC.h, whenbAllowDirectCaptureandbPushModelremain enabled (withbWithCursor = NVFBC_FALSE), the NVIDIA X driver automatically attaches to a qualifying fullscreen unoccluded application and transparently resumes X-driver desktop frame generation when it detaches.Trade-off: when cursor capture is disabled and direct capture is not attached,
bPushModelstaysNVFBC_TRUE(a prerequisite forbAllowDirectCapture), so the NVIDIA X driver generates desktop frames on X damage events rather than atdwSamplingRateMs. Sunshine's capture/encode loop remains paced at the configured stream framerate, and the default path (cursor == true) is unchanged.Screenshot
Issues Fixed or Closed
Roadmap Issues
Testing
cuda::nvfbc::display_t::reinit()is thin NvFBC driver glue and the change only deletes the startup probe; verifying automaticbDirectCaptureattach/detach transitions requires a real NVIDIA X11 driver and fullscreen application. Happy to extract a testable ops seam forreinit()if preferred.grab_info.bDirectCapture(removed from this PR), confirmed automatic transitionsNo(desktop) →Yes(fullscreenframe_lab) →No(windowed) repeating across multiple fullscreen toggles without reconnecting or toggling cursor capture (__GL_SHOW_GRAPHICS_OSD=1also switchedBLIT↔FLIP).uv run --locked --no-sync lb-update-clang-format— no changes.clang-format --dry-run --Werror src/platform/linux/cuda.cpp— passed.master;test_sunshinewas not re-run locally after the rebase.Type of Change
Checklist
AI Usage
See our AI usage policy.