Skip to content

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

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

Renkoto wants to merge 31 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 aims to adds 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, that 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 to FreeBSD requires a hell 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 have been tested with both NVIDIA and AMD GPUs, so neither Xaero nor I can verify how they work on Intel integrated graphics. They 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.

Additional info

  • 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 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.

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.

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