Skip to content
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

[Bug]: Unable to use OpenGL ES backend with ANGLE #23042

Open
xNul opened this issue Jan 26, 2025 · 16 comments
Open

[Bug]: Unable to use OpenGL ES backend with ANGLE #23042

xNul opened this issue Jan 26, 2025 · 16 comments
Labels
bug report Something is not working properly

Comments

@xNul
Copy link

xNul commented Jan 26, 2025

Problem description

Running OpenGL applications with the OpenGL ES backend provided by angle-android causes an error even though it's supported by my GPU.

~ $ ~/vgl glmark2
using virgl angle=gl.
with OpenGL/ES config.
ERR: renderergl_utils.cpp:3065 (HandleError): GL call functions->texImage2D(nativegl::GetTextureBindingTarget(target), static_cast<GLint>(level), texImageFormat.internalFormat, size.width, size.height, 0, texImageFormat.format, texImageFormat.type, pixels) generated error 0x00000502 in ../../../cache/tmp-checkout/angle/src/libANGLE/renderer/gl/TextureGL.cpp, setImageHelper:276. 
ERR: renderergl_utils.cpp:3065 (HandleError): GL call functions->texImage2D(nativegl::GetTextureBindingTarget(target), static_cast<GLint>(level), texImageFormat.internalFormat, size.width, size.height, 0, texImageFormat.format, texImageFormat.type, pixels) generated error 0x00000502 in ../../../cache/tmp-checkout/angle/src/libANGLE/renderer/gl/TextureGL.cpp, setImageHelper:276. 
ERR: renderergl_utils.cpp:3065 (HandleError): GL call functions->texImage2D(nativegl::GetTextureBindingTarget(target), static_cast<GLint>(level), texImageFormat.internalFormat, size.width, size.height, 0, texImageFormat.format, texImageFormat.type, pixels) generated error 0x00000502 in ../../../cache/tmp-checkout/angle/src/libANGLE/renderer/gl/TextureGL.cpp, setImageHelper:276. 
ERR: renderergl_utils.cpp:3065 (HandleError): GL call functions->texImage2D(nativegl::GetTextureBindingTarget(target), static_cast<GLint>(level), texImageFormat.internalFormat, size.width, size.height, 0, texImageFormat.format, texImageFormat.type, pixels) generated error 0x00000502 in ../../../cache/tmp-checkout/angle/src/libANGLE/renderer/gl/TextureGL.cpp, setImageHelper:276. 
ERR: renderergl_utils.cpp:3065 (HandleError): GL call functions->texImage2D(nativegl::GetTextureBindingTarget(target), static_cast<GLint>(level), texImageFormat.internalFormat, size.width, size.height, 0, texImageFormat.format, texImageFormat.type, pixels) generated error 0x00000502 in ../../../cache/tmp-checkout/angle/src/libANGLE/renderer/gl/TextureGL.cpp, setImageHelper:276. 
ERR: renderergl_utils.cpp:3065 (HandleError): GL call functions->texImage2D(nativegl::GetTextureBindingTarget(target), static_cast<GLint>(level), texImageFormat.internalFormat, size.width, size.height, 0, texImageFormat.format, texImageFormat.type, pixels) generated error 0x00000502 in ../../../cache/tmp-checkout/angle/src/libANGLE/renderer/gl/TextureGL.cpp, setImageHelper:276. 
vtest_client_dispatch_commands: client context created.
vrend_winsys_make_context_current: Error switching context: EGL_BAD_ACCESS
../src/src/vrend_winsys.c:192: int vrend_winsys_make_context_current(virgl_renderer_gl_context): assertion "!ret && "Failed to switch GL context"" failed
lost connection to rendering server on 8 read -1 104
/data/data/com.termux/files/home/vgl: line 160: 29943 Aborted                 "$@"

What steps will reproduce the bug?

  1. Fresh install of latest Termux and Termux X11
  2. Install xfce4 via https://github.com/ar37-rs/xfce4-termux
  3. Install vgl tool via https://github.com/ar37-rs/virgl-angle-termux
  4. Execute these commands in the desktop environment: ~/vgl use-angle, ~/vgl angle=gl, and finally ~/vgl glmark2

