Ryzen 7 + GTX 1660Ti: blank screen on external outputs in Hybrid graphics mode

Sorry for the delay! Here is the post on my blog

Yes, thanks for sharing that. I was exploring the integrated video option thinking it was going to give me longer battery life. It turns out, the battery seems to lasts longer using the discrete card. Bear in mind, I don’t have hard data to back this claim. Once I solved the issues, I didn’t look more into it.

Thanks Carlos!,
just for know, the lcd brightness didn’t work?, i currently have with discrete only for this reason, because in middle to dark rooms maximum brightness hurts my eyes.

Just for know2: How long last the battery with hybrid mode?, with discrete only last 3hr aprox.

Thanks for all!!!
Regards!

Sorry, I haven’t check the 5.10 kernel, I’ll need to stay with version 5.9 for a few more days before moving to the newer version.

I could not fix the LCD brightness control with hybrid video.
The battery life seemed shorter using hybrid video too.
Sorry I can’t provide more info, I switched to discrete video too.

Thanks for reviving this thread guys.

So looks like there is no solution for the backlight control in Hybrid mode yet.

I ran a few tests with Hybrid mode on Windows, and the battery life difference is minimal, between 5 and 20% at most, and only when you’re idle. I suspect the NVIDIA card is not powered down properly even on Windows, and the AMD one is not as power efficient as we were lead to believe.

Still I’d like to run the same tests on Linux to see if there’s a difference, but I guess now we’ll have to wait…

Hi Friend,

Indeed, if the with screen at maximun brightness losse all the posibles beneficts of the non-nvidia save power, even drain more than nvidia with mid brightness level. And the fact of the maximum brightness hurts severely the eyes, actually there is no deal use this hybrid mode right now. If some one fix it, will be a deal breaker.

Regards!

Did you guys run any battery tests in hybrid mode on Windows?

Like I said I get around 4 hours of battery in Linux, and in Windows I got at most 1 hour more, and this was not doing anything, just letting the computer sit there. Using the computer I got maybe 30 minutes more… so totally not worth it using Hybrid even in Windows.

I think it was finally fixed in 5.10, I do get an HDMI signal with that kernel version but that’s when only having the Nvidia GPU set (non-hybrid mode). I tried to make the HDMI output work with hybrid graphics but I’m getting a bit stuck. When I connect the HDMI monitor KDE detects it but does not activate it (activating it manually doesn’t change anything, the setting is reverted as soon as I open the system settings again) and changing the external display modes don’t do anything.

This seems weird since I configured Xorg as the Nvidia docs detail:

Section "ServerLayout"
  Identifier     "X.org Configured"
  Screen      0  "AMD"
  Inactive "nvidia"
  Option "AllowNVIDIAGPUScreens"
EndSection

Section "Device"
     Identifier "AMD"
     Driver "amdgpu"
     BusID  "PCI:05:0:0"
     Option "DRI" "3"
     Option "TearFree" "true"
EndSection

Section "Screen"
    Identifier "AMD"
    Device "AMD"
EndSection

Section "Device"
    Identifier  "nvidia"
    Driver      "nvidia"
    Option "AllowEmptyInitialConfiguration"
    BusID       "PCI:01:0:0"
EndSection

Section "Screen"
    Identifier "nvidia"
    Device "nvidia"
EndSection

Section "ServerFlags"
    Option "IgnoreABI" "1"
EndSection

I also tried the next commands once the HDMI monitor is plugged in:

xrandr --setprovideroutputsource 1 0
xrandr --auto

The screen flashes rapidly and the next error is given:

xrandr: Configure crtc 4 failed

But at least I can finally use an external monitor with just the Nvidia GPU (and some quick-switch scripts I made) thanks to the kernel fix!

Hi Jorgetech!,

Can you prepare a tutorial please here, reddit or the plase you want to guide another friends with lenovo legion 5 + linux.
The brightness works for you in integrated, hibryd or nvidia modes?

Regards!

1 Like

If you mean being able to adjust the brightness or the brightness being restored to the previous value, then I do have that working in hybrid and nvidia-only modes, do note that I’m using an Asus TUF FX505DT laptop though (Ryzen 5 3550H + Nvidia GTX), so I have no idea what’s the status of brightness control on recent Legion laptops (I had to install an additional kernel module for having the keyboard lights work in the Asus).

Even though I don’t know about the brightness thing (maybe @carlosmorales777 knows about that), there could be some things in common with this recent Ryzen + Nvidia laptops, so I’m going to give more detail on how I had everything working with Ubuntu 20.10.

First of all, I recommend using at least kernel 5.8 since I was having some problems with the kernel Ubuntu 20.04 LTS was using (sometimes the laptop would freeze on boot, but that may be an Asus TUF specific thing, fixed in newer kernels) and it’s better anyways if you are using recent Ryzen CPUs, for the moment I decided to settle on 5.10.0 since the brightness was a bit weird with Ubuntu’s 5.8 (brightness was not set to previous value on reboot).

After performing a normal installation of (K)Ubuntu 20.10 I first installed the 5.10.0 kernel using the very useful software for installing newer kernels in Ubuntu called Mainline. Then I installed the Nvidia drivers (460 series) from the proprietary graphics drivers PPA. After rebooting the driver will be installed correctly but I wasn’t able to use hybrid mode since for some reason the GPUs are not fully detected, this can be easily fixed with a custom Xorg configuration that specifies the PCI BusIDs assigned to each GPU, you can check that with the lspci command or something like KDE’s Info Center or Hardinfo, the format is “PCI:X:X:X” and it may vary depending on the laptop you have, in my case the Xorg configuration to make Hybrid graphics work was as follows (placed in “/usr/share/X11/xorg.conf.d” in case of Ubuntu, “/etc/X11/xorg.conf.d” may also work):

Section "ServerLayout"
  Identifier     "X.org Configured"
  Screen      0  "AMD"
  Inactive "nvidia"
  Option "AllowNVIDIAGPUScreens"
EndSection

Section "Device"
     Identifier "AMD"
     Driver "amdgpu"
     BusID  "PCI:05:0:0"
     Option "DRI" "3"
     Option "TearFree" "true"
EndSection

Section "Screen"
    Identifier "AMD"
    Device "AMD"
EndSection

Section "Device"
    Identifier  "nvidia"
    Driver      "nvidia"
    Option "AllowEmptyInitialConfiguration"
    BusID       "PCI:01:0:0"
EndSection

Section "Screen"
    Identifier "nvidia"
    Device "nvidia"
EndSection

Section "ServerFlags"
    Option "IgnoreABI" "1"
EndSection

Of course, as I already mentioned, I cannot get external HDMI displays working with this mode even though they should, but they do work if you use an Xorg configuration that sets up the Nvidia GPU as the primary display:

Section "ServerLayout"
    Identifier "layout"
    Screen 0 "nvidia"
    Inactive "AMD"
EndSection

Section "Device"
    Identifier  "nvidia"
    Driver      "nvidia"
    BusID       "PCI:01:0:0"
EndSection

Section "Screen"
    Identifier "nvidia"
    Device "nvidia"
EndSection

Section "Device"
    Identifier  "AMD"
    Driver      "amdgpu"
    BusID       "PCI:05:0:0"
    Option "DRI" "3"
    Option "TearFree" "true"
EndSection

Section "Screen"
    Identifier "AMD"
    Device "amdgpu"
EndSection

But changing manually between the two is too cumbersome, for solving that I created two custom scripts that I linked to the desktop (keep in mind they require superuser access to work, I used KDE’s kdesu in the desktop shortcut, you could use pkexec in GNOME since gksu was brilliantly removed with GNOME 3).

This script for using Hybrid mode:

#!/bin/bash

sudo mv /usr/share/X11/xorg.conf.d/09-optimus-nvidia.conf /usr/share/X11/xorg.conf.d/09-optimus-nvidia.conf.bak
sudo mv /usr/share/X11/xorg.conf.d/09-optimus-hybrid.conf.bak /usr/share/X11/xorg.conf.d/09-optimus-hybrid.conf

And this one for using only the Nvidia GPU (HDMI working):

#!/bin/bash

sudo mv /usr/share/X11/xorg.conf.d/09-optimus-hybrid.conf /usr/share/X11/xorg.conf.d/09-optimus-hybrid.conf.bak
sudo mv /usr/share/X11/xorg.conf.d/09-optimus-nvidia.conf.bak /usr/share/X11/xorg.conf.d/09-optimus-nvidia.conf

After executing those scripts you reboot and you are done.

I’m trying to get hybrid graphics to work on a Lenovo Legion 5 Pro. I followed the comments in this thread and tried the following:

  1. Compiled custom kernel (5.12.1) with CONFIG_TRANSPARENT_HUGEPAGE=n
  2. Setup my xorg.conf as described by @JORGETECH_Jorge
  3. Also tried various other xorg.conf configurations.
  4. Ran xrandr --setprovideroutputsource NVIDIA-G0 0 followed by xrandr --auto.

xrandr --auto results in the following error:

xrandr: Configure crtc 4 failed

And from my dmesg:

[  440.395798] ------------[ cut here ]------------
[  440.395806] WARNING: CPU: 6 PID: 1044 at drivers/dma-buf/dma-buf.c:880 dma_buf_pin+0x24/0x30
[  440.395821] Modules linked in: rfcomm ccm cmac iwlmvm algif_hash intel_rapl_msr snd_hda_codec_realtek algif_skcipher intel_rapl_common af_alg mac80211 snd_hda_codec_generic ledtrig_audio bnep edac_mce_amd libarc4 snd_hda_intel snd_intel_dspcfg snd_intel_sdw_acpi iwlwifi mousedev nls_iso8859_1 snd_hda_codec btusb vfat kvm_amd btrtl btbcm snd_hda_core btintel fat hid_multitouch kvm cfg80211 bluetooth snd_hwdep snd_pcm irqbypass rapl r8169 snd_timer wdat_wdt ucsi_acpi snd typec_ucsi realtek ideapad_laptop ecdh_generic cm32181 platform_profile mdio_devres typec joydev wmi_bmof sp5100_tco sparse_keymap libphy i2c_piix4 ecc soundcore roles rfkill industrialio i2c_hid_acpi i2c_hid acpi_cpufreq pinctrl_amd mac_hid crypto_user fuse ip_tables x_tables ext4 crc32c_generic crc16 mbcache jbd2 dm_crypt cbc encrypted_keys trusted nvidia_uvm(POE) usbhid nvidia_drm(POE) nvidia_modeset(POE) crct10dif_pclmul serio_raw crc32_pclmul crc32c_intel atkbd ghash_clmulni_intel libps2 aesni_intel dm_mod
[  440.395939]  nvidia(POE) crypto_simd cryptd xhci_pci ccp xhci_pci_renesas tpm_crb wmi amdgpu i8042 tpm_tis tpm_tis_core serio tpm video rng_core drm_ttm_helper ttm gpu_sched i2c_algo_bit drm_kms_helper syscopyarea sysfillrect sysimgblt fb_sys_fops cec drm agpgart
[  440.395977] CPU: 6 PID: 1044 Comm: Xorg Tainted: P        W  OE     5.12.1-arch1-1-custom #1
[  440.395982] Hardware name: LENOVO 82JQ/LNVNB161216, BIOS GKCN34WW 03/19/2021
[  440.395985] RIP: 0010:dma_buf_pin+0x24/0x30
[  440.395991] Code: 5d c3 0f 1f 40 00 0f 1f 44 00 00 48 83 7f 30 00 48 8b 07 74 15 48 8b 40 20 48 8b 40 18 48 85 c0 74 05 e9 ff f4 70 00 31 c0 c3 <0f> 0b eb e7 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 83 7f 30 00
[  440.395995] RSP: 0018:ffffb5e781c5fd38 EFLAGS: 00010246
[  440.395999] RAX: ffff94b2eb5dbc00 RBX: 0000000000000000 RCX: 0000000000000000
[  440.396002] RDX: ffff94b284561f80 RSI: 0000000000000000 RDI: ffff94b29a4465a0
[  440.396004] RBP: ffff94b2eb5dbc00 R08: ffff94b28d67d218 R09: 0000000000000000
[  440.396006] R10: 0000000000000001 R11: 0000000000000000 R12: ffff94b29a4465a0
[  440.396008] R13: ffff94b28193e0c8 R14: 0000000000000000 R15: ffff94b280b68dc8
[  440.396011] FS:  00007ffa8d35c940(0000) GS:ffff94b891f80000(0000) knlGS:0000000000000000
[  440.396014] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  440.396016] CR2: 00007ff414900000 CR3: 000000011583e000 CR4: 0000000000750ee0
[  440.396018] PKRU: 55555554
[  440.396020] Call Trace:
[  440.396024]  dma_buf_dynamic_attach+0x119/0x250
[  440.396042]  drm_gem_prime_import_dev.part.0+0x1e/0xc0 [drm]
[  440.396095]  drm_gem_prime_fd_to_handle+0xc0/0x1d0 [drm]
[  440.396128]  ? drm_prime_destroy_file_private+0x20/0x20 [drm]
[  440.396159]  drm_ioctl_kernel+0xb2/0x100 [drm]
[  440.396194]  drm_ioctl+0x215/0x390 [drm]
[  440.396225]  ? drm_prime_destroy_file_private+0x20/0x20 [drm]
[  440.396258]  __x64_sys_ioctl+0x83/0xb0
[  440.396268]  do_syscall_64+0x33/0x40
[  440.396275]  entry_SYSCALL_64_after_hwframe+0x44/0xae
[  440.396282] RIP: 0033:0x7ffa8dd60e6b
[  440.396288] Code: ff ff ff 85 c0 79 8b 49 c7 c4 ff ff ff ff 5b 5d 4c 89 e0 41 5c c3 66 0f 1f 84 00 00 00 00 00 f3 0f 1e fa b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d d5 af 0c 00 f7 d8 64 89 01 48
[  440.396291] RSP: 002b:00007ffc6d3d9978 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
[  440.396294] RAX: ffffffffffffffda RBX: 00007ffc6d3d99bc RCX: 00007ffa8dd60e6b
[  440.396296] RDX: 00007ffc6d3d99bc RSI: 00000000c00c642e RDI: 0000000000000017
[  440.396298] RBP: 00000000c00c642e R08: 0000000001fa4000 R09: 00000000ffffffff
[  440.396300] R10: 0000000000000100 R11: 0000000000000246 R12: 0000000000030101
[  440.396302] R13: 0000000000000017 R14: 000055b340ca8250 R15: 000055b3426309a0
[  440.396308] ---[ end trace 842dd35f0b2d9b89 ]---
[  440.396708] ------------[ cut here ]------------
[  440.396716] WARNING: CPU: 6 PID: 1044 at drivers/dma-buf/dma-buf.c:903 dma_buf_unpin+0x22/0x30
[  440.396731] Modules linked in: rfcomm ccm cmac iwlmvm algif_hash intel_rapl_msr snd_hda_codec_realtek algif_skcipher intel_rapl_common af_alg mac80211 snd_hda_codec_generic ledtrig_audio bnep edac_mce_amd libarc4 snd_hda_intel snd_intel_dspcfg snd_intel_sdw_acpi iwlwifi mousedev nls_iso8859_1 snd_hda_codec btusb vfat kvm_amd btrtl btbcm snd_hda_core btintel fat hid_multitouch kvm cfg80211 bluetooth snd_hwdep snd_pcm irqbypass rapl r8169 snd_timer wdat_wdt ucsi_acpi snd typec_ucsi realtek ideapad_laptop ecdh_generic cm32181 platform_profile mdio_devres typec joydev wmi_bmof sp5100_tco sparse_keymap libphy i2c_piix4 ecc soundcore roles rfkill industrialio i2c_hid_acpi i2c_hid acpi_cpufreq pinctrl_amd mac_hid crypto_user fuse ip_tables x_tables ext4 crc32c_generic crc16 mbcache jbd2 dm_crypt cbc encrypted_keys trusted nvidia_uvm(POE) usbhid nvidia_drm(POE) nvidia_modeset(POE) crct10dif_pclmul serio_raw crc32_pclmul crc32c_intel atkbd ghash_clmulni_intel libps2 aesni_intel dm_mod
[  440.396823]  nvidia(POE) crypto_simd cryptd xhci_pci ccp xhci_pci_renesas tpm_crb wmi amdgpu i8042 tpm_tis tpm_tis_core serio tpm video rng_core drm_ttm_helper ttm gpu_sched i2c_algo_bit drm_kms_helper syscopyarea sysfillrect sysimgblt fb_sys_fops cec drm agpgart
[  440.396849] CPU: 6 PID: 1044 Comm: Xorg Tainted: P        W  OE     5.12.1-arch1-1-custom #1
[  440.396853] Hardware name: LENOVO 82JQ/LNVNB161216, BIOS GKCN34WW 03/19/2021
[  440.396855] RIP: 0010:dma_buf_unpin+0x22/0x30
[  440.396858] Code: 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 83 7f 30 00 48 8b 07 74 13 48 8b 40 20 48 8b 40 20 48 85 c0 74 05 e9 cf f4 70 00 c3 <0f> 0b eb e9 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 85 ff
[  440.396861] RSP: 0018:ffffb5e781c5fd40 EFLAGS: 00010246
[  440.396864] RAX: ffff94b2eb5dbc00 RBX: 0000000000000001 RCX: 0000000000118a06
[  440.396866] RDX: 0000000000118806 RSI: 38e605ef0ea44d67 RDI: ffff94b29a4465a0
[  440.396868] RBP: ffff94b29a4465a0 R08: 0000000000000000 R09: ffff94b28eb13808
[  440.396870] R10: 00000000fbfa0000 R11: 0000000000000001 R12: ffff94b2eb5dbc00
[  440.396871] R13: ffff94b282e55b28 R14: ffff94b282e55a50 R15: ffff94b282e55a38
[  440.396874] FS:  00007ffa8d35c940(0000) GS:ffff94b891f80000(0000) knlGS:0000000000000000
[  440.396876] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  440.396878] CR2: 00007ff414900000 CR3: 000000011583e000 CR4: 0000000000750ee0
[  440.396881] PKRU: 55555554
[  440.396882] Call Trace:
[  440.396886]  dma_buf_detach+0x78/0x100
[  440.396893]  drm_prime_gem_destroy+0x2d/0x40 [drm]
[  440.396932]  __nv_drm_gem_dma_buf_free+0x10/0x20 [nvidia_drm]
[  440.396942]  drm_gem_object_release_handle+0x6b/0x80 [drm]
[  440.396975]  drm_gem_handle_delete+0x58/0x90 [drm]
[  440.397005]  ? drm_gem_handle_create+0x40/0x40 [drm]
[  440.397150]  drm_ioctl_kernel+0xb2/0x100 [drm]
[  440.397188]  ? rm_ioctl+0x63/0xb0 [nvidia]
[  440.397915]  drm_ioctl+0x215/0x390 [drm]
[  440.397955]  ? drm_gem_handle_create+0x40/0x40 [drm]
[  440.397988]  __x64_sys_ioctl+0x83/0xb0
[  440.397998]  do_syscall_64+0x33/0x40
[  440.398005]  entry_SYSCALL_64_after_hwframe+0x44/0xae
[  440.398013] RIP: 0033:0x7ffa8dd60e6b
[  440.398016] Code: ff ff ff 85 c0 79 8b 49 c7 c4 ff ff ff ff 5b 5d 4c 89 e0 41 5c c3 66 0f 1f 84 00 00 00 00 00 f3 0f 1e fa b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d d5 af 0c 00 f7 d8 64 89 01 48
[  440.398020] RSP: 002b:00007ffc6d3d9958 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
[  440.398024] RAX: ffffffffffffffda RBX: 00007ffc6d3d9998 RCX: 00007ffa8dd60e6b
[  440.398026] RDX: 00007ffc6d3d9998 RSI: 0000000040086409 RDI: 0000000000000017
[  440.398028] RBP: 0000000040086409 R08: 00007ffc6d3d9ab0 R09: 00007ffc6d3d9ac4
[  440.398029] R10: 0000000000000001 R11: 0000000000000246 R12: 000055b340ca8250
[  440.398031] R13: 0000000000000017 R14: 000055b340e773e0 R15: 000055b3426309a0
[  440.398036] ---[ end trace 842dd35f0b2d9b8a ]---

