Skip to content
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
5 changes: 2 additions & 3 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ impl crate::Adapter for super::Adapter {
let queue = self
.shared
.device
.lock()
.new_command_queue_with_max_command_buffer_count(MAX_COMMAND_BUFFERS);

// Acquiring the meaning of timestamp ticks is hard with Metal!
Expand All @@ -72,7 +71,7 @@ impl crate::Adapter for super::Adapter {
// Based on:
// * https://github.com/gfx-rs/wgpu/pull/2528
// * https://github.com/gpuweb/gpuweb/issues/1325#issuecomment-761041326
let timestamp_period = if self.shared.device.lock().name().starts_with("Intel") {
let timestamp_period = if self.shared.device.name().starts_with("Intel") {
83.333
} else {
// Known for Apple Silicon (at least M1 & M2, iPad Pro 2018) and AMD GPUs.
Expand Down Expand Up @@ -121,7 +120,7 @@ impl crate::Adapter for super::Adapter {
Tfc::empty()
};
let is_not_apple1x = super::PrivateCapabilities::supports_any(
self.shared.device.lock().as_ref(),
self.shared.device.as_ref(),
&[
MTLFeatureSet::iOS_GPUFamily2_v1,
MTLFeatureSet::macOS_GPUFamily1_v1,
Expand Down
33 changes: 12 additions & 21 deletions wgpu-hal/src/metal/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use alloc::{borrow::ToOwned as _, sync::Arc, vec::Vec};
use core::{ptr::NonNull, sync::atomic};
use std::{thread, time};

use parking_lot::Mutex;

use super::{conv, PassthroughShader};
use crate::auxil::map_naga_stage;
use crate::metal::ShaderModuleSource;
Expand Down Expand Up @@ -215,7 +213,6 @@ impl super::Device {
let library = self
.shared
.device
.lock()
.new_library_with_source(source.as_ref(), &options)
.map_err(|err| {
log::warn!("Naga generated shader:\n{source}");
Expand Down Expand Up @@ -362,7 +359,7 @@ impl super::Device {
super::Buffer { raw, size }
}

pub fn raw_device(&self) -> &Mutex<metal::Device> {
pub fn raw_device(&self) -> &metal::Device {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an entry to CHANGELOG.md if we are going to merge this

&self.shared.device
}
}
Expand All @@ -386,7 +383,7 @@ impl crate::Device for super::Device {
//TODO: HazardTrackingModeUntracked

objc::rc::autoreleasepool(|| {
let raw = self.shared.device.lock().new_buffer(desc.size, options);
let raw = self.shared.device.new_buffer(desc.size, options);
if let Some(label) = desc.label {
raw.set_label(label);
}
Expand Down Expand Up @@ -460,7 +457,7 @@ impl crate::Device for super::Device {
descriptor.set_usage(conv::map_texture_usage(desc.format, desc.usage));
descriptor.set_storage_mode(MTLStorageMode::Private);

let raw = self.shared.device.lock().new_texture(&descriptor);
let raw = self.shared.device.new_texture(&descriptor);
if raw.as_ptr().is_null() {
return Err(crate::DeviceError::OutOfMemory);
}
Expand Down Expand Up @@ -612,7 +609,7 @@ impl crate::Device for super::Device {
if self.features.contains(wgt::Features::TEXTURE_BINDING_ARRAY) {
descriptor.set_support_argument_buffers(true);
}
let raw = self.shared.device.lock().new_sampler(&descriptor);
let raw = self.shared.device.new_sampler(&descriptor);

self.counters.samplers.add(1);

Expand Down Expand Up @@ -883,7 +880,7 @@ impl crate::Device for super::Device {
let uses = conv::map_resource_usage(&layout.ty);

// Create argument buffer for this array
let buffer = self.shared.device.lock().new_buffer(
let buffer = self.shared.device.new_buffer(
8 * count as u64,
MTLResourceOptions::HazardTrackingModeUntracked
| MTLResourceOptions::StorageModeShared,
Expand Down Expand Up @@ -1065,8 +1062,8 @@ impl crate::Device for super::Device {
num_workgroups,
} => {
let options = metal::CompileOptions::new();
// Obtain the locked device from shared
let device = self.shared.device.lock();
// Obtain the device from shared
let device = &self.shared.device;
let library = device
.new_library_with_source(source, &options)
.map_err(|e| crate::ShaderError::Compilation(format!("MSL: {e:?}")))?;
Expand Down Expand Up @@ -1263,11 +1260,7 @@ impl crate::Device for super::Device {
}

let ds_descriptor = create_depth_stencil_desc(ds);
let raw = self
.shared
.device
.lock()
.new_depth_stencil_state(&ds_descriptor);
let raw = self.shared.device.new_depth_stencil_state(&ds_descriptor);
Some((raw, ds.bias))
}
None => None,
Expand Down Expand Up @@ -1340,7 +1333,6 @@ impl crate::Device for super::Device {
let raw = self
.shared
.device
.lock()
.new_render_pipeline_state(&descriptor)
.map_err(|e| {
crate::PipelineError::Linkage(
Expand Down Expand Up @@ -1437,7 +1429,6 @@ impl crate::Device for super::Device {
let raw = self
.shared
.device
.lock()
.new_compute_pipeline_state(&descriptor)
.map_err(|e| {
crate::PipelineError::Linkage(
Expand Down Expand Up @@ -1480,7 +1471,7 @@ impl crate::Device for super::Device {
let size = desc.count as u64 * crate::QUERY_SIZE;
let options = MTLResourceOptions::empty();
//TODO: HazardTrackingModeUntracked
let raw_buffer = self.shared.device.lock().new_buffer(size, options);
let raw_buffer = self.shared.device.new_buffer(size, options);
if let Some(label) = desc.label {
raw_buffer.set_label(label);
}
Expand All @@ -1492,7 +1483,7 @@ impl crate::Device for super::Device {
}
wgt::QueryType::Timestamp => {
let size = desc.count as u64 * crate::QUERY_SIZE;
let device = self.shared.device.lock();
let device = &self.shared.device;
let destination_buffer = device.new_buffer(size, MTLResourceOptions::empty());

let csb_desc = metal::CounterSampleBufferDescriptor::new();
Expand Down Expand Up @@ -1544,7 +1535,7 @@ impl crate::Device for super::Device {
unsafe fn create_fence(&self) -> DeviceResult<super::Fence> {
self.counters.fences.add(1);
let shared_event = if self.shared.private_caps.supports_shared_event {
Some(self.shared.device.lock().new_shared_event())
Some(self.shared.device.new_shared_event())
} else {
None
};
Expand Down Expand Up @@ -1606,7 +1597,7 @@ impl crate::Device for super::Device {
if !self.shared.private_caps.supports_capture_manager {
return false;
}
let device = self.shared.device.lock();
let device = &self.shared.device;
let shared_capture_manager = metal::CaptureManager::shared();
let default_capture_scope = shared_capture_manager.new_capture_scope_with_device(&device);
shared_capture_manager.set_default_capture_scope(&default_capture_scope);
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl Default for Settings {
}

struct AdapterShared {
device: Mutex<metal::Device>,
device: metal::Device,
disabilities: PrivateDisabilities,
private_caps: PrivateCapabilities,
settings: Settings,
Expand All @@ -343,7 +343,7 @@ impl AdapterShared {
Self {
disabilities: PrivateDisabilities::new(&device),
private_caps,
device: Mutex::new(device),
device,
settings: Settings::default(),
presentation_timer: time::PresentationTimer::new(),
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/metal/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl crate::Surface for super::Surface {
_ => (),
}

let device_raw = device.shared.device.lock();
let device_raw = &device.shared.device;
render_layer.set_device(&device_raw);
render_layer.set_pixel_format(caps.map_format(config.format));
render_layer.set_framebuffer_only(framebuffer_only);
Expand Down
Loading