Skip to content

Instantly share code, notes, and snippets.

@ghostface
Last active July 29, 2021 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghostface/c8e7a75900ff02c4aef079cde7026551 to your computer and use it in GitHub Desktop.
Save ghostface/c8e7a75900ff02c4aef079cde7026551 to your computer and use it in GitHub Desktop.
Zephyrus G14 - tty1,sway,iGPU and tty2,xorg,dGPU

Intro

On the Zephyrus G14 the gpu situation is as follows:

  • HDMI port is wired to the iGPU (amd)
  • USB-C Displayport is wired to the dGPU (nvidia)

Sway (wayland) now supports prime render offloading with nvidia 470 drivers however:

  • Render offloading has a performance hit so not ideal for gaming
  • Using the dGPU as primary doesn't work to my knowledge
  • As such no usb-c -> displayport support
  • So gsync isn't working yet either

Details

  • Hardware: 2021 Zephyrus G14 GA401QM
  • Distribution: Archlinux
  • External monitor connected via HDMI and USB-C Displayport

Goal

In order to use the nvidia as primary gpu when gaming with gsync support I want to:

  • switch to tty2
  • launch an xorg session utilizing the nvidia gpu as primary
  • windowmanager should be something minimal (i3,openbox etc.)
  • when done, logout, switch back to tty1 and turn the dGPU back off.

Usecases

Regular/work

Running sway on tty1 using the amd iGPU, nvidia dGPU is off

asusctl graphics -m integrated

Gaming

Switch to tty2, run startgamex script to:

  • switch dGPU to compute mode
  • launch xserver using the nvidia dGPU as primary gpu
  • launch i3 with custom config (optional)

Setup

Create a new folder for our special xorg.conf

mk /etc/X11/xorg_nvidia/

Create a new xorg config file there : /etc/X11/xorg_nvidia/99-nvidia.conf It will set the nvidia gpu as primary and the amdgpu as secondary.

Make sure to have it start with 99- so it gets loaded last.

Section "OutputClass"
     Identifier "AMDgpu"
     MatchDriver "amdgpu"
     Driver "amdgpu"
     Option "PrimaryGPU" "no"
     Option "VariableRefresh" "true"
 EndSection

 Section "OutputClass"
    Identifier "nvidia"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "AllowEmptyInitialConfiguration"
    Option "PrimaryGPU" "yes"
 EndSection

Create start script startgamex and put it somewhere accessible. Replace i3 with openbox or whatever your system and .xinitrc is equiped to handle

#!/bin/bash
asusctl graphics -m compute
startx i3 -- -config xorg_nvidia/99-nvidia.conf

Don't forget to make it executable chmod +x startgamex

Notebook monitor is black

If you want to use the monitor of your notebook instead or in addition to an external one, you need to run this:

xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --output eDP-1-1 --auto

For i3 putting it at the end of your .config/i3/config will work. So like this:

exec xrandr --setprovideroutputsource modesetting NVIDIA-0
exec xrandr --output eDP-1-1 --auto

Can't switch back to integrated (nvidia module in use)

Run lsof /dev/nvidia0 to figure out which process is hogging it. For instance launching firefox after the dGPU has been turned on will for some reason hog the nvidia modules. Closing firefox, switching to integrated and then starting firefox again will be fine. Having firefox running before the dGPU is turned off is also fine

All done. You should now be able to switch to tty2 run the stargamex script and launch an xserver with i3, using the dgpu with working gsync and no render offload overhead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment