How do i run Firefox through the Nvidia card?

Hello
i have a laptop and use optimus manager.
i noticed that when i run the laptop through the nvidia card,i get a much better performance with less glitches in Firefox.
i would like to run the laptop in hybrid mode and use the Nvidia card with Firefox.
how can i achieve that?;
is it through prime-run?(i’d appreciate an explanation as i have never done that),
or do i have to do all the VA-API settings i saw in the Arch wiki which seems quit complicated to set up.?

Hello @linub :wink:

In general you can speed up browsing when running with dGPU by running it with prime-run firefox if the dGPU is a nvida card and the nvidia driver are installed, but to be clear: hardware accelerated video decoding does not work in firefox with nvidia due the limitation to VA-API, but It works with some intel cards at the moment.

1 Like

so does running FF with prime-run firefox in hybrid mode will be the same a running FF when the whole laptop is on the Nvidia card?

and also,if yes,how do i automate this?

i saw i needed to copy and edit the .desktop file which i think is under /usr/share/applications/ and put it in ~/.local/share/applications/,or do i edit it directly in it’s current location?

I’m supposed to modify Exec= , and put prime-run over there,but i see three lines with Exec= in them:
Exec=/usr/lib/firefox/firefox %u
Exec=/usr/lib/firefox/firefox --new-window %u
Exec=/usr/lib/firefox/firefox --private-window %u
i guess it’s the first one?or all of them?

do i also need to change the Name= field?

-isn’t there a simple way to add a program to be used with Nvidia under the Nvidia xserver setting?

Not the same, but only FF will run with nvidia while the rest of the system work still with intel. It only offloads graphical work like GFX, Rendering and OpenGL.

Better copy it to the home folder because at updates it will be overwritten.

I guess you have to it to all:

Exec=/usr/bin/prime-run /usr/lib/firefox/firefox %u
Exec=/usr/bin/prime-run /usr/lib/firefox/firefox --new-window %u
Exec=/usr/bin/prime-run /usr/lib/firefox/firefox --private-window %u

No :wink:

Not that i know, but possible. In general prime-run add these variables:

__NV_PRIME_RENDER_OFFLOAD=1 
__VK_LAYER_NV_optimus=NVIDIA_only 
__GLX_VENDOR_LIBRARY_NAME=nvidia

Hope that helps :wink:

1 Like

it helps a lot,
Thanks!
I’ll try it and report back.

it seems to be working.
the gpu temp is ramping up and i see a process running under nvidia-smi ,but it doesn’t say explicitly Firefox.
is there a way/command line to confirm that Firefox is using the Nvidia card?

also i wonder why you wrote:

Exec=/usr/bin/prime-run /usr/lib/firefox/firefox %u

which i applied,
instead of:

Exec=prime-run /usr/lib/firefox/firefox %u 

which i saw some people use.

If you type nvidia-smi in the terminal,it should appear all the process that are using the nvidia gpu,firefox should be there.

it doesn’t explicitly says Firefox

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.56       Driver Version: 460.56       CUDA Version: 11.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  GeForce GTX 1050    Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   36C    P8    N/A /  N/A |      6MiB /  4040MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A       840      G   /usr/lib/Xorg                       4MiB |
+-----------------------------------------------------------------------------+

Mine its working

Sun Mar 28 17:21:22 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.56       Driver Version: 460.56       CUDA Version: 11.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  GeForce GTX 105...  Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   53C    P8    N/A /  N/A |     24MiB /  4040MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A       837      G   /usr/lib/Xorg                      20MiB |
|    0   N/A  N/A     54022      G   /usr/lib/firefox/firefox            1MiB |
+-----------------------------------------------------------------------------+

l have like this in the .desktop
Exec=MOZ_X11_EGL=1 prime-run /usr/lib/firefox/firefox %u

(The MOZ_X11_EGL is for hardware acceleration for my intel)

that’s weird,so maybe prime-run doesn’t work for me?
i still see changes in temperature in the nvidia xserver settings/Thermals when stressing Firefox.

You can test prime-run with prime-run glxgears,should appear in the nvidia-smi as its rendering with the nvidia card the gears.

glxgears does appear in nvidia-smi…

does anyone have an idea why i don’t seem to be running Firefox with nvidia?

when running prime-run Firefox i still can’t see it in nvidia-smi.
i also tried running __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia firefox but it’s the same.
i tried editing the .desktop file under ~/.local/share/applications/ with both:
Exec=/usr/bin/prime-run /usr/lib/firefox/firefox %u
Exec=prime-run /usr/lib/firefox/firefox %u
but it doesn’t matter.

i also tried to update the desktop file like it’s shown in the Arch wiki with
```update-desktop-database ~/.local/share/applications``
it created a mimeinfo.cache file but that’s about it.

also tried renaming the firefox.desktop file to firefoxnvidia and also change the Name= inside the file.

I don’t know why is not working with the prime-run command,but what if you try to use WebRender and the VA-API settings on arch wiki to see if you get better performance than stock?

https://wiki.archlinux.org/index.php/Firefox#Hardware_video_acceleration

This is not complicated at all.

1 Like

if i understand correctly,VA-API is meant for getting better performance from the intel gpu.
that’s not what I’m looking for,
in that case, i prefer running the whole laptop on the Nvidia card.

Maybe Firefox is not using the GPU all the time? Try this when running Firefox:

watch -n1 nvidia-smi

Also GPU Rendering must be activated in FF :wink:

It is just more accurate to use the full path to avoid bugs or similar.

1 Like
watch -n1 nvidia-smi

didn’t bring up nvidia in that list,but opening multiple youtube videos do make it’s temp ramp up,so maybe it’s doing something.

i have layers.acceleration.force-enabled to true and gfx.webrender.all to true

in order for it to work i had to set gfx.x11-egl.force-enabled to true and gfx.x11-egl.force-disabled to false in about:config.
it’s the equivalent of running it with MOZ_X11_EGL=1 like @XRaTiX said.

but i get errors on launch;

[GFX1-]: Failed to create EGLSurface!: 0x3009
[GFX1-]: Failed to create EGLSurface
[GFX1-]: Fallback WR to SW-WR
[GFX1-]: Failed to connect WebRenderBridgeChild.
IPDL protocol error: Handler returned error code!

###!!! [Parent][DispatchSyncMessage] Error: PCompositorBridge::Msg_NotifyChildRecreated Processing error: message was deserialized, but the handler returned false (indicating failure)

[GFX1-]: Failed to connect WebRenderBridgeChild.

any idea if that’s normal,or anything that can be done about it?

Edit:
everything still seems to be working fine.

Edit2:
the error doesn’t appear when using MOZ_X11_EGL=1 prime-run firefox,
but it does appear when enabling gfx.x11-egl.force-enabled instead and i think that’s related to the fact that i have webgl disabled.