mesa-for-android-container icon indicating copy to clipboard operation
mesa-for-android-container copied to clipboard

[Bug] Adreno 650 (SD870) fails on HyperOS (Android 14): KGSL "invalid param 13" in Freedreno & Swapchain failure in Zink

Open Flen-Plnens opened this issue 1 year ago • 7 comments

Image Image

Device Information:

  • Device: Xiaomi Pad 6
  • SoC: Snapdragon 870 (Adreno 650)
  • OS: Android 14 / Xiaomi HyperOS 2.0.7.0
  • Kernel: (Standard Xiaomi Kernel)
  • Environment: Termux + Proot-Distro (Debian 13) + Termux:X11
  • Driver Package: mesa-android-container_25.3.0-devel-20250725_debian_trixie_arm64.tar.gz

Description: I am attempting to use this patched Mesa build to fix performance issues with VirGL. I have configured the LD_LIBRARY_PATH and LIBGL_DRIVERS_PATH to point to the extracted driver files.

However, both the Native Freedreno driver and the Zink driver fail to run glmark2. The GPU is correctly identified as "FD650" or "Turnip Adreno 650", but execution crashes immediately.

Scenario 1: Native Freedreno (OpenGL)

  • Command: MESA_LOADER_DRIVER_OVERRIDE=freedreno glmark2
  • Result: Recognizes FD650, but crashes with a KGSL parameter error and Segmentation Fault.
  • Log:
MESA-LOADER: failed to retrieve device information
MESA: error: kgsl_pipe_get_param:103: invalid param id: 13
MESA: error: dri3_alloc_render_buffer:1580 xcb_dri3_pixmap_from_buffer[s] failed
MESA: error: X error: 2
...
GL_RENDERER:   FD650
...
[build] use-vbo=false: Segmentation fault

Scenario 2: Zink (OpenGL over Vulkan)

  • Command: MESA_LOADER_DRIVER_OVERRIDE=zink TU_DEBUG=noconform glmark2
  • Result: Recognizes Turnip Adreno 650, but fails to create the swapchain.
  • Log:
MESA: error: CreateSwapchainKHR failed with VK_ERROR_INITIALIZATION_FAILED
MESA: error: zink: could not create swapchain
...
GL_RENDERER:   zink Vulkan 1.3(Turnip Adreno (TM) 650 (MESA_TURNIP))
...
[build] use-vbo=false:X Error of failed request:  GLXBadCurrentWindow

Steps to Reproduce:

  1. Setup Termux:X11 and Debian 13 Proot.
  2. Extract the debian_trixie_arm64 tarball.
  3. Export LD_LIBRARY_PATH to the extracted usr/lib/aarch64-linux-gnu.
  4. Run glmark2 with the environment variables mentioned above.

Suspected Cause: It appears there is a mismatch with the KGSL kernel driver on Xiaomi's Android 14 (HyperOS) implementation, specifically regarding param id: 13. For Zink, the DRI3/WSI patch seems unable to establish a swapchain with the Termux:X11 surface.

Is there a workaround or a specific build flag required for HyperOS devices?

Flen-Plnens avatar Nov 29 '25 13:11 Flen-Plnens

Please try MESA_LOADER_DRIVER_OVERRIDE=kgsl TU_DEBUG=noconform glmark2.

I have tested the driver on Redmi K40 Pro (SD888, Adreno 660, MIUI 12.5) and it works well. So I think it's no problem for HyperOS/MIUI.

lfdevs avatar Nov 29 '25 14:11 lfdevs

Thank you for the quick response. I would like to clarify that I have already attempted that exact command (MESA_LOADER_DRIVER_OVERRIDE=kgsl TU_DEBUG=noconform glmark2) before submitting this issue, and the result is identical to the crash log I provided. You mentioned testing on MIUI 12.5, which is based on Android 11. My device is running HyperOS, which is based on Android 14. It is highly possible that the KGSL kernel interface or allowed ioctl parameters have changed significantly between Android 11 and Android 14. The error kgsl_pipe_get_param:103: invalid param id: 13 specifically suggests that the driver is requesting a parameter ID that the newer Android 14 kernel no longer recognizes or supports. Since the command fails immediately on my side, could you guide me on how to debug this further? For example, would an strace log help identify which system call is being rejected? Attached is the specific output when running your suggested command: Image

Flen-Plnens avatar Nov 29 '25 15:11 Flen-Plnens

Here is the full strace log captured on Xiaomi Pad 6 (SD870, Android 14 HyperOS).

The log confirms that the failure happens in two stages:

  1. Early stage (Line 94): MESA: error: kgsl_pipe_get_param:103: invalid param id: 13. This confirms the driver userspace logic is rejecting the kernel response (or lack thereof) for this specific parameter.

  2. Crash stage (Line 717): MESA: error: dri3_alloc_render_buffer... failed. This confirms that due to the parameter failure, the DRI3 buffer allocation logic is broken, leading to the X11 BadMatch / X error: 2.

It seems unavoidable without patching the source to handle param id: 13 gracefully on newer KGSL versions.

Attachment: trace_log.txt

Flen-Plnens avatar Nov 30 '25 03:11 Flen-Plnens

I still believe this isn’t an issue specific to HyperOS or the Android version. I also tested glmark2 in a Debian 13 PRoot container on a Xiaomi Pad 6 Pro (HyperOS 2.0.213.0, Android 15, Adreno 730), where I encountered the same error: MESA: error: kgsl_pipe_get_param:103: invalid param id: 13. However, the Freedreno driver worked correctly, and the benchmark ran successfully as shown in the results below. Redmi K40 Pro also passed tests under LineageOS 22.2 (based on Android 15).

