Want to run Unity with the nvidia prime-run

Hi, I have an Optimus laptop (amd igpu & nvidia dgpu). I already have the correct drivers for running the nvidia, I use prime-run to run the application I need using the dgpu however when attempting to do the same for Unity it is a bit different, as Unity has evolved and now they use a “hub” which then allows you to run the project with the “editor version” you need and thus the hub is what launches unity, personally if you ask me it’s all messed up unity made it way more complicated than it needs to be.

Anyhow I already posted on their forum and waiting for an answer, I as well found someone who said he tried something similar to bypass the hub and launch the editor directly but I was unable to follow through till the editor launches, here is the link: https://forum.unity.com/threads/unity-editor-running-with-prime-run-on-linux.1128050/

edit: I as well tried the optimus-manager, while it got the dgpu working on everything it’s not the most efficient as the dgpu will be the only gpu working and not use the hybrid mechanism that I need.

here is the inxi output:

Ξ ~ git:(master) ▶ inxi --full --admin --filter --width
System:
  Kernel: 6.1.44-1-MANJARO arch: x86_64 bits: 64 compiler: gcc v: 13.2.1
    clocksource: hpet available: acpi_pm
    parameters: BOOT_IMAGE=/boot/vmlinuz-6.1-x86_64
    root=UUID=b395b351-d6f7-40f1-88ff-43ee89d7e608 rw quiet acpi_osi=Linux
    apparmor=1 security=apparmor udev.log_priority=3 acpi_backlight=native
    nowatchdog
  Desktop: KDE Plasma v: 5.27.7 tk: Qt v: 5.15.10 info: latte-dock
    wm: kwin_x11 vt: 2 dm: SDDM Distro: Manjaro Linux base: Arch Linux
Machine:
  Type: Laptop System: LENOVO product: 82B5 v: Lenovo Legion 5 15ARH05
    serial: <superuser required> Chassis: type: 10 v: Lenovo Legion 5 15ARH05
    serial: <superuser required>
  Mobo: LENOVO model: LNVNB161216 v: SDK0J40709 WIN
    serial: <superuser required> UEFI: LENOVO v: EUCN37WW date: 04/14/2022
Battery:
  ID-1: BAT0 charge: 26.7 Wh (56.9%) condition: 46.9/60.0 Wh (78.2%)
    power: 23.2 W volts: 16.2 min: 15.4 model: SMP L19M4PC0 type: Li-poly
    serial: <filter> status: charging cycles: 839
CPU:
  Info: model: AMD Ryzen 5 4600H with Radeon Graphics bits: 64 type: MT MCP
    arch: Zen 2 gen: 3 level: v3 note: check built: 2020-22
    process: TSMC n7 (7nm) family: 0x17 (23) model-id: 0x60 (96) stepping: 1
    microcode: 0x8600106
  Topology: cpus: 1x cores: 6 tpc: 2 threads: 12 smt: enabled cache:
    L1: 384 KiB desc: d-6x32 KiB; i-6x32 KiB L2: 3 MiB desc: 6x512 KiB L3: 8 MiB
    desc: 2x4 MiB
  Speed (MHz): avg: 2119 high: 3979 min/max: 1400/3000 boost: enabled
    scaling: driver: acpi-cpufreq governor: ondemand cores: 1: 1397 2: 1703
    3: 1397 4: 1765 5: 1521 6: 1396 7: 3434 8: 3287 9: 1775 10: 1772 11: 2005
    12: 3979 bogomips: 71897
  Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm
  Vulnerabilities:
  Type: gather_data_sampling status: Not affected
  Type: itlb_multihit status: Not affected
  Type: l1tf status: Not affected
  Type: mds status: Not affected
  Type: meltdown status: Not affected
  Type: mmio_stale_data status: Not affected
  Type: retbleed mitigation: untrained return thunk; SMT enabled with STIBP
    protection
  Type: spec_rstack_overflow mitigation: safe RET
  Type: spec_store_bypass mitigation: Speculative Store Bypass disabled via
    prctl
  Type: spectre_v1 mitigation: usercopy/swapgs barriers and __user pointer
    sanitization
  Type: spectre_v2 mitigation: Retpolines, IBPB: conditional, STIBP:
    always-on, RSB filling, PBRSB-eIBRS: Not affected
  Type: srbds status: Not affected
  Type: tsx_async_abort status: Not affected
