Skip to content

Commit

Permalink
Use objc2-metal
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed May 19, 2024
1 parent 18b758e commit 6648295
Show file tree
Hide file tree
Showing 12 changed files with 1,144 additions and 1,004 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ By @atlv24 and @cwfitzgerald in [#5154](https://github.com/gfx-rs/wgpu/pull/5154
#### Metal

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

#### DX12

Expand Down
99 changes: 67 additions & 32 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ termcolor = "1.4.1"
#web-sys = { path = "../wasm-bindgen/crates/web-sys" }
#js-sys = { path = "../wasm-bindgen/crates/js-sys" }
#wasm-bindgen = { path = "../wasm-bindgen" }
block2 = { git = "https://github.com/madsmtm/objc2", branch = "metal-wgpu" }
objc2 = { git = "https://github.com/madsmtm/objc2", branch = "metal-wgpu" }
objc2-encode = { git = "https://github.com/madsmtm/objc2", branch = "metal-wgpu" }
objc-sys = { git = "https://github.com/madsmtm/objc2", branch = "metal-wgpu" }
objc2-foundation = { git = "https://github.com/madsmtm/objc2", branch = "metal-wgpu" }
objc2-quartz-core = { git = "https://github.com/madsmtm/objc2", branch = "metal-wgpu" }
objc2-metal = { git = "https://github.com/madsmtm/objc2", branch = "metal-wgpu" }

[profile.release]
lto = "thin"
Expand Down
16 changes: 8 additions & 8 deletions wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ignored = ["cfg_aliases"]

[features]
default = ["link"]
metal = ["naga/msl-out", "dep:block"]
metal = ["naga/msl-out"]
vulkan = [
"naga/spv-out",
"dep:ash",
Expand Down Expand Up @@ -76,7 +76,7 @@ windows_rs = ["dep:gpu-allocator"]
dxc_shader_compiler = ["dep:hassle-rs"]
renderdoc = ["dep:libloading", "dep:renderdoc-sys"]
fragile-send-sync-non-atomic-wasm = ["wgt/fragile-send-sync-non-atomic-wasm"]
link = ["metal/link"]
link = []
# Panic when running into an out-of-memory error (for debugging purposes).
#
# Only affects the d3d12 and vulkan backends.
Expand Down Expand Up @@ -156,13 +156,13 @@ d3d12 = { path = "../d3d12/", version = "0.20.0", optional = true, features = [
"libloading",
] }

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

metal = { version = "0.28.0" }
objc = "0.2.5"
core-graphics-types = "0.1"
[target.'cfg(any(target_os="macos", target_os="ios"))'.dependencies]
objc2 = "0.5.1"
objc2-foundation = { version = "0.2.0", features = ["all"] }
objc2-quartz-core = { version = "0.2.0", features = ["all"] }
objc2-metal = { version = "0.2.0", features = ["all"] }
block2 = "0.5"

[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
wasm-bindgen = "0.2.87"
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 @@ -1261,10 +1261,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() as *mut Object, layer];
let layer: *mut AnyObject =
msg_send![handle.ns_view.as_ptr() as *mut AnyObject, layer];
layer as *mut ffi::c_void
};
window_ptr
Expand Down
Loading

0 comments on commit 6648295

Please sign in to comment.