user@localhost:~$ XDG_RUNTIME_DIR=/tmp DISPLAY=':2' LOAD_LIBRARY_PATH=usr/lib/aarch64-linux-gnu LIBGL_DRIVERS_PATH=usr/lib/aarch64-linux-gnu/dri MESA_LOADER_DRIVER_OVERRIDE=kgsl TU_DEBUG=noconform glmark2
MESA-LOADER: failed to retrieve device information
MESA: error: kgsl_pipe_get_param:103: invalid param id: 13
=======================================================
    glmark2 2023.01
=======================================================
    OpenGL Information
    GL_VENDOR:      freedreno
    GL_RENDERER:    FD725
    GL_VERSION:     4.6 (Compatibility Profile) Mesa 25.3.0-devel (git-e2bacee7a5)
    Surface Config: buf=32 r=8 g=8 b=8 a=8 depth=24 stencil=0 samples=0
    Surface Size:   800x600 windowed
=======================================================
[build] use-vbo=false: FPS: 2237 FrameTime: 0.447 ms
[build] use-vbo=true: FPS: 1223 FrameTime: 0.818 ms
[texture] texture-filter=nearest: FPS: 1145 FrameTime: 0.874 ms
[texture] texture-filter=linear: FPS: 1198 FrameTime: 0.835 ms
[texture] texture-filter=mipmap: FPS: 1149 FrameTime: 0.870 ms
[shading] shading=gouraud: FPS: 1480 FrameTime: 0.676 ms
[shading] shading=blinn-phong-inf: FPS: 1653 FrameTime: 0.605 ms
[shading] shading=phong: FPS: 1220 FrameTime: 0.820 ms
[shading] shading=cel: FPS: 1250 FrameTime: 0.800 ms
[bump] bump-render=high-poly: FPS: 1676 FrameTime: 0.597 ms

Therefore, the critical error messages are likely the following two lines, which may stem from experimental upstream DRI3 patches.

MESA: error: dri3_alloc_render_buffer:1580 xcb_dri3_pixmap_from_buffer[s] failed
MESA: error: X error: 2

I recommend first creating a clean PRoot container—without installing any desktop environment—then installing only glmark2. After that, directly extract the archive to the root directory, restart the container, and check whether glmark2 runs successfully. You could also try mesa-for-android-container_25.3.0-devel-20250725_archlinux_arm64.tar, as it was builded and packaged using Arch Linux ARM’s official build scripts and might offer better compatibility. If that still doesn’t work, you may also test this Mesa 24.3.4 driver version, which fully incorporates @xMeM’s original patches without any modifications made to accommodate newer versions: mesa-for-android-container_24.3.4_debian_trixie_arm64.tar.gz

If none of the above methods work, try setting the environment variable LIBGL_DRI3_DISABLE=1 to disable DRI3.

lfdevs avatar Nov 30 '25 14:11 lfdevs

Update on suggested fixes:

  • Disabling DRI3: I tried export LIBGL_DRI3_DISABLE=1, but it had no effect. The strace log (attached) still shows the driver attempting DRI3 calls (DRI3 and Present extensions) and failing at dri3_alloc_render_buffer immediately after the KGSL error. It seems the driver ignores this env var or forces DRI3 for this backend.
  • Older Drivers: The older builds failed to load entirely (MESA-LOADER: failed to retrieve device information). Image

Crucial Discovery regarding Winlator: I tested Winlator (Windows emulator for Android) on this exact device, and it runs Ren'Py games perfectly smooth using the Turnip + Zink/DXVK backend. This suggests that the Freedreno/Turnip driver CAN work on this HyperOS kernel, but the specific build/patches used in Winlator likely contain a workaround for the KGSL param 13 issue that is missing in this upstream-based build. Image

Do you know if there are specific "Turnip for Android Emulation" patches that we could merge here?

Flen-Plnens avatar Dec 06 '25 10:12 Flen-Plnens

I have managed to locate the exact build script used for the Turnip driver that runs successfully on Winlator for this device. It turns out the solution is not a standard upstream patch, but rather a specific set of sed commands applied during the build process to neutralize the cached memory logic, which seems to be the root cause of the incompatibility with the HyperOS kernel. The script explicitly reverts the usage of tu_bo_init_new_cached back to tu_bo_init_new in src/freedreno/vulkan/tu_query.cc and forcibly sets the VK_MEMORY_PROPERTY_HOST_CACHED_BIT flag to 0 in src/freedreno/vulkan/tu_device.h.

This strongly suggests that the newer Xiaomi kernels on Adreno 6xx devices are strictly rejecting these specific memory caching flags, leading to the crashes we observed. You can examine the exact logic in the prepare_source function of the turnip_builder.sh file within this repository: https://github.com/StevenMXZ/freedreno_turnip-CI. I believe applying a similar workaround to disable this caching behavior in your build configuration would resolve the kgsl initialization error for Android 14 users.

Flen-Plnens avatar Dec 06 '25 13:12 Flen-Plnens

@lfdevs Oh, it seems I need to provide some additional information.
My Xiaomi Pad 6 is not rooted, which is why I am using this method. I also realized that I might have uploaded the wrong log file. Here is the log file: trace_log(1).txt By the way, the build script I found might not be applicable to this driver, as I was in a hurry when searching for it and I'm not very familiar with this area. After analyzing it with Gemini, I directly sent you the link. If you have time, you could check if this might solve the issue I encountered.

Flen-Plnens avatar Dec 13 '25 09:12 Flen-Plnens