Game and X server freeze using fullscreen and NVIDIA On-Demand on laptop with hybrid RTX 3070

Hello there,

recently I acquired a Lenovo ThinkPad T15g g2 which has a discrete video card (NVidia GeForce RTX 3070 mobile). In order to reduce stress on the video card and battery I am using the prime profile NVIDIA On-Demand from the nvidia-settings configuration menu.

The problem is that whenever I want to play a game using the discrete video card I have to use windowed mode because otherwise the game and probably the X server freeze.

E.g. I start Splitgate using Steam and the launch options
The game starts without problems, I start looking for a session and when I get into a match itself the game freezes.
I can still hear sound but I cannot interact with the X server and I also cannot switch to a virtual terminal. Using the magic SysRq key combination REISUB I can reboot the machine as gracefully as possible or I can ssh into the machine and restart SDDM (killing the game doesn’t do anything - the process disappears but the game image is still frozen on the screen, that is why I think the X server is also affected) but otherwise I cannot do anything short of a hard reset.

I also cannot pinpoint when the freeze occurs. It happens both with native Linux games and with games running Proton. Watch Dogs, for example, freezes almost immediately right at the start when the first logos appear. Splitgate freezes when I get into a match and wait for it to start. Something like the training camp or the race still works.
I was able to play DOOM 2016 for 15 minutes or so until it froze, Far Cry 5 a bit less. I cannot say when it occurs.
Sometimes I cannot even get into the options menu fast enough to set it to windowed mode to stop the freeze. For ELEX I had to manually edit the config file while in Control I could get into the options and set it to windowed.

I haven’t tested it thoroughly but I think that when using the performance mode, i.e. everything runs on the discrete card, this issue doesn’t occur. Also just setting to windowed mode completely negates the issue. Everything works without a problem. I am not sure about borderless windowed mode.

I am running Ubuntu 21.04 with KDE Plasma but I guess all of this information should be inside the bug report.

nvidia-bug-report.log.gz (1.1 MB)