WLR capture: black frames on NVIDIA with wlroots Vulkan renderer
Chưa có ai nhận issue này.
- #5988 của @arkheya — đã đóng, không merge
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 28/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- cpp, linux
- Lĩnh vực
- backend, performance
Hướng nghiên cứu
Start in src/platform/linux/wayland.cpp at the WLR capture ready callback and trace how dmabuf_t::ready() obtains and uses the next frame. Check the current Wayland capture flow and synchronization behavior against wlroots’ Vulkan renderer and NVIDIA imports; the report’s proof of concept is untested outside one setup. Done means reproducing the black frames and validating a reliable synchronization fix without introducing unacceptable latency across relevant configurations.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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?
I didn't read the issue template
Describe the Bug
Disclaimer: I have fixed this issue for myself using LLM that wrote a patch. The issue is gone, and it completely satisfies me, I'm going to apply this patch going forward after every Sunshine update. However, sharing the issue here in case anyone had the same issue or someone might want to take a look at it. This patch is probably unoptimal, it makes CPU thread wait, introduces latency/delays, untested on other hardware or other software configuration, and might not even be applicable to future versions of wlr / renderers. Or maybe even unrelated to Sunshine and should be fixed on wlr/vulkan/nvidia side.
The problem is: I'm having severe flickering when streaming something with Vulkan renderer from Sway.
Environment
- Arch Linux, kernel 7.2.11
- RTX 5070 Ti, nvidia-open 615.78.08
- sway 1.12 / wlroots 0.20.2,
WLR_RENDERER=vulkan - Sunshine v2026.914.233613 (AUR, built with CUDA 13.4.3, but without CUDA same issue),
capture = wlr, hevc_nvenc - Capturing headless outputs (1340x800@60), Artemis on Android
Problem
Streams flash black frames. It looks like severe flickering, especially during heavy gameplay: XPlane12, Minecraft. I'm trying to stream instrument panels of XPlane from HEADLESS outputs but I think it's irrelevant which ones to stream. Rate scales with GPU load: occasional at idle, tens per second while a game is running, especially with an XWayland game focused and the cursor over it (though might be unrelated to cursor).
WLR_RENDERER=gles2: no flicker (the gles2 renderer stalls on the GPU instead, which is unusable under load). This only happens withWLR_RENDERER=vulkan.- Non-CUDA build (GPU -> RAM -> GPU) flickers too.
Cause (likely) (written by LLM)
dmabuf_t::ready() uses the buffer as soon as ready arrives. The wlroots Vulkan renderer sends ready after submitting the copy and relies on the implicit fence on the dma-buf. NVIDIA's import doesn't wait on implicit fences, so Sunshine reads a freshly allocated, not-yet-written GBM buffer, which shows up as black.
Proof of concept (written by LLM)
Wait for the dma-buf write fence (poll(POLLIN)) in ready(). On timeout, repeat the previous frame. This fixes it for me. It's a CPU-side wait; a proper fix would probably export the fence (DMA_BUF_IOCTL_EXPORT_SYNC_FILE) and have the GPU wait on it via EGL. The patch is against v2026.914.233613; wayland.cpp has been refactored on master since.
Patch
--- a/src/platform/linux/wayland.cpp
+++ b/src/platform/linux/wayland.cpp
@@ -536,15 +536,35 @@
std::uint32_t tv_sec_lo,
std::uint32_t tv_nsec
) {
- // Frame is ready for use, GBM buffer now contains screen content
- current_frame->destroy();
- current_frame = get_next_frame();
+ // The compositor may send `ready` before its GPU copy has finished, relying
+ // on the implicit fence attached to the dma-buf. NVIDIA's EGL/CUDA import
+ // ignores implicit fences, so wait for the write fence (POLLIN on a dma-buf
+ // fd blocks until pending writes are done). If the copy still isn't done,
+ // drop the new frame and keep the previous one instead of sending a
+ // half-copied (usually black) frame.
+ auto next_frame = get_next_frame();
+ bool copy_done = true;
+ if (next_frame->sd.fds[0] >= 0) {
+ struct pollfd pfd = {};
+ pfd.fd = next_frame->sd.fds[0];
+ pfd.events = POLLIN;
+ copy_done = poll(&pfd, 1, 100) == 1;
+ }
- std::uint64_t sec = (std::uint64_t(tv_sec_hi) << 32) | tv_sec_lo;
- auto ready_ts = std::chrono::seconds(sec) + std::chrono::nanoseconds(tv_nsec);
- current_frame->frame_timestamp = std::chrono::steady_clock::time_point {
- std::chrono::duration_cast<std::chrono::steady_clock::duration>(ready_ts)
- };
+ if (!copy_done && current_frame->sd.fds[0] >= 0) {
+ BOOST_LOG(debug) << "[wayland] Screencopy not finished in time, repeating previous frame"sv;
+ next_frame->destroy();
+ } else {
+ // Frame is ready for use, GBM buffer now contains screen content
+ current_frame->destroy();
+ current_frame = next_frame;
+
+ std::uint64_t sec = (std::uint64_t(tv_sec_hi) << 32) | tv_sec_lo;
+ auto ready_ts = std::chrono::seconds(sec) + std::chrono::nanoseconds(tv_nsec);
+ current_frame->frame_timestamp = std::chrono::steady_clock::time_point {
+ std::chrono::duration_cast<std::chrono::steady_clock::duration>(ready_ts)
+ };
+ }
// Keep the GBM buffer alive but destroy the Wayland objects
if (current_wl_buffer) {
Expected Behavior
No response
Additional Context
No response
Host Operating System
Linux
Operating System Version
Arch Linux
Architecture
amd64/x86_64
Package
Linux - AUR (Third Party)
GPU Type
NVIDIA
GPU Model
5070Ti
GPU Driver/Mesa Version
615.78.08
Capture Method
No response
Apps
Log output
Online logs
No response
- Ngôn ngữ chính
- C++
- Star
- 43k
- Fork
- 2.4k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của LizardByte/Sunshine
-
Linux keyboard backend has no mapping for VK_ABNT_C1 (ABNT2 dedicated `/ ?` key) — key is silently droppedCó thể đã có người làm @NestorBrasileiro đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
LizardByte/Sunshine#6051 · 2 bình luận ·
-
PIN pairing fails with "Missing CSRF token" - web UI never fetches/attaches the tokenCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
LizardByte/Sunshine#5467 · 2 bình luận ·
-
Virtual HID Driver License notifications appearing even though Enable Gamepad Input is uncheckedĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
LizardByte/Sunshine#6222 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 47/100
LizardByte/Sunshine#6208 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
LizardByte/Sunshine#6202 · 1 bình luận ·
Tất cả issue của LizardByte/Sunshine
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
Maintainer thường phản hồi trong vòng 2 ngày
-
bug data-types
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ClickHouse/clickhouse-cpp#645 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug compatibility difficulty:easy prio:normal
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
NatronGitHub/openfx-misc#524 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[内容提案] 现在C++模块的CMake支持有更新,需要进行同步Đang mởdocumentation enhancement help wanted P0
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Awesome-Embedded-Learning-Studio/Tutorial_AwesomeModernCPP#359 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Type: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
openscad/openscad#7360 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày