Skip to content

[not for merging] enhance(main/mesa): Lucas Fryzek and xMeM's freedreno kgsl for mesa 25.1.1 #24840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

robertkirkman
Copy link
Contributor

@robertkirkman robertkirkman commented May 25, 2025

  • Fixes (partially) Freedreno? #24222 (this driver requested there is experimental and might never become completely finished to the point of working on all devices)

  • This is xMeM@401982b entirely copied and pasted and rebased into mesa 25.1.1 and opened as a draft PR so that it's easier to download for people who want it, not necessarily for merging

  • The original inventor of this code is Lucas Fryzek, whose SurfaceFlinger(ANativeWindow)-compatible version was posted here, https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21570, but who has closed that PR and does not plan to make any more official updates for it

  • The Termux:X11 port of this code was created by xMeM and uploaded into their repository, but without making any PRs to termux-packages, so the visibility was low

  • There was a conflict between 0010-fix-zink.patch and 0015-termux-x11-kgsl.patch, and I did not really understand what to do, so I merged them into a single patch and guessed at choosing the change from 0015-termux-x11-kgsl.patch and it works for me

  • Unfortunately, this driver does not work 100% perfectly. On some devices it does not work, and on devices where it does work, it produces some minor visual artifacts.

    • Example of a device it works on for me: Samsung Galaxy A70 SM-A705FN with Adreno 612
    • Example of a device it does not work on for me: Samsung Galaxy S9 SM-G960U with Adreno 630
      • Error: MESA: error: kgsl_pipe_get_param:103: invalid param id: 13 MESA: error: kgsl_bo_new_dmabuf:251: Failed to allocate dma-buf (Not a typewriter) Segmentation fault
  • To use, run Termux:X11 with a desktop environment outside of proot as normal, but use the command export MESA_LOADER_DRIVER_OVERRIDE=kgsl to activate it instead of the default Zink + Turnip driver, before running OpenGL programs.

… 25.1.1

- This is xMeM@401982b entirely copied and pasted and rebased into `mesa` 25.1.1 and opened as a draft PR so that it's easier to download for people who want it, not necessarily for merging

- The original inventor of this code is Lucas Fryzek, whose SurfaceFlinger(ANativeWindow)-compatible version was posted here, https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21570, but who has closed that PR and does not plan to make any more official updates for it

- The Termux:X11 port of this code was created by xMeM and uploaded into their repository, but without making any PRs to termux-packages, so the visibility was low

- There was a conflict between `0010-fix-zink.patch` and `0015-termux-x11-kgsl.patch`, and I did not really understand what to do, so I merged them into a single patch and guessed at choosing the change from `0015-termux-x11-kgsl.patch` and it works for me

- Unfortunately, this driver does not work 100% perfectly. On some devices it does not work, and on devices where it does work, it produces some minor visual artifacts.
  - Example of a device it **works** on for me: **Samsung Galaxy A70 SM-A705FN with Adreno 612**
  - Example of a device it **does not work** on for me: **Samsung Galaxy S9 SM-G960U with Adreno 630**
    - Error: `MESA: error: kgsl_pipe_get_param:103: invalid param id: 13 MESA: error: kgsl_bo_new_dmabuf:251: Failed to allocate dma-buf (Not a typewriter) Segmentation fault`

- To use, run Termux:X11 with a desktop environment **outside of proot** as normal, but use the command `export MESA_LOADER_DRIVER_OVERRIDE=kgsl` to activate it instead of the default Zink + Turnip driver, before running OpenGL programs.
@hansm629
Copy link

hansm629 commented Jun 2, 2025

@robertkirkman
Thank you Sir!
Tested on Galaxy S24 Ultra (Adreno 750)!

Performance is great based on glmark2 & glmark2-es2 benchmarks,
but there are small artifacts in [bump]!

~$ glmark2
MESA: error: kgsl_pipe_get_param:103: invalid param id: 13
=======================================================
    glmark2 2023.01
=======================================================
    OpenGL Information
    GL_VENDOR:      freedreno
    GL_RENDERER:    FD750
    GL_VERSION:     4.6 (Compatibility Profile) Mesa 25.1.1
    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: 2492 FrameTime: 0.401 ms
[build] use-vbo=true: FPS: 2869 FrameTime: 0.349 ms
[texture] texture-filter=nearest: FPS: 3515 FrameTime: 0.285 ms
[texture] texture-filter=linear: FPS: 3395 FrameTime: 0.295 ms
[texture] texture-filter=mipmap: FPS: 3343 FrameTime: 0.299 ms
[shading] shading=gouraud: FPS: 3075 FrameTime: 0.325 ms
[shading] shading=blinn-phong-inf: FPS: 3057 FrameTime: 0.327 ms
[shading] shading=phong: FPS: 3016 FrameTime: 0.332 ms
[shading] shading=cel: FPS: 2965 FrameTime: 0.337 ms
[bump] bump-render=high-poly: FPS: 2638 FrameTime: 0.379 ms
[bump] bump-render=normals: FPS: 2465 FrameTime: 0.406 ms
[bump] bump-render=height: FPS: 2823 FrameTime: 0.354 ms
[effect2d] kernel=0,1,0;1,-4,1;0,1,0;: FPS: 2092 FrameTime: 0.478 ms
[effect2d] kernel=1,1,1,1,1;1,1,1,1,1;1,1,1,1,1;: FPS: 2209 FrameTime: 0.453 ms
[pulsar] light=false:quads=5:texture=false: FPS: 2453 FrameTime: 0.408 ms
[desktop] blur-radius=5:effect=blur:passes=1:separable=true:windows=4: FPS: 1231 FrameTime: 0.812 ms
[desktop] effect=shadow:windows=4: FPS: 2004 FrameTime: 0.499 ms
[buffer] columns=200:interleave=false:update-dispersion=0.9:update-fraction=0.5:update-method=map: FPS: 473 FrameTime: 2.116 ms
[buffer] columns=200:interleave=false:update-dispersion=0.9:update-fraction=0.5:update-method=subdata: FPS: 1030 FrameTime: 0.971 ms
[buffer] columns=200:interleave=true:update-dispersion=0.9:update-fraction=0.5:update-method=map: FPS: 631 FrameTime: 1.586 ms
[ideas] speed=duration: FPS: 1157 FrameTime: 0.865 ms
[jellyfish] <default>: FPS: 2824 FrameTime: 0.354 ms
[terrain] <default>: FPS: 401 FrameTime: 2.494 ms
[shadow] <default>: FPS: 2036 FrameTime: 0.491 ms
[refract] <default>: FPS: 708 FrameTime: 1.413 ms
[conditionals] fragment-steps=0:vertex-steps=0: FPS: 2785 FrameTime: 0.359 ms
[conditionals] fragment-steps=5:vertex-steps=0: FPS: 2809 FrameTime: 0.356 ms
[conditionals] fragment-steps=0:vertex-steps=5: FPS: 2808 FrameTime: 0.356 ms
[function] fragment-complexity=low:fragment-steps=5: FPS: 2782 FrameTime: 0.360 ms
[function] fragment-complexity=medium:fragment-steps=5: FPS: 2798 FrameTime: 0.357 ms
[loop] fragment-loop=false:fragment-steps=5:vertex-steps=5: FPS: 2763 FrameTime: 0.362 ms
[loop] fragment-steps=5:fragment-uniform=false:vertex-steps=5: FPS: 2784 FrameTime: 0.359 ms
[loop] fragment-steps=5:fragment-uniform=true:vertex-steps=5: FPS: 2791 FrameTime: 0.358 ms
=======================================================
                                  glmark2 Score: 2339 
=======================================================
os_same_file_description couldn't determine if two DRM fds reference the same file description. (Try again)
Let's just assume that file descriptors for the same file probablyshare the file description instead. This may cause problems whenthat isn't the case.

