From b7151c6dbb9e6e4dadc12e84f5cbf5ddea6272e7 Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Fri, 31 Dec 2021 10:48:50 +0300 Subject: [PATCH 01/10] Use EGL surfaceless platform when windowing system is not found Falling back to egl::DEFAULT_DISPLAY usually results in X11 EGL platform being picked and then rejected because of unavailability on a head/GPU-less system. EGL_PLATFORM_SURFACELESS_MESA works with both radeonsi and llvmpipe/swrast when Xorg/Wayland sockets are being hidden from application. Needs to be tested in a truly GPU-less environment such as CI it is required to run in. Addresses #1551 Signed-off-by: Dmitry Sharshakov --- wgpu-hal/src/gles/egl.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index f1c7695355..6b3e1a8785 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -160,6 +160,7 @@ fn choose_config( ) -> Result<(egl::Config, bool), crate::InstanceError> { //TODO: EGL_SLOW_CONFIG let tiers = [ + ("surfaceless", &[egl::SURFACE_TYPE, egl::PBUFFER_BIT][..]), ( "off-screen", &[egl::RENDERABLE_TYPE, egl::OPENGL_ES2_BIT][..], @@ -618,8 +619,13 @@ impl crate::Instance for Instance { .unwrap(); (display, Some(Arc::new(library)), WindowKind::AngleX11) } else { - log::info!("Using default platform"); - let display = egl.get_display(egl::DEFAULT_DISPLAY).unwrap(); + log::info!("No windowing system present. Using surfaceless platform"); + let egl = egl + .upcast::() + .expect("Failed to get EGL 1.5 for surfaceless"); + let display = egl + .get_platform_display(0x31DD, std::ptr::null_mut(), &[egl::ATTRIB_NONE]) // EGL_PLATFORM_SURFACELESS_MESA + .unwrap(); (display, None, WindowKind::Unknown) }; From 3a57e854572ee65f76935ffea79cbc092501f96e Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Fri, 31 Dec 2021 10:59:40 +0300 Subject: [PATCH 02/10] Set backend for capture by environment variables Useful for testing surfaceless Signed-off-by: Dmitry Sharshakov --- red.png | Bin 0 -> 559 bytes wgpu/examples/capture/main.rs | 10 ++++++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 red.png diff --git a/red.png b/red.png new file mode 100644 index 0000000000000000000000000000000000000000..8a964b52f849aa3449f322b11f008150e05ae485 GIT binary patch literal 559 zcmeAS@N?(olHy`uVBq!ia0vp^DL{OJgAGW^*|;2JU|^i!>EaktG3U)iM?nSyjsphI z;=ee!$)CLHcz^!R6$UEDCP+9Z@pKxFGUyoyM;PWE0!C33C~l}_uNVWv|Nl%tQ~&>G aW^ium_c&IR{GklUXYh3Ob6Mw<&;$Stn71nc literal 0 HcmV?d00001 diff --git a/wgpu/examples/capture/main.rs b/wgpu/examples/capture/main.rs index 108f2d2360..83f6815bc2 100644 --- a/wgpu/examples/capture/main.rs +++ b/wgpu/examples/capture/main.rs @@ -28,10 +28,12 @@ async fn create_red_image_with_dimensions( width: usize, height: usize, ) -> (Device, Buffer, BufferDimensions) { - let adapter = wgpu::Instance::new(wgpu::Backends::all()) - .request_adapter(&wgpu::RequestAdapterOptions::default()) - .await - .unwrap(); + let adapter = wgpu::Instance::new( + wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all), + ) + .request_adapter(&wgpu::RequestAdapterOptions::default()) + .await + .unwrap(); let (device, queue) = adapter .request_device( From 30a2cb113fa260f83b41207ae314549b6bcd1512 Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Sat, 1 Jan 2022 09:04:17 +0300 Subject: [PATCH 03/10] Check for EGL_MESA_platform_surfaceless extension before using surfaceless platform Signed-off-by: Dmitry Sharshakov --- wgpu-hal/src/gles/egl.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index 6b3e1a8785..d664c4f456 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -15,6 +15,7 @@ const EGL_PLATFORM_X11_KHR: u32 = 0x31D5; const EGL_PLATFORM_ANGLE_ANGLE: u32 = 0x3202; const EGL_PLATFORM_ANGLE_NATIVE_PLATFORM_TYPE_ANGLE: u32 = 0x348F; const EGL_PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED: u32 = 0x3451; +const EGL_PLATFORM_SURFACELESS_MESA: u32 = 0x31DD; const EGL_GL_COLORSPACE_KHR: u32 = 0x309D; const EGL_GL_COLORSPACE_SRGB_KHR: u32 = 0x3089; @@ -618,15 +619,19 @@ impl crate::Instance for Instance { ) .unwrap(); (display, Some(Arc::new(library)), WindowKind::AngleX11) - } else { + } else if client_ext_str.contains("EGL_MESA_platform_surfaceless") { log::info!("No windowing system present. Using surfaceless platform"); let egl = egl .upcast::() .expect("Failed to get EGL 1.5 for surfaceless"); let display = egl - .get_platform_display(0x31DD, std::ptr::null_mut(), &[egl::ATTRIB_NONE]) // EGL_PLATFORM_SURFACELESS_MESA + .get_platform_display(EGL_PLATFORM_SURFACELESS_MESA, std::ptr::null_mut(), &[egl::ATTRIB_NONE]) .unwrap(); (display, None, WindowKind::Unknown) + } else { + log::info!("EGL_MESA_platform_surfaceless not available. Using default platform"); + let display = egl.get_display(egl::DEFAULT_DISPLAY).unwrap(); + (display, None, WindowKind::Unknown) }; if desc.flags.contains(crate::InstanceFlags::VALIDATION) From c107b8826b798bcc3af1dda45733d34351aa2a98 Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Sat, 1 Jan 2022 09:17:07 +0300 Subject: [PATCH 04/10] Format Signed-off-by: Dmitry Sharshakov --- wgpu-hal/src/gles/egl.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index d664c4f456..cabb83adb1 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -625,7 +625,11 @@ impl crate::Instance for Instance { .upcast::() .expect("Failed to get EGL 1.5 for surfaceless"); let display = egl - .get_platform_display(EGL_PLATFORM_SURFACELESS_MESA, std::ptr::null_mut(), &[egl::ATTRIB_NONE]) + .get_platform_display( + EGL_PLATFORM_SURFACELESS_MESA, + std::ptr::null_mut(), + &[egl::ATTRIB_NONE], + ) .unwrap(); (display, None, WindowKind::Unknown) } else { From 43f648f7e52010fa977478df6bef2b68cf04d93f Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Sat, 1 Jan 2022 09:29:55 +0300 Subject: [PATCH 05/10] Unify types for GLES config tiers Signed-off-by: Dmitry Sharshakov --- wgpu-hal/src/gles/egl.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index cabb83adb1..19e1b16b0a 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -161,11 +161,8 @@ fn choose_config( ) -> Result<(egl::Config, bool), crate::InstanceError> { //TODO: EGL_SLOW_CONFIG let tiers = [ - ("surfaceless", &[egl::SURFACE_TYPE, egl::PBUFFER_BIT][..]), - ( - "off-screen", - &[egl::RENDERABLE_TYPE, egl::OPENGL_ES2_BIT][..], - ), + ("surfaceless", &[egl::SURFACE_TYPE, egl::PBUFFER_BIT]), + ("off-screen", &[egl::RENDERABLE_TYPE, egl::OPENGL_ES2_BIT]), ("presentation", &[egl::SURFACE_TYPE, egl::WINDOW_BIT]), #[cfg(not(target_os = "android"))] ("native-render", &[egl::NATIVE_RENDERABLE, egl::TRUE as _]), From 4fe017c34d12c2d148df6d9ca63cd04529d54c86 Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Sat, 1 Jan 2022 09:34:32 +0300 Subject: [PATCH 06/10] Remove red.png Signed-off-by: Dmitry Sharshakov --- red.png | Bin 559 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 red.png diff --git a/red.png b/red.png deleted file mode 100644 index 8a964b52f849aa3449f322b11f008150e05ae485..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 559 zcmeAS@N?(olHy`uVBq!ia0vp^DL{OJgAGW^*|;2JU|^i!>EaktG3U)iM?nSyjsphI z;=ee!$)CLHcz^!R6$UEDCP+9Z@pKxFGUyoyM;PWE0!C33C~l}_uNVWv|Nl%tQ~&>G aW^ium_c&IR{GklUXYh3Ob6Mw<&;$Stn71nc From 5079e815ab4b302db4e453e43d892dd38dfea586 Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Mon, 3 Jan 2022 19:30:33 +0300 Subject: [PATCH 07/10] Enable GL backend for CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3179d8734..66a1daabce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: target: x86_64-unknown-linux-gnu tool: clippy kind: local - backends: vulkan # gl + backends: vulkan gl - name: Linux aarch64 os: ubuntu-20.04 From 0d41ec2f89f62449c6b8ffe7915452fc0a0ee328 Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Mon, 3 Jan 2022 20:16:41 +0300 Subject: [PATCH 08/10] Bump outliers count for skybox_etc2 due to llvmpipe test (102) --- wgpu/examples/skybox/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu/examples/skybox/main.rs b/wgpu/examples/skybox/main.rs index ac3ed8d565..2debcae171 100644 --- a/wgpu/examples/skybox/main.rs +++ b/wgpu/examples/skybox/main.rs @@ -499,7 +499,7 @@ fn skybox_etc2() { optional_features: wgpu::Features::TEXTURE_COMPRESSION_ETC2, base_test_parameters: framework::test_common::TestParameters::default(), tolerance: 5, - max_outliers: 100, // Bounded by llvmpipe + max_outliers: 105, // Bounded by llvmpipe }); } From 107302be6aa86d8dbd4e1e7f235aa826f37e840c Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Mon, 3 Jan 2022 22:20:30 +0300 Subject: [PATCH 09/10] Add SURFACE_TYPE PBUFFER_BIT requirement to off-screen surface tier --- wgpu-hal/src/gles/egl.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index 19e1b16b0a..03299cc75f 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -161,11 +161,21 @@ fn choose_config( ) -> Result<(egl::Config, bool), crate::InstanceError> { //TODO: EGL_SLOW_CONFIG let tiers = [ - ("surfaceless", &[egl::SURFACE_TYPE, egl::PBUFFER_BIT]), - ("off-screen", &[egl::RENDERABLE_TYPE, egl::OPENGL_ES2_BIT]), - ("presentation", &[egl::SURFACE_TYPE, egl::WINDOW_BIT]), + ( + "off-screen", + &[ + egl::SURFACE_TYPE, + egl::PBUFFER_BIT, + egl::RENDERABLE_TYPE, + egl::OPENGL_ES2_BIT, + ][..], + ), + ("presentation", &[egl::SURFACE_TYPE, egl::WINDOW_BIT][..]), #[cfg(not(target_os = "android"))] - ("native-render", &[egl::NATIVE_RENDERABLE, egl::TRUE as _]), + ( + "native-render", + &[egl::NATIVE_RENDERABLE, egl::TRUE as _][..], + ), ]; let mut attributes = Vec::with_capacity(9); From 1b1e273abf0e9ff90f0e9f3102b0c5cdc394f5ac Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Sat, 19 Feb 2022 00:08:32 -0500 Subject: [PATCH 10/10] Re-nix GL Backend on CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66a1daabce..f3179d8734 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: target: x86_64-unknown-linux-gnu tool: clippy kind: local - backends: vulkan gl + backends: vulkan # gl - name: Linux aarch64 os: ubuntu-20.04