Skip to content

[hal][egl] Fix robust context creation failing on some devices #7952

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

FlorianDenis
Copy link
Contributor

@FlorianDenis FlorianDenis commented Jul 16, 2025

What

On certain devices, context creation would fail with the following log message:
Instance::new: failed to create Gl backend: InstanceError { message: "unable to create GLES 3.x context", source: Some(BadAttribute) }

This would surface up to the client as a RequestAdapterError::NotFound

Typically, this would happen predominantly on Motorola devices (Moto G54 5G and Moto G73 5G) but also on some Samsung devices (Galaxy S24+), under both Android 14 and 15.

Why

The root of the issue seem to be a misunderstanding of how robust context creation interplays with the EGL 1.5 specification.
The current code assumes that if the EGL version is >= 1.5, then robustness must be supported (except for ANGLE specifically which apparently was already identified as being problematic and so was hardcoded to go to Ext directly).

However, from the spec (section 3.7.1.5, emphasis mine)

If the EGL_CONTEXT_OPENGL_ROBUST_ACCESS attribute is set to EGL_TRUE, a
context supporting robust buffer access will be created. OpenGL contexts must
support the GL_ARB_robustness extension, or equivalent core API functional-
ity. OpenGL ES contexts must support the GL_EXT_robustness extension, or
equivalent core API functionality. [...] If the implementation does not support robust buffer access, context creation will fail.

How the fix works

Unfortunately this is a bit of a cat-and-mouse game: we need to check the context extensions to know if the robustness parameter will be supported, and we need the robustness parameter to create the context...

The proposed fix simply tries Core -> Ext -> No robustness, in this order, starting from which makes the most sense (aka. Core if we have EGL >= 1.5, and then Ext if the EGL extension is defined), only retrying if the returned error is the specified BAD_ATTRIBUTE.

Note: this eliminates the need for the hardcoded ANGLE IOP as it will fail with "Core" and go to "Ext", at which point it will supposedly succeed. In fact, the comment already had identified the correct underlying issue but simply built a specific IOP instead of a generic solution.

Note 2: in practice it seems that most devices I am encountering the issue with fail with "Core" and succeed with "Ext" (just as ANGLE, which is a strange behavior admittedly). One could possibly exchange the Ext then Core checks as it was done in a previous version of the code. It is not clear to me why the check was inverted in the linked commit, I'll let @kvark chime in. In any case, I believe this proposed solution is more robust (🥁)

Testing

Manually tested on some devices and rolled out to a subset of users for which the previous method was failing.

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@FlorianDenis FlorianDenis requested a review from a team as a code owner July 16, 2025 08:14
@@ -580,7 +580,6 @@ impl Inner {
})
.unwrap();

let needs_robustness = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This boolean perplexed me; Not mutable, unconditionaly set to true and then checked later on. I think this might be leftover debug code

@FlorianDenis FlorianDenis changed the title [egl] Fix robust context creation failing on some devices [hal][egl] Fix robust context creation failing on some devices Jul 16, 2025
@cwfitzgerald cwfitzgerald self-assigned this Jul 16, 2025
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.

2 participants