What is the expected behavior?

glmark2 is able to run its benchmark without issue

System information

~ $ termux-info
Termux Variables:
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=16857
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.1
TERMUX__USER_ID=0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-main stable main
# x11-repo (sources.list.d/x11.list)
deb https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-x11 x11 main
# tur-repo (sources.list.d/tur.list)
deb https://tur.kcubeterm.com tur-packages tur tur-on-device tur-continuous
# glibc-repo (sources.list.d/glibc.list)
deb https://packages-cf.termux.dev/apt/termux-glibc/ glibc stable
Updatable packages:
All packages up to date
termux-tools version:
1.44.6
Android version:
15
Kernel build information:
Linux localhost 6.1.123-android14-11-ga50630ffbf7b #1 SMP PREEMPT Tue Jan  7 08:12:11 UTC 2025 aarch64 Android
Device manufacturer:
Google
Device model:
Pixel 9
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.x11 versionCode:15


GPU is Mali-G715
@xNul xNul added bug report Something is not working properly untriaged labels Jan 26, 2025
@xNul
Copy link
Author

xNul commented Jan 26, 2025

I've been doing some more research on this and running virgl_test_server_android --angle-gl does work to use the ANGLE OpenGL ES backend. So it seems like the angle-android library isn't up to date with the latest virgl_test_server binary or there is just a known fundamental incompatibility between angle-android and virgl_test_server that I'm missing which is resolved with virglrenderer-android.

@xNul
Copy link
Author

xNul commented Jan 27, 2025

Unsure if it's related but ~/vgl use-android (virgl_test_server_android) and then ~/vgl glmark2 fails with the below error

~ $ ~/vgla glmark2
using virgl android.
with OpenGL/ES config.
vtest_client_dispatch_commands: client context created.
** GLX does not support GLX_EXT_swap_control or GLX_MESA_swap_control!
** Failed to set swap interval. Results may be bounded above by refresh rate.
=======================================================
    glmark2 2023.01
=======================================================
    OpenGL Information
    GL_VENDOR:      Mesa
    GL_RENDERER:    virgl (Mali-G715)
    GL_VERSION:     4.1 (Compatibility Profile) Mesa 24.3.4
    Surface Config: buf=32 r=8 g=8 b=8 a=8 depth=32 stencil=0 samples=0
    Surface Size:   800x600 windowed
=======================================================
** GLX does not support GLX_EXT_swap_control or GLX_MESA_swap_control!
../src/src/gallium/auxiliary/cso_cache/cso_context.c:407: void cso_unbind_context(struct cso_context *): assertion "maxsam <= PIPE_MAX_SAMPLERS" failed
client: VTEST_CLIENT_DISCONNECTED
/data/data/com.termux/files/home/vgla: line 163: 23341 Aborted

but ~/vgl use-android and then ~/vgl chromium-browser runs the WebGL Aquarium test without issue.

@licy183
Copy link
Member

licy183 commented Jan 27, 2025

GL_VERSION: 4.1 (Compatibility Profile) Mesa 24.3.4

It seems that ~/vgl script overrides the GL version with env MESA_GL_VERSION_OVERRIDE. This will cause issues.

@licy183 licy183 removed the untriaged label Jan 27, 2025
@xNul
Copy link
Author

xNul commented Jan 27, 2025

@licy183 commenting that line out, doesn't fix the issue for me. I tried commenting the other overrides out as well and it errors out in every case

~ $ ~/vgla glmark2
using virgl android.
with OpenGL/ES config.
vtest_client_dispatch_commands: client context created.
** GLX does not support GLX_EXT_swap_control or GLX_MESA_swap_control!
** Failed to set swap interval. Results may be bounded above by refresh rate.
=======================================================
    glmark2 2023.01
=======================================================
    OpenGL Information
    GL_VENDOR:      Mesa
    GL_RENDERER:    virgl (Mali-G715)
    GL_VERSION:     2.1 Mesa 24.3.4
    Surface Config: buf=32 r=8 g=8 b=8 a=8 depth=32 stencil=0 samples=0
    Surface Size:   800x600 windowed
