Skip to content

fix(pipewire): gate variable rate capture and fix fractional framerates - #5538

Merged
ReenigneArcher merged 1 commit into
LizardByte:masterfrom
psyke83:pipewire_compositor_pacing
Aug 26, 2026
Merged

fix(pipewire): gate variable rate capture and fix fractional framerates#5538
ReenigneArcher merged 1 commit into
LizardByte:masterfrom
psyke83:pipewire_compositor_pacing

Conversation

@psyke83

@psyke83 psyke83 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Description

fix(pipewire): gate variable rate capture and fix fractional framerates

Targeted fix for half-speed desktop animations that will apply to KWin 6.8+, but also improves compatibility with
mutter, and ensures that NTSC fractional framerates are requested properly. Unfortunately, KWin 6.7 will
continue exhibiting half-speed desktop animations unless the related fix is backported to this branch.

  • Isolate variable rate capture to KWin 5.x-6.7.x. Other compositors
    and KWin 6.8+ will request the actual framerate.
    Ref: https://bugs.kde.org/show_bug.cgi?id=524129
  • Since we now rely on compositor pacing, ensure that the pipewire
    session negotiates using the fractional rate instead of the coarse
    framerate value.
  • Nit: rename refresh_rate to more descriptive target_framerate
  • Nit: ensure target_framerate is populated during initial format negotiation
  • Nit: log host-side delay interval when variable rate is negotiated

Co-authored-by: Kishi85 41839133+Kishi85@users.noreply.github.com

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

See our AI usage policy.

  • 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

@psyke83

psyke83 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Technically I'm happy with the change as-is, but I'm keeping it in draft as it's a quasi-breaking change until Plasma 6.8 releases in October, or if the related fix for improved pacing gets backported to older branches.

Summary of effects:

  • Mutter/GNOME: no downsides. Sunshine will no longer need to renegotiate pipewire session on first probe, so it's an overall improvement.
  • Users of KWin 5.x-6.7 will see overall pacing get worse (1% skew or ~57fps on a 60fps stream).
  • Users of KWin 6.7 will see the general 1% pacing skew, but desktop animations will run at proper speed (albeit with the same 1% skew).
  • Users of KWin 6.8 will have good pacing for both desktop animations and general/in-game pacing.

If anyone is interested in testing the improved pacing, it's trivial to manually backport the single commit to KWin 6.7.

@Kishi85

Kishi85 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Technically I'm happy with the change as-is, but I'm keeping it in draft as it's a quasi-breaking change until Plasma 6.8 releases in October, or if the related fix for improved pacing gets backported to older branches.

Summary of effects:

  • Mutter/GNOME: no downsides. Sunshine will no longer need to renegotiate pipewire session on first probe, so it's an overall improvement.
  • Users of KWin 5.x-6.7 will see overall pacing get worse (1% skew or ~57fps on a 60fps stream).
  • Users of KWin 6.7 will see the general 1% pacing skew, but desktop animations will run at proper speed (albeit with the same 1% skew).
  • Users of KWin 6.8 will have good pacing for both desktop animations and general/in-game pacing.

If anyone is interested in testing the improved pacing, it's trivial to manually backport the single commit to KWin 6.7.

Not sure if holding this back until 6.8 will help as much because only rolling release distributions will get the fix within a reasonable time frame. Most regular distributions will stick to the KDE (therefore KWin) version that it shipped on release and therefore will lack behind until a new release is available (and upgraded to by the user).

One way to handle this would be to detect the running KWin version and change the logic accordingly based on that. IMHO we should avoid such workarounds if possible (keep code simple for future maintenance) but atm it's the only thing I could come up that would solve the issues above for users stuck on older versions of KWin.

@psyke83

psyke83 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

We should probably keep in mind that Plasma 6.6 is the currently assigned LTS release, and that version currently has no downsides with variable rate pacing; only 6.7 onwards exhibits the half-rate desktop animation bug. Merging this PR as-is would not be good for distros adhering to the 6.6 LTS release or earlier.

Other non-rolling release distros that use Plasma 6.7 (such as Fedora 43 onwards) will also be impacted, as they have good general pacing but very poor desktop responsiveness due to the animation bug caused by variable pacing.

Maybe a version check to determine whether to set up variable rate is warranted, and we can justify the effort by also using it to determine if the compositor is not KWin at all, just avoid variable rate entirely and thus avoid mutter having to renegotiate. Let's first see if the pacing improvement commit is cherry-picked to the 6.7 branch at least... but I doubt it.

