Skip to content

Commit

Permalink
Use EGL surfaceless platform when windowing system is not found (#2339)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Set backend for capture by environment variables

Useful for testing surfaceless

Signed-off-by: Dmitry Sharshakov <[email protected]>

* Check for EGL_MESA_platform_surfaceless extension before using surfaceless platform

Signed-off-by: Dmitry Sharshakov <[email protected]>

* Format

Signed-off-by: Dmitry Sharshakov <[email protected]>

* Unify types for GLES config tiers

Signed-off-by: Dmitry Sharshakov <[email protected]>

* Remove red.png

Signed-off-by: Dmitry Sharshakov <[email protected]>

* Enable GL backend for CI

* Bump outliers count for skybox_etc2 due to llvmpipe test (102)

* Add SURFACE_TYPE PBUFFER_BIT requirement to off-screen surface tier

* Re-nix GL Backend on CI

Co-authored-by: Connor Fitzgerald <[email protected]>
  • Loading branch information
dsseng and cwfitzgerald authored Feb 19, 2022
1 parent bfcdcd6 commit 70db03d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
30 changes: 26 additions & 4 deletions wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -168,11 +169,19 @@ fn choose_config(
let tiers = [
(
"off-screen",
&[egl::RENDERABLE_TYPE, egl::OPENGL_ES2_BIT][..],
&[
egl::SURFACE_TYPE,
egl::PBUFFER_BIT,
egl::RENDERABLE_TYPE,
egl::OPENGL_ES2_BIT,
][..],
),
("presentation", &[egl::SURFACE_TYPE, egl::WINDOW_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);
Expand Down Expand Up @@ -666,8 +675,21 @@ impl crate::Instance<super::Api> for Instance {
)
.unwrap();
(display, Some(Arc::new(library)), WindowKind::AngleX11)
} else if client_ext_str.contains("EGL_MESA_platform_surfaceless") {
log::info!("No windowing system present. Using surfaceless platform");
let egl = egl
.upcast::<egl::EGL1_5>()
.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],
)
.unwrap();
(display, None, WindowKind::Unknown)
} else {
log::info!("Using default platform");
log::info!("EGL_MESA_platform_surfaceless not available. Using default platform");
let display = egl.get_display(egl::DEFAULT_DISPLAY).unwrap();
(display, None, WindowKind::Unknown)
};
Expand Down
10 changes: 6 additions & 4 deletions wgpu/examples/capture/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/skybox/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,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
});
}

Expand Down

0 comments on commit 70db03d

Please sign in to comment.