=======================================================
** GLX does not support GLX_EXT_swap_control or GLX_MESA_swap_control!
../src/src/gallium/auxiliary/cso_cache/cso_context.c:407: void cso_unbind_context(struct cso_context *): assertion "maxsam <= PIPE_MAX_SAMPLERS" failed
client: VTEST_CLIENT_DISCONNECTED
/data/data/com.termux/files/home/vgla: line 163:  5895 Aborted                 "$@"

@xNul
Copy link
Author

xNul commented Jan 27, 2025

Oh you were responding to my first post. Thank you, that does fix my issue. The OpenGL ES backend is working perfectly now. Any idea what is causing the second error?

@licy183
Copy link
Member

licy183 commented Jan 27, 2025

The vendored OpenGL driver shipped for Mali GPU doesn't work out of box with virgl_test_server_android. As Termux doesn't have control to system libs, angle-android is added to be a "compatibility layer" to reduce differences between drivers from different manufacturers. That's why angle-android is added.

@xNul
Copy link
Author

xNul commented Jan 27, 2025

Does it work for Adreno GPUs? If it does, could support theoretically be added for Mali GPUs to work out of the box with virgl_test_server_android similar to Adreno GPUs and it simply hasn't been done yet?

@licy183
Copy link
Member

licy183 commented Jan 27, 2025

It is theoretically possible, but issues about running virgl directly over Mali's OpenGL is much difficult to resolve.

  1. Running virgl over ANGLE is acceptable. Most of the GL libraries provided by manufacturers are not open source. If virgl is specialized for Mali, issues may occur on other GPUs. According to the test results on Adreno GPU, running virgl on ANGLE's OpenGL will only result in about 5% performance loss, which will not hurt the performance too much.
  2. Running virgl over Android's OpenGL is not supported by virglrenderer's developers. It is actually an abuse (?) of the virgl_test_server. It is much more difficult to find a solution to make virgl work on Mali GPUs without upstream support.

@xNul
Copy link
Author

xNul commented Jan 27, 2025

Great information, thank you. One last question. Is it possible to use WebGL with llvmpipe? I tried on both Firefox and Chrome, but both think there is no OpenGL support. The commands I used using the xfce4 script were ~/xfce4 driver=lvp and then the command to execute the application in the desktop environment.

@licy183
Copy link
Member

licy183 commented Jan 27, 2025

IIRC both chromium and firefox have support for llvmpipe for WebGL. Try access get.webgl.org and see if there is a spinning cube.

@xNul
Copy link
Author

xNul commented Jan 28, 2025

Chrome says "Your browser supports WebGL" but fails to show the cube and the WebGL Aquarium demo errors out. The console logs:

get.webgl.org
Image

WebGL Aquarium
Image

Firefox says "Your browser supports WebGL" and shows the cube spinning, but the WebGL Aquarium demo fails to run. The console logs:

WebGL Aquarium
Image

output from working get.webgl.org
Image

WebGL Aquarium works on both browsers when using ANGLE. Firefox with ~/vgl use-angle, ~/vgl angle=vulkan-null, and ~/vgl firefox. Chrome with ~/chrome via this script.

@xNul
Copy link
Author

xNul commented Feb 1, 2025

The vendored OpenGL driver shipped for Mali GPU doesn't work out of box with virgl_test_server_android. As Termux doesn't have control to system libs, angle-android is added to be a "compatibility layer" to reduce differences between drivers from different manufacturers. That's why angle-android is added.

@licy183 looking back over this, you say here the Mali GPU vendored driver doesn't work out of the box with virgl_test_server_android but launching ~/vgl chromium-browser does work. Is there some difference here?

Also, I realized I made a mistake and the initial fix actually does not work for me.

@xNul
Copy link
Author

xNul commented Feb 1, 2025

So to recap:

  1. Using the ANGLE OpenGL ES backend like so LD_LIBRARY_PATH=/data/data/com.termux/files/usr/opt/angle-android/gl virgl_test_server --use-egl-surfaceless --use-gles and GALLIUM_DRIVER=virpipe glmark2 causes this error
