Skip to content

GLES: fix context creation on Wayland #2076

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

Merged
merged 2 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ impl<A: HalApi> Adapter<A> {
}

let caps = &self.raw.capabilities;
if !caps.downlevel.is_webgpu_compliant() {
if wgt::Backends::PRIMARY.contains(wgt::Backends::from(A::VARIANT))
&& !caps.downlevel.is_webgpu_compliant()
{
let missing_flags = wgt::DownlevelFlags::compliant() - caps.downlevel.flags;
log::warn!(
"Missing downlevel flags: {:?}\n{}",
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,12 @@ impl super::Adapter {
let vertex = gl
.create_shader(glow::VERTEX_SHADER)
.expect("Could not create shader");
gl.shader_source(vertex, include_str!("./shader_clear.vert"));
gl.shader_source(vertex, include_str!("./shaders/clear.vert"));
gl.compile_shader(vertex);
let fragment = gl
.create_shader(glow::FRAGMENT_SHADER)
.expect("Could not create shader");
gl.shader_source(fragment, include_str!("./shader_clear.frag"));
gl.shader_source(fragment, include_str!("./shaders/clear.frag"));
gl.compile_shader(fragment);
gl.attach_shader(program, vertex);
gl.attach_shader(program, fragment);
Expand Down
58 changes: 34 additions & 24 deletions wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,21 @@ fn test_wayland_display() -> Option<libloading::Library> {
Some(library)
}

#[derive(Clone, Copy, Debug)]
enum SrgbFrameBufferKind {
/// No support for SRGB surface
None,
/// Using EGL 1.5's support for colorspaces
Core,
/// Using EGL_KHR_gl_colorspace
Khr,
}

/// Choose GLES framebuffer configuration.
fn choose_config(
egl: &egl::DynamicInstance<egl::EGL1_4>,
display: egl::Display,
srgb_kind: SrgbFrameBufferKind,
) -> Result<(egl::Config, bool), crate::InstanceError> {
//TODO: EGL_SLOW_CONFIG
let tiers = [
Expand All @@ -147,7 +158,7 @@ fn choose_config(
("native-render", &[egl::NATIVE_RENDERABLE, egl::TRUE as _]),
];

let mut attributes = Vec::with_capacity(7);
let mut attributes = Vec::with_capacity(9);
for tier_max in (0..tiers.len()).rev() {
let name = tiers[tier_max].0;
log::info!("\tTrying {}", name);
Expand All @@ -156,6 +167,14 @@ fn choose_config(
for &(_, tier_attr) in tiers[..=tier_max].iter() {
attributes.extend_from_slice(tier_attr);
}
// make sure the Alpha is enough to support sRGB
match srgb_kind {
SrgbFrameBufferKind::None => {}
_ => {
attributes.push(egl::ALPHA_SIZE);
attributes.push(8);
}
}
attributes.push(egl::NONE);

match egl.choose_first_config(display, &attributes) {
Expand Down Expand Up @@ -227,16 +246,6 @@ fn gl_debug_message_callback(source: u32, gltype: u32, id: u32, severity: u32, m
}
}

#[derive(Debug)]
enum SrgbFrameBufferKind {
/// No support for SRGB surface
None,
/// Using EGL 1.5's support for colorspaces
Core,
/// Using EGL_KHR_gl_colorspace
Khr,
}

/// A wrapper around a [`glow::Context`] and the required EGL context that uses locking to guarantee
/// exclusive access when shared with multiple threads.
pub struct AdapterContext {
Expand Down Expand Up @@ -356,22 +365,34 @@ impl Inner {
display_extensions.split_whitespace().collect::<Vec<_>>()
);

let srgb_kind = if version >= (1, 5) {
log::info!("\tEGL surface: +srgb");
SrgbFrameBufferKind::Core
} else if display_extensions.contains("EGL_KHR_gl_colorspace") {
log::info!("\tEGL surface: +srgb khr");
SrgbFrameBufferKind::Khr
} else {
log::warn!("\tEGL surface: -srgb");
SrgbFrameBufferKind::None
};

if log::max_level() >= log::LevelFilter::Trace {
log::trace!("Configurations:");
let config_count = egl.get_config_count(display).unwrap();
let mut configurations = Vec::with_capacity(config_count);
egl.get_configs(display, &mut configurations).unwrap();
for &config in configurations.iter() {
log::trace!("\tCONFORMANT=0x{:X}, RENDERABLE=0x{:X}, NATIVE_RENDERABLE=0x{:X}, SURFACE_TYPE=0x{:X}",
log::trace!("\tCONFORMANT=0x{:X}, RENDERABLE=0x{:X}, NATIVE_RENDERABLE=0x{:X}, SURFACE_TYPE=0x{:X}, ALPHA_SIZE={}",
egl.get_config_attrib(display, config, egl::CONFORMANT).unwrap(),
egl.get_config_attrib(display, config, egl::RENDERABLE_TYPE).unwrap(),
egl.get_config_attrib(display, config, egl::NATIVE_RENDERABLE).unwrap(),
egl.get_config_attrib(display, config, egl::SURFACE_TYPE).unwrap(),
egl.get_config_attrib(display, config, egl::ALPHA_SIZE).unwrap(),
);
}
}

let (config, supports_native_window) = choose_config(&egl, display)?;
let (config, supports_native_window) = choose_config(&egl, display, srgb_kind)?;
egl.bind_api(egl::OPENGL_ES_API).unwrap();

let needs_robustness = true;
Expand Down Expand Up @@ -439,17 +460,6 @@ impl Inner {
})?
};

let srgb_kind = if version >= (1, 5) {
log::info!("\tEGL surface: +srgb");
SrgbFrameBufferKind::Core
} else if display_extensions.contains("EGL_KHR_gl_colorspace") {
log::info!("\tEGL surface: +srgb khr");
SrgbFrameBufferKind::Khr
} else {
log::warn!("\tEGL surface: -srgb");
SrgbFrameBufferKind::None
};

Ok(Self {
egl,
display,
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/src/gles/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ impl Surface {
let vertex = gl
.create_shader(glow::VERTEX_SHADER)
.expect("Could not create shader");
gl.shader_source(vertex, include_str!("./web/present.vert"));
gl.shader_source(vertex, include_str!("./shaders/present.vert"));
gl.compile_shader(vertex);
let fragment = gl
.create_shader(glow::FRAGMENT_SHADER)
.expect("Could not create shader");
gl.shader_source(fragment, include_str!("./web/present.frag"));
gl.shader_source(fragment, include_str!("./shaders/present.frag"));
gl.compile_shader(fragment);
gl.attach_shader(program, vertex);
gl.attach_shader(program, fragment);
Expand Down