nvidia-prime + xorg 1.19 + sddm = artifacts around mouse on first login

I originally filed this bug with sddm, but I think it would be worth it to post it here:

This has been an issue for ubuntu users of sddm for a while now. With newer xorg versions, sddm has an artifact around the mouse that carries on into the desktop session.

[url]https://bugs.launchpad.net/ubuntu/+source/plasma-workspace/+bug/1684240[/url]

[url]https://www.kubuntuforums.net/showthread.php/72149-Mouse-artifact-introduced-in-7-26-update[/url]

I have this issue so I am willing to be a guinea pig for any testing.

It seems that Nvidia opengl has trouble initializing on first boot.

So I found some interesting results.

The first login, which triggers the artifacting:
https://pastebin.com/raw/8vj1qVeR

The second login, which is normal:
https://pastebin.com/raw/bjXi7BAA

The diff between the two:
https://pastebin.com/raw/f0pwCxFi

Now I try to break down the diff:

The first diff:

(EE) /dev/dri/card0: failed to set DRM interface version 1.4: Permission denied

I don’t know why drm would fail on the first login.

The second:

(WW) Falling back to old probe method for modesetting

Then the diff becomes really big. The second login seems to run modeset properly:

(==) modeset(G0): Depth 24, (==) framebuffer bpp 32
 (**) modeset(G0): Option "AccelMethod" "None"
 (==) modeset(G0): RGB weight 888
 (==) modeset(G0): Default visual is TrueColor
 (**) modeset(G0): glamor disabled
 (II) modeset(G0): ShadowFB: preferred YES, enabled YES
 (II) modeset(G0): Double-buffered shadow updates: off
 (II) modeset(G0): Output eDP-1-1 has no monitor section
 (II) modeset(G0): Output HDMI-1-1 has no monitor section
 (II) modeset(G0): EDID for output eDP-1-1
 (II) modeset(G0): Manufacturer: LGD  Model: 4b9  Serial#: 0
 (II) modeset(G0): Year: 2015  Week: 0
 (II) modeset(G0): EDID Version: 1.4
 (II) modeset(G0): Digital Display Input
 (II) modeset(G0): 6 bits per channel
 (II) modeset(G0): Digital interface is DisplayPort
 (II) modeset(G0): Max Image Size [cm
 (II) modeset(G0): Gamma: 2.20
 (II) modeset(G0): DPMS capabilities: StandBy Suspend Off
 (II) modeset(G0): Supported color encodings: RGB 4:4:4 YCrCb 4:4:4 
 (II) modeset(G0): First detailed timing is preferred mode
 (II) modeset(G0): Preferred mode is native pixel format and refresh rate
 (II) modeset(G0): redX: 0.580 redY: 0.350   greenX: 0.340 greenY: 0.560
 (II) modeset(G0): blueX: 0.155 blueY: 0.125   whiteX: 0.313 whiteY: 0.329
 (II) modeset(G0): Manufacturer's mask: 0
 (II) modeset(G0): Supported detailed timing:
 (II) modeset(G0): clock: 138.7 MHz   Image Size:  344 x 194 mm
 (II) modeset(G0): h_active: 1920  h_sync: 1968  h_sync_end 2000 h_blank_end 2080 h_border: 0
 (II) modeset(G0): v_active: 1080  v_sync: 1083  v_sync_end 1088 v_blanking: 1111 v_border: 0
 (II) modeset(G0): Supported detailed timing:
 (II) modeset(G0): clock: 111.0 MHz   Image Size:  344 x 194 mm
 (II) modeset(G0): h_active: 1920  h_sync: 1968  h_sync_end 2000 h_blank_end 2080 h_border: 0
 (II) modeset(G0): v_active: 1080  v_sync: 1083  v_sync_end 1088 v_blanking: 1111 v_border: 0
 (II) modeset(G0):  9HG62�156WF6
 (II) modeset(G0): Unknown vendor-specific block 0
 (II) modeset(G0): EDID (in hex):
 (II) modeset(G0):      00ffffffffffff0030e4b90400000000
 (II) modeset(G0):      0019010495221378eaa1c59459578f27
 (II) modeset(G0):      20505400000001010101010101010101
 (II) modeset(G0):      0101010101012e3680a070381f403020
 (II) modeset(G0):      350058c21000001a5c2b80a070381f40
 (II) modeset(G0):      3020350058c21000001a000000fe0039
 (II) modeset(G0):      48473632803135365746360a00000000
 (II) modeset(G0):      0000413196001000000a010a20200058
 (II) modeset(G0): Printing probed modes for output eDP-1-1
 (II) modeset(G0): Modeline "1920x1080"x60.0  138.70  1920 1968 2000 2080  1080 1083 1088 1111 +hsync -vsync (66.7 kHz eP)
 (II) modeset(G0): Modeline "1920x1080"x59.9  138.50  1920 1968 2000 2080  1080 1083 1088 1111 +hsync -vsync (66.6 kHz d)
 (II) modeset(G0): Modeline "1920x1080"x48.0  111.00  1920 1968 2000 2080  1080 1083 1088 1111 +hsync -vsync (53.4 kHz e)
 (II) modeset(G0): Modeline "1680x1050"x60.0  146.25  1680 1784 1960 2240  1050 1053 1059 1089 -hsync +vsync (65.3 kHz d)
 (II) modeset(G0): Modeline "1680x1050"x59.9  119.00  1680 1728 1760 1840  1050 1053 1059 1080 +hsync -vsync (64.7 kHz d)
 (II) modeset(G0): Modeline "1600x1024"x60.2  103.12  1600 1600 1656 1664  1024 1024 1029 1030 +hsync +vsync (62.0 kHz d)
 (II) modeset(G0): Modeline "1400x1050"x60.0  122.00  1400 1488 1640 1880  1050 1052 1064 1082 +hsync +vsync (64.9 kHz d)
 (II) modeset(G0): Modeline "1280x1024"x60.0  108.00  1280 1328 1440 1688  1024 1025 1028 1066 +hsync +vsync (64.0 kHz d)
 (II) modeset(G0): Modeline "1440x900"x59.9  106.50  1440 1520 1672 1904  900 903 909 934 -hsync +vsync (55.9 kHz d)
 (II) modeset(G0): Modeline "1280x960"x60.0  108.00  1280 1376 1488 1800  960 961 964 1000 +hsync +vsync (60.0 kHz d)
 (II) modeset(G0): Modeline "1360x768"x59.8   84.75  1360 1432 1568 1776  768 771 781 798 -hsync +vsync (47.7 kHz d)
 (II) modeset(G0): Modeline "1360x768"x60.0   72.00  1360 1408 1440 1520  768 771 781 790 +hsync -vsync (47.4 kHz d)
 (II) modeset(G0): Modeline "1152x864"x60.0   81.62  1152 1216 1336 1520  864 865 868 895 -hsync +vsync (53.7 kHz d)
 (II) modeset(G0): Modeline "1024x768"x120.1  133.47  1024 1100 1212 1400  768 768 770 794 doublescan -hsync +vsync (95.3 kHz d)
 (II) modeset(G0): Modeline "1024x768"x60.0   65.00  1024 1048 1184 1344  768 771 777 806 -hsync -vsync (48.4 kHz d)
 (II) modeset(G0): Modeline "960x720"x120.0  117.00  960 1024 1128 1300  720 720 722 750 doublescan -hsync +vsync (90.0 kHz d)
 (II) modeset(G0): Modeline "928x696"x120.1  109.15  928 976 1088 1264  696 696 698 719 doublescan -hsync +vsync (86.4 kHz d)
 (II) modeset(G0): Modeline "896x672"x120.0  102.40  896 960 1060 1224  672 672 674 697 doublescan -hsync +vsync (83.7 kHz d)
 (II) modeset(G0): Modeline "960x600"x120.0   77.00  960 984 1000 1040  600 601 604 617 doublescan +hsync -vsync (74.0 kHz d)
 (II) modeset(G0): Modeline "960x540"x120.0   69.25  960 984 1000 1040  540 541 544 555 doublescan +hsync -vsync (66.6 kHz d)
 (II) modeset(G0): Modeline "800x600"x120.0   81.00  800 832 928 1080  600 600 602 625 doublescan +hsync +vsync (75.0 kHz d)
 (II) modeset(G0): Modeline "800x600"x60.3   40.00  800 840 968 1056  600 601 605 628 +hsync +vsync (37.9 kHz d)
 (II) modeset(G0): Modeline "800x600"x56.2   36.00  800 824 896 1024  600 601 603 625 +hsync +vsync (35.2 kHz d)
 (II) modeset(G0): Modeline "840x525"x120.0   73.12  840 892 980 1120  525 526 529 544 doublescan -hsync +vsync (65.3 kHz d)
 (II) modeset(G0): Modeline "840x525"x119.8   59.50  840 864 880 920  525 526 529 540 doublescan +hsync -vsync (64.7 kHz d)
 (II) modeset(G0): Modeline "800x512"x120.3   51.56  800 800 828 832  512 512 514 515 doublescan +hsync +vsync (62.0 kHz d)
 (II) modeset(G0): Modeline "700x525"x120.0   61.00  700 744 820 940  525 526 532 541 doublescan +hsync +vsync (64.9 kHz d)
 (II) modeset(G0): Modeline "640x512"x120.0   54.00  640 664 720 844  512 512 514 533 doublescan +hsync +vsync (64.0 kHz d)
 (II) modeset(G0): Modeline "720x450"x119.8   53.25  720 760 836 952  450 451 454 467 doublescan -hsync +vsync (55.9 kHz d)
 (II) modeset(G0): Modeline "640x480"x120.0   54.00  640 688 744 900  480 480 482 500 doublescan +hsync +vsync (60.0 kHz d)
 (II) modeset(G0): Modeline "640x480"x59.9   25.18  640 656 752 800  480 490 492 525 -hsync -vsync (31.5 kHz d)
 (II) modeset(G0): Modeline "680x384"x119.6   42.38  680 716 784 888  384 385 390 399 doublescan -hsync +vsync (47.7 kHz d)
 (II) modeset(G0): Modeline "680x384"x119.9   36.00  680 704 720 760  384 385 390 395 doublescan +hsync -vsync (47.4 kHz d)
 (II) modeset(G0): Modeline "576x432"x120.1   40.81  576 608 668 760  432 432 434 447 doublescan -hsync +vsync (53.7 kHz d)
 (II) modeset(G0): Modeline "512x384"x120.0   32.50  512 524 592 672  384 385 388 403 doublescan -hsync -vsync (48.4 kHz d)
 (II) modeset(G0): Modeline "400x300"x120.6   20.00  400 420 484 528  300 300 302 314 doublescan +hsync +vsync (37.9 kHz d)
 (II) modeset(G0): Modeline "400x300"x112.7   18.00  400 412 448 512  300 300 301 312 doublescan +hsync +vsync (35.2 kHz d)
 (II) modeset(G0): Modeline "320x240"x120.1   12.59  320 328 376 400  240 245 246 262 doublescan -hsync -vsync (31.5 kHz d)
 (II) modeset(G0): EDID for output HDMI-1-1
 (==) modeset(G0): Using gamma correction (1.0, 1.0, 1.0)
 (==) modeset(G0): DPI set to (96, 96)
 (II) Loading sub module "fb"
 (II) LoadModule: "fb"
 (II) Loading /usr/lib/xorg/modules/libfb.so
 (II) Module fb: vendor="X.Org Foundation"
        compiled for 1.19.3, module version = 1.0.0
        ABI class: X.Org ANSI C Emulation, version 0.4
 (II) Loading sub module "shadow"
 (II) LoadModule: "shadow"
 (II) Loading /usr/lib/xorg/modules/libshadow.so
 (II) Module shadow: vendor="X.Org Foundation"
        compiled for 1.19.3, module version = 1.1.0
        ABI class: X.Org ANSI C Emulation, version 0.4
 (--) Depth 24 pixmap format is 32 bpp
 (==) modeset(G0): Backing store enabled
 (==) modeset(G0): Silken mouse enabled
 (II) modeset(G0): RandR 1.2 enabled, ignore the following RandR disabled message.
 (==) modeset(G0): DPMS enabled
 (WW) modeset(G0): Option "AllowEmptyInitialConfiguration" is not used
 (WW) modeset(G0): Option "IgnoreDisplayDevices" is not used

While the first login falls back on glamourgl, which I think is the issue:

(II) config/udev: Adding drm device (/dev/dri/card0)
 (II) xfree86: Adding drm device (/dev/dri/card0)
 (II) LoadModule: "modesetting"
 (II) Loading /usr/lib/xorg/modules/drivers/modesetting_drv.so
 (II) Module modesetting: vendor="X.Org Foundation"
        compiled for 1.19.3, module version = 1.19.3
        Module class: X.Org Video Driver
        ABI class: X.Org Video Driver, version 23.0
 (II) UnloadModule: "modesetting"
 (II) Unloading modesetting
 (II) Failed to load module "modesetting" (already loaded, 22019)
 (II) modeset(G0): using drv /dev/dri/card0
 (==) modeset(G0): Depth 24, (==) framebuffer bpp 32
 (==) modeset(G0): RGB weight 888
 (==) modeset(G0): Default visual is TrueColor
 (II) Loading sub module "glamoregl"
 (II) LoadModule: "glamoregl"
 (II) Loading /usr/lib/xorg/modules/libglamoregl.so
 (II) Module glamoregl: vendor="X.Org Foundation"
        compiled for 1.19.3, module version = 1.0.0
        ABI class: X.Org ANSI C Emulation, version 0.4
 (II) glamor: OpenGL accelerated X.org driver based.
 (EE) modeset(G0): eglGetDisplay() failed
 (EE) modeset(G0): glamor initialization failed
 (II) modeset(G0): ShadowFB: preferred YES, enabled YES
 (II) modeset(G0): Double-buffered shadow updates: off
 (II) modeset(G0): Output eDP-1-1 has no monitor section
 (II) modeset(G0): Output HDMI-1-1 has no monitor section
 (==) modeset(G0): Using gamma correction (1.0, 1.0, 1.0)
 (==) modeset(G0): DPI set to (96, 96)
 (II) Loading sub module "fb"
 (II) LoadModule: "fb"
 (II) Loading /usr/lib/xorg/modules/libfb.so
 (II) Module fb: vendor="X.Org Foundation"
        compiled for 1.19.3, module version = 1.0.0
        ABI class: X.Org ANSI C Emulation, version 0.4
 (II) Loading sub module "shadow"
 (II) LoadModule: "shadow"
 (II) Loading /usr/lib/xorg/modules/libshadow.so
 (II) Module shadow: vendor="X.Org Foundation"
        compiled for 1.19.3, module version = 1.1.0
        ABI class: X.Org ANSI C Emulation, version 0.4
 (==) modeset(G0): Backing store enabled
 (==) modeset(G0): Silken mouse enabled
 (II) modeset(G0): RandR 1.2 enabled, ignore the following RandR disabled message.
 (==) modeset(G0): DPMS enabled
 (WW) modeset(G0): Option "AllowEmptyInitialConfiguration" is not used
 (WW) modeset(G0): Option "IgnoreDisplayDevices" is not used
 (II) modeset(G0): Damage tracking initialized
 xf86: found device 2

Anyways any help solving this issue would be appreciated, and I am willing to test any possible fixes.