@Kishi85

Kishi85 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Here's a simple check for KWin including the currently running version using it's DBus supportInformation() method I've come up using only GLib which is already required for pipewire and also used by portalgrab's dbus stuff (should you use it for this PR a Co-Authored-By on the commit adding it would be nice):

  /**
   * Fetch the currently running KWin version (if applicable from it's DBUS support information method)
   *
   * @return A vector with 3 elements containing KWin's major.minor.micro version or an empty vector if KWin's version could not be determined
   */
  static std::vector<int> get_running_kwin_version() {
    auto conn = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr);
    std::vector<int> result;
    if (conn) {
      if (auto reply = g_dbus_connection_call_sync(conn, "org.kde.KWin", "/KWin", "org.kde.KWin", "supportInformation", nullptr, G_VARIANT_TYPE("(s)"), G_DBUS_CALL_FLAGS_NONE, -1, nullptr, nullptr); reply) {
        gchar *support_info = nullptr;
        g_variant_get(reply, "(s)", &support_info);
        auto *regex = g_regex_new("KWin version: ([0-9]+)\\.([0-9]+)\\.([0-9]+)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, nullptr);
        GMatchInfo *match_info = nullptr;
        g_regex_match(regex, support_info, G_REGEX_MATCH_DEFAULT, &match_info);
        if (g_match_info_matches(match_info)) {
          gchar *major = g_match_info_fetch(match_info, 1);
          result.emplace_back(atoi(major));
          g_free(major);
          gchar *minor = g_match_info_fetch(match_info, 2);
          result.emplace_back(atoi(minor));
          g_free(minor);
          gchar *micro = g_match_info_fetch(match_info, 3);
          result.emplace_back(atoi(micro));
          g_free(micro);
        }
        g_match_info_free(match_info);
        g_regex_unref(regex);
        g_free(support_info);
        g_variant_unref(reply);
      }
      g_clear_object(&conn);
    }
    return result;
  }

Example usage:

      if (auto kwin_version = get_running_kwin_version(); !kwin_version.empty()) {
        BOOST_LOG(debug) << "[pipewire] KWin version: "sv << kwin_version[0] << "."sv << kwin_version[1] << "."sv << kwin_version[2];
        if (kwin_version[0] == 5 || (kwin_version[0] == 6 && kwin_version[1] < 8)) {
          BOOST_LOG(info) << "[pipewire] KWin variable rate capture";
        } else {
          BOOST_LOG(info) << "[pipewire] KWin compositor-side pacing";
        }
      } else {
        BOOST_LOG(info) << "[pipewire] No KWin support information available"sv;
      }

Depending on how often this is called it might be a good idea to cache the function result as it shouldn't change during Sunshine's process lifetime.

@psyke83
psyke83 force-pushed the pipewire_compositor_pacing branch 2 times, most recently from 90f2b2e to c3ac121 Compare August 25, 2026 05:58
@psyke83

psyke83 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

@Kishi85 appreciated.

I've added some extra fixes related to framerate negotiation, but decided to overwrite the original commit to make absolutely sure that you get the co-author credit if/when the branch gets squashed for merge to master.

The new behaviour is:

  • KWin 5.x-6.7.x continues to use variable rate. No regressions to overall pacing, but the 6.7.x series still has the half-speed desktop animations.
  • Kwin 6.8+ and all other compositors that are not recognized by your function will use a proper target framerate and have the best overall pacing. This happens to improve mutter's behaviour (no renegotiation necessary).
  • NTSC/fractional rates requested by clients are now properly supported.

@psyke83 psyke83 changed the title fix(pipewire): revert back to compositor-side pacing fix(pipewire): gate variable rate capture and fix fractional scaling Aug 25, 2026
@psyke83
psyke83 force-pushed the pipewire_compositor_pacing branch from 97cec93 to a760b0c Compare August 25, 2026 06:38
@psyke83 psyke83 changed the title fix(pipewire): gate variable rate capture and fix fractional scaling fix(pipewire): gate variable rate capture and fix fractional framerates Aug 25, 2026
@psyke83
psyke83 force-pushed the pipewire_compositor_pacing branch from a760b0c to 14418f6 Compare August 25, 2026 07:09
@ReenigneArcher

Copy link
Copy Markdown
Member

but decided to overwrite the original commit to make absolutely sure that you get the co-author credit if/when the branch gets squashed for merge to master.

