Skip to content

fix(linux/vulkan): auto-detect GPU with connected display#4961

Open
neatnoise wants to merge 1 commit intoLizardByte:masterfrom
neatnoise:vulkan-default-gpu
Open

fix(linux/vulkan): auto-detect GPU with connected display#4961
neatnoise wants to merge 1 commit intoLizardByte:masterfrom
neatnoise:vulkan-default-gpu

Conversation

@neatnoise
Copy link
Copy Markdown
Contributor

@neatnoise neatnoise commented Apr 8, 2026

Description

On multi-GPU Linux systems, the Vulkan encoder hardcoded /dev/dri/renderD128 as the default render device when adapter_name was not configured. This caused the encoder to use the wrong GPU (e.g. Intel iGPU instead of the Nvidia dGPU driving the display), leading to encode failures or unnecessary cross-GPU copies.

This PR adds platf::find_render_node_with_display() which scans DRM card devices for a connector in DRM_MODE_CONNECTED state and returns the corresponding render node via drmGetRenderDeviceNameFromFd(). This is used as the default GPU selection when adapter_name is empty.

Fallback chain (unchanged for users with explicit config):

  1. User's adapter_name config → used as-is
  2. Auto-detected GPU with connected display
  3. /dev/dri/renderD128 if detection fails
  4. FFmpeg default (final fallback)

All Vulkan capture paths benefit (KMS, portal, wlgrab) since they all funnel through the same create_vulkan_hwdevice() or the video.cpp fallback.

This creates a common method to auto choose GPU. It can be used with other encoders like VAAPI (which is also static) as well in the future.

Screenshot

Issues Fixed or Closed

Roadmap Issues

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
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@neatnoise neatnoise changed the title fix(linux/vulkan): auto-detect GPU with connected display for Vulkan encoder fix(linux): auto-detect GPU with connected display for Vulkan encoder Apr 8, 2026
@ReenigneArcher ReenigneArcher changed the title fix(linux): auto-detect GPU with connected display for Vulkan encoder fix(linux/vulkan): auto-detect GPU with connected display Apr 8, 2026
@ReenigneArcher ReenigneArcher added this to the vulkan milestone Apr 8, 2026
@neatnoise neatnoise force-pushed the vulkan-default-gpu branch from 82c9239 to a0b3617 Compare April 8, 2026 14:49
…renderD128

On multi-GPU systems the Vulkan encoder defaulted to /dev/dri/renderD128
which may not be the GPU driving the display. This caused encode failures
or unnecessary cross-GPU copies.

Add platf::find_render_node_with_display() which scans DRM connectors to
find the GPU with a connected monitor and returns its render node path.
Use this as the default when adapter_name is not configured.

Fallback chain: user config > auto-detected GPU > renderD128 > FFmpeg default.
@neatnoise neatnoise force-pushed the vulkan-default-gpu branch from a0b3617 to 1e54ff0 Compare April 8, 2026 15:10
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 8, 2026

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Bundle Report

Bundle size has no change ✅

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

❌ Patch coverage is 0% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.96%. Comparing base (e61d9ba) to head (1e54ff0).
⚠️ Report is 3 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/platform/linux/misc.cpp 0.00% 29 Missing ⚠️
src/platform/linux/vulkan_encode.cpp 0.00% 3 Missing ⚠️
src/video.cpp 0.00% 3 Missing ⚠️
src/platform/macos/misc.mm 0.00% 2 Missing ⚠️
src/platform/windows/misc.cpp 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4961      +/-   ##
==========================================
- Coverage   17.99%   17.96%   -0.04%     
==========================================
  Files         108      108              
  Lines       23317    23354      +37     
  Branches    10263    10288      +25     
==========================================
- Hits         4197     4195       -2     
+ Misses      16033    15025    -1008     
- Partials     3087     4134    +1047     
Flag Coverage Δ
Archlinux 11.65% <0.00%> (-0.03%) ⬇️
FreeBSD-14.3-aarch64 ?
FreeBSD-14.3-amd64 13.59% <0.00%> (-0.01%) ⬇️
Homebrew-ubuntu-22.04 13.98% <0.00%> (-0.04%) ⬇️
Linux-AppImage 12.18% <0.00%> (-0.03%) ⬇️
Windows-AMD64 14.91% <0.00%> (-0.01%) ⬇️
Windows-ARM64 13.23% <0.00%> (-0.01%) ⬇️
macOS-arm64 19.02% <0.00%> (-0.01%) ⬇️
macOS-x86_64 18.37% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/platform/common.h 32.40% <ø> (ø)
src/platform/macos/misc.mm 9.00% <0.00%> (-0.07%) ⬇️
src/platform/windows/misc.cpp 16.40% <0.00%> (-0.04%) ⬇️
src/platform/linux/vulkan_encode.cpp 0.35% <0.00%> (-0.01%) ⬇️
src/video.cpp 32.32% <0.00%> (-0.16%) ⬇️
src/platform/linux/misc.cpp 14.83% <0.00%> (-0.77%) ⬇️

... and 40 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e61d9ba...1e54ff0. Read the comment docs.

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.

Black screen when forcing Vulkan encoder – appears to select iGPU instead of Nvidia GPU

2 participants