From c9725d3b78211e08bcdcd3f7aabff68fc01c7ab6 Mon Sep 17 00:00:00 2001 From: Andreas Schaafsma Date: Thu, 3 Sep 2026 10:10:52 +0200 Subject: [PATCH] mutter tearing patches --- .../drivebystation-nix/default.nix | 3 +- .../mutter-50-tearing-compat.patch | 51 +++++++++++++++++++ .../drivebystation-nix/mutter-tearing.nix | 50 ++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 systems/x86_64-linux/drivebystation-nix/mutter-50-tearing-compat.patch create mode 100644 systems/x86_64-linux/drivebystation-nix/mutter-tearing.nix diff --git a/systems/x86_64-linux/drivebystation-nix/default.nix b/systems/x86_64-linux/drivebystation-nix/default.nix index b269b5e..2e3bd88 100644 --- a/systems/x86_64-linux/drivebystation-nix/default.nix +++ b/systems/x86_64-linux/drivebystation-nix/default.nix @@ -34,6 +34,7 @@ in # inherit system; imports = [ ./configuration.nix + ./mutter-tearing.nix ./video.nix inputs.aagl.nixosModules.default ]; @@ -222,4 +223,4 @@ in systemd.targets.hibernate.enable = false; systemd.targets.hybrid-sleep.enable = false; }; -} \ No newline at end of file +} diff --git a/systems/x86_64-linux/drivebystation-nix/mutter-50-tearing-compat.patch b/systems/x86_64-linux/drivebystation-nix/mutter-50-tearing-compat.patch new file mode 100644 index 0000000..bcec785 --- /dev/null +++ b/systems/x86_64-linux/drivebystation-nix/mutter-50-tearing-compat.patch @@ -0,0 +1,51 @@ +diff --git a/src/compositor/meta-compositor-view-native.c b/src/compositor/meta-compositor-view-native.c +--- a/src/compositor/meta-compositor-view-native.c ++++ b/src/compositor/meta-compositor-view-native.c +@@ -289,9 +289,11 @@ find_scanout_candidate (MetaCompositorView *compositor_view, + return FALSE; + + if (!meta_stage_view_is_cursor_overlay_inhibited (view) && ++ !meta_onscreen_native_is_tearing_enabled ( ++ META_ONSCREEN_NATIVE (framebuffer)) && + surface_actor_has_overlapping_cursor_overlays (compositor, + compositor_view, + surface_actor)) + { + meta_topic (META_DEBUG_RENDER, + "No direct scanout candidate: overlapping software cursors"); +diff --git a/src/meson.build b/src/meson.build +--- a/src/meson.build ++++ b/src/meson.build +@@ -1077,5 +1077,6 @@ wayland_protocols = [ + ['single-pixel-buffer', 'staging', 1, ], + ['tablet', 'stable', 2, ], ++ ['tearing-control', 'staging', 1, ], + ['text-input-unstable-v3', 'private', ], + ['viewporter', 'stable', ], + ['xdg-activation', 'staging', 1, ], +diff --git a/src/wayland/meta-wayland-dma-buf.c b/src/wayland/meta-wayland-dma-buf.c +--- a/src/wayland/meta-wayland-dma-buf.c ++++ b/src/wayland/meta-wayland-dma-buf.c +@@ -630,11 +630,22 @@ has_modifier (GArray *modifiers, + } + + #ifdef HAVE_NATIVE_BACKEND ++static gboolean ++async_supports_modifier (MetaKmsPlane *plane, ++ uint32_t drm_format, ++ uint64_t drm_modifier) ++{ ++ GArray *async_modifiers = ++ meta_kms_plane_get_async_modifiers_for_format (plane, drm_format); ++ return async_modifiers && has_modifier (async_modifiers, drm_modifier); ++} ++ + static gboolean + crtc_supports_modifier (MetaCrtcKms *crtc_kms, + uint32_t drm_format, +- uint64_t drm_modifier) ++ uint64_t drm_modifier, ++ gboolean is_async) + { + MetaKmsPlane *plane = meta_crtc_kms_get_assigned_primary_plane (crtc_kms); + GArray *crtc_modifiers; diff --git a/systems/x86_64-linux/drivebystation-nix/mutter-tearing.nix b/systems/x86_64-linux/drivebystation-nix/mutter-tearing.nix new file mode 100644 index 0000000..f1c26ed --- /dev/null +++ b/systems/x86_64-linux/drivebystation-nix/mutter-tearing.nix @@ -0,0 +1,50 @@ +{ lib, pkgs, ... }: + +let + # GNOME/mutter!3797, pinned because the MR is still under development. + mutterTearingRevision = "a8d56d423edde9e6d76f6b9cab663d82c65cf1a2"; + mutterTearingPatch = pkgs.fetchurl { + url = "https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3797.diff"; + hash = "sha256-3up5PsHX+BSQRKb9JS5bnJLPaTGmvV55M18tKkepIng="; + }; +in +{ + nixpkgs.overlays = [ + (final: prev: { + mutter = prev.mutter.overrideAttrs (old: { + pname = "mutter-tearing"; + + # The MR currently targets Mutter 51. Apply it to the packaged Mutter + # 50 source, then resolve the four small context conflicts separately. + prePatch = '' + ${old.prePatch or ""} + + set +e + patch --batch -p1 --forward < ${mutterTearingPatch} + mr_status=$? + set -e + + if [ "$mr_status" -ne 0 ]; then + reject_count="$(find . -name '*.rej' -type f | wc -l)" + if [ "$reject_count" -ne 3 ]; then + echo "Unexpected number of Mutter !3797 rejects: $reject_count" >&2 + exit 1 + fi + fi + + patch --batch -p1 --forward < ${./mutter-50-tearing-compat.patch} + find . -name '*.rej' -type f -delete + ''; + + passthru = (old.passthru or { }) // { + tearingMr = 3797; + tearingRevision = mutterTearingRevision; + }; + }); + }) + ]; + + # Mutter keeps tearing support behind an experimental runtime switch. + environment.sessionVariables.MUTTER_DEBUG_EXPERIMENTAL_FEATURES = + lib.mkDefault "tearing"; +}