Just, FYI. When I squash and merge, I keep the co-authors.

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 58 lines in your changes missing coverage. Please review.
✅ Project coverage is 33.78%. Comparing base (790d70f) to head (9e0362d).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/platform/linux/pipewire.cpp 0.00% 36 Missing and 22 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5538      +/-   ##
==========================================
- Coverage   33.84%   33.78%   -0.07%     
==========================================
  Files         104      104              
  Lines       25089    25135      +46     
  Branches    11098    11126      +28     
==========================================
  Hits         8492     8492              
+ Misses      15610    12982    -2628     
- Partials      987     3661    +2674     
Flag Coverage Δ
Archlinux 0.00% <0.00%> (ø)
FreeBSD-amd64 19.46% <0.00%> (-0.06%) ⬇️
Homebrew-macos-14 30.76% <ø> (ø)
Homebrew-macos-15 31.47% <ø> (ø)
Homebrew-macos-26 31.58% <ø> (-0.01%) ⬇️
Homebrew-ubuntu-24.04 20.77% <0.00%> (-0.05%) ⬇️
Linux-AppImage 20.18% <0.00%> (-0.06%) ⬇️
Windows-AMD64 25.78% <ø> (ø)
Windows-ARM64 21.65% <ø> (-0.01%) ⬇️
macOS-arm64 25.57% <ø> (ø)
macOS-x86_64 26.22% <ø> (ø)

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

Files with missing lines Coverage Δ
src/platform/linux/pipewire.cpp 0.15% <0.00%> (-0.02%) ⬇️

... and 57 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

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

@psyke83

psyke83 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

but decided to overwrite the original commit to make absolutely sure that you get the co-author credit if/when the branch gets squashed for merge to master.

Just, FYI. When I squash and merge, I keep the co-authors.

Thanks. This is technically ready for review, but if the improved pacing is backported to KWin 6.7.x we could adjust the version gating logic before merging. Otherwise, there's no hurry to merge; aside from the NTSC fractional framerate fix that also affects mutter, this will only have major impact when KWin 6.8 is released in October.

@psyke83
psyke83 marked this pull request as ready for review August 25, 2026 16:39
@Kishi85

Kishi85 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

@psyke83 Could you change the e-mail on the co-author to 41839133+Kishi85@users.noreply.github.com ? Thanks!

@psyke83
psyke83 force-pushed the pipewire_compositor_pacing branch from e2fe3fc to d1784a9 Compare August 25, 2026 17:06
@psyke83

psyke83 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

@Kishi85

Done. I squashed the commit while updating so that your real email is not visible on my branch either. Hopefully that's ok with you.

Targeted fix for half-speed desktop animations that will apply to KWin 6.8+, but also improves compatibility with
mutter, and ensures that NTSC fractional framerates are requested properly. Unfortunately, KWin 6.7 will
continue exhibiting half-speed desktop animations unless the related fix is backported to this branch.

* Isolate variable rate capture to KWin 5.x-6.7.x. Other compositors
  and KWin 6.8+ will request the actual framerate.
  Ref: https://bugs.kde.org/show_bug.cgi?id=524129
* Since we now rely on compositor pacing, ensure that the pipewire
  session negotiates using the fractional rate instead of the coarse
  framerate value.
* Nit: rename refresh_rate to more descriptive target_framerate
* Nit: ensure target_framerate is populated during initial format negotiation
* Nit: log host-side delay interval when variable rate is negotiated

Co-authored-by: Kishi85 <41839133+Kishi85@users.noreply.github.com>
@psyke83
psyke83 force-pushed the pipewire_compositor_pacing branch from d1784a9 to 9e0362d Compare August 25, 2026 17:10
@Kishi85

Kishi85 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

@Kishi85

Done. I squashed the commit while updating so that your real email is not visible on my branch either. Hopefully that's ok with you.

All good! Thanks again.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Last Updated 2026-08-25 23:31:39 UTC
Source Run CI Run #5109
Commit 9e0362ddd9b5cfbf55786f54e6df1fa0617e5cb2

Screenshot Comparison

PR #5538 screenshots vs screenshots baseline.

Matrix: AppImage

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: Windows-AMD64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: Windows-ARM64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: macOS-arm64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: macOS-x86_64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

@ReenigneArcher ReenigneArcher added this to the pipewire milestone Aug 25, 2026
@ReenigneArcher
ReenigneArcher merged commit f273ce8 into LizardByte:master Aug 26, 2026
167 of 172 checks passed
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.

3 participants