Need some help with amd+nvidia setup

Hello everyone,

I’m not able to get my new laptop use my external display and the laptop display at the same time. I first thought to make use of the internal gpu when possible, but right now I’d be happy to get back to work. I want the laptop display and the external monitor to work at the same time.

Here are some Infos about my system:

$ inxi -SMGx
System:    Host: kalamos Kernel: 5.10.32 x86_64 bits: 64 compiler: gcc v: 10.2.0 Desktop: herbstluftwm 0.9.2
           Distro: NixOS 21.05.git.4397711c75f (Okapi)
Machine:   Type: Laptop System: Schenker product: XMG CORE 15(M20, GTX 1650xx) v: Standard serial: <superuser required>
           Mobo: Schenker model: GK5NxxO M20 v: Standard serial: <superuser required> UEFI: American Megatrends v: N.1.20.A03
           date: 12/10/2020
Graphics:  Device-1: NVIDIA TU116M [GeForce GTX 1650 Ti Mobile] vendor: Tongfang Hongkong Limited driver: nvidia v: 460.73.01
           bus-ID: 01:00.0
           Device-2: Advanced Micro Devices [AMD/ATI] Renoir vendor: Tongfang Hongkong Limited driver: amdgpu v: kernel
           bus-ID: 06:00.0
           Device-3: Sonix HD Webcam type: USB driver: uvcvideo bus-ID: 3-4:4
           Display: x11 server: X.Org 1.20.11 driver: loaded: amdgpu,nvidia resolution: 1920x1080~144Hz
           OpenGL: renderer: AMD RENOIR (DRM 3.40.0 5.10.32 LLVM 11.1.0) v: 4.6 Mesa 21.0.1 direct render: Yes
$ nix-info -m
  • system: "x86_64-linux"
  • host os: Linux 5.10.32, NixOS, 21.05.git.4397711c75f (Okapi)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.3.10
  • channels(root): "nixos-21.05pre285574.8e4fe32876c"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

NixOS config (relevant parts):

{ config, pkgs, ... }:
{
  services.openssh.enable = true;
  hardware = {
    enableAllFirmware = true;
    cpu.amd.updateMicrocode = true;  #needs unfree
    opengl.enable = true;
    opengl.driSupport32Bit = true;
  };
  services.xserver = {
    videoDrivers = [ "nvidia" ];
  };
  boot.extraModulePackages =
    [ config.boot.kernelPackages.nvidia_x11
    ];
  hardware.nvidia = {
    prime = {
      #offload.enable = true;
      sync.enable = true;
      amdgpuBusId = "PCI:6:0:0";
      nvidiaBusId = "PCI:1:0:0";
    };
    modesetting.enable = true;
  };
}

I first tried with prime.offload=true with no luck. Offloading worked, but the external display was not working - only the laptop screen. I can give much more detail on what I tried, but I then read somewhere that tihs is not a good approach when using both displays. After a lot of trial&error I installed ubuntu to see if that can make sense where I fail. And surprise, surprise, both displays work out of the box. Here are some infos from Ubuntu:

xrandr --listproviders  #Ubuntu
Providers: number : 2
Provider 0: id: 0x1b8 cap: 0x1, Source Output crtcs: 4 outputs: 5 associated providers: 1 name:NVIDIA-0
Provider 1: id: 0x1fc cap: 0x6, Sink Output, Source Offload crtcs: 4 outputs: 1 associated providers: 1 name:Unknown AMD Radeon GPU @ pci:0000:06:00.0

Here the nvidia card is first provider and the igpu is second. I guessed that this is the way “prime.sync=true” works in nixos? While this worked with Ubuntu, the nvidia card must be marked as “always on”. When setting it to “on demand” in nvidia-settings I can’t get it to work in Ubuntu, either.

Now with NixOS and the above config, the laptop screen is black but the external monitor shows GDM and I can login. The providers look a bit different, though:

xrandr --listproviders  # NixOS 
Providers: number : 2
Provider 0: id: 0x1b8 cap: 0x1, Source Output crtcs: 4 outputs: 5 associated providers: 0 name:NVIDIA-0
Provider 1: id: 0x206 cap: 0x0 crtcs: 4 outputs: 1 associated providers: 0 name:Unknown AMD Radeon GPU @ pci:0000:06:00.0

This looks very similar to the output from ubuntu, but the amd card has no capabilities; so the xrandr commands to set the outputsource is not working. In ubunut it showed two capabilities: Sink Output, Source Offload.

