Skip to content

Commit

Permalink
[Metal] Add a way to create a device and queue from raw resources in …
Browse files Browse the repository at this point in the history
…wgpu-hal (#3338)
  • Loading branch information
AdrianEddy authored Feb 1, 2023
1 parent 1e27fd4 commit 2562f32
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions wgpu-hal/src/metal/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<mtl::Device> {
&self.shared.device
}
Expand Down
7 changes: 7 additions & 0 deletions wgpu-hal/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AdapterShared>,
features: wgt::Features,
Expand Down

0 comments on commit 2562f32

Please sign in to comment.