ERR: renderergl_utils.cpp:3065 (HandleError): GL call functions->texImage2D(nativegl::GetTextureBindingTarget(target), static_cast<GLint>(level), texImageFormat.internalFormat, size.width, size.height, 0, texImageFormat.format, texImageFormat.type, pixels) generated error 0x00000502 in ../../../cache/tmp-checkout/angle/src/libANGLE/renderer/gl/TextureGL.cpp, setImageHelper:276. 
ERR: renderergl_utils.cpp:3065 (HandleError): GL call functions->texImage2D(nativegl::GetTextureBindingTarget(target), static_cast<GLint>(level), texImageFormat.internalFormat, size.width, size.height, 0, texImageFormat.format, texImageFormat.type, pixels) generated error 0x00000502 in ../../../cache/tmp-checkout/angle/src/libANGLE/renderer/gl/TextureGL.cpp, setImageHelper:276. 
ERR: renderergl_utils.cpp:3065 (HandleError): GL call functions->texImage2D(nativegl::GetTextureBindingTarget(target), static_cast<GLint>(level), texImageFormat.internalFormat, size.width, size.height, 0, texImageFormat.format, texImageFormat.type, pixels) generated error 0x00000502 in ../../../cache/tmp-checkout/angle/src/libANGLE/renderer/gl/TextureGL.cpp, setImageHelper:276. 
ERR: renderergl_utils.cpp:3065 (HandleError): GL call functions->texImage2D(nativegl::GetTextureBindingTarget(target), static_cast<GLint>(level), texImageFormat.internalFormat, size.width, size.height, 0, texImageFormat.format, texImageFormat.type, pixels) generated error 0x00000502 in ../../../cache/tmp-checkout/angle/src/libANGLE/renderer/gl/TextureGL.cpp, setImageHelper:276. 
ERR: renderergl_utils.cpp:3065 (HandleError): GL call functions->texImage2D(nativegl::GetTextureBindingTarget(target), static_cast<GLint>(level), texImageFormat.internalFormat, size.width, size.height, 0, texImageFormat.format, texImageFormat.type, pixels) generated error 0x00000502 in ../../../cache/tmp-checkout/angle/src/libANGLE/renderer/gl/TextureGL.cpp, setImageHelper:276. 
ERR: renderergl_utils.cpp:3065 (HandleError): GL call functions->texImage2D(nativegl::GetTextureBindingTarget(target), static_cast<GLint>(level), texImageFormat.internalFormat, size.width, size.height, 0, texImageFormat.format, texImageFormat.type, pixels) generated error 0x00000502 in ../../../cache/tmp-checkout/angle/src/libANGLE/renderer/gl/TextureGL.cpp, setImageHelper:276. 
vtest_client_dispatch_commands: client context created.
vrend_winsys_make_context_current: Error switching context: EGL_BAD_ACCESS
../src/src/vrend_winsys.c:192: int vrend_winsys_make_context_current(virgl_renderer_gl_context): assertion "!ret && "Failed to switch GL context"" failed
  1. Using the Android vendored drivers like so virgl_test_server_android and GALLIUM_DRIVER=virpipe MESA_GL_VERSION_OVERRIDE=4.1COMPAT glmark2 causes this error but GALLIUM_DRIVER=virpipe MESA_GL_VERSION_OVERRIDE=4.1COMPAT chromium-browser works
** GLX does not support GLX_EXT_swap_control or GLX_MESA_swap_control!
** Failed to set swap interval. Results may be bounded above by refresh rate.
=======================================================
    glmark2 2023.01
=======================================================
    OpenGL Information
    GL_VENDOR:      Mesa
    GL_RENDERER:    virgl (Mali-G715)
    GL_VERSION:     4.1 (Compatibility Profile) Mesa 24.3.4
    Surface Config: buf=32 r=8 g=8 b=8 a=8 depth=32 stencil=0 samples=0
    Surface Size:   800x600 windowed
=======================================================
** GLX does not support GLX_EXT_swap_control or GLX_MESA_swap_control!
../src/src/gallium/auxiliary/cso_cache/cso_context.c:407: void cso_unbind_context(struct cso_context *): assertion "maxsam <= PIPE_MAX_SAMPLERS" failed
Aborted
  1. Using llvmpipe like so LIBGL_ALWAYS_SOFTWARE=1 glmark2 works but LIBGL_ALWAYS_SOFTWARE=1 chromium-browser and LIBGL_ALWAYS_SOFTWARE=1 firefox fail (with the errors in the screenshots above).

