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

[Partially fixed] 6X FPS droped with regression from latest version 27

Open Dr4kzor opened this issue 1 month ago • 8 comments

Severe perf regression on Adreno 830: mesa-27.0.0-devel-20261025 vs mesa-26.3.0-devel-20260824 (~5.6× slower); MESA_DRI3_DISABLE_PRESENT_WAIT_FENCE does not help on Wayland

Repo: lfdevs/mesa-for-android-container Suspect PR: #96 — Fix/kgsl present wait fence (@KiralyCraft, merged 2026-09-28) Related: #105 — dri3: add an option to disable the Present wait-fence bridge (@lfdevs, merged 2026-10-08) — opt-out introduced after the regression was noticed

Summary

Upgrading from mesa-26.3.0-devel-20260824 to mesa-27.0.0-devel-20261025 on Adreno 830 (Snapdragon 8 Elite) under KDE Plasma Wayland (Anland chroot) causes glmark2 to drop from 4454 → 797 glmark2 score (~5.6×). The [build] subtest alone drops 5010 → 737 FPS (~6.8×). The DRI3 opt-out added in PR #105 (MESA_DRI3_DISABLE_PRESENT_WAIT_FENCE=1) has no measurable effect on the Wayland path — the wait-fence appears to be sitting below DRI3 (in the KGSL/EGL/present layer) where the kill-switch doesn't reach.

The PR #96 author already flagged on their own PR that they weren't fully confident in the change ("A Codex assisted patch which attempts to fix…", "I am not 100% sure what is going on here", "it might be better to rework this") and reported their own 20% drop on glxgears on Adreno 740. On newer Adreno 830 the hit is far larger.

Environment

Field Value
GPU Adreno (TM) 830v1 (reported by Mesa)
SoC Qualcomm Snapdragon 8 Elite
Kernel 6.6.142-4k-g999b95d4792d
Android base Termux (ARM64)
Container Ubuntu Resolute 26.04 ARM64 chroot (Anland)
Compositor KDE Plasma Wayland on KWin 6.6.6-0ubuntu91 (lfdevs anland build)
XWayland 2:24.1.10-92 (Ubuntu resolute arm64)
apt mesa underlay 26.0.8-1ubuntu0.3 (identical between A and B runs)
Mesa driver path KGSL (FD_FORCE_KGSL=1, MESA_LOADER_DRIVER_OVERRIDE=kgsl, GALLIUM_DRIVER=freedreno)

Reproduction

A/B overlay of mesa-for-android-container_<ver>_ubuntu_resolute_arm64.tar.gz into /, ldconfig, then relaunch KDE Plasma session and run glmark2-wayland.

A — mesa-26.3.0-devel-20260824

glmark2 2023.01
GL_VENDOR:      freedreno
GL_RENDERER:    Adreno (TM) 830v1
GL_VERSION:     4.6 (Compatibility Profile) Mesa 26.3.0-devel (git-98f3d6229d)
Surface Size:   800x600 windowed

[build] use-vbo=false: FPS: 5010 FrameTime: 0.200 ms
[build] use-vbo=true : FPS: 4856 FrameTime: 0.206 ms
[texture] texture-filter=nearest: FPS: 3501 FrameTime: 0.286 ms (interrupted)

glmark2 Score: 4454

B — mesa-27.0.0-devel-20261025 (no env override)

GL_RENDERER:    Adreno (TM) 830v1
GL_VERSION:     4.3 (Compatibility Profile) Mesa 27.0.0-devel (git-6f90e92dfd)

[build] use-vbo=false: FPS: 737 FrameTime: 1.359 ms
[build] use-vbo=true : FPS: 859 FrameTime: 1.164 ms

glmark2 Score: 797

C — mesa-27.0.0-devel-20261025 with MESA_DRI3_DISABLE_PRESENT_WAIT_FENCE=1 exported from the Plasma session (PR #105 opt-out)

GL_RENDERER:    Adreno (TM) 830v1
GL_VERSION:     4.3 (Compatibility Profile) Mesa 27.0.0-devel (git-6f90e92dfd)

[build] use-vbo=false: FPS: 737 FrameTime: 1.357 ms
[build] use-vbo=true : FPS: 822 FrameTime: 1.217 ms
[texture] texture-filter=nearest: FPS: 911 FrameTime: 1.098 ms (interrupted)

glmark2 Score: 822

C' — Same as C, glmark2-es2-wayland (OpenGL ES 3.2 path)

GL_VERSION:     OpenGL ES 3.2 Mesa 27.0.0-devel (git-6f90e92dfd)
[build] use-vbo=false: FPS: 712 FrameTime: 1.406 ms
[build] use-vbo=true : FPS: 877 FrameTime: 1.141 ms
glmark2 Score: 793

Observations

  1. Regression size: 5010 → 737 FPS on [build] use-vbo=false (6.8×). glmark2 overall: 4454 → 797 (5.6×). Dwarfs the 20% drop the PR author reported on their Adreno 740.
  2. DRI3 opt-out ineffective on Wayland: C ≈ B. PR #105's env var does not reach whatever wait is actually hurting a KWin Wayland session on KGSL.
  3. GL version regression: mesa-26.3 negotiates GL 4.6 compat; mesa-27 falls back to GL 4.3 compat on the same hardware, suggesting the init path is partially failing / taking a slow fallback — not just slower.
  4. GLES 3.2 path (C') is also hit — regression is not GL-specific.
  5. All three runs use the same KWin / XWayland / apt-mesa / kernel / env; only the mesa-for-android-container overlay was swapped between runs.

Suspected cause

PR #96 adds a KGSL present wait-fence. The author's words on the PR:

A Codex assisted patch which attempts to fix reading buffers too early and causing flash-to-black issues … I am not 100% sure what is going on here … -20% on glxgears compared to unfixed version: 1757 fps original vs 1337 with this patch. … I do not completely trust what is going on here … It might be better to rework this for better integration and style adaptation.

PR #105's title ("dri3: add an option to disable the Present wait-fence bridge") and description ("opt-in workaround for Android/Xwayland sessions affected by the Present wait-fence bridge introduced in PR #96") confirms the regression was already known for XWayland. The data in run C shows the same wait is active on the native Wayland path too (likely in the KGSL/EGL/present layer below DRI3), so the opt-out needs to be moved lower OR the fence logic needs to be rebuilt.

Suggested next steps

  • Revert PR #96 on dev/adreno-main while the fix is reworked, or gate it behind an opt-in rather than opt-out until the perf impact on A6xx/A7xx/A8xx is understood.
  • If keeping PR #96, extend the kill-switch introduced in PR #105 to the KGSL/EGL/present path so Wayland sessions can opt out too.
  • Add Adreno 830 (Snapdragon 8 Elite) to the CI/benchmark matrix if feasible — the regression there is >5×, much larger than the Adreno 740 numbers in the original PR.

Files to overlay-swap for reproduction (handy for triage)

  • mesa-for-android-container_26.3.0-devel-20260824_ubuntu_resolute_arm64.tar.gz (sha256 ee762f0855c47f9a245df3ce53a46d40b2240ede9b5c9ddf7606e724362fec77, 12,069,639 bytes)
  • mesa-for-android-container_27.0.0-devel-20261025_ubuntu_resolute_arm64.tar.gz (sha256 51aa11a8e7bc8c98bc9e852b260ee2dac99392b4ee8658182e4837c309818faf, 12,674,045 bytes)

Reproducer script (both runs identical except overlay):

sudo tar -zxf mesa-for-android-container_<ver>_ubuntu_resolute_arm64.tar.gz -C /
sudo ldconfig
# relog Plasma session, then:
glmark2-wayland
glmark2-es2-wayland
# optional, to verify opt-out ineffective:
MESA_DRI3_DISABLE_PRESENT_WAIT_FENCE=1 glmark2-wayland

Dr4kzor avatar Oct 28 '26 11:10 Dr4kzor

Woah, that is quite an achievement. @lfdevs did you have this issue on your 830?

KiralyCraft avatar Oct 28 '26 12:10 KiralyCraft

A quick way to test this is using my https://github.com/Dr4kzor/Chroot_Ubuntu and installing Anland chroot and just run it +/- 5000 FPS glmark2 with mesa 26.3, then inside the home dir we have a update_mesa.sh run it to upgrade to latest version and restart chroot now you will have a 700 FPS glmark2 with mesa 27 only the mesa version was changed between tests

Dr4kzor avatar Oct 28 '26 12:10 Dr4kzor

I am replicating your setup on my 710 to see if the thing persists. I don't have root on this device, but PR105 showed we can fix / profile things without it. Still, there are quite some commits between PR96 and this release; I really hope we don't step into bisecting, that would not be fun;

EDIT: I seem to be able to reproduce it, dropping from 428 FPS to 241 FPS with version 27. Now digging into it;

KiralyCraft avatar Oct 28 '26 12:10 KiralyCraft

An update: I did end up bisecting this, and I found two separate regressions. One comes from #96, and another comes from the later shared KGSL changes in #100.

I reproduced the drop on an Adreno 710 using Ubuntu Resolute and KDE Plasma/KWin 6.6.6 under Anland. This device is not rooted, so I used PRoot rather than your chroot. I first tested the published Ubuntu archives using the overlay/ldconfig/restart method you described, then rebuilt the source revisions to narrow it down.

For the source comparisons, I kept the same KWin process running with the old Mesa and changed only the application's private Mesa libraries. The tests used native glmark2-wayland at 800x600, with FD_MESA_DEBUG=noubwc,notile. No recording or profiler ran during the performance measurements; profiling was done separately afterward.

The rebuilt release endpoints gave a median of 443 for 98f3d6229d and 194 for 6f90e92dfd. These are short, fixed three-scene tests, not full glmark2 scores, so they should not be compared directly with your 4454/797 numbers. I reproduced the direction of the regression, but not its exact magnitude on your 830.

After bisecting the merge boundaries, I tested the relevant commits against their direct parents:

Change Test Parent Commit
a3eb373e9f5, from #96 Three scenes, median of 3 runs 435 228
84fc50fab280, from #100 Off-screen build scene, median of 6 alternating samples 330 254.5

The first test contains build without VBO, build with VBO, and texture, each lasting three seconds. The off-screen test contains only build without VBO and uses glFinish() instead of swapping frames into a window. The two rows measure different workloads; the useful comparison is parent versus commit within each row.

For #96, the relevant change is in fd_flush_resource(). KGSL now waits with FD_BO_PREP_READ when explicit_present_fence is false. The X11 Present-fence path can avoid that CPU wait by carrying the rendering fence to the server. Native Wayland uses ordinary dri_flush() rather than dri_flush_with_fence_fd(), so it takes the conservative blocking fallback instead.

The separate three-second profiles confirm that this path executes: the parent had 8 GPU timestamp waits inside 1,207 flushes, whereas a3eb373e9f5 had 668 inside 738 flushes. Average dri_flush() time rose from about 0.91 ms to 1.83 ms. These instrumented timings are diagnostic evidence, not the benchmark results above.

So your observation about MESA_DRI3_DISABLE_PRESENT_WAIT_FENCE=1 is consistent with the code. It controls the X11 DRI3 bridge; it does not remove this shared KGSL fallback from the native Wayland path. Despite the commit's dri3 title, that part of the change affects native Wayland clients too.

The second regression is independent of window presentation. 84fc50fab280 disables buffer_map_persistent_coherent for all KGSL screens and adds cache maintenance to ordinary upload/unmap paths. I reproduced its off-screen performance drop even with the VA frontend disabled in the build, so the affected path is not limited to video decoding.

In the separate off-screen profiles, neither revision called dri_flush(). The parent issued one startup IOCTL_KGSL_GPUOBJ_SYNC. The child issued 1,478 IOCTL_KGSL_GPUMEM_SYNC_CACHE calls and 1,479 IOCTL_KGSL_GPUOBJ_SYNC calls. Both ioctl forms succeeded on this device, and the helper issues both even when the first succeeds. This identifies a substantial new upload/cache cost, although I have not yet isolated the contribution of each sub-change within that commit.

That same commit also explains the reported OpenGL 4.6 to 4.3 change: disabling the persistent-coherent capability removes GL_ARB_buffer_storage, which is required for OpenGL 4.4. Both revisions still use the FD710 renderer. The version change therefore does not, by itself, indicate failed GPU initialization or software rendering.

There is also a separate XWayland issue worth distinguishing here. XWayland PR #2 fixes the fenced Present freezes while retaining asynchronous X11 rendering. That is relevant to X11 applications running under KDE, but these native Wayland tests bypass XWayland, so that fix cannot remove the costs measured here.

A couple of limits for reproducibility: the official PRoot launcher defaults to ANLAND_SKIP_IMPLICIT_SYNC_WAIT=1, so this is not an exact replica of your rooted chroot. Also, the historical #100 commit needed Clang's thread-safety diagnostic treated as a warning to build; I applied that same compiler setting to both sides of that adjacent comparison, without modifying either source tree.

I have not validated a production fix yet. The #96 fallback exists because an exported KGSL buffer does not automatically carry Mesa's rendering-completion fence to an implicit-sync consumer. Removing the wait without replacing that handoff could bring the original flickering back. I think the next work should be a valid asynchronous handoff for native Wayland, alongside checking which resources actually need the new cache maintenance, while preserving the working X11 fence path. The bisect gives us concrete places to investigate, but the final fix and its effect on your 830 still need testing. I'll keep posting updates here.

KiralyCraft avatar Oct 28 '26 14:10 KiralyCraft

It looks like there is no performance regression on my 740 device with PR96 (obviously, since that's what I tested it on) or the latest Mesa 27 release using the Termux:X11 route. I do not have Wayland set up on that device, but I am testing it on the 710. Now that we know that Mesa 27 doesn't regress in terms of performance there, but it does for Wayland, I'm looking more into this. I'll be back with updates. The best performing Wayland-friendly commit is currently the parent of PR#96, which gives me a clue of where to start

KiralyCraft avatar Oct 28 '26 15:10 KiralyCraft

Okay, I now have a basic understanding of the current situation. I plan to ~~revert the present wait fence-related changes on the dev/adreno-main branch,~~ then try to fix the issue causing OpenGL to be downgraded to version 4.3. ~~The present wait fence-related code will be moved to a new branch, variant/wait-fence, and released as an optional variant.~~

lfdevs avatar Oct 28 '26 17:10 lfdevs

It looks like PR 100 is the cause for the OpenGL downgrade, as it comes from buffer_map_persistent_coherent being disabled there. I'm working on a fix for Wayland compositors

KiralyCraft avatar Oct 28 '26 18:10 KiralyCraft

I submitted a patch for this issue, for now. @Dr4kzor, after the artifacts in that PR build, would you mind testing to see if it behaves as expected for you?

KiralyCraft avatar Oct 28 '26 19:10 KiralyCraft