Skip to content

fix(linux): allow NvFBC direct capture to attach after startup - #6199

Open
medialaxis wants to merge 1 commit into
SunshineStream:masterfrom
medialaxis:fix/linux-nvfbc-direct-capture
Open

medialaxis wants to merge 1 commit into
SunshineStream:masterfrom
medialaxis:fix/linux-nvfbc-direct-capture

Conversation

@medialaxis

Copy link
Copy Markdown

Description

Remove the 3-frame NVFBC_TOCUDA_GRAB_FLAGS_NOWAIT startup probe in cuda::nvfbc::display_t::reinit() that disabled bAllowDirectCapture and bPushModel (and recreated the capture session) whenever grab_info.bDirectCapture was not immediately true.

That probe prevented NvFBC direct capture in two common cases when cursor capture is disabled:

  • Fullscreen application already running: Three consecutive NOWAIT grabs can execute within the same millisecond—returning one initial non-direct frame followed by two No new frame results before the application presents—triggering an immediate fallback to non-direct desktop capture.
  • Fullscreen application launched after stream start (e.g. connecting to Desktop, then launching a game): Direct capture is not active on the desktop at session startup, so the probe disables bAllowDirectCapture for the rest of the session and NvFBC can never attach once a fullscreen application starts.

Per third-party/nvfbc/NvFBC.h, when bAllowDirectCapture and bPushModel remain enabled (with bWithCursor = 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, bPushModel stays NVFBC_TRUE (a prerequisite for bAllowDirectCapture), so the NVIDIA X driver generates desktop frames on X damage events rather than at dwSamplingRateMs. 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

  • Why no automated regression test was added: cuda::nvfbc::display_t::reinit() is thin NvFBC driver glue and the change only deletes the startup probe; verifying automatic bDirectCapture attach/detach transitions requires a real NVIDIA X11 driver and fullscreen application. Happy to extract a testable ops seam for reinit() if preferred.
  • Manual validation (Linux X11, NVIDIA NvFBC, Moonlight, cursor capture disabled):
    • With temporary diagnostic logging on grab_info.bDirectCapture (removed from this PR), confirmed automatic transitions No (desktop) → Yes (fullscreen frame_lab) → No (windowed) repeating across multiple fullscreen toggles without reconnecting or toggling cursor capture (__GL_SHOW_GRAPHICS_OSD=1 also switched BLIT ↔ FLIP).
    • Verified the simplified patch without diagnostic logging in a live stream.
  • Formatting checks:
    • uv run --locked --no-sync lb-update-clang-format — no changes.
    • clang-format --dry-run --Werror src/platform/linux/cuda.cpp — passed.
  • Checks not run:
    • Live hardware validation was performed on an earlier local build before rebasing onto current master; test_sunshine was not re-run locally after the rebase.
    • Not tested across multiple X11 compositors.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Tests have been added or updated for new or modified functionality, including regression tests for bug fixes

AI Usage

See our AI usage policy.

  • AI tools were used while preparing this PR
  • Codex (GPT-6 Sol) assisted with investigating the NvFBC direct-capture behavior and implementing the fix.
  • Antigravity (Gemini 4 Neon, high thinking level) assisted with reviewing correctness/trade-offs, cleaning up the commit, and drafting this PR description.

This pull request was generated with Codex (GPT-6 Sol) for investigation/implementation and Antigravity (Gemini 4 Neon, high thinking level) for review and PR drafting

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.
@medialaxis

Copy link
Copy Markdown
Author

This pull request was generated with Codex (GPT-6 Sol) for investigation/implementation and Antigravity (Gemini 4 Neon, high thinking level) for review and PR drafting

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant