Skip to content

Commit 1ba60a7

Browse files
authored
Bump objc2 framework crates to 0.3.2 (#294)
`objc2` released a new set of framework crates with most functions marked as safe now, causing a lot of "unneeded `unsafe {}` block" warnings. By removing those we also have to affix the minimum crate versions to `0.3.2` otherwise things will no longer compile on older versions.
1 parent 3d4466e commit 1ba60a7

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ egui_extras = { version = ">=0.24, <=0.27", optional = true, default-features =
3535
hashbrown = { version = "0.16.0", optional = true }
3636

3737
[target.'cfg(target_vendor = "apple")'.dependencies]
38-
objc2 = { version = "0.6", default-features = false, optional = true }
39-
objc2-foundation = { version = "0.3", default-features = false, optional = true }
40-
objc2-metal = { version = "0.3", default-features = false, features = [
38+
objc2 = { version = "0.6.3", default-features = false, optional = true }
39+
objc2-foundation = { version = "0.3.2", default-features = false, optional = true }
40+
objc2-metal = { version = "0.3.2", default-features = false, features = [
4141
"MTLAccelerationStructure",
4242
"MTLAllocation",
4343
"MTLBuffer",
@@ -72,7 +72,7 @@ features = [
7272
]
7373

7474
[target.'cfg(target_vendor = "apple")'.dev-dependencies]
75-
objc2-metal = { version = "0.3", default-features = false, features = [
75+
objc2-metal = { version = "0.3.2", default-features = false, features = [
7676
"MTLPixelFormat",
7777
] }
7878

examples/metal-buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn main() {
9999

100100
// Test allocating texture
101101
{
102-
let texture_desc = unsafe { MTLTextureDescriptor::new() };
102+
let texture_desc = MTLTextureDescriptor::new();
103103
texture_desc.setPixelFormat(MTLPixelFormat::RGBA8Unorm);
104104
unsafe { texture_desc.setWidth(64) };
105105
unsafe { texture_desc.setHeight(64) };

src/metal/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl MemoryType {
261261
)?;
262262

263263
if let Some(rs) = &self.global_residency_set {
264-
unsafe { rs.addAllocation(mem_block.heap.as_ref()) }
264+
rs.addAllocation(mem_block.heap.as_ref())
265265
}
266266

267267
let block_index = self.memory_blocks.iter().position(|block| block.is_none());
@@ -343,7 +343,7 @@ impl MemoryType {
343343
)?;
344344

345345
if let Some(rs) = &self.global_residency_set {
346-
unsafe { rs.addAllocation(mem_block.heap.as_ref()) }
346+
rs.addAllocation(mem_block.heap.as_ref())
347347
}
348348

349349
let new_block_index = if let Some(block_index) = empty_block_index {
@@ -411,7 +411,7 @@ impl MemoryType {
411411
}
412412

413413
if let Some(rs) = &self.global_residency_set {
414-
unsafe { rs.removeAllocation(block.heap.as_ref()) }
414+
rs.removeAllocation(block.heap.as_ref())
415415
}
416416

417417
// Note that `block` will be destroyed on `drop` here
@@ -425,21 +425,21 @@ impl Allocator {
425425
pub fn new(desc: &AllocatorCreateDesc) -> Result<Self> {
426426
let heap_types = [
427427
(MemoryLocation::GpuOnly, {
428-
let heap_desc = unsafe { MTLHeapDescriptor::new() };
428+
let heap_desc = MTLHeapDescriptor::new();
429429
heap_desc.setCpuCacheMode(MTLCPUCacheMode::DefaultCache);
430430
heap_desc.setStorageMode(MTLStorageMode::Private);
431431
heap_desc.setType(MTLHeapType::Placement);
432432
heap_desc
433433
}),
434434
(MemoryLocation::CpuToGpu, {
435-
let heap_desc = unsafe { MTLHeapDescriptor::new() };
435+
let heap_desc = MTLHeapDescriptor::new();
436436
heap_desc.setCpuCacheMode(MTLCPUCacheMode::WriteCombined);
437437
heap_desc.setStorageMode(MTLStorageMode::Shared);
438438
heap_desc.setType(MTLHeapType::Placement);
439439
heap_desc
440440
}),
441441
(MemoryLocation::GpuToCpu, {
442-
let heap_desc = unsafe { MTLHeapDescriptor::new() };
442+
let heap_desc = MTLHeapDescriptor::new();
443443
heap_desc.setCpuCacheMode(MTLCPUCacheMode::DefaultCache);
444444
heap_desc.setStorageMode(MTLStorageMode::Shared);
445445
heap_desc.setType(MTLHeapType::Placement);
@@ -448,13 +448,13 @@ impl Allocator {
448448
];
449449

450450
let global_residency_set = if desc.create_residency_set {
451-
Some(unsafe {
452-
let rs_desc = objc2_metal::MTLResidencySetDescriptor::new();
453-
rs_desc.setLabel(Some(ns_string!("gpu-allocator global residency set")));
451+
let rs_desc = objc2_metal::MTLResidencySetDescriptor::new();
452+
rs_desc.setLabel(Some(ns_string!("gpu-allocator global residency set")));
453+
Some(
454454
desc.device
455455
.newResidencySetWithDescriptor_error(&rs_desc)
456-
.expect("Failed to create MTLResidencySet. Unsupported MacOS/iOS version?")
457-
})
456+
.expect("Failed to create MTLResidencySet. Unsupported MacOS/iOS version?"),
457+
)
458458
} else {
459459
None
460460
};

0 commit comments

Comments
 (0)