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

Prefer OpenGL over OpenGL ES #5482

Merged
merged 8 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ Bottom level categories:
- Device lost callbacks are invoked when replaced and when global is dropped. By @bradwerth in [#5168](https://github.com/gfx-rs/wgpu/pull/5168)
- Fix panic when creating a surface while no backend is available. By @wumpf [#5166](https://github.com/gfx-rs/wgpu/pull/5166)

#### WGL

- In Surface::configure and Surface::present, fix the current GL context not being unset when releasing the lock that guards access to making the context current. This was causing other threads to panic when trying to make the context current. By @Imberflur in [#5087](https://github.com/gfx-rs/wgpu/pull/5087).
#### OpenGL
- In WGL Surface::configure and Surface::present, fix the current GL context not being unset when releasing the lock that guards access to making the context current. This was causing other threads to panic when trying to make the context current. By @Imberflur in [#5087](https://github.com/gfx-rs/wgpu/pull/5087).
- OpenGL will now be preferred over OpenGL ES on EGL, making it consistent with WGL. By @valaphee in [#5482](https://github.com/gfx-rs/wgpu/pull/5482)

#### Naga
- Make use of `GL_EXT_texture_shadow_lod` to support sampling a cube depth texture with an explicit LOD. By @cmrschwarz in #[5171](https://github.com/gfx-rs/wgpu/pull/5171).
Expand Down
14 changes: 9 additions & 5 deletions tests/tests/clear_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,15 @@ static CLEAR_TEXTURE_UNCOMPRESSED: GpuTestConfiguration = GpuTestConfiguration::
.parameters(
TestParameters::default()
.expect_fail(
FailureCase::backend(wgpu::Backends::GL)
.panic("texture with format Rg8Snorm was not fully cleared")
.panic("texture with format Rgb9e5Ufloat was not fully cleared")
.validation_error("GL_INVALID_FRAMEBUFFER_OPERATION")
.validation_error("GL_INVALID_OPERATION"),
FailureCase {
backends: Some(wgpu::Backends::GL),
driver: Some("OpenGL ES"),
..FailureCase::default()
}
.panic("texture with format Rg8Snorm was not fully cleared")
.panic("texture with format Rgb9e5Ufloat was not fully cleared")
.validation_error("GL_INVALID_FRAMEBUFFER_OPERATION")
.validation_error("GL_INVALID_OPERATION"),
)
.features(wgpu::Features::CLEAR_TEXTURE),
)
Expand Down
28 changes: 24 additions & 4 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl super::Adapter {
}
}

fn make_info(vendor_orig: String, renderer_orig: String) -> wgt::AdapterInfo {
fn make_info(vendor_orig: String, renderer_orig: String, version: String) -> wgt::AdapterInfo {
let vendor = vendor_orig.to_lowercase();
let renderer = renderer_orig.to_lowercase();

Expand Down Expand Up @@ -178,13 +178,33 @@ impl super::Adapter {
0
};

let driver;
let driver_info;
if version.starts_with("WebGL ") || version.starts_with("OpenGL ") {
let es_sig = " ES";
match version.find(es_sig) {
Some(pos) => {
driver = version[..pos + es_sig.len()].to_owned();
driver_info = version[pos + es_sig.len() + 1..].to_owned();
}
None => {
let pos = version.find(' ').unwrap();
driver = version[..pos].to_owned();
driver_info = version[pos + 1..].to_owned();
}
}
} else {
driver = "OpenGL".to_owned();
driver_info = version;
}

wgt::AdapterInfo {
name: renderer_orig,
vendor: vendor_id,
device: 0,
device_type: inferred_device_type,
driver: String::new(),
driver_info: String::new(),
driver,
driver_info,
backend: wgt::Backend::Gl,
}
}
Expand Down Expand Up @@ -799,7 +819,7 @@ impl super::Adapter {
es: es_ver.is_some(),
}),
},
info: Self::make_info(vendor, renderer),
info: Self::make_info(vendor, renderer, version),
features,
capabilities: crate::Capabilities {
limits,
Expand Down
26 changes: 25 additions & 1 deletion wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,24 @@ impl Inner {
}

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

let supports_opengl = if version >= (1, 4) {
let client_apis = egl
.query_string(Some(display), khronos_egl::CLIENT_APIS)
.unwrap()
.to_string_lossy();
client_apis
.split(' ')
.any(|client_api| client_api == "OpenGL")
} else {
false
};
egl.bind_api(if supports_opengl {
khronos_egl::OPENGL_API
} else {
khronos_egl::OPENGL_ES_API
})
.unwrap();

let needs_robustness = true;
let mut khr_context_flags = 0;
Expand Down Expand Up @@ -938,6 +955,7 @@ impl crate::Instance<super::Api> for Instance {
srgb_kind: inner.srgb_kind,
})
}

unsafe fn destroy_surface(&self, _surface: Surface) {}

unsafe fn enumerate_adapters(&self) -> Vec<crate::ExposedAdapter<super::Api>> {
Expand All @@ -954,6 +972,12 @@ impl crate::Instance<super::Api> for Instance {
})
};

// In contract with OpenGL ES, OpenGL requires explicitly enabling sRGB conversions,
valaphee marked this conversation as resolved.
Show resolved Hide resolved
// as otherwise the user has to do the sRGB conversion.
if !matches!(inner.srgb_kind, SrgbFrameBufferKind::None) {
unsafe { gl.enable(glow::FRAMEBUFFER_SRGB) };
}
valaphee marked this conversation as resolved.
Show resolved Hide resolved

if self.flags.contains(wgt::InstanceFlags::DEBUG) && gl.supports_debug() {
log::debug!("Max label length: {}", unsafe {
gl.get_parameter_i32(glow::MAX_LABEL_LENGTH)
Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/gles/wgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ impl crate::Instance<super::Api> for Instance {
.supported_extensions()
.contains("GL_ARB_framebuffer_sRGB");

// In contract with OpenGL ES, OpenGL requires explicitly enabling sRGB conversions,
// as otherwise the user has to do the sRGB conversion.
if srgb_capable {
unsafe { gl.enable(glow::FRAMEBUFFER_SRGB) };
}
Expand Down