Portal + VAAPI: streaming fails, encoder loops with EGL_BAD_PARAMETER

未关闭
#6,114 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp, linux
领域
backend

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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

主要语言
C++
星标
43k
派生
2.4k
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

LizardByte/Sunshine 的其他 Issue

查看 LizardByte/Sunshine 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。