Skip to content

WIP: freedreno/drm: Add KGSL backend for freedreno

Lucas Fryzek requested to merge Hazematman/mesa:freedreno_kgsl into main

In order to get a KGSL backend working in freedreno, a few other changes had to be made to facilitate the backend working. This includes adding new APIs to backend API to facilitate behavior in KGSL that is different than the existing backend (MSM & virtio). This includes adding 2 APIs to fd_device_funcs for getting a bo from a dmabuf, and for closing the handle of a bo. This also includes 1 API for fd_bo_funcs for mapping the bo. This is required because the dmabufs for KGSL come from the qualcomm gralloc implementation which requires a different fd and mmap strategy than the gpu memory directly allocated by KGSL.

These changes also include some platform level changes for DRI in gallium and egl. I'm seeking feedback on these changes because I'm not really sure I implemented them in the best possible way. Right now they consist of a bunch of ifdefs where the existing DRI backend will call into drm to instead call some hardcoded KGSL specific behavior.

One note is that there is currently an outstanding bug I'm running into with KGSL that triggers an "iommu fault" from the "CCU". This happens because it is possible for gralloc to allocate a surface that doesn't have a height aligned by 4. The freedreno driver will expect all surfaces it draws to have a height aligned by 4 (at least on a6xx devices, see https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/freedreno/fdl/fd6_layout.c#L148-L152). Since gralloc is not aligning the height by 4 not enough memory is allocated and the "CCU" will write to unallocated memory.

If you would like to test these changes on real hardware here is some instructions for building and running:

  1. You'll need a cross compiling script for android. I'm currently using the following one. If you want to copy it, make sure to modify it to match the NDK paths on your system. https://pastebin.com/h46yM7sD
  2. To configure the build make sure you have the following build options set
--cross-file <name of meson cross compiling script> -Dplatforms=android -Dplatform-sdk-version=26 -Dandroid-stub=true -Dgallium-drivers=freedreno -Dvulkan-drivers= -Dfreedreno-kgsl=true -Degl=enabled -Ddri-search-path="/vendor/lib64/egl" --prefix <where you will locally install built libraries>
  1. run ninja install
  2. Make sure you have RW access to the system partition on your android device
  3. run adb setprop "mesa.loader.driver.override" "kgsl" or add mesa.loader.driver.override=kgsl to your build.prop file
    • These changes don't have a way to force mesa to use KGSL when its built with support for KGSL. So you need to force mesa to use the KGSL backend with this property.
  4. Run the following commands to copy the build libraries over to your device
adb push install-android/lib/libEGL.so /vendor/lib64/egl/libEGL_adreno.so
adb push install-android/lib/libGLESv1_CM.so /vendor/lib64/egl/libGLESv1_CM_adreno.so
adb push install-android/lib/libGLESv2.so /vendor/lib64/egl/libGLESv2_adreno.so
adb push install-android/lib/libglapi.so /vendor/lib64/egl/libglapi.so 
adb push install-android/lib/dri/kgsl_dri.so /vendor/lib64/egl/kgsl_dri.so
  1. Run a OpenGLES application on your device

Note you may need to set ro.zygote.disable_gl_preload=true in your build.prop file, if your device is caching the current OpenGLES driver on boot.

Merge request reports