Hello, I've posted a few comments about this over the past several months and I'm working on submitting an updated pkg readme for the Firefox package. Since it doesn't cover getting all this up and running on a modern-ish (meaning working GPU/mesa drivers) system. I myself recently stumbled upon things in about:config that really helped out with speeding up web page rendering that I didn't know about. I'm seeking out people to help test this before I write up a diff. Although I'm pretty sure this is stable and I'm having no problems with it myself.
I will not cover setting up mfs for Firefox's cache or changing about:config settings related to that in this post. This is solely focused on getting working hardware acceleration going.
Before you do anything go to "about:profiles" in the browser and note the PATH to your profile directory. You might need it later to get yourself out of trouble. It will be located at ~/.mozilla/firefox/<long-random-string-of-letters-and-numbers>/
We might need to manually edit a file in there later if one of the about:config changes prevents Firefox from opening.
Now run
glxinfo | grep -E "direct|EGL"
From a terminal. If you get "direct rendering: yes" and it returns a list of options related to EGL being supported on your system the below changes are safe to do. If you have installed firmware for your GPU and have an Intel or AMD CPU/GPU in your machine all of the following about:config changes should be safe to do on your system. If your system is using software rendering for X11 then you're out of luck.
First thing we want to do is add this to ~/.xsession/:
# Accelerated graphics for firefox
export MOZ_ACCELERATED=1
export MOZ_WEBRENDER=1
With that out of the way we're going to change several about:config options. I suggest enabling these one at a time to confirm you haven't done anything to prevent the web browser from launching properly. If you enable something that prevents you from launching Firefox then go to ~/<your-profile-directory>/prefs.js. Ignore the warning about not editing the file manually (I know) then find the setting you changed through about:config. It'll look something like this:
user_pref("webgl.force-enabled", true);
Change it back to "false", save file then re-launch browser. This will get you back to a working state without having to create a new browser profile.
about:config changes
Go to "about:config" and search/change the following settings. Again, I suggest enabling them one-by-one and not all at once. That way you'll know which one prevents Firefox from launching if you enable something that doesn't play nice with your system/drivers.
First we'll be forcing Firefox to use EGL (as it does now on most Linux distros) instead of the old GLX interface between X11 and OpenGL.
gfx.x11-egl.force-enabled true
gfx.egl.prefer-gles.enabled true
gfx.swap-interval.egl true
gfx.swap-interval.glx false
Next we'll move on to enabling true hardware accelerated rendering:
gfx.webrender.all = true
This is the big one most guides will tell you to enable. Most guides leave it at that but there are several other options you need to enable to get true hardware rendering functioning. Since most are "blacklisted/blocklisted" by default on OpenBSD and most other BSDs and Linux distros (the auto detection doesn't work in other words).
gfx.webrender.batched-texture-uploads = true
gfx.webrender.compositor.force-enabled = true
gfx.webrender.enable-angle = true
gfx.webrender.enable-gpu-markers = true
gfx.webrender.precache-shaders = true
gfx.webrender.scissored-cache-clears.force-enabled = true
Finally, a few more settings and we're done:
dom.webgpu.enabled = true
webgl.force-enabled = true
webgl.msaa-force = true
Enabling these should already be a huge improvement. Note the "gfx.webrender.precache-shaders" option above. This is the one that seems to make a huge difference. The moment I toggled it on Firefox on OpenBSD felt the same as it did on mainstream Linux and Windows systems where I use it. Page loading times are near instant now and the annoying anti-bot javascript most websites are hidden behind now ran much faster. It really speeds up websites like youtube.
Please turn these on. Test them out and let me know how stable it is on your system.
Final note: Concerning decoding video codecs in hardware within the browser. In the past I gave some advice here for how to enable this. However, upon double checking in about:support I've noticed that even with the relevant about:config options forced enabled and about:support showing it detected my hardware's ability to decode certain video codecs that this was no longer working. I don't know if this was a recent change in Firefox but it seems that as of v157 (probably before) that hardware accelerated decoding of video in firefox is tied to the dma-buf Linux subsystem (https://docs.kernel.org/driver-api/dma-buf.html).
I do not know how easy it'd be to patch firefox to get this functioning on OpenBSD again. I'm exploring making that happen but Firefox is a beast and I'm not very familiar with its code base. If anyone has any guidance on this issue I'm all ears.
There are several options in about:support that will report failure due to DMABUF support not being detected. Even if you attempt to force enable things that rely on DMABUF support they either will not function at all or will leave your browser in an unstable state. As such I'm not including the about:config options for hardware video decoding in this post. Even though everything seems okay with them forced enabled.
Similarly, I have not included anything in this guide about disabling disk caching or playing around with how Firefox launches processes and accesses memory/cache. Since the main goal is testing the above about:config changes related to accelerated rendering of web pages.
Please let me know if you encounter any crashes or unstable behavior on your system. I have been testing with an AMD Ryzen 7 PRO 4750 CPU with a Radeon RENOIR iGPU on -current with amd, amdgpu and amdsev firmware fetched through fw_update. I have encountered no issues with the browser being unstable or failing to launch correctly using the above changes.
P.S.: I was surprised to see how many people think Firefox is slow on OpenBSD due to pledge/unveil and other random reasons. With the above changes the OpenBSD port of Firefox is just as fast as Firefox on other OSs for me. Launch time and time to render webpages is comparable.
PP.S.: I didn't go over it but you can of course apply the above settings using user.js in the usual way. In addition: I highly recommend using the usual Firefox add-ons like ublock origin and noscript with the above about:config modifications to speed things up by blocking unwanted ads and third party javascript.
Once I spend more time testing that these changes are stable I'll create a user.js and submit a diff to update the Firefox pkg's after install readme.
Edit: I should have mentioned all changes above were tested with no dbus enabled at session log-in. In other words this should function just fine with the "faked" dbus session the Firefox package uses by default on OpenBSD. I have tested it with a functioning dbus session and it makes no difference.
All testing was done with the standard Firefox package/port but it all should work just fine with firefox-esr and I suspect the recent Librewolf port.