Portal + VAAPI: streaming fails, encoder loops with EGL_BAD_PARAMETER

Aperta
#6,114 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
42/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp, linux
Ambito
backend

Direzione di ricerca

Start with build_format_parameter() and make_avcodec_encode_device() in the capture and encoder negotiation paths, then trace how the portal stream reports its negotiated buffer type to the encode thread. The report identifies an empty modifier list, shared memory negotiation, and repeated VAAPI import failures; check those paths against the attached logs and probe notes. Done means portal capture with VAAPI streams frames whether DMA-BUF is negotiated or memory buffers are used.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Is there an existing issue for this?
  • I have searched the existing issues
Is your issue described in the documentation?
  • I have read the documentation
Is your issue present in the latest beta/pre-release?

This issue is present in the latest pre-release

Describe the Bug

I can't stream on this machine when both capture = portal and encoder = vaapi
are set. The client connects, but not a single frame arrives, and the log keeps
printing the same four lines while the connection is up:

[21:31:24.502] [pipewire] using memory buffers
[21:31:24.515] Creating encoder [hevc_vaapi]
[21:31:24.537] Error: Couldn't import RGB Image: 0000300C
[21:31:24.537] Error: Could not convert image

0000300C is EGL_BAD_PARAMETER, roughly once per frame.

Configuration Result
capture = portal, encoder = software (libx264) works
capture = kms, encoder = vaapi, kernel 7.3.4 works
capture = portal, encoder = vaapi fails

So the capture path and the encoder each work on their own; only this pairing
fails.

The failure comes from five steps chained together. Each step only holds under its
own precondition, and each one only accounts for the change that precondition
brings.

First, this machine reports no modifiers. I ran eglQueryDmaBufModifiersEXT for
AR24/XR24 on every real GPU path: the Wayland platform, the card1 EGL device, GBM
on renderD128, and GBM on card1. All returned 0. Only the software EGL device
reports LINEAR. That is not a fault in itself; it just means there is no layout
label to announce, and the CPU copy path still works. Conversely, if the system
did report modifiers, this step and the following ones would not apply.

Second, with an empty list the modifier property never goes out at all. When
Sunshine builds the request, build_format_parameter() only writes the
SPA_FORMAT_VIDEO_modifier field if n_modifiers > 0; with an empty list that
whole branch is skipped. So the request that reaches the compositor has no
modifier entry in it whatsoever. Still nothing broken at this point.

Third, when that property is missing, KWin 6.8 only offers shared memory. Its
onStreamParamChanged() clears the DMA-BUF state when it cannot find the field. I
did not verify other compositors. This is where the problem starts: "not
specified" is read as "not needed", so the stream falls back to shared memory. On
its own this step is only a downgrade, slower but not broken.

Fourth, the encoder is chosen without looking at the negotiation result.
make_avcodec_encode_device() picks the vram path from n_dmabuf_infos > 0, and
that number counts formats, not modifiers. It stays above zero even after the
stream negotiated memory buffers. This is where it actually breaks: the encoder
assumes DMA-BUF while the frames have no fd behind them, so every import throws
EGL_BAD_PARAMETER. If the stream had been on DMA-BUF all along, this step alone
would be harmless.

Fifth, nothing degrades after a failed import. convert() returns an error, the
encode thread exits, the session restarts, and the same choice is made again. A
single failed import is enough to take the whole stream down for good, and the
client never gets a frame.

Expected Behavior

capture = portal with encoder = vaapi should produce video. Either path is
fine: DMA-BUF if the compositor offers it, memory copy otherwise. If an import
does fail, the stream should fall back to the memory copy instead of exiting the
encode thread and rebuilding the session.

Additional Context

Full logs, the EGL probe programs I used, and the notes from this investigation
are in one place, one directory per date:
https://github.com/aningQwQ/backup/tree/main/sunshine/2026-11-16

There's also a branch where I tried a fix, mostly so you can see what I mean:
https://github.com/aningQwQ/Sunshine/tree/2026-11-16
Built from that, the same machine logs using DMA-BUF buffers and no import
failures over an 8 minute session.

That fix came out of an AI-assisted session and I can't review the code myself,
so I'm not opening a PR.

One more thing I noticed while looking at this: a pw-dump taken during streaming
shows KWin announcing two formats, one with a modifier and one without. Since the
client request carries no modifier property, the negotiation lands on the second
one.

Host Operating System

Linux

Operating System Version

Linux xuyingjun-cachyos 7.3.4-1-cachyos #1 SMP PREEMPT_DYNAMIC Fri, 13 Nov 2026 19:45:18 +0000 x86_64 GNU/Linux

Architecture

amd64/x86_64

Package

Linux - AUR (Third Party)

GPU Type

AMD

GPU Model

Radeon RX 590 GME (Polaris 10)

GPU Driver/Mesa Version

GPU Driver/Mesa Version: Mesa 26.2.6-arch3.1, LLVM 23

Capture Method

XDG Portal Grab (FreeBSD/Linux)

Apps

Log output
https://github.com/aningQwQ/backup/tree/main/sunshine/2026-11-16
Online logs

https://github.com/aningQwQ/backup/tree/main/sunshine/2026-11-16

Lingua principale
C++
Stelle
43k
Fork
2.4k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di LizardByte/Sunshine

Tutte le issue di LizardByte/Sunshine

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.