Skip to content

Commit

Permalink
Make sure to unset current context in wgl Surface::configure/present (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Imberflur authored and cwfitzgerald committed Jan 21, 2024
1 parent c094e62 commit e1481b6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 17 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,36 @@ Bottom level categories:
- Hal
-->

## Unreleased

### New features

- Many numeric built-ins have had a constant evaluation implementation added for them, which allows them to be used in a `const` context:
- [#4879](https://github.com/gfx-rs/wgpu/pull/4879) by @ErichDonGubler:
- `abs`
- `acos`
- `acosh`
- `asin`
- `asinh`
- `atan`
- `atanh`
- `cos`
- `cosh`
- `round`
- `saturate`
- `sin`
- `sinh`
- `sqrt`
- `step`
- `tan`
- `tanh`

### Bug Fixes

#### 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).

## v0.19.0 (2024-01-17)

This release includes:
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,7 @@ impl Surface {
.map_err(|e| {
log::error!("swap_buffers failed: {}", e);
crate::SurfaceError::Lost
// TODO: should we unset the current context here?
})?;
self.egl
.instance
Expand Down
41 changes: 24 additions & 17 deletions wgpu-hal/src/gles/wgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ impl AdapterContext {

AdapterContextLock { inner }
}

/// Obtain a lock to the WGL context and get handle to the [`glow::Context`] that can be used to
/// do rendering.
///
/// Unlike [`lock`](Self::lock), this accepts a device to pass to `make_current` and exposes the error
/// when `make_current` fails.
#[track_caller]
fn lock_with_dc(&self, device: HDC) -> Result<AdapterContextLock<'_>, Error> {
let inner = self
.inner
.try_lock_for(Duration::from_secs(CONTEXT_LOCK_TIMEOUT_SECS))
.expect("Could not lock adapter context. This is most-likely a deadlock.");

inner
.context
.make_current(device)
.map(|()| AdapterContextLock { inner })
}
}

/// A guard containing a lock to an [`AdapterContext`]
Expand Down Expand Up @@ -603,16 +621,10 @@ impl Surface {
window: self.window,
};

let inner = context.inner.lock();

if let Err(e) = inner.context.make_current(dc.device) {
let gl = context.lock_with_dc(dc.device).map_err(|e| {
log::error!("unable to make the OpenGL context current for surface: {e}",);
return Err(crate::SurfaceError::Other(
"unable to make the OpenGL context current for surface",
));
}

let gl = &inner.gl;
crate::SurfaceError::Other("unable to make the OpenGL context current for surface")
})?;

unsafe { gl.bind_framebuffer(glow::DRAW_FRAMEBUFFER, None) };
unsafe { gl.bind_framebuffer(glow::READ_FRAMEBUFFER, Some(sc.framebuffer)) };
Expand Down Expand Up @@ -693,16 +705,11 @@ impl crate::Surface<super::Api> for Surface {
}

let format_desc = device.shared.describe_texture_format(config.format);
let inner = &device.shared.context.inner.lock();

if let Err(e) = inner.context.make_current(dc.device) {
let gl = &device.shared.context.lock_with_dc(dc.device).map_err(|e| {
log::error!("unable to make the OpenGL context current for surface: {e}",);
return Err(crate::SurfaceError::Other(
"unable to make the OpenGL context current for surface",
));
}
crate::SurfaceError::Other("unable to make the OpenGL context current for surface")
})?;

let gl = &inner.gl;
let renderbuffer = unsafe { gl.create_renderbuffer() }.map_err(|error| {
log::error!("Internal swapchain renderbuffer creation failed: {error}");
crate::DeviceError::OutOfMemory
Expand Down

0 comments on commit e1481b6

Please sign in to comment.