External monitor not working under Gnome Wayland (Optimus laptop)

So, as the title says, if I connect an external monitor to my laptop it doesn't work if I am on Wayland. On Xorg this doesn't happen, as it connects with no problem whatsoever. I am currently using Nvidia proprietary drivers, and I know that sometimes they can work badly with wayland, but other than the issue with the monitor I think they are working fine.
I'd like to stick with wayland because of its gestures and the possibility of using kinetic scrolling with firefox, since they are really useful on a laptop.
Anyway, this is the output of glxinfo | grep "OpenGL renderer": OpenGL renderer string: Mesa DRI Intel(R) UHD Graphics 630 (CFL GT2), so that means that wayland is using the onboard intel graphics and not the nvidia one.
This is the partial output of inxi --full --verbosity=7 --filter --no-host regarding the graphics:

Graphics:
  Device-1: Intel UHD Graphics 630 vendor: Micro-Star MSI driver: i915 
  v: kernel bus-ID: 00:02.0 chip-ID: 8086:3e9b class-ID: 0300 
  Device-2: NVIDIA TU106M [GeForce RTX 2060 Mobile] vendor: Micro-Star MSI 
  driver: nvidia v: 465.31 bus-ID: 01:00.0 chip-ID: 10de:1f15 class-ID: 0300 
  Display: wayland server: X.Org 1.21.1.1 compositor: gnome-shell driver: 
  loaded: intel,nvidia unloaded: modesetting,nouveau 
  alternate: fbdev,nv,vesa resolution: 1920x1080~120Hz s-dpi: 96 
  OpenGL: renderer: Mesa DRI Intel UHD Graphics 630 (CFL GT2) 
  v: 4.6 Mesa 21.1.1 compat-v: 3.0 direct render: Yes

But what bothers me the most is the output of xrandr:

Screen 0: minimum 16 x 16, current 1920 x 1080, maximum 32767 x 32767
XWAYLAND0 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 340mm x 190mm
   1920x1080    120.01*+
   1440x1080    120.03  
   1400x1050    120.01  
   1280x1024    119.96  
   1280x960     119.89  
   1152x864     119.94  
   1024x768     120.02  
   800x600      119.85  
   640x480      119.52  
   320x240      119.73  
   1680x1050    119.99  
   1440x900     120.07  
   1280x800     120.01  
   720x480      119.65  
   640x400      119.64  
   320x200      117.55  
   1600x900     120.07  
   1368x768     119.99  
   1280x720     119.86  
   1024x576     119.85  
   864x486      119.69  
   720x400      119.54  
   640x350      120.03

since the HDMI port is not even listed. On Xorg even with the external display disconnected the port is there.

Sorry if this is a stupid question, I have seen similar issues but they were either unsolved or what I tried didn't work, so any idea would be greatly appreciated.
Thanks in advance.

Seems to be an Nvidia driver limitation:

My take: use Xorg for now if you want to use the dGPU. :man_shrugging:

4 Likes

I kinda expected that, but I hoped there was a solution. Anyway, thank you!

Sorry if I removed this post from the solution, but I tried some other things and I am more confused than ever.
Apparently the problem itself isn't the fact that nvidia-prime doesn't support wayland, but for some reason the problem is gdm.
I tried launching a wayland session from lightdm, and from there there is no problem whatsoever. So I'm trying to understand why the same thing from two different login managers gets two different results. I don't know if gdm fails to launch or start the gpu, but if I run nvidia-smi I get:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 465.31       Driver Version: 465.31       CUDA Version: 11.3     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  On   | 00000000:01:00.0 Off |                  N/A |
| N/A   40C    P0    13W /  N/A |      1MiB /  5934MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

so the card is on and on persistence mode, but for some reason prime-run and the external display are not working, while on lightdm they do.

If I try to launch prime-run glxgears -info this is what I get

X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  150 (GLX)
  Minor opcode of failed request:  3 (X_GLXCreateContext)
  Value in failed request:  0x0
  Serial number of failed request:  26
  Current serial number in output stream:  27
1 Like

Since your issue is solved, I suggest you report and contribute upstream (whichever package developer) to improve their compatibility.

There is a misunderstanding about Wayland.
Because some distros, or Gnome introduces Wayland as default, people think it’s ready for production.
Totally wrong. They are just experimenting/testing, because they… can.
The majority of experienced Linux users know Xorg very well.
Only a few heroes know about Wayland troubleshooting.
I’m not one of them.
If you find anyone, please, ask him to help in here from time to time. :slightly_smiling_face:

2 Likes

Thanks, unfortunately for what I've seen Wayland is still not very compatible with Nvidia except in some specific cases. Unfortunately I've not found a way to make it work in Gnome from GDM. I guess that for gaming / using an external HDMI I'll stick to Xorg for the time being. Anyway, thanks for the input!

1 Like

Until wayland is ready :wink:

Have you tried running gdm in Xorg?

What I mean to say is that prime-run works on xorg from both gdm and lightdm. It barely works on wayland if I launch a session from lightdm, but not from gdm

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.

I've just hit the same thing.

Internal panel running on the iGPU works fine when forcing Wayland with an amdgpu+nvidia laptop. Adding an external display (USB-C -> DisplayPort) causes GDM to crash a few times then restart in Xorg mode, and then the external display works perfectly using the dGPU.

Note, I do not use any management software with GNOME as it picks up the GPUs and routes things correctly.

I suspect this is something that will improve with Wayland/Nvidia, but for now Xorg is the way forwards (and it will be one reason why Xorg is preferred by /usr/lib/udev/rules.d/61-gdm.rules).

2 Likes