From db3731b88799ec90d8ac90f7c85a38aed28ff4d8 Mon Sep 17 00:00:00 2001 From: nixdrin <146267602+nixdrin@users.noreply.github.com> Date: Thu, 19 Oct 2023 23:03:09 +0200 Subject: [PATCH] chromium: fix libpci GPU detection Chromium has blocklists that workaround various GPU driver bugs, either by forcing software rendering [1] or by disabling use of certain GPU features [2]. These blocklists can only be applied successfully if the GPU vendor and device is detected correctly. One of the methods used for GPU detection is to load libpci.so via dlopen() at runtime to read the PCI vendor and device ID. The current derivation already contains a sed command to rewrite the dlopen() to the absolute path of libpci.so in the Nix store, namely sed -i -e '/libpci_loader.*Load/s!"\(libpci\.so\)!"${pciutils}/lib/\1!' \ gpu/config/gpu_info_collector_linux.cc However, in Chromium 59 (6 years ago), this code was moved into the ANGLE library used by Chromium [3]. This sed command no longer works. There is similar code in ANGLE now [4] that must be similarly patched to ensure the GPU vendor and device is always detected correctly. Without libpci some GPUs are not detected correctly. For example, in a VMWare virtual machine opening chrome://gpu in the browser shows: VENDOR= 0x0000 [Google Inc. (VMware, Inc.)], DEVICE=0x0000 [ANGLE (VMware Inc., SVGA3D; build: RELEASE; LLVM;, OpenGL 4.1 (Core Profile) Mesa 23.0.3)], DRIVER_VENDOR=Mesa, DRIVER_VERSION=23.0.3 *ACTIVE* Note the VENDOR=0x0000 and DEVICE=0x0000. Adding libpci.so to the library path fixes this: VENDOR= 0x15ad [Google Inc. (VMware, Inc.)], DEVICE=0x0405 [ANGLE (VMware Inc., SVGA3D; build: RELEASE; LLVM;, OpenGL 4.1 (Core Profile) Mesa 23.0.3)], DRIVER_VENDOR=Mesa, DRIVER_VERSION=23.0.3 *ACTIVE* Note the VENDOR=0x15ad and DEVICE=0x0405. Also now the blocklist entries are applied correctly, fixing some graphical issues. Fix this by adding pciutils to the rpath set with patchelf. This avoids having to patch lines in the source code that might get moved around. [1]: https://chromium.googlesource.com/chromium/src/+/e52f33f30b91b4ddfad649acddc39ab570473b86/gpu/config/software_rendering_list.json [2]: https://chromium.googlesource.com/chromium/src/+/e52f33f30b91b4ddfad649acddc39ab570473b86/gpu/config/gpu_driver_bug_list.json [3]: https://github.com/chromium/chromium/commit/873b27d518038be94df98d1128a2e8047e0ef942 [4]: https://github.com/google/angle/blob/05f45adc147393562b518ca1f82a3ccba7ee40f7/src/gpu_info_util/SystemInfo_libpci.cpp#L41 --- pkgs/applications/networking/browsers/chromium/common.nix | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkgs/applications/networking/browsers/chromium/common.nix b/pkgs/applications/networking/browsers/chromium/common.nix index e3bb552d57c0d..f2c1568e8d280 100644 --- a/pkgs/applications/networking/browsers/chromium/common.nix +++ b/pkgs/applications/networking/browsers/chromium/common.nix @@ -312,9 +312,6 @@ let sed -i -e '/lib_loader.*Load/s!"\(libudev\.so\)!"${lib.getLib systemd}/lib/\1!' \ device/udev_linux/udev?_loader.cc '' + '' - sed -i -e '/libpci_loader.*Load/s!"\(libpci\.so\)!"${pciutils}/lib/\1!' \ - gpu/config/gpu_info_collector_linux.cc - # Allow to put extensions into the system-path. sed -i -e 's,/usr,/run/current-system/sw,' chrome/common/chrome_paths.cc @@ -476,9 +473,10 @@ let postFixup = '' # Make sure that libGLESv2 and libvulkan are found by dlopen. + # libpci (from pciutils) is needed by dlopen in angle/src/gpu_info_util/SystemInfo_libpci.cpp chromiumBinary="$libExecPath/$packageName" origRpath="$(patchelf --print-rpath "$chromiumBinary")" - patchelf --set-rpath "${lib.makeLibraryPath [ libGL vulkan-loader ]}:$origRpath" "$chromiumBinary" + patchelf --set-rpath "${lib.makeLibraryPath [ libGL vulkan-loader pciutils ]}:$origRpath" "$chromiumBinary" ''; passthru = {