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

Draft
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Draft
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 @@ -79,6 +79,9 @@ By @brodycj in [#6925](https://github.com/gfx-rs/wgpu/pull/6925).
- Fix `wgpu` not building with `--no-default-features` on when targeting `wasm32-unknown-unknown`. By @wumpf in [#6946](https://github.com/gfx-rs/wgpu/pull/6946).
- Fix `CopyExternalImageDestInfo` not exported on `wgpu`. By @wumpf in [#6962](https://github.com/gfx-rs/wgpu/pull/6962).

#### 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).

#### Vulkan

- Stop naga causing undefined behavior when a ray query misses. By @Vecvec in [#6752](https://github.com/gfx-rs/wgpu/pull/6752).
Expand Down
130 changes: 81 additions & 49 deletions Cargo.lock

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

59 changes: 54 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,59 @@ thiserror = "2"
winit = { version = "0.29", features = ["android-native-activity"] }

# Metal dependencies
metal = "0.31.0"
block = "0.1"
core-graphics-types = "0.1"
objc = "0.2.5"
block2 = "0.6"
objc2 = "0.6"
objc2-core-foundation = { version = "0.3", default-features = false, features = [
"std",
"CFCGTypes",
] }
objc2-foundation = { version = "0.3", default-features = false, features = [
"std",
"NSError",
"NSProcessInfo",
"NSRange",
"NSString",
] }
objc2-metal = { version = "0.3", default-features = false, features = [
"std",
"block2",
"MTLAllocation",
"MTLBlitCommandEncoder",
"MTLBlitPass",
"MTLBuffer",
"MTLCaptureManager",
"MTLCaptureScope",
"MTLCommandBuffer",
"MTLCommandEncoder",
"MTLCommandQueue",
"MTLComputeCommandEncoder",
"MTLComputePass",
"MTLComputePipeline",
"MTLCounters",
"MTLDepthStencil",
"MTLDevice",
"MTLDrawable",
"MTLEvent",
"MTLLibrary",
"MTLPipeline",
"MTLPixelFormat",
"MTLRenderCommandEncoder",
"MTLRenderPass",
"MTLRenderPipeline",
"MTLResource",
"MTLSampler",
"MTLStageInputOutputDescriptor",
"MTLTexture",
"MTLTypes",
"MTLVertexDescriptor",
] }
objc2-quartz-core = { version = "0.3", default-features = false, features = [
"std",
"objc2-core-foundation",
"CALayer",
"CAMetalLayer",
"objc2-metal",
] }

# Vulkan dependencies
android_system_properties = "0.1.1"
Expand Down Expand Up @@ -190,7 +239,7 @@ termcolor = "1.4.1"
# android dependencies
ndk-sys = "0.5.0"

# These overrides allow our examples to explicitly depend on release crates
# These overrides allow our examples to explicitly depend on release crates
[patch.crates-io]
wgpu = { path = "./wgpu" }

Expand Down
18 changes: 9 additions & 9 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 @@ -46,7 +45,6 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(web_sys_unstable_apis)'] }
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 @@ -197,10 +195,12 @@ mach-dxcompiler-rs = { workspace = true, optional = true }

[target.'cfg(target_vendor = "apple")'.dependencies]
# Backend: Metal
block = { workspace = true, optional = true }
core-graphics-types.workspace = true
metal.workspace = true
objc.workspace = true
block2.workspace = true
objc2.workspace = true
objc2-core-foundation.workspace = true
objc2-foundation.workspace = true
objc2-metal.workspace = true
objc2-quartz-core.workspace = true

#########################
### Platform: Android ###
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 @@ -1326,10 +1326,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