HyperHDR icon indicating copy to clipboard operation
HyperHDR copied to clipboard

Fix PipeWire grabber performance for Wayland/HDR screen capture

Open Olbrasoft opened this issue 3 weeks ago • 1 comments

Summary

This PR fixes significant performance issues with the PipeWire screen grabber when capturing Wayland/HDR displays, improving capture rate from ~15 FPS to ~25-30 FPS.

Changes

1. Increased FPS limit (10 → 30)

  • Updated _requestedFPS in constructor and reset function
  • Removes artificial throttling that was limiting capture performance

2. Disabled slow EGL/DmaBuf GPU path

  • Added early return in initEGL() function
  • The EGL path uses synchronous glGetTexImage() calls for GPU-to-CPU transfer, creating a significant bottleneck
  • Forces the faster CPU path (MemFd/MemPtr) which uses direct memory access

3. Build configuration note

  • For full EGL disable, compile with: cmake -DENABLE_PIPEWIRE_EGL=OFF
  • This prevents EGL code from being compiled at all

Performance Impact

Metric Before After
FPS Limit 10 FPS 30 FPS
Actual Capture Rate ~15.2 FPS ~25-30 FPS
Capture Path DmaBuf/EGL (GPU) MemFd/MemPtr (CPU)
Frame Transfer Slow glGetTexImage() Fast memory copy

Technical Details

The root cause was twofold:

  1. Low FPS limit: Default 10 FPS was unnecessarily low for modern systems
  2. Slow GPU path: The EGL/DmaBuf path requires synchronous GPU→CPU transfer via glGetTexImage(), which blocks the capture thread and adds significant latency

The CPU memory path (MemFd/MemPtr) is actually faster for PipeWire screen capture because:

  • Direct memory access without GPU synchronization
  • No blocking on GPU operations
  • Simpler code path with less overhead

Testing

Tested successfully on:

  • OS: Debian 13 (Trixie)
  • Desktop: Gnome Wayland with HDR enabled
  • Capture: PipeWire via xdg-desktop-portal (Portal.ScreenCast v5)
  • Hardware: System with NVIDIA GPU

Verified that:

  • Stream successfully uses MemFD frame type
  • Hardware acceleration properly reported as DISABLED (as expected for CPU path)
  • LED ambilight system works smoothly at ~25-30 FPS
  • No Wayland rendering issues or artifacts

Closes

Addresses #1133 - Software Screen Capture not working when HDR is enabled under Gnome

Additional Notes

This change makes the CPU path the default, which is counterintuitive but empirically faster for PipeWire screen capture. The EGL/GPU path may have been designed for different use cases, but for real-time screen capture with immediate processing, the CPU path provides better performance.

Users experiencing similar issues should also ensure their systemGrabber FPS setting in the database is set appropriately (e.g., 30 FPS instead of the old 10/15 FPS defaults).

Olbrasoft avatar Dec 03 '25 19:12 Olbrasoft

Hi I think there has been some misunderstanding here or the AI went a bit overboard: in this class, some default values were used because you have to initialize these values in C++ somehow. But in reality, the scheme/user setting takes precedence so you can set it as you want. And no: we will not disable EGL outright—although it would be useful to be able to do it as a parameter in the scheme. However, then it would need to be hidden in the UI so it does not appear on other systems, just like, for example, tone mapping used in the Windows DirectX system grabber. And as far I know the Gnome issue was fix by the update as the problem was on the OS or pipewire side and EGL has nothing to do with it so no immediately fix is required.

awawa-dev avatar Dec 06 '25 13:12 awawa-dev