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

Don't use a callback to return backend instance handles. #2991

Merged
merged 1 commit into from
Sep 3, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ the same every time it is rendered, we now warn if it is missing.
### Changes

#### General
- Changed `Instance::as_hal<A>` to just return an `Option<&A::Instance>` rather than taking a callback. By @jimb in [#2991](https://github.com/gfx-rs/wgpu/pull/2991)
- Added downlevel restriction error message for `InvalidFormatUsages` error by @Seamooo in [#2886](https://github.com/gfx-rs/wgpu/pull/2886)
- Add warning when using CompareFunction::*Equal with vertex shader that is missing @invariant tag by @cwfitzgerald in [#2887](https://github.com/gfx-rs/wgpu/pull/2887)
- Update Winit to version 0.27 and raw-window-handle to 0.5 by @wyatt-herkamp in [#2918](https://github.com/gfx-rs/wgpu/pull/2918)
Expand Down
10 changes: 3 additions & 7 deletions wgpu-core/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,13 +1135,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

/// # Safety
///
/// - The raw handle obtained from the hal Instance must not be manually destroyed
pub unsafe fn instance_as_hal<A: HalApi, F: FnOnce(Option<&A::Instance>) -> R, R>(
&self,
hal_instance_callback: F,
) -> R {
let hal_instance = A::instance_as_hal(&self.instance);
hal_instance_callback(hal_instance)
/// - The raw instance handle returned must not be manually destroyed.
pub unsafe fn instance_as_hal<A: HalApi>(&self) -> Option<&A::Instance> {
A::instance_as_hal(&self.instance)
}

/// # Safety
Expand Down
10 changes: 5 additions & 5 deletions wgpu/src/backend/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ impl Context {
))
}

pub unsafe fn instance_as_hal<A: wgc::hub::HalApi, F: FnOnce(Option<&A::Instance>) -> R, R>(
&self,
hal_instance_callback: F,
) -> R {
self.0.instance_as_hal::<A, F, R>(hal_instance_callback)
/// # Safety
///
/// - The raw instance handle returned must not be manually destroyed.
pub unsafe fn instance_as_hal<A: wgc::hub::HalApi>(&self) -> Option<&A::Instance> {
self.0.instance_as_hal::<A>()
}

pub unsafe fn from_core_instance(core_instance: wgc::instance::Instance) -> Self {
Expand Down
18 changes: 9 additions & 9 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1671,19 +1671,19 @@ impl Instance {
}
}

/// Returns the inner hal Instance using a callback. The hal instance will be `None` if the
/// backend type argument does not match with this wgpu Instance
/// Return a reference to a specific backend instance, if available.
///
/// If this `Instance` has a wgpu-hal [`Instance`] for backend
/// `A`, return a reference to it. Otherwise, return `None`.
///
/// # Safety
///
/// - The raw handle obtained from the hal Instance must not be manually destroyed
/// - The raw instance handle returned must not be manually destroyed.
///
/// [`Instance`]: hal::Api::Instance
#[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))]
pub unsafe fn as_hal<A: wgc::hub::HalApi, F: FnOnce(Option<&A::Instance>) -> R, R>(
&self,
hal_instance_callback: F,
) -> R {
self.context
.instance_as_hal::<A, F, R>(hal_instance_callback)
pub unsafe fn as_hal<A: wgc::hub::HalApi>(&self) -> Option<&A::Instance> {
self.context.instance_as_hal::<A>()
}

/// Create an new instance of wgpu from a wgpu-core instance.
Expand Down