Skip to content

[Draft] feat: add BSD platform backends and build support - #2217

Draft
Renkoto wants to merge 36 commits into
flightlessmango:masterfrom
Renkoto:pr3-freebsd
Draft

Renkoto wants to merge 36 commits into
flightlessmango:masterfrom
Renkoto:pr3-freebsd

Conversation

@Renkoto

@Renkoto Renkoto commented Nov 17, 2026 •

Copy link
Copy Markdown

Note: This is a draft PR that depends on #2215 and #2216

This draft (originally intended to be one PR but had to split it because it grown too big) aims to add native FreeBSD (and some general BSD) support to MangoHud without requiring Linux compatibility layers (linprocfs/linsysfs).

Summary of Changes

  • Build system (meson.build, src/meson.build, mangohud-next/legacy_gpu_wrapper/):
    • Enable Unix build paths for freebsd, netbsd, openbsd, and dragonfly, wiring backend_modules (<module>_<os>.cpp), notify_kqueue.cpp, and net_getifaddrs.cpp.
    • Restrict $LIB token expansion and mangohud-next (which depends on sd-bus/Wayland IPC) to Linux; provide a no-op wrapper_stub.cpp for MangoHud_LegacyGPUWrapper on non-Linux hosts.
    • Pass -Wl,--undefined-version on FreeBSD so lld accepts symbols in mangohud.version that are absent on BSD builds, and pass dep_x11 when checking NVCtrl/NVCtrl.h so /usr/local/include is searched.
    • Link libdrm, libdrm_amdgpu, and libkvm on FreeBSD.
  • Runtime linker lookup (mangohud-next/client/real_dlsym.c):
    • Search *ld-elf*.so* on FreeBSD and DragonFlyBSD, where real dlopen/dlsym symbols reside in rtld rather than libc.
  • FreeBSD platform backends (src/*_freebsd.cpp, src/sysctl_utils.h):
    • GPU enumeration (gpu_freebsd.cpp): Enumerate display devices via /dev/pci (PCIOCGETCONF) so GPUs without DRM render nodes (such as the proprietary NVIDIA driver versions 470xx and earlier, which unlike its Linux counterparts don't have it) are still detected.
    • AMDGPU (amdgpu_freebsd.cpp): Query GPU load, clocks, temperature, power, voltage, and VRAM/GTT usage directly through libdrm_amdgpu (amdgpu_query_sensor_info / amdgpu_query_heap_info).
    • CPU (cpu_freebsd.cpp): Read per-core and aggregate tick counters via kern.cp_times / kern.cp_time, frequencies via dev.cpu.N.freq, temperatures via dev.cpu.N.temperature (coretemp/amdtemp), and package power via RAPL MSRs through cpuctl(4) (/dev/cpuctl0).
    • Memory (memory_freebsd.cpp): Read VM page statistics from vm.stats.vm.*, swap usage via kvm_getswapinfo(), and per-process RSS/virtual size via KERN_PROC_PID.
    • Process & I/O stats (file_utils_freebsd.cpp, iostats_freebsd.cpp): Resolve executable paths, comm, argv, and loaded libraries via KERN_PROC_* sysctls and dl_iterate_phdr(), and estimate process I/O bytes from ki_rusage.ru_inblock/ru_oublock scaled by filesystem f_iosize.
    • Battery (battery_freebsd.cpp): Query hw.acpi.battery.* sysctls and /dev/acpi (ACPIIO_BATT_GET_BIX / ACPIIO_BATT_GET_BST) for multi-battery state and discharge wattage.
    • Config watcher & Network (notify_kqueue.cpp, net_getifaddrs.cpp, system_info_freebsd.cpp): Watch config file changes with kqueue (EVFILT_VNODE) and read interface byte counters from AF_LINK getifaddrs() entries.

Purpose of this

Currently, porting and build MangoHud on FreeBSD requires a hellish set of patches because MangoHud assumes many Linux-specific features and paths, leaving MangoHUD stuck on version 0.6.9 in the FreeBSD ports tree for this very reason, and the port was broken for years. This series of PRs aims to address these issues; of course, certain edge cases might remain. This was tested on FreeBSD 15.1-RELEASE.

shoutout to @XaeroVincent for the patches, I took care of implementing them in a distilled way. Xaero's patches in the old port have been tested with both NVIDIA and AMD GPUs, so neither Xaero nor I can verify how they work on Intel integrated graphics. Most of them should apply to a wide range of Mesa drivers and the proprietary NVIDIA drivers.

This is the final preparation phase for FreeBSD support that started in 2021 with #652, as with the rest, I'm open to any change for this.

For those who want to build it on FreeBSD 15.1:

Dependencies for the default build so far, or at least the ones I've tracked
eson ninja pkgconf glslang vulkan-loader vulkan-headers libdrm libX11 libxkbcommon wayland dbus mesa-libs

-Dwith_xnvctrl=disabled is needed because there's not a s standalone libXNVCtrl port yet on FreeBSD, the library is part of the nvidia-settings port, I made a standalonelibXNVCtrl port for that, and as a NVIDIA user I can confirm that the default option works if the library is present.

export CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib
meson setup build --buildtype=release -Dtests=disabled -Dwith_xnvctrl=disabled
ninja -C build

The reason why the CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib is for Meson to locate the needed headers for MangoHud, I don't know what you would think about it.

Additional info and limitations

  • Making mangohud-next to work on FreeBSD is out of scope for this PR, it depends on systemd-components and systemd is Linux-only, FreeBSD supports Wayland and Wayland on OpenBSD is currently experimental, hopefully that may be addressed in the future.
  • This has been proven to run with both native FreeBSD OpenGL and Vulkan games (there may be some quirks on certain setups) and games running on the New WoW64 Wine through DXVK, the Direct3D subproject hasn't been touched (I'm still wondering what is that for...) Games running through the Linux Compatibility Layer/Linuxulator are out of scope for this PR.
  • No Intel GPU support, I can't add nor test it (my HDMI port is wired to the NVIDIA card.)

TODO before marking ready for review

@Renkoto

Renkoto commented Nov 17, 2026 •

Copy link
Copy Markdown
Author

By the way, I recently found a regression on FreeBSD with imgui on the NVIDIA proprietary driver, I will check that later.

imagen

Edit: That last part was done, I think it should work as intended now, there are still some 2 things to check, there are segfaults in some OpenGL and Vulkan applications that happens in different hardware setups apparently.

Edit 2: I can say that at least the std::bad_cast crash was addressed for FreBSD, but the same thing will happen on any system that define RTLD_DEEPBIND.

@Renkoto
Renkoto force-pushed the pr3-freebsd branch 6 times, most recently from 6d63fd9 to 1466f25 Compare November 23, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant