From 51418801e2293d62b0c63f1339f5e2feeced1278 Mon Sep 17 00:00:00 2001 From: quaternic <57393910+quaternic@users.noreply.github.com> Date: Mon, 1 Jul 2024 21:23:19 +0300 Subject: [PATCH 01/11] fix extension querying logic --- glutin/src/api/egl/device.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/glutin/src/api/egl/device.rs b/glutin/src/api/egl/device.rs index 498651dca7..43866afe09 100644 --- a/glutin/src/api/egl/device.rs +++ b/glutin/src/api/egl/device.rs @@ -41,9 +41,9 @@ impl Device { // // Or we can check for the EGL_EXT_device_base extension since it contains both // extensions. - if (!no_display_extensions.contains("EGL_EXT_device_enumeration") - && !no_display_extensions.contains("EGL_EXT_device_query")) - || !no_display_extensions.contains("EGL_EXT_device_base") + if !no_display_extensions.contains("EGL_EXT_device_base") + && ( !no_display_extensions.contains("EGL_EXT_device_enumeration") + || !no_display_extensions.contains("EGL_EXT_device_query")) { return Err(ErrorKind::NotSupported("EGL does not support EGL_EXT_device_base").into()); } From be25181e4d13c521d87b26cf0c17fdfa6430a085 Mon Sep 17 00:00:00 2001 From: quaternic <57393910+quaternic@users.noreply.github.com> Date: Mon, 1 Jul 2024 22:00:29 +0300 Subject: [PATCH 02/11] fmt --- glutin/src/api/egl/device.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glutin/src/api/egl/device.rs b/glutin/src/api/egl/device.rs index 43866afe09..aff0972c36 100644 --- a/glutin/src/api/egl/device.rs +++ b/glutin/src/api/egl/device.rs @@ -42,8 +42,8 @@ impl Device { // Or we can check for the EGL_EXT_device_base extension since it contains both // extensions. if !no_display_extensions.contains("EGL_EXT_device_base") - && ( !no_display_extensions.contains("EGL_EXT_device_enumeration") - || !no_display_extensions.contains("EGL_EXT_device_query")) + && (!no_display_extensions.contains("EGL_EXT_device_enumeration") + || !no_display_extensions.contains("EGL_EXT_device_query")) { return Err(ErrorKind::NotSupported("EGL does not support EGL_EXT_device_base").into()); } From af86cdd408b9fb55c7c9ed1436fe2202a1d07f2b Mon Sep 17 00:00:00 2001 From: quaternic <57393910+quaternic@users.noreply.github.com> Date: Wed, 3 Jul 2024 23:10:55 +0300 Subject: [PATCH 03/11] remove redundant check and clarify error message --- glutin/src/api/egl/device.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/glutin/src/api/egl/device.rs b/glutin/src/api/egl/device.rs index aff0972c36..b91407c3ae 100644 --- a/glutin/src/api/egl/device.rs +++ b/glutin/src/api/egl/device.rs @@ -33,7 +33,7 @@ impl Device { None => return Err(ErrorKind::NotFound.into()), }; - let no_display_extensions = + let client_extensions = CLIENT_EXTENSIONS.get_or_init(|| get_extensions(egl, egl::NO_DISPLAY)); // Querying devices requires EGL_EXT_device_enumeration and @@ -41,11 +41,13 @@ impl Device { // // Or we can check for the EGL_EXT_device_base extension since it contains both // extensions. - if !no_display_extensions.contains("EGL_EXT_device_base") - && (!no_display_extensions.contains("EGL_EXT_device_enumeration") - || !no_display_extensions.contains("EGL_EXT_device_query")) + if !client_extensions.contains("EGL_EXT_device_base") + && !client_extensions.contains("EGL_EXT_device_enumeration") { - return Err(ErrorKind::NotSupported("EGL does not support EGL_EXT_device_base").into()); + return Err(ErrorKind::NotSupported( + "enumerating devices is not supported by the EGL instance", + ) + .into()); } let mut device_count = 0; From 233ef610c921c8ffab25f41ba522e4598e49c578 Mon Sep 17 00:00:00 2001 From: quaternic <57393910+quaternic@users.noreply.github.com> Date: Thu, 4 Jul 2024 01:25:48 +0300 Subject: [PATCH 04/11] restructured conditionals with more specific error messages --- glutin/src/api/egl/device.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/glutin/src/api/egl/device.rs b/glutin/src/api/egl/device.rs index b91407c3ae..a684c5d38d 100644 --- a/glutin/src/api/egl/device.rs +++ b/glutin/src/api/egl/device.rs @@ -4,6 +4,7 @@ use std::collections::HashSet; use std::ffi::{c_void, CStr}; use std::ptr; +use bitflags::Flags; use glutin_egl_sys::egl; use glutin_egl_sys::egl::types::EGLDeviceEXT; @@ -36,18 +37,21 @@ impl Device { let client_extensions = CLIENT_EXTENSIONS.get_or_init(|| get_extensions(egl, egl::NO_DISPLAY)); - // Querying devices requires EGL_EXT_device_enumeration and - // EGL_EXT_device_query. + // Querying devices requires EGL_EXT_device_enumeration or EGL_EXT_device_base. // - // Or we can check for the EGL_EXT_device_base extension since it contains both - // extensions. - if !client_extensions.contains("EGL_EXT_device_base") - && !client_extensions.contains("EGL_EXT_device_enumeration") - { - return Err(ErrorKind::NotSupported( - "enumerating devices is not supported by the EGL instance", - ) - .into()); + // The former depends on EGL_EXT_device_query, so also check that for validation. + if !client_extensions.contains("EGL_EXT_device_base") { + let query = client_extensions.contains("EGL_EXT_device_query"); + let enumr = client_extensions.contains("EGL_EXT_device_enumeration"); + if !(query & enumr) { + let msg = if query { + "enumerating devices is not supported by the EGL instance" + } else { + // this should not happen as device_enumeration depends on device_query + "EGL_EXT_device_enumeration without EGL_EXT_device_query, buggy driver?" + }; + return Err(ErrorKind::NotSupported(msg).into()); + } } let mut device_count = 0; From c9cd3cc8facb559e2d77e1634db294b0c2d663d0 Mon Sep 17 00:00:00 2001 From: quaternic <57393910+quaternic@users.noreply.github.com> Date: Thu, 4 Jul 2024 01:29:38 +0300 Subject: [PATCH 05/11] undo accidental use --- glutin/src/api/egl/device.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/glutin/src/api/egl/device.rs b/glutin/src/api/egl/device.rs index a684c5d38d..6157d670ee 100644 --- a/glutin/src/api/egl/device.rs +++ b/glutin/src/api/egl/device.rs @@ -4,7 +4,6 @@ use std::collections::HashSet; use std::ffi::{c_void, CStr}; use std::ptr; -use bitflags::Flags; use glutin_egl_sys::egl; use glutin_egl_sys::egl::types::EGLDeviceEXT; From eadcd60a5fba6bc7da827f8c96ac4c1050e218ca Mon Sep 17 00:00:00 2001 From: quaternic <57393910+quaternic@users.noreply.github.com> Date: Thu, 4 Jul 2024 01:40:07 +0300 Subject: [PATCH 06/11] ... and fix the newly added logic bug --- glutin/src/api/egl/device.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glutin/src/api/egl/device.rs b/glutin/src/api/egl/device.rs index 6157d670ee..4e653f53fd 100644 --- a/glutin/src/api/egl/device.rs +++ b/glutin/src/api/egl/device.rs @@ -43,7 +43,7 @@ impl Device { let query = client_extensions.contains("EGL_EXT_device_query"); let enumr = client_extensions.contains("EGL_EXT_device_enumeration"); if !(query & enumr) { - let msg = if query { + let msg = if !enumr { "enumerating devices is not supported by the EGL instance" } else { // this should not happen as device_enumeration depends on device_query From d3b30f3d897ad0818980986829d43d84b56a30d9 Mon Sep 17 00:00:00 2001 From: quaternic <57393910+quaternic@users.noreply.github.com> Date: Thu, 4 Jul 2024 01:47:06 +0300 Subject: [PATCH 07/11] fmt --- glutin/src/api/egl/device.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glutin/src/api/egl/device.rs b/glutin/src/api/egl/device.rs index 4e653f53fd..15a8a7a22b 100644 --- a/glutin/src/api/egl/device.rs +++ b/glutin/src/api/egl/device.rs @@ -38,7 +38,7 @@ impl Device { // Querying devices requires EGL_EXT_device_enumeration or EGL_EXT_device_base. // - // The former depends on EGL_EXT_device_query, so also check that for validation. + // The former depends on EGL_EXT_device_query, so also check that just in case. if !client_extensions.contains("EGL_EXT_device_base") { let query = client_extensions.contains("EGL_EXT_device_query"); let enumr = client_extensions.contains("EGL_EXT_device_enumeration"); From f34d20868f52d8b768d97f4d4d675bd96c8c1c89 Mon Sep 17 00:00:00 2001 From: quaternic <57393910+quaternic@users.noreply.github.com> Date: Thu, 4 Jul 2024 01:58:59 +0300 Subject: [PATCH 08/11] changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18b0938cd6..62567a0a97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +- Fixed EGL's `Device::query_devices()` being too strict about required extensions + # Version 0.32.0 - **Breaking:** updated `raw-window-handle` dependency to `0.6`. From 7a86379b780b82c47be89971487ca4ff42100e3a Mon Sep 17 00:00:00 2001 From: quaternic <57393910+quaternic@users.noreply.github.com> Date: Thu, 4 Jul 2024 17:46:44 +0300 Subject: [PATCH 09/11] error message Co-authored-by: Marijn Suijten --- glutin/src/api/egl/device.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glutin/src/api/egl/device.rs b/glutin/src/api/egl/device.rs index 15a8a7a22b..cdcd77391a 100644 --- a/glutin/src/api/egl/device.rs +++ b/glutin/src/api/egl/device.rs @@ -44,7 +44,7 @@ impl Device { let enumr = client_extensions.contains("EGL_EXT_device_enumeration"); if !(query & enumr) { let msg = if !enumr { - "enumerating devices is not supported by the EGL instance" + "Enumerating devices is not supported by the EGL instance" } else { // this should not happen as device_enumeration depends on device_query "EGL_EXT_device_enumeration without EGL_EXT_device_query, buggy driver?" From 2d377662747f442c7831959147734921854c7c3d Mon Sep 17 00:00:00 2001 From: quaternic <57393910+quaternic@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:55:46 +0300 Subject: [PATCH 10/11] Apply suggestions from code review Co-authored-by: Kirill Chibisov --- glutin/src/api/egl/device.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glutin/src/api/egl/device.rs b/glutin/src/api/egl/device.rs index cdcd77391a..2d28d515b6 100644 --- a/glutin/src/api/egl/device.rs +++ b/glutin/src/api/egl/device.rs @@ -42,11 +42,11 @@ impl Device { if !client_extensions.contains("EGL_EXT_device_base") { let query = client_extensions.contains("EGL_EXT_device_query"); let enumr = client_extensions.contains("EGL_EXT_device_enumeration"); - if !(query & enumr) { + if !(query && enumr) { let msg = if !enumr { "Enumerating devices is not supported by the EGL instance" } else { - // this should not happen as device_enumeration depends on device_query + // This should not happen as device_enumeration depends on device_query. "EGL_EXT_device_enumeration without EGL_EXT_device_query, buggy driver?" }; return Err(ErrorKind::NotSupported(msg).into()); From 5f4874986ee7b119421e236faa8f943ebbcdb867 Mon Sep 17 00:00:00 2001 From: quaternic <57393910+quaternic@users.noreply.github.com> Date: Sun, 7 Jul 2024 22:14:12 +0300 Subject: [PATCH 11/11] reorganized --- glutin/src/api/egl/device.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/glutin/src/api/egl/device.rs b/glutin/src/api/egl/device.rs index 2d28d515b6..30b48baab8 100644 --- a/glutin/src/api/egl/device.rs +++ b/glutin/src/api/egl/device.rs @@ -37,19 +37,20 @@ impl Device { CLIENT_EXTENSIONS.get_or_init(|| get_extensions(egl, egl::NO_DISPLAY)); // Querying devices requires EGL_EXT_device_enumeration or EGL_EXT_device_base. - // - // The former depends on EGL_EXT_device_query, so also check that just in case. if !client_extensions.contains("EGL_EXT_device_base") { - let query = client_extensions.contains("EGL_EXT_device_query"); - let enumr = client_extensions.contains("EGL_EXT_device_enumeration"); - if !(query && enumr) { - let msg = if !enumr { - "Enumerating devices is not supported by the EGL instance" - } else { - // This should not happen as device_enumeration depends on device_query. - "EGL_EXT_device_enumeration without EGL_EXT_device_query, buggy driver?" - }; - return Err(ErrorKind::NotSupported(msg).into()); + if !client_extensions.contains("EGL_EXT_device_enumeration") { + return Err(ErrorKind::NotSupported( + "Enumerating devices is not supported by the EGL instance", + ) + .into()); + } + // EGL_EXT_device_enumeration depends on EGL_EXT_device_query, + // so also check that just in case. + if !client_extensions.contains("EGL_EXT_device_query") { + return Err(ErrorKind::NotSupported( + "EGL_EXT_device_enumeration without EGL_EXT_device_query, buggy driver?", + ) + .into()); } }