And Supertuxkart also has great performance but has artifacts.

2025_06_03.00_01.mp4

In addition, the following messages are commonly displayed in OpenGL & OpenGL ES environments.

MESA: error: kgsl_pipe_get_param:103: invalid param id: 13
os_same_file_description couldn't determine if two DRM fds reference the same file description. (Try again)
Let's just assume that file descriptors for the same file probablyshare the file description instead. This may cause problems whenthat isn't the case.

@hansm629
Copy link

hansm629 commented Jun 2, 2025

@xMeM
Hello sir
Could you please make a patch with improved error messages and artifacts?

@zanfix
Copy link

zanfix commented Jun 2, 2025

Well this is amazing!

Apart from some flickering here and there, i get excellent performance on my rooted samsung galaxy z flip 6 in a devuan chroot!

  • glxgears gets ~4500 fps
  • glmark2 at 800x600 gets a score of 2067 (terrain ~700fps)
  • supertuxkart at 1920x1080 fullscreen gets 110 fps but flickers badly, with vsync enabled i get 60 fps solid with no flickering or artifacts!
  • dhewm3 1920x1080 fullscreen gets around 60/70 fps but flickers badly, with vsync enabled i get ~60fps with minimal flickering
  • gzdoom fullscreen with RO.pk3 and DV.wad gets ~300fps, very mininal flickering, no artifacts
  • openarena at 1920x1080 fullscreen is ~100 fps, minimal flickering, vsync enabled does not seem to change much

here is my cmdline: LD_LIBRARY_PATH=/usr/local/lib/aarch64-linux-gnu/ LIBGL_ALWAYS_SOFTWARE=0 LD_PRELOAD= vblank_mode=1 GALLIUM_DRIVER=freedreno MESA_LOADER_DRIVER_OVERRIDE=kgsl mesa_glthread=true MESA_GL_VERSION_OVERRIDE=4.6COMPAT MESA_GLES_VERSION_OVERRIDE=3.2 $@

@robertkirkman
Copy link
Contributor Author

Yes, I also get artifacts, and also I had artifacts with this driver with previous versions of Mesa as well.
Unfortunately, I do not know how to fix the artifacts either, so that is why I will leave this as Draft.

@twaik
Copy link
Member

twaik commented Jun 3, 2025

Graphical artifacts + perfomance "improvement" mean lacking Vsync or some other sync primitive being used between X server and mesa client. Check if mesa uses fences properly.

@zanfix
Copy link

zanfix commented Jun 3, 2025

I had a look at the PR, if i'm understanding correctly fences have been removed.
I tried adding the missing code back just to see what would happen.
glxgears outputs:

MESA: error: kgsl_pipe_get_param:103: invalid param id: 13
ATTENTION: default value of option mesa_glthread overridden by environment.
Running synchronized to the vertical refresh. The framerate should be
approximately the same as the monitor refresh rate.
X Error of failed request: BadRequest (invalid request code or no such operation)
Major opcode of failed request: 137 ()
Minor opcode of failed request: 5
Serial number of failed request: 42
Current serial number in output stream: 48

@robertkirkman
Copy link
Contributor Author

That is interesting, could you show what code you tried? I would like to try it also

@zanfix
Copy link

zanfix commented Jun 4, 2025

That is interesting, could you show what code you tried? I would like to try it also

I could be wrong... anyway have a look at the PR: there is some code about xshmfence that has been removed from the file /src/gallium/frontends/dri/loader_dri3_helper.c

glxinfo works, but it seems to me that glxgears crashes as soon as it outputs one frame

I may also have applied the code back and made a mistake while doing it...

@fish4terrisa-MSDSM
Copy link

I believe the removal of xshmfence related code is because of this:

https://github.com/termux/termux-x11/blob/2a1fac20f39467bebe9621e8371590f9cc67f2ed/app/src/main/cpp/lorie/xshmfence.c#L42-L46

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.

5 participants