Skip to content

Commit 1573efd

Browse files
committed
Use objc2-metal with metal naming scheme
To keep the diff smaller and easier to review, this uses a temporary fork of `objc2-metal` and `objc2-quartz-core` whose methods use the naming scheme of the `metal` crate. One particular difficult part with this is that the `metal` crate has several methods where the order of the arguments are swapped relative to the corresponding Objective-C methods. This includes most perilously (since these have both an offset and an index argument, both of which are integers): - `set_bytes` - `set_vertex_bytes` - `set_fragment_bytes` - `set_buffer` - `set_vertex_buffer` - `set_fragment_buffer` - `set_threadgroup_memory_length` But also: - `set_vertex_texture` - `set_fragment_texture` - `set_sampler_state` - `set_vertex_sampler_state` - `set_fragment_sampler_state`
1 parent f227ca1 commit 1573efd

File tree

12 files changed

+1220
-1044
lines changed

12 files changed

+1220
-1044
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ By @atlv24 in [#5383](https://github.com/gfx-rs/wgpu/pull/5383)
167167

168168
- Fix enablement of subgroup ops extension on Vulkan devices that don't support Vulkan 1.3. By @cwfitzgerald in [#5624](https://github.com/gfx-rs/wgpu/pull/5624).
169169

170+
#### Metal
171+
- 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).
172+
170173
#### GLES / OpenGL
171174

172175
- Fix regression on OpenGL (EGL) where non-sRGB still used sRGB [#5642](https://github.com/gfx-rs/wgpu/pull/5642)

Cargo.lock

Lines changed: 67 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ termcolor = "1.4.1"
192192
#web-sys = { path = "../wasm-bindgen/crates/web-sys" }
193193
#js-sys = { path = "../wasm-bindgen/crates/js-sys" }
194194
#wasm-bindgen = { path = "../wasm-bindgen" }
195+
block2 = { git = "https://github.com/madsmtm/objc2", branch = "metal-wgpu" }
196+
objc2 = { git = "https://github.com/madsmtm/objc2", branch = "metal-wgpu" }
197+
objc2-encode = { git = "https://github.com/madsmtm/objc2", branch = "metal-wgpu" }
198+
objc-sys = { git = "https://github.com/madsmtm/objc2", branch = "metal-wgpu" }
199+
objc2-foundation = { git = "https://github.com/madsmtm/objc2", branch = "metal-wgpu" }
200+
objc2-quartz-core = { git = "https://github.com/madsmtm/objc2", branch = "metal-wgpu" }
201+
objc2-metal = { git = "https://github.com/madsmtm/objc2", branch = "metal-wgpu" }
195202

196203
[profile.release]
197204
lto = "thin"

wgpu-hal/Cargo.toml

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ rust-version = "1.74"
1818
[package.metadata.docs.rs]
1919
# Ideally we would enable all the features.
2020
#
21-
# However, the metal features fail to be documented because the docs.rs runner cross-compiling under
22-
# x86_64-unknown-linux-gnu and metal-rs cannot compile in that environment at the moment. The same applies
23-
# for the dx12 feature.
24-
features = ["vulkan", "gles", "renderdoc"]
21+
# However, the dx12 features fail to be documented because the docs.rs runner cross-compiling under
22+
# x86_64-unknown-linux-gnu cannot compile in that environment at the moment.
23+
features = ["metal", "vulkan", "gles", "renderdoc"]
2524
rustdoc-args = ["--cfg", "docsrs"]
2625
targets = [
2726
"x86_64-unknown-linux-gnu",
@@ -37,7 +36,7 @@ ignored = ["cfg_aliases"]
3736
[lib]
3837

3938
[features]
40-
metal = ["naga/msl-out", "dep:block"]
39+
metal = ["naga/msl-out"]
4140
vulkan = [
4241
"naga/spv-out",
4342
"dep:ash",
@@ -156,11 +155,50 @@ d3d12 = { path = "../d3d12/", version = "0.20.0", optional = true, features = [
156155

157156
[target.'cfg(any(target_os="macos", target_os="ios"))'.dependencies]
158157
# backend: Metal
159-
block = { version = "0.1", optional = true }
160-
161-
metal = { version = "0.28.0" }
162-
objc = "0.2.5"
163-
core-graphics-types = "0.1"
158+
block2 = "0.5.1"
159+
objc2 = "0.5.2"
160+
objc2-foundation = { version = "0.2.2", features = [
161+
"NSError",
162+
"NSGeometry",
163+
"NSProcessInfo",
164+
"NSRange",
165+
"NSString",
166+
] }
167+
objc2-metal = { version = "0.2.2", features = [
168+
"block2",
169+
"MTLBlitCommandEncoder",
170+
"MTLBlitPass",
171+
"MTLBuffer",
172+
"MTLCaptureManager",
173+
"MTLCaptureScope",
174+
"MTLCommandBuffer",
175+
"MTLCommandEncoder",
176+
"MTLCommandQueue",
177+
"MTLComputeCommandEncoder",
178+
"MTLComputePass",
179+
"MTLComputePipeline",
180+
"MTLCounters",
181+
"MTLDepthStencil",
182+
"MTLDevice",
183+
"MTLDrawable",
184+
"MTLLibrary",
185+
"MTLPipeline",
186+
"MTLPixelFormat",
187+
"MTLRenderCommandEncoder",
188+
"MTLRenderPass",
189+
"MTLRenderPipeline",
190+
"MTLResource",
191+
"MTLSampler",
192+
"MTLStageInputOutputDescriptor",
193+
"MTLTexture",
194+
"MTLTypes",
195+
"MTLVertexDescriptor",
196+
] }
197+
objc2-quartz-core = { version = "0.2.2", features = [
198+
"CALayer",
199+
"CAMetalLayer",
200+
"objc2-metal",
201+
] }
164202

165203
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
166204
wasm-bindgen = "0.2.87"

wgpu-hal/src/gles/egl.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,10 +1259,11 @@ impl crate::Surface for Surface {
12591259
let window_ptr = handle.ns_view.as_ptr();
12601260
#[cfg(target_os = "macos")]
12611261
let window_ptr = {
1262-
use objc::{msg_send, runtime::Object, sel, sel_impl};
1262+
use objc2::msg_send;
1263+
use objc2::runtime::AnyObject;
12631264
// ns_view always have a layer and don't need to verify that it exists.
1264-
let layer: *mut Object =
1265-
msg_send![handle.ns_view.as_ptr() as *mut Object, layer];
1265+
let layer: *mut AnyObject =
1266+
msg_send![handle.ns_view.as_ptr() as *mut AnyObject, layer];
12661267
layer as *mut ffi::c_void
12671268
};
12681269
window_ptr

0 commit comments

Comments
 (0)