xrandr --setprovideroutputsource 1 0
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  140 (RANDR)
  Minor opcode of failed request:  35 (RRSetProviderOutputSource)
  Value in failed request:  0x206
  Serial number of failed request:  16
  Current serial number in output stream:  17

So the laptop screen cannot be connected and also does not show up in the output of xrandr.

I read a lot of posts (some were a bit older), some said that the amdgpu doesn’t work and one should use the modesetting driver. So I changed this in nixpkgs’ nvidia.nix where the corresponding changes appear.

With this change (using modesetting instead of amdgpu), the output shows one capapility and I can successfully run the xrandr --setprovideroutputsource command. But the notebook display is all black like not switched on.

I realized that the driver is marked as “Inactive” in the xorg config in nvidia.nix. So I removed this. Then the display stays on showing the boot output. The external display shows X. But xrandr --listproviders shows only one provider - the nvidia card.

I’m glad for any pointers to solve and/or better understand the whole thing. It would be nice to somehow get to the same state as Ubuntu (ubuntu has no xorg.conf to look at).

Thank you in advance and regards
Eike

Hi Eike,

I have the same issue on an Asus Scar 17 (Ryzen 5900HS + Nvidia RTX 3070). The HDMI output is wired to the AMD GPU and the DisplayPort (USB-C alt) to the NVIDIA GPU. Did you manage to get it working? I am able to set the provider output source (once I added amdgpu to the driver list) and the connections show up in xrandr. But once I try enabling the display I get an xrandr (crtc 4) error.

Thank you,
Yves

Hi Yves,

unfortunately I haven’t had any luck yet. But I also stopped trying for now, because my partner needs a laptop until end of june (without external monitor… I’m using my old one). So I’ll start digging into it again later :frowning: The crtc error you mentioned rings a bell! I had the same when trying with nvidia offload mode. From my notes back then:

nvidia offload: amd card is first provider, nvidia is second:

$ xrandr --listproviders
Providers: number : 2
Provider 0: id: 0x54 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 4 outputs: 1 associated providers: 1 name:Unknown AMD Radeon GPU @ pci:0000:06:00.0
Provider 1: id: 0x1f6 cap: 0x2, Sink Output crtcs: 4 outputs: 5 associated providers: 1 name:NVIDIA-G0

When I call xrandr --auto it complains with: xrandr: Configure crtc 4 failed.

I tried to find out more via xrandr --verbose. It shows that while the ePD display has a CRTC number assigned, the other display has not.

xrandr --verbose|grep -i crtc
    CRTC:       0
    CRTCs:      0 1 2 3
    CRTCs:      4 5 6 7
    CRTCs:      4 5 6 7
    CRTCs:      4 5 6 7
    CRTCs:      4 5 6 7
    CRTCs:      4 5 6 7

The CRTCs (note the s at the end) array is on each display, but only one has a single crtc number. What does this number mean?

end of my notes

I don’t know what this crtc number is. Never had to deal with this before. I also wasn’t able to see how exactly ubuntu managed it. And on ubuntu it also seemed to be not very performant (but at the time I didn’t care at all about this … just a first impression).

I then wanted to try a “normal old xorg” conf, where I have two separate screens. I know I had something like this running some years ago. But I failed to properly configure it with NixOS, it’s been some years since I wrote a xorg conf myself and it wasn’t very obvious to me where to put it :confused:. Shortly after I had to pause :slight_smile:

Should you find out something with your computer, I’d like to know :upside_down_face:

Hi all,

I have the same issue with my Tuxedo Polaris 15 and Gnome/GDM. Any hint how to fix it would be welcome.

At the moment, I switch between the proprietary (external screens works) and open source nvidia drivers (internal screen works).

Thanks,
Tom

Hi @pro70,
thank you for your reply! How do you manage this - do you have to restart into another configuration, or can you change this using a command? I think I could live with this for a while, too.
Thanks,
Eike

Hi @eikek,

I have two configurations, one with the xserver driver line commented and one with the line enabled, and choose depending if I’m on my desk or not.

Anyway, would be nice to have a better solution and the internal screen also usable on the desk.

Regards,
Thomas

1 Like

Hello!

I too am having this problem, which I currently fix by changing the configuration and then rebooting, when I want to switch between external monitor usage and the laptop monitor.

Did anyone find a better solution, would be much appreciated!