If I'm wrong about any of this, or this is the wrong place to open up an issue for any of these, please let me know.

@licy183
Copy link
Member

licy183 commented Feb 1, 2025

Is there some difference here?

I'm not sure what the script ~/vgl does.

  1. Using the ANGLE OpenGL ES backend like so LD_LIBRARY_PATH=/data/data/com.termux/files/usr/opt/angle-android/gl virgl_test_server

/data/data/com.termux/files/usr/bin/virgl_test_server should use the GL libs shipped for Termux, i.e. the GL libs in /data/data/com.termux/files/usr/lib. The GL libs in /data/data/com.termux/files/usr/opt/angle-android/gl is shipped for Android. So setting LD_LIBRARY_PATH will not use the ANGLE OpenGL ES backend.

  1. Using the Android vendored drivers like so virgl_test_server_android and GALLIUM_DRIVER=virpipe MESA_GL_VERSION_OVERRIDE=4.1COMPAT glmark2 causes this error but GALLIUM_DRIVER=virpipe MESA_GL_VERSION_OVERRIDE=4.1COMPAT chromium-browser works

It is answered by the comments about why angle-android is added above.

  1. Using llvmpipe like so LIBGL_ALWAYS_SOFTWARE=1 glmark2 works but LIBGL_ALWAYS_SOFTWARE=1 chromium-browser and LIBGL_ALWAYS_SOFTWARE=1 firefox fail (with the errors in the screenshots above).

I'm confirming why this happens.

@xNul
Copy link
Author

xNul commented Feb 2, 2025

I'm not sure what the script ~/vgl does.

It's a pretty small script located here. The equivalent minimal and reproducible code is included with 2.

For example,

This fails

virgl_test_server_android &
GALLIUM_DRIVER=virpipe MESA_GL_VERSION_OVERRIDE=4.1COMPAT glmark2

But this still works somehow

virgl_test_server_android &
GALLIUM_DRIVER=virpipe MESA_GL_VERSION_OVERRIDE=4.1COMPAT chromium-browser

Does Chromium somehow have a way to use vendored drivers that glmark2 can't? Maybe Chromium is actually using a non-vendored driver and that's why it works?

/data/data/com.termux/files/usr/bin/virgl_test_server should use the GL libs shipped for Termux, i.e. the GL libs in /data/data/com.termux/files/usr/lib. The GL libs in /data/data/com.termux/files/usr/opt/angle-android/gl is shipped for Android. So setting LD_LIBRARY_PATH will not use the ANGLE OpenGL ES backend.

Ah gotcha, so it was not intended to be used this way, even though it happens to work when LD_LIBRARY_PATH is set to ANGLE Vulkan (/data/data/com.termux/files/usr/opt/angle-android/vulkan) and Vulkan-null (/data/data/com.termux/files/usr/opt/angle-android/vulkan-null).

It is answered by the comments about why angle-android is added above.

If the problem is there is no vendored Mali GPU support, why does Chromium seem to work with vendored Mali GPU support? Is it using angle-android even though I tried to run it without ANGLE?

I'm confirming why this happens.

Sounds good, ty.

Appreciate the help.

@licy183
Copy link
Member

licy183 commented Feb 2, 2025

If the problem is there is no vendored Mali GPU support, why does Chromium seem to work with vendored Mali GPU support?

I personally think that the reason is the way Chromium calls OpenGL doesn't make Virgl over Mali's OpenGL fail. If Mali's OpenGL is used as virgl, it is recommended to pass --angle-gl.

Is it using angle-android even though I tried to run it without ANGLE?

No. It will use the system OpenGL (maybe over ANGLE bundled in chromium). If you're using chromium with GALLIUM_DRIVER=virpipe and virgl_test_server_android --angle-gl, the chain is (chromium-bundled ANGLE -> ) mesa (virpipe) -> virgl_test_server_android -> ANGLE's GL in angle-android -> GL in /system/lib64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Something is not working properly
Projects
None yet
Development

No branches or pull requests

2 participants