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

Check Opengl version is 3.3+ before creating a GL context over a GL ES context #5996

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

Rapdorian
Copy link
Contributor

@Rapdorian Rapdorian commented Jul 19, 2024

Connections
#5989

Description
Describe what problem this is solving, and how it's solved.
When creating a GL context wgpu prefers GL over GL ES if GL is available, regardless of version. If GL ES 3.1 is available and GL 3.3 is not (but an older GL is) wgpu is not able to create the GL ES context

If GL is supported I am creating a context of any version to check the GL version supported, if less than GL 3.3 we try to build a GL ES context instead of a GL context.

Testing
Explain how this change is tested.

Checklist

  • Run cargo fmt.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
    • --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.

@Rapdorian Rapdorian requested a review from a team as a code owner July 19, 2024 23:53
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

Beyond a few nits looking good!
Also, please add a changelog entry, this is definitely a change users want to be able to read up upon :)

Maybe @valaphee who did a lot of the non-es OpenGL support previously wants to have a look as well?

wgpu-hal/src/gles/egl.rs Outdated Show resolved Hide resolved
wgpu-hal/src/gles/egl.rs Outdated Show resolved Hide resolved
wgpu-hal/src/gles/egl.rs Outdated Show resolved Hide resolved
@Rapdorian Rapdorian force-pushed the jpruitt/gles_version_check branch from aa50156 to 901d326 Compare July 26, 2024 20:58
@valaphee
Copy link
Contributor

valaphee commented Aug 1, 2024

Personally I would handle the error rather than of preventing it. (would also remove unsafe and unwrap, and from_loader_function is quite heavy, as it gathers all function pointers)

e.g. https://github.com/gfx-rs/wgpu/blob/trunk/wgpu-hal/src/gles/egl.rs#L609 fails because of https://github.com/gfx-rs/wgpu/blob/trunk/wgpu-hal/src/gles/egl.rs#L554

and if it fails and OpenGL is used, then I would bind the OPENGL_ES_API and try again as this is the unlikely-path anyway.

@Rapdorian Rapdorian force-pushed the jpruitt/gles_version_check branch from 195ebfa to d432f3f Compare August 3, 2024 04:29
@Rapdorian
Copy link
Contributor Author

I've reworked the changes wrt @valaphee's recommendation.
The code now lets the GL context creation fails and then retrys with GLES.

@Rapdorian Rapdorian requested a review from Wumpf August 3, 2024 04:32
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

ah this makes sense. Thank you @valaphee for pointing this out and @Rapdorian for improving accordingly!
Style suggestion for readability (anything but 20 line match head plz 😄 ), otherwise I think we're good

wgpu-hal/src/gles/egl.rs Outdated Show resolved Hide resolved
@Rapdorian Rapdorian requested a review from Wumpf August 5, 2024 23:56
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

thanks again!

@Wumpf Wumpf enabled auto-merge (squash) August 6, 2024 08:10
@Wumpf Wumpf merged commit 594476c into gfx-rs:trunk Aug 6, 2024
25 checks passed
alokedesai pushed a commit to warpdotdev/wgpu that referenced this pull request Aug 20, 2024
…S context (gfx-rs#5996)

* Retry with GLES if creating a GL context fails

* Cleaner GL context creation retry
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.

3 participants