Whatever I do I seem to get that error. Has anyone encountered this issue before? I feel like I’m missing something obvious.

ps. for what it’s worth, I’m on nvidia-dkms 465.27.

@hansg91, have you had any luck yet with your hybrid graphics set up? Are you able to try the 460 driver series in case this is a regression in the 465 series?

Also, I guess you’re trying to use the L5P’s HDMI port, but I’m curious to know if you have a USB-C HDMI adapter and if it also has this same problem, ie if it also routes via the nvidia card and also causes a kernel crash.

I had a little luck, but nothing definitive. I’m currently using the LTS kernel (5.10.34), again with CONFIG_TRANSPARENT_HUGEPAGE=n, but still no luck. I also tried with nvidia driver 460 but it appears to behave the same.

The positive part is that I do now get “some” functionality. I have my laptop attached to a 4k monitor, but if I set it to 800x600 (xrandr --output HDMI-1-1 --mode 1280x720 --left-of eDP-2) then it gives me some output (only the cursor for some reason, nothing GNOME related will show up there). If I try to set a higher resolution than 800x600 I get the following error in Xorg.0.log:

(EE) modeset(G0): failed to set mode: No space left on device

No clue why this is, or what space it is trying to use. I’m not too familiar with video drivers etc.

I’m going to try other combinations of kernel and xorg.conf settings, I’ll report back if I find anything.

