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

Use EGL surfaceless platform when windowing system is not found #2339

Merged
merged 10 commits into from
Feb 19, 2022
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 @@ -162,11 +163,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 @@ -617,8 +626,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");
dsseng marked this conversation as resolved.
Show resolved Hide resolved
let egl = egl
.upcast::<egl::EGL1_5>()
kvark marked this conversation as resolved.
Show resolved Hide resolved
.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 @@ -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
});
}

Expand Down