diff --git a/CHANGELOG.md b/CHANGELOG.md index d8f9e30845..86c182df29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -269,6 +269,9 @@ By @jimblandy in [#3254](https://github.com/gfx-rs/wgpu/pull/3254). - Add `MULTISAMPLE_X2`, `MULTISAMPLE_X4` and `MULTISAMPLE_X8` to `TextureFormatFeatureFlags`. By @39ali in [3140](https://github.com/gfx-rs/wgpu/pull/3140) - Sync `TextureFormat.describe` with the spec. By @teoxoy in [3312](https://github.com/gfx-rs/wgpu/pull/3312) +#### Metal +- Add a way to create `Device` and `Queue` from raw Metal resources in wgpu-hal. By @AdrianEddy in [#3338](https://github.com/gfx-rs/wgpu/pull/3338) + ### Bug Fixes #### General diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index 8ba2702ee4..59208d8245 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -219,6 +219,13 @@ impl super::Device { } } + pub unsafe fn device_from_raw(raw: mtl::Device, features: wgt::Features) -> super::Device { + super::Device { + shared: Arc::new(super::AdapterShared::new(raw)), + features, + } + } + pub fn raw_device(&self) -> &Mutex { &self.shared.device } diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index 37f101cff7..4c17252bb9 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -286,6 +286,13 @@ pub struct Queue { unsafe impl Send for Queue {} unsafe impl Sync for Queue {} +impl Queue { + pub unsafe fn queue_from_raw(raw: mtl::CommandQueue) -> Self { + Self { + raw: Arc::new(Mutex::new(raw)), + } + } +} pub struct Device { shared: Arc, features: wgt::Features,