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

[Metal] Add a way to create a device and queue from raw resources in wgpu-hal #3338

Merged
merged 13 commits into from
Feb 1, 2023
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
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 {
cwfitzgerald marked this conversation as resolved.
Show resolved Hide resolved
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