Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Device fence sharing with metal on macOS #6575

Closed
sotaroikeda opened this issue Nov 21, 2024 · 0 comments · Fixed by #6610
Closed

Support Device fence sharing with metal on macOS #6575

sotaroikeda opened this issue Nov 21, 2024 · 0 comments · Fixed by #6610
Assignees

Comments

@sotaroikeda
Copy link
Contributor

Is your feature request related to a problem? Please describe.

It is necessary to add a capability of sharing Device fence synchronization between gecko. See Bug 1910520.
Metal provides MTLSharedEvent to do it. MTLSharedEvent is supported on macOS 10.14+ and iOS 12.0+.

Similar capability is already added on Windows by #4872. It uses ID3D12Fence for synchronization.

Describe the solution you'd like

MTLSharedEvents can be got from the Device fence like

    let shared_event = unsafe {
        global.device_fence_as_hal::<wgc::api::Metal, _, Option<metal::SharedEvent>>(
            device_id,
            |hal_fence| hal_fence.map(|fence| fence.raw_shared_event().clone()),
        )
    };

MTLSharedEvent could be added to Fence like.

 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>,
 }

MTLSharedEvent could be created in Fence like

     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: shared_event,
         })
     }

Describe alternatives you've considered

Necessary api to wgpu-core is already added by #4872. Modifying wgpu-hal metal source could address the problem.

Additional context

Device fence sharing with metal on macOS in gecko is tracked in Bug 1910520.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant