This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Failing to create shared contexts on Mali T760, T860, T830, T720 on Android

We're in the process of releasing a high performance GLES3 game on Android, it's currently in open beta here: https://play.google.com/store/apps/details?id=se.illusionlabs.touchgrindbmx2

It works great on many devices, including some Mali GPUs like Mali G72 in the Galaxy S9.

Unfortunately we are having problems getting it to work on many other devices that run Mali GPUs. I've mentioned a few of them in the topic, there probably are more.

What's happening is we are trying to create shared egl contexts that will be used to load some resources in background threads, but on devices running some Mali GPUs, the creation fails with the error EGL_BAD_CONTEXT, indicating there is something wrong with the share_context parameter.

The main egl context is created by the standard android GLSurfaceView, but the extra shared contexts are created in native code (most of our code is native C++).

The native code use eglGetCurrentContext to get the context created by java, and it at least gets something that is not GL_NO_CONTEXT.

We save the EGL_CONFIG_ID we use to create the main context, and pass it along to the native code, so we can create a matching context

EGLint configAttrs[] =
{
EGL_CONFIG_ID,
eglConfigID,
EGL_NONE
};

ilLogD("choosing config id %d", eglConfigID);

EGLConfig config;
GLint numConfig = 0;
eglChooseConfig(defaultDisplay, configAttrs, &config, 1, &numConfig);

EGLint contextAttrs[] =
{
EGL_CONTEXT_CLIENT_VERSION,
3,
EGL_NONE
};

EGLContext context = eglCreateContext(defaultDisplay, config, defaultContext, contextAttrs);

This works for most Android devices, but not on these.

According to EGL1.4 specifications (3.7.1) BAD_CONTEXT can happen "If share context is neither zero nor a valid
context of the same client API type as the newly created context."

But I don't see how this could happen, unless the value I receive from eglGetCurrentContext is garbage...

I definitely call eglGetCurrentContext in the same thread as GLSurfaceView is creating it's surface. In the live beta, eglCreateContext is called in a background thread, I've tried to move it to the same thread where I do eglGetCurrentContext, but I still get the same error.

In desperation, I've tried every available configuration, but all fail the same.

What is going on here? Is shareing not working at all on these GPUs, or what am I doing wrong?

I'm running out of ideas to try, and hope I can get some help here so we don't have to turn off support for these GPUs. (not using background loading threads is not really an option for our game)

  • Ok, we have solved this issue now. It turns out there was a mismatch in the "EGL_CONTEXT_CLIENT_VERSION" used when creating the main context on the java side and when trying to create our shared contexts.

    Possibly the drivers from other vendors always returned a GLES3 context, and that's why it was working on most hardware.