Eliminate screen tearing with Intel/Mesa

Hi, I’m relatively to Nix and setting up a Lenovo X1 Carbon Gen 9.

I’d really appreciate help setting up the graphical side of things. With my current setup, I experience a lot of screen tearing. At least, that’s what I think it is. When switching from one program to another (e.g. alacritty to firefox), some portion of the screen will remain unchanged. Sometimes this is brief, and other times, I have to move the mouse for the screen to completely refresh.

Like @thomas says here:

This is really a very similarly motivated post, just for Intel Mesa rather than Nvidia.

I tried following the configuration steps in the NixOS manual. I also tried the configuration suggested there for troubleshooting screen tearing, but that actually made things worse.

Some relevant information:

  • Graphics: Mesa Intel Xe Graphics (TGL GT2)
  • Display: 14" 16:10 2840 x 2400
  • /etc/nixos/configuration.nix (the relevant parts):
        # ...
        imports = [ ./hardware-configuration.nix ];
        services.xserver = {
            enabled = true;
            displayManager.gdm.enable = true;
            desktopManager.gnome.enable = true;
            layout = "us";
            libinput.enable = true;
            videoDrivers = [ "modesetting" ];
            useGlamor = true;
        nixpkgs.config.packageOverrides = pkgs: {
            vaapiIntel = pkgs.vaapiIntel.override { enableHybridCodec = true; };
        hardware.opengl = {
            enable = true;
            driSupport = true;
            extraPackages = with pkgs; [
        # ...
  • /etc/nixos/harware-configuration.nix (the relevant parts):
    # ...
    hardware.video.hidpi.enable = lib.mkDefault true;
    # ...
  • glxgears runs at about 60FPS
  • Some additional query information:
    $ lspci -k | grep -E "(VGA|3D)"
    00:02.0 VGA compatible controller: Intel Corporation TigerLake-LP GT2 [Iris Xe Graphics] (rev 01)
    $ xrandr --listproviders
    Providers: number : 0
    $ nix-info -m
     - system: `"x86_64-linux"`
     - host os: `Linux 5.10.43, NixOS, 21.11pre295280.fa0326ce523 (Porcupine)`
     - multi-user?: `yes`
     - sandbox: `yes`
     - version: `nix-env (Nix) 2.3.12`
     - channels(rule): `"home-manager, nixos-21.11pre304626.8ecc61c91a5"`
     - channels(root): `"nixos-21.11pre295280.fa0326ce523"`
     - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
    $ glxinfo | grep "OpenGL renderer"
    OpenGL renderer string: Mesa Intel(R) Xe Graphics (TGL GT2)

If there’s other information that would be helpful, let me know. I appreciate your help!

1 Like

One other thing…

Gnome’s System Settings “About” panel reports that I’m using Wayland and so does my environment:


I thought I was using X, so I’m not sure what’s going on here, but wanted to report in case it’s relevant. Thanks!

Hey! :wave: I’m afraid I don’t have any good tips for you with this setup, but I appreciate the mention :grinning_face_with_smiling_eyes: I’ve also got a Yoga on the way which should roughly match your specs, so I’ll be watching this thread with a lot of interest.

Finally, as someone told me in my thread: thanks for providing all the info! It makes it much easier to help you debug the issue. Hopefully someone with more experience with your Mesa systems will drop by and be able to help you out.

Just had a quick look at the docs you linked, so I’m sure you’ve covered it already, but have you tried setting

  services.xserver.videoDrivers = [ "intel" ];
  services.xserver.deviceSection = ''
    Option "DRI" "2"
    Option "TearFree" "true"

No effect?


I’ve your same laptop but I never experienced your issues, I’ve switched to wayland since a month and before I’ve never used full desktop environments like you. Anyway, I think that I’m using a much recent kernel release, the 2.13.12, as of now. For that, I’ve this line in my config:

boot.kernelPackages = pkgs.linuxPackages_latest;

You can find more of my config here, look for the config of the bean host.

1 Like

Glad to hear that somebody else is interested in figuring this out :slight_smile:

I did try the settings mentioned in the docs, and there was an effect. It actually made things notably worse.

Oh, yeah, sorry. I should have re-read the opening post better; you already said so :see_no_evil: Sorry, my bad! But yeah, in that case, I don’t have many other suggestions for now.

Thanks @azazel75 - your configuration looks a lot more mature than mine. I’m just getting started with NixOS, so I’m not sure I understand all the layers involved.

I did adopt your kernel release suggestion, but that didn’t seem to resolve the issue.

I’m wondering if the problem is related to the fact that I have a 4K screen. Do you have that on your machine?

Edit: Oh, one other thing…are you using sway with Wayland or some other window manager? Thanks!

Still no solution, but here’s an update on what I’ve tried.

I set services.xserver.displayManager.gdm.wayland to false to force the use of X11 and then tried the manual’s suggestion of using intel, DRI2, TearFree, etc. That made things much worse with all sorts of visual artifacts and very slow graphics performance (basically unusable).

I’m currently in X11 with:

services.xserver.videoDrivers = [ "modesetting" ];
services.xserver.UseGlamor = true;

I still experience the same sorts of artifacts.

Oh, bummer! the other things i do usually is to update all the firmwares using fwupdmgr utility and pay attention to install all the updated in the “lenovo thinkvantage” utility in windows… some are the same that fwupdmgr would install but some don’t.

I’ve a 5K 34" LG connected to it.

Yes, you can see its configuration in the module azazel/wayland.nix inside my repository. I must say that this may not be a good moment to switch to sway on unstable because one its main dependencies, wlroots, seems to be undergoing some major refactorings and this seems to be the root of some instabilities and issues with some apps, like firefox.

One other thing that comes to mind: are you connecting the display directly via HDMI or USB-C or are you using some dongle or other devices that does some conversion maybe? In such case that may be the culprit? (I’m connecting the display directly via USB-C-Thunderbolt)

edit: yes, I’m using sway :wink:

Didn’t know about this - thanks! I’m not dual-booting, so I don’t have access to the “lenovo thinkvantage” utility, but I didn’t know about fwupdmgr at all.

I’m just using the built-in screen, which is 14" 3840 x 2400.

Re: sway

Thanks! It’s too bad that there’s some instability right now, but I might try it anyway.

To try it out I think you’ll have to set services.fwupd.enable = true as well :wink:

1 Like

I think I may be getting somewhere.

I’m still in X11 but removed these lines from /etc/nixos/configuration.nix:

services.xserver.videoDrivers = [ "modesetting" ];
services.xserver.UseGlamor = true;

The NixOS manual recommends these two lines, but I’m experiencing far fewer graphics artifacts without them.

I now infrequently see:

  • the alt-tab interface doesn’t appear the first time I hit Alt + Tab
  • The tab bar in Gnome’s default Terminal application will occasionally lag in updating

Both of these issues seem to be specific to Gnome.

Modern gnome uses wayland by default. This is probably a good thing, once you figure out screen sharing, which IME is the main snag.

This might be considered a bug, since you use services.xserver, so you’d think it would launch an X server for your user, but gdm is what handles your actual user session. That is, I think currently you’re starting gdm in an X server, which then launches wayland.

You can disable this with services.xserver.displayManager.gdm.wayland.

As for your remaining “screen tearing” - no idea. I think that’s more likely to be a wayland/gnome bug than driver related, but others are more qualified to answer that.

Whoops, discourse seens to have loaded a cached copy or something, didn’t see the other replies until just now, sorry!

No problem, @TLATER - your original reply is still helpful :slight_smile:

Just as a quick experiment, I turned off X11 + Gnome, copied the suggested configuration details for sway from the NixOS wiki page, rebuilt, and rebooted. I now have a host of new tools to configure, but I’m no longer seeing any graphics artifacts :smiley:

My best guess is that the artifacts I was seeing came from Gnome, though I’m not entirely sure why.

I also had horrible tearing with my Intel i7-1185G7 Xe Graphics, even though I was using Wayland. Turns out Panel Self Refresh is buggy (PSR causes short freezes on Dell XPS 13 9310 2-in-1 (Tigerlake) (#3496) · Issues · drm / intel) and I have to set

boot.kernelParams = [ "i915.enable_psr=0" ];

@hmenke - Interesting! I haven’t noticed any issues since switching to Wayland. It looks like Panel Self Refrsh is designed to improve power consumption, so I might want to keep enabled unless I notice a problem, right?

I believe that this is specific to this particular iGPU (it’s also documented on the Arch Wiki for my laptop: Dell XPS 13 (9310) - ArchWiki). But even with PSR turned off I didn’t witness any noticeable increase in power draw, so I think the returns of this feature are diminishing and if it causes issues is safe to turn off.

1 Like

This sounds like it should be added to nixos-hardware :slight_smile:

There is a config for your device available already: nixos-hardware/default.nix at 342048461da7fc743e588ee744080c045613a226 · NixOS/nixos-hardware · GitHub. Maybe there should be a common config for that processor and it should be added to all devices that run it?

1 Like

Just wanted to chime in after getting my gen 6 X1 Yoga (which is essentially the same as the Carbon, just foldable) :raising_hand_man:

I use X and EXWM and I had screen tearing with the default settings. However, switching to using the latest kernel packages and using the secondary option (intel video driver) seems to have fixed it. The docs mention that this may cause some performance issues, but I don’t think that’s going to cause much of an issue. At least I hope not.

I do have a follow-up question, though: could the screen tearing that appears with the modesetting option be fixed by a late set of kernel packages? That is, if I switch back to using modesetting, could it one day magically be fixed by updating the system?