Graphics:
  Device-1: NVIDIA TU117M [GeForce GTX 1650 Ti Mobile] vendor: Lenovo
    driver: nvidia v: 535.98 alternate: nouveau,nvidia_drm non-free: 535.xx+
    status: current (as of 2023-08) arch: Turing code: TUxxx
    process: TSMC 12nm FF built: 2018-22 pcie: gen: 1 speed: 2.5 GT/s lanes: 8
    link-max: gen: 3 speed: 8 GT/s lanes: 16 bus-ID: 01:00.0 chip-ID: 10de:1f95
    class-ID: 0300
  Device-2: AMD Renoir vendor: Lenovo driver: amdgpu v: kernel arch: GCN-5
    code: Vega process: GF 14nm built: 2017-20 pcie: gen: 4 speed: 16 GT/s
    lanes: 16 ports: active: eDP-1 empty: none bus-ID: 05:00.0
    chip-ID: 1002:1636 class-ID: 0300 temp: 54.0 C
  Device-3: Bison Integrated Camera driver: uvcvideo type: USB rev: 2.0
    speed: 480 Mb/s lanes: 1 mode: 2.0 bus-ID: 1-3:2 chip-ID: 5986:212b
    class-ID: 0e02
  Display: x11 server: X.Org v: 21.1.8 compositor: kwin_x11 driver: X:
    loaded: amdgpu,nvidia unloaded: modesetting,nouveau alternate: fbdev,nv,vesa
    dri: radeonsi gpu: amdgpu display-ID: :0 screens: 1
  Screen-1: 0 s-res: 1920x1080 s-dpi: 96 s-size: 508x285mm (20.00x11.22")
    s-diag: 582mm (22.93")
  Monitor-1: eDP-1 mapped: eDP model: AU Optronics 0xd1ed built: 2019
    res: 1920x1080 hz: 120 dpi: 142 gamma: 1.2 size: 344x193mm (13.54x7.6")
    diag: 394mm (15.5") ratio: 16:9 modes: max: 1920x1080 min: 640x480
  API: OpenGL v: 4.6 Mesa 23.1.5 renderer: AMD Radeon Graphics (renoir LLVM
    15.0.7 DRM 3.49 6.1.44-1-MANJARO) direct-render: Yes
Audio:
  Device-1: NVIDIA driver: snd_hda_intel v: kernel pcie: gen: 1 speed: 2.5 GT/s
    lanes: 8 link-max: gen: 3 speed: 8 GT/s lanes: 16 bus-ID: 01:00.1
    chip-ID: 10de:10fa class-ID: 0403
  Device-2: AMD ACP/ACP3X/ACP6x Audio Coprocessor vendor: Lenovo driver: N/A
    alternate: snd_pci_acp3x, snd_rn_pci_acp3x, snd_pci_acp5x, snd_pci_acp6x,
    snd_acp_pci, snd_rpl_pci_acp6x, snd_pci_ps, snd_sof_amd_renoir,
    snd_sof_amd_rembrandt pcie: gen: 4 speed: 16 GT/s lanes: 16 bus-ID: 05:00.5
    chip-ID: 1022:15e2 class-ID: 0480
  Device-3: AMD Family 17h/19h HD Audio vendor: Lenovo driver: snd_hda_intel
    v: kernel pcie: gen: 4 speed: 16 GT/s lanes: 16 bus-ID: 05:00.6
    chip-ID: 1022:15e3 class-ID: 0403
  API: ALSA v: k6.1.44-1-MANJARO status: kernel-api with: aoss
    type: oss-emulator tools: alsactl,alsamixer,amixer
  Server-1: JACK v: 1.9.22 status: off tools: N/A
  Server-2: PipeWire v: 0.3.77 status: off with: pipewire-media-session
    status: active tools: pw-cli
  Server-3: PulseAudio v: 16.1 status: active with: 1: pulseaudio-alsa
    type: plugin 2: pulseaudio-jack type: module tools: pacat,pactl,pulsemixer
Network:
  Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet
    vendor: Lenovo driver: r8169 v: kernel pcie: gen: 1 speed: 2.5 GT/s lanes: 1
    port: 2000 bus-ID: 03:00.0 chip-ID: 10ec:8168 class-ID: 0200
  IF: eno1 state: down mac: <filter>
  Device-2: Intel Wi-Fi 6 AX200 driver: iwlwifi v: kernel pcie: gen: 2
    speed: 5 GT/s lanes: 1 bus-ID: 04:00.0 chip-ID: 8086:2723 class-ID: 0280
  IF: wlp4s0 state: up mac: <filter>
Bluetooth:
  Device-1: Intel AX200 Bluetooth driver: btusb v: 0.8 type: USB rev: 2.0
    speed: 12 Mb/s lanes: 1 mode: 1.1 bus-ID: 3-3:3 chip-ID: 8087:0029
    class-ID: e001
  Report: rfkill ID: hci0 rfk-id: 2 state: down bt-service: enabled,running
    rfk-block: hardware: no software: yes address: see --recommends
Drives:
  Local Storage: total: 1.14 TiB used: 975.92 GiB (83.4%)
  SMART Message: Unable to run smartctl. Root privileges required.
  ID-1: /dev/nvme0n1 maj-min: 259:0 vendor: Samsung model: MZVLB256HBHQ-000L2
    size: 238.47 GiB block-size: physical: 512 B logical: 512 B speed: 31.6 Gb/s
    lanes: 4 tech: SSD serial: <filter> fw-rev: 3L1QEXH7 temp: 63.9 C
    scheme: GPT
  ID-2: /dev/sda maj-min: 8:0 vendor: Western Digital model: WD10SPSX-08A6W
    size: 931.51 GiB block-size: physical: 4096 B logical: 512 B speed: 6.0 Gb/s
    tech: HDD rpm: 7200 serial: <filter> fw-rev: 1A01 scheme: GPT
Partition:
  ID-1: / raw-size: 51.29 GiB size: 50.31 GiB (98.08%) used: 34.75 GiB (69.1%)
    fs: ext4 dev: /dev/nvme0n1p5 maj-min: 259:5
  ID-2: /boot/efi raw-size: 100 MiB size: 96 MiB (96.00%)
    used: 46.9 MiB (48.8%) fs: vfat dev: /dev/nvme0n1p1 maj-min: 259:1
  ID-3: /home raw-size: 68.07 GiB size: 66.45 GiB (97.62%)
    used: 49.33 GiB (74.2%) fs: ext4 dev: /dev/nvme0n1p7 maj-min: 259:7
Swap:
  Kernel: swappiness: 60 (default) cache-pressure: 100 (default) zswap: yes
    compressor: zstd max-pool: 20%
  ID-1: swap-1 type: partition size: 20.48 GiB used: 908 MiB (4.3%)
    priority: -2 dev: /dev/nvme0n1p6 maj-min: 259:6
Sensors:
  System Temperatures: cpu: 67.8 C mobo: N/A gpu: amdgpu temp: 53.0 C
  Fan Speeds (rpm): N/A
Info:
  Processes: 376 Uptime: 1h 7m wakeups: 1 Memory: total: 16 GiB note: est.
  available: 15 GiB used: 8.89 GiB (59.3%) Init: systemd v: 253
  default: graphical tool: systemctl Compilers: gcc: 13.2.1 clang: 15.0.7
  Packages: 1791 pm: dpkg pkgs: 0 pm: pacman pkgs: 1771 libs: 460
  tools: pamac,yay pm: flatpak pkgs: 7 pm: snap pkgs: 13 Shell: Zsh v: 5.9
  running-in: konsole inxi: 3.3.29

mhwd ouptut:

Ξ ~ git:(master) ▶ mhwd -li -l
> Installed PCI configs:
--------------------------------------------------------------------------------
                  NAME               VERSION          FREEDRIVER           TYPE
--------------------------------------------------------------------------------
video-hybrid-amd-nvidia-prime            2023.03.23               false            PCI
           video-linux            2018.05.04                true            PCI


Warning: No installed USB configs!
> 0000:03:00.0 (0200:10ec:8168) Network controller Realtek Semiconductor Co., Ltd.:
--------------------------------------------------------------------------------
                  NAME               VERSION          FREEDRIVER           TYPE
--------------------------------------------------------------------------------
         network-r8168            2016.04.20                true            PCI


> 0000:01:00.0 (0300:10de:1f95) Display controller nVidia Corporation:
--------------------------------------------------------------------------------
                  NAME               VERSION          FREEDRIVER           TYPE
--------------------------------------------------------------------------------
video-hybrid-amd-nvidia-prime            2023.03.23               false            PCI
video-hybrid-amd-nvidia-470xx-prime            2023.03.23               false            PCI
          video-nvidia            2023.03.23               false            PCI
    video-nvidia-470xx            2023.03.23               false            PCI
           video-linux            2018.05.04                true            PCI
     video-modesetting            2020.01.13                true            PCI
            video-vesa            2017.03.12                true            PCI


> 0000:05:00.0 (0300:1002:1636) Display controller ATI Technologies Inc:
--------------------------------------------------------------------------------
                  NAME               VERSION          FREEDRIVER           TYPE
--------------------------------------------------------------------------------
video-hybrid-amd-nvidia-prime            2023.03.23               false            PCI
video-hybrid-amd-nvidia-470xx-prime            2023.03.23               false            PCI
           video-linux            2018.05.04                true            PCI
     video-modesetting            2020.01.13                true            PCI
            video-vesa            2017.03.12                true            PCI

Lastly glxinfo output:

Ξ ~ git:(master) ▶ glxinfo | grep "OpenGL renderer"                    
OpenGL renderer string: AMD Radeon Graphics (renoir, LLVM 15.0.7, DRM 3.49, 6.1.44-1-MANJARO)
Ξ ~ git:(master) ▶ prime-run glxinfo | grep "OpenGL renderer"
OpenGL renderer string: NVIDIA GeForce GTX 1650 Ti/PCIe/SSE2

Does this mean you are using the package unityhub from the AUR?
Or … how have you installed unity exactly?

I have unityhub from the AUR

So … unity suggest making a wrapper script

(and only provides actual instructions for win and mac, but says linux is the ~same … I will modify it here)
(( I will also use the env vars that prime-run sets, instead of the prime-run script itself ))

unityhub-nvidia.sh

#!/usr/bin/env bash
# env vars here: 
__NV_PRIME_RENDER_OFFLOAD=1
__VK_LAYER_NV_optimus=NVIDIA_only
__GLX_VENDOR_LIBRARY_NAME=nvidia
# launch and detach quietly
nohup xdg-open /usr/share/applications/unityhub.desktop &>/dev/null &

Then mark executable: chmod +x unityhub-nvidia.sh
And then you can run it:

./unityhub-nvidia.sh

But … I think thats kinda silly.


I would probably copy the .desktop file to ~/.local/share/applications/ and then modify its Exec line to use prime-run …

mkdir -p ~/.local/share/applications
cp /usr/share/applications/unityhub.desktop ~/.local/share/applications/unityhub-nv.desktop

Then edit the Exec line (ex: micro ~/.local/share/applications/unityhub-nv.desktop):

[..]
Exec=/usr/bin/bash -c '/usr/bin/prime-run /opt/unityhub/unityhub %U'
[..]

…let me know if any of that works for you.

Reference links:

2 Likes

I do appreciate the detailed response and the research you have made, however, though it doesn’t seem to have worked, I followed what you said exactly but it didn’t work, below is checking the usage of the nvidia gpu to see if it’s working however it doesn’t seem to have been working I tried to as well open Godot with prime-run to test to see maybe the gpu is bugging out or something however that wasn’t the case.

Ξ ~ git:(master) ▶ nvidia-smi                                                                                      
Fri Aug 18 03:13:53 2023                                                                                           
+---------------------------------------------------------------------------------------+                          
| NVIDIA-SMI 535.98                 Driver Version: 535.98       CUDA Version: 12.2     |                          
|-----------------------------------------+----------------------+----------------------+                          
| 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 GTX 1650 Ti     Off | 00000000:01:00.0 Off |                  N/A |                          
| N/A   51C    P8               1W /  50W |    993MiB /  4096MiB |      0%      Default |                          
|                                         |                      |                  N/A |                          
+-----------------------------------------+----------------------+----------------------+                          
                                                                                                                   
+---------------------------------------------------------------------------------------+                          
| Processes:                                                                            |                          
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |                          
|        ID   ID                                                             Usage      |                          
|=======================================================================================|                          
|    0   N/A  N/A      3385      G   /usr/lib/Xorg                                34MiB |
|    0   N/A  N/A     12706      G   /usr/bin/godot3                             956MiB |
+---------------------------------------------------------------------------------------+
Ξ ~ git:(master) ▶ nvidia-smi
Fri Aug 18 03:14:55 2023        
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.98                 Driver Version: 535.98       CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| 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 GTX 1650 Ti     Off | 00000000:01:00.0 Off |                  N/A |
| N/A   52C    P8               1W /  50W |      6MiB /  4096MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                          
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      3385      G   /usr/lib/Xorg                                 4MiB |
+---------------------------------------------------------------------------------------+

also one other thing I noticed when I try to run the script “./unityhub-nvidia.sh” it doesn’t open the unityhub instead it opens Kate editor and the file that’s open is unityhub.desktop and below are all the lines that are in there.

[Desktop Entry]
Name=Unity Hub
Exec=/usr/bin/bash -c '/usr/bin/prime-run /opt/unityhub/unityhub %U'
Terminal=false
Type=Application
Icon=unityhub
StartupWMClass=unityhub
Comment=The Official Unity Hub
Categories=Development;
TryExec=unityhub
MimeType=x-scheme-handler/unityhub;

I edited that exec line here, hope that I didn’t mess up the steps you mentioned earlier.

Its 2 different approaches, and they should not affect each other with the paths being wholly defined.

(unless you mean you edited the original file at /usr/share/applications)

Though I cant test either.

Oh yeah … long standing bug.

Instead use kioclient5 exec

#!/usr/bin/env bash
# env vars here: 
__NV_PRIME_RENDER_OFFLOAD=1
__VK_LAYER_NV_optimus=NVIDIA_only
__GLX_VENDOR_LIBRARY_NAME=nvidia
# launch and detach quietly
nohup kioclient5 exec /usr/share/applications/unityhub.desktop &>/dev/null &

Sorry for the late reply

I believe that I did that on a whim even though I knew that they are 2 different approaches, anyhow I decided to go ahead and try again today, and for some reason I am not sure what but it worked with your after using kioclient5 exec, maybe I needed to reboot or something not sure.
I have also tried with the script and both of them worked.

~ git:(master) ▶ nvidia-smi 
nvidia-smiMon Aug 21 18:55:36 2023       
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.98                 Driver Version: 535.98       CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| 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 GTX 1650 Ti     Off | 00000000:01:00.0 Off |                  N/A |
| N/A   53C    P8               1W /  50W |    181MiB /  4096MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      3449      G   /usr/lib/Xorg                                44MiB |
|    0   N/A  N/A     37149    C+G   ...Hub/Editor/2021.3.29f1/Editor/Unity        8MiB |
|    0   N/A  N/A     39821    C+G   ...Hub/Editor/2020.3.48f1/Editor/Unity      125MiB |
+---------------------------------------------------------------------------------------+

So, many thanks to you good sir.

1 Like

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