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

egl/display: ensure provider after version check #1690

Merged
merged 14 commits into from
Sep 10, 2024

Conversation

janKilika
Copy link
Contributor

@janKilika janKilika commented Aug 26, 2024

Issue addressed: EGL's Display::new making a Khr display (those are only valid for 1.5) when EGL version for the platform is actually 1.4, which causes errors when 1.5 surface creation is attempted afterwards. Caused by libglvnd "aliasing" eglGetPlatformDisplay and eglGetPlatformDisplayEXT (as in both functions call the same vendor function internally), which makes the former succeed and create a display that is only valid as an Ext display despite what otherwise would be expected according to specification.

Solution: Check for the version after performing an eglInitialize call, as it returns the actual version for the platform's implementation of EGL and therefore enables us to detect whether the aliasing issue occurred and downgrade the display from Khr to Ext if it did.

Changes: The only actual change is that it is checked in Display::initialize_display with the Display::sanitize_libglvnd_aliasing function whether (a) EglDisplay is of variant Khr and (b) version is equal to 1.4, and if both conditions are true, EglDisplay is downgraded from Khr to Ext. This seems to be safe, as eglGetPlatformDisplay and eglGetPlatformDisplayEXT in practice are made to be aliases of each other by libglvnd, and if any of the attributes passed are invalid for the underlying function, it is presumed that it would return with an error.

See issue #1689 for further details.
Also see issue #251 on libglvnd's repository.

See comments in `Display::sanitize_libglvnd_aliasing`.
Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

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

We can probably fit a more descriptive title than "aliasing issue" without going over any character limit.

glutin/src/api/egl/display.rs Outdated Show resolved Hide resolved
Copy link
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

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

Also need a changelog entry for this.

glutin/src/api/egl/display.rs Outdated Show resolved Hide resolved
Documented changes made by the PR.
@janKilika
Copy link
Contributor Author

Also need a changelog entry for this.

Done!

glutin/src/api/egl/display.rs Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@janKilika janKilika changed the title Patch the libglvnd aliasing issue for EGL. Implement a workaround for libglvnd aliasing eglGetPlatformDisplay and eglGetPlatformDisplayEXT and causing errors at surface creation due to use of KHR functions when the EGL version for the dispaly is 1.4. Sep 2, 2024
Rephrased from "fix" to "workaround".
@MarijnS95
Copy link
Member

https://registry.khronos.org/EGL/sdk/docs/man/html/eglQueryString.xhtml

It's unfortunate that we cannot use eglQueryString with NO_DISPLAY to "supposedly" (?) read the EGL version before calling eglInitialize(), until version 1.5? It's unclear to me if that version requirement applies to EGL_EXTENSIONS because that's the only query listed to support NO_DISPLAY - but it would mean our call is invalid on your given libglvnd too?

@MarijnS95
Copy link
Member

Reading somewhat further, we don't ever check if https://registry.khronos.org/EGL/extensions/EXT/EGL_EXT_client_extensions.txt works and following that, https://registry.khronos.org/EGL/extensions/EXT/EGL_EXT_platform_base.txt is available before calling eglGetPlatformDisplayEXT()?

@janKilika
Copy link
Contributor Author

https://registry.khronos.org/EGL/sdk/docs/man/html/eglQueryString.xhtml

It's unfortunate that we cannot use eglQueryString with NO_DISPLAY to "supposedly" (?) read the EGL version before calling eglInitialize(), until version 1.5? It's unclear to me if that version requirement applies to EGL_EXTENSIONS because that's the only query listed to support NO_DISPLAY - but it would mean our call is invalid on your given libglvnd too?

If by call you mean querying the client extensions, then, as far I can see, libglvnd provides querying for client extensions through eglQueryString (the function exists in libglvnd and specifically checks for NO_DISPLAY) in accord with both the 1.5 specification and EGL_EXT_client_extensions, so the call is technically valid.

… comments inside the sanitization function
@MarijnS95
Copy link
Member

Yes I mean us calling eglQueryString for NO_DISPLAY. According to https://registry.khronos.org/EGL/sdk/docs/man/html/eglQueryString.xhtml that's only supported from 1.5 onwards but EGL_EXT_client_extensions (which requires 1.4) specifies that it's possible as long you handle the NULL+BAD_DISPLAY case gracefully.

I was wondering if we could use something like that to detect and prevent the failure case from happening (by never calling eglGetPlatformDisplay()) but it seems like we have a chicken-egg problem here anyway by not knowing if we have a 1.5 display before calling functions that "rely on" knowing the version and/or extensions 😅


Also, reading back the PR description, can you reword it to provide a summary of both the problem and proposed solution, rather than linking through to an 18-comment-dense issue thread "for further details"?

CHANGELOG.md Outdated Show resolved Hide resolved
glutin/src/api/egl/display.rs Outdated Show resolved Hide resolved
@kchibisov
Copy link
Member

Could also link to upstream issue I've just opened.

janKilika and others added 3 commits September 2, 2024 15:29
Co-authored-by: Marijn Suijten <marijns95@gmail.com>
Co-authored-by: Marijn Suijten <marijns95@gmail.com>
…s in the comments for the sanitization function
@janKilika
Copy link
Contributor Author

Also, reading back the PR description, can you reword it to provide a summary of both the problem and proposed solution, rather than linking through to an 18-comment-dense issue thread "for further details"?

Sure, relevant information provided.

@MarijnS95
Copy link
Member

MarijnS95 commented Sep 2, 2024

Apologies in advance for being so messy @janKilika - it looks like we're in a situation where we're deciding whether and how the current workaround is sensible or could be written in a different way (while also reviewing the existing implementation) while I'm also suggesting light changes on the current workaround and comments (which could be superseded by the former) 😅

Copy link
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

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

Review based on upstream interactions.

glutin/src/api/egl/display.rs Outdated Show resolved Hide resolved
…comments in accord with the requested changes
Copy link
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

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

I hope that this is the last one.

CHANGELOG.md Outdated Show resolved Hide resolved
glutin/src/api/egl/display.rs Outdated Show resolved Hide resolved
glutin/src/api/egl/display.rs Outdated Show resolved Hide resolved
glutin/src/api/egl/display.rs Outdated Show resolved Hide resolved
@kchibisov kchibisov merged commit dae89a5 into rust-windowing:master Sep 10, 2024
43 checks passed
@MarijnS95 MarijnS95 changed the title Implement a workaround for libglvnd aliasing eglGetPlatformDisplay and eglGetPlatformDisplayEXT and causing errors at surface creation due to use of KHR functions when the EGL version for the dispaly is 1.4. egl/display: ensure provider after version check Sep 10, 2024
@MarijnS95 MarijnS95 changed the title egl/display: ensure provider after version check egl/display: ensure provider after version check Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants