allow creating wgpu::Instance from wgpu_core::Instance

This commit is contained in:
i509VCB authored and Jim Blandy committed 2022-06-26 15:32:34 -07:00
1 parent 533fc13afe
commit f041991d0c
3 files changed
+40 -4

No files matched your search

+12
View File
@@ -930,6 +930,18 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
hal_instance_callback(hal_instance)
}
/// # Safety
///
/// - The raw handles obtained from the Instance must not be manually destroyed
pub unsafe fn from_instance(factory: G, instance: Instance) -> Self {
profiling::scope!("new", "Global");
Self {
instance,
surfaces: Registry::without_backend(&factory, "Surface"),
hubs: Hubs::new(&factory),
}
}
pub fn clear_backend<A: HalApi>(&self, _dummy: ()) {
let mut surface_guard = self.surfaces.data.write();
let hub = A::hub(self);
+10 -2
View File
@@ -47,7 +47,7 @@ impl Context {
))
}
#[cfg(any(not(target_arch = "wasm32"), feature = "webgl2"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))]
pub unsafe fn instance_as_hal<A: wgc::hub::HalApi, F: FnOnce(Option<&A::Instance>) -> R, R>(
&self,
hal_instance_callback: F,
@@ -55,6 +55,14 @@ impl Context {
self.0.instance_as_hal::<A, F, R>(hal_instance_callback)
}
#[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))]
pub unsafe fn from_core_instance(core_instance: wgc::instance::Instance) -> Self {
Self(wgc::hub::Global::from_instance(
wgc::hub::IdentityManagerFactory,
core_instance,
))
}
pub(crate) fn global(&self) -> &wgc::hub::Global<wgc::hub::IdentityManagerFactory> {
&self.0
}
@@ -75,7 +83,7 @@ impl Context {
self.0.create_adapter_from_hal(hal_adapter, PhantomData)
}
#[cfg(any(not(target_arch = "wasm32"), feature = "webgl2"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))]
pub unsafe fn adapter_as_hal<A: wgc::hub::HalApi, F: FnOnce(Option<&A::Adapter>) -> R, R>(
&self,
adapter: wgc::id::AdapterId,
+18 -2
View File
@@ -1648,7 +1648,7 @@ impl Instance {
/// # Safety
///
/// - The raw handle obtained from the hal Instance must not be manually destroyed
#[cfg(any(not(target_arch = "wasm32"), feature = "webgl2"))]
#[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,
@@ -1657,6 +1657,22 @@ impl Instance {
.instance_as_hal::<A, F, R>(hal_instance_callback)
}
/// Create an new instance of wgpu from a wgpu-core instance.
///
/// # Arguments
///
/// - `core_instance` - wgpu-core instance.
///
/// # Safety
///
/// Refer to the creation of wgpu-core Instance.
#[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))]
pub unsafe fn from_core(core_instance: wgc::instance::Instance) -> Self {
Self {
context: Arc::new(C::from_core_instance(core_instance)),
}
}
/// Retrieves all available [`Adapter`]s that match the given [`Backends`].
///
/// # Arguments
@@ -1877,7 +1893,7 @@ impl Adapter {
/// # Safety
///
/// - The raw handle obtained from the hal Adapter must not be manually destroyed
#[cfg(any(not(target_arch = "wasm32"), feature = "webgl2"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))]
pub unsafe fn as_hal<A: wgc::hub::HalApi, F: FnOnce(Option<&A::Adapter>) -> R, R>(
&self,
hal_adapter_callback: F,