Add Metal SharedEvent to fence if it is supported (#6610)

Co-authored-by: Sotaro Ikeda <you@example.com>
Co-authored-by: Erich Gubler <erichdongubler@gmail.com>
This commit is contained in:
sotaroikeda 2024-11-27 04:25:07 +09:00 committed by GitHub
parent a9f14c7a90
commit 9ffafcf7b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 0 deletions

View File

@ -828,6 +828,7 @@ impl super::PrivateCapabilities {
&& ((device.supports_family(MTLGPUFamily::Apple8)
&& device.supports_family(MTLGPUFamily::Mac2))
|| device.supports_family(MTLGPUFamily::Apple9)),
supports_shared_event: version.at_least((10, 14), (12, 0), os_is_mac),
}
}

View File

@ -1326,9 +1326,15 @@ 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())
} else {
None
};
Ok(super::Fence {
completed_value: Arc::new(atomic::AtomicU64::new(0)),
pending_command_buffers: Vec::new(),
shared_event,
})
}

View File

@ -289,6 +289,7 @@ struct PrivateCapabilities {
supports_simd_scoped_operations: bool,
int64: bool,
int64_atomics: bool,
supports_shared_event: bool,
}
#[derive(Clone, Debug)]
@ -428,6 +429,10 @@ impl crate::Queue for Queue {
signal_fence
.pending_command_buffers
.push((signal_value, raw.to_owned()));
if let Some(shared_event) = signal_fence.shared_event.as_ref() {
raw.encode_signal_event(shared_event, signal_value);
}
// only return an extra one if it's extra
match command_buffers.last() {
Some(_) => None,
@ -818,6 +823,7 @@ pub struct Fence {
completed_value: Arc<atomic::AtomicU64>,
/// The pending fence values have to be ascending.
pending_command_buffers: Vec<(crate::FenceValue, metal::CommandBuffer)>,
shared_event: Option<metal::SharedEvent>,
}
impl crate::DynFence for Fence {}
@ -841,6 +847,10 @@ impl Fence {
self.pending_command_buffers
.retain(|&(value, _)| value > latest);
}
pub fn raw_shared_event(&self) -> Option<&metal::SharedEvent> {
self.shared_event.as_ref()
}
}
struct IndexState {