Also, @rockorequin , I don’t have a USB-C to HDMI adapter so I can’t test that unfortunately. I think I read somewhere that the UCB-C is also connected to the nvidia card, so I expect it will behave the same.

Note that this was using the AMD modesetting driver, although I’m not sure what that exactly does. Using the amdgpu driver I get no output through HDMI, but I get this error instead:

(II) AMDGPU(0): Allocate new frame buffer 3360x1600
(II) AMDGPU(0):  => pitch 13824 bytes
randr: failed to create shared pixmap
(EE) NVIDIA(G0): Failed to configure Reverse PRIME on output HDMI-1-0.
(EE) AMDGPU(0): drmmode_do_crtc_dpms cannot get last vblank counter

Regardless of the chosen resolution. I’m a bit stuck at the moment :)

@hansg91: I wonder if it’s worth reporting those as kernel bugs in the amdgpu driver?

@aplattner: is the transparent huge pages thing a bug in the amdgpu driver or in the nvidia driver, or just a philosophical difference? Also, you said seven months ago that you were investigating workarounds - has there been any progress? I want to buy a new laptop with an NVIDIA card, but not if a fundamental thing like driving external monitors doesn’t work…

@hansg91 I see that in the 470 beta driver says it now supports PRIME display offload with the amdgpu driver as the offload source. (See Linux x64 (AMD64/EM64T) Display Driver | 470.42.01 | Linux 64-bit | NVIDIA)

Are you able to try the beta driver to see if it fixes your issue?

@rockorequin that’s great news! I’ll be sure to try it out soon (hopefully) and let you know my findings.

Hi, I also have a Legion 5 Ryzen 7 4800h CPU and an Nvidia RTX 2060 GPU. Using dualboot Ubuntu and W10. Have you been able to get the Touchpad to work with Linux?

@rockorequin everything seems to work fine. Browsing webpages, watching content on youtube. No complaints yet :). I’m now using the amdgpu driver as primary driver, while displaying a screen over HDMI using reverse prime. Time to celebrate?

For reference; I’m using the 5.10.42-1-lts kernel from Arch with nvidia-beta-dkms (470.42.01) from the AUR.

@hansg91 Great news, thanks for getting back to me about that!