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] Use objc2-metal #5641

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ By @bradwerth [#6216](https://github.com/gfx-rs/wgpu/pull/6216).
- Vulkan debug labels assumed no interior nul byte. By @DJMcNab in [#6257](https://github.com/gfx-rs/wgpu/pull/6257)
- Add `.index_type(vk::IndexType::NONE_KHR)` when creating `AccelerationStructureGeometryTrianglesDataKHR` in the raytraced triangle example to prevent a validation error. By @Vecvec in [#6282](https://github.com/gfx-rs/wgpu/pull/6282)

#### Metal

- Use autogenerated `objc2` bindings internally, which should resolve a lot of leaks and unsoundness. By @madsmtm in [#5641](https://github.com/gfx-rs/wgpu/pull/5641).

### Changes

- `wgpu_hal::gles::Adapter::new_external` now requires the context to be current when dropping the adapter and related objects. By @Imberflur in [#6114](https://github.com/gfx-rs/wgpu/pull/6114).
Expand Down
128 changes: 73 additions & 55 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 45 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,51 @@ wgpu-types = { version = "22.0.0", path = "./wgpu-types" }
winit = { version = "0.29", features = ["android-native-activity"] }

# Metal dependencies
block = "0.1"
core-graphics-types = "0.1"
metal = { version = "0.29.0" }
objc = "0.2.5"
block2 = "0.5.1"
objc2 = "0.5.2"
objc2-foundation = { version = "0.2.2", features = [
"NSError",
"NSGeometry",
"NSProcessInfo",
"NSRange",
"NSString",
"NSThread",
] }
objc2-metal = { version = "0.2.2", features = [
"block2",
"MTLBlitCommandEncoder",
"MTLBlitPass",
"MTLBuffer",
"MTLCaptureManager",
"MTLCaptureScope",
"MTLCommandBuffer",
"MTLCommandEncoder",
"MTLCommandQueue",
"MTLComputeCommandEncoder",
"MTLComputePass",
"MTLComputePipeline",
"MTLCounters",
"MTLDepthStencil",
"MTLDevice",
"MTLDrawable",
"MTLLibrary",
"MTLPipeline",
"MTLPixelFormat",
"MTLRenderCommandEncoder",
"MTLRenderPass",
"MTLRenderPipeline",
"MTLResource",
"MTLSampler",
"MTLStageInputOutputDescriptor",
"MTLTexture",
"MTLTypes",
"MTLVertexDescriptor",
] }
objc2-quartz-core = { version = "0.2.2", features = [
"CALayer",
"CAMetalLayer",
"objc2-metal",
] }

# Vulkan dependencies
android_system_properties = "0.1.1"
Expand Down
18 changes: 8 additions & 10 deletions wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ rust-version = "1.76"
[package.metadata.docs.rs]
# Ideally we would enable all the features.
#
# However, the metal features fail to be documented because the docs.rs runner cross-compiling under
# x86_64-unknown-linux-gnu and metal-rs cannot compile in that environment at the moment. The same applies
# for the dx12 feature.
features = ["vulkan", "gles", "renderdoc"]
# However, the dx12 features fail to be documented because the docs.rs runner cross-compiling under
# x86_64-unknown-linux-gnu cannot compile in that environment at the moment.
features = ["metal", "vulkan", "gles", "renderdoc"]
rustdoc-args = ["--cfg", "docsrs"]
targets = [
"x86_64-unknown-linux-gnu",
Expand All @@ -43,7 +42,6 @@ ignored = ["cfg_aliases"]
metal = [
# Metal is only available on Apple platforms, therefore request MSL output also only if we target an Apple platform.
"naga/msl-out-if-target-apple",
"dep:block",
]
vulkan = [
"naga/spv-out",
Expand Down Expand Up @@ -166,11 +164,11 @@ glutin_wgl_sys = { workspace = true, optional = true }

[target.'cfg(any(target_os="macos", target_os="ios"))'.dependencies]
# backend: Metal
block = { workspace = true, optional = true }

metal.workspace = true
objc.workspace = true
core-graphics-types.workspace = true
block2.workspace = true
objc2.workspace = true
objc2-foundation.workspace = true
objc2-metal.workspace = true
objc2-quartz-core.workspace = true

[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
wasm-bindgen.workspace = true
Expand Down
7 changes: 4 additions & 3 deletions wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,10 +1313,11 @@ impl crate::Surface for Surface {
let window_ptr = handle.ns_view.as_ptr();
#[cfg(target_os = "macos")]
let window_ptr = {
use objc::{msg_send, runtime::Object, sel, sel_impl};
use objc2::msg_send;
use objc2::runtime::AnyObject;
// ns_view always have a layer and don't need to verify that it exists.
let layer: *mut Object =
msg_send![handle.ns_view.as_ptr().cast::<Object>(), layer];
let layer: *mut AnyObject =
msg_send![handle.ns_view.as_ptr().cast::<AnyObject>(), layer];
layer.cast::<ffi::c_void>()
};
window_ptr
Expand Down
Loading
Loading