gfx-rs/wgpu

Add a way to notify with `Queue::submit()` to `Vulkan's vk::Semaphore` allocated outside of `wgpu`

Opened this issue · 0 comments

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

Like #4872 and #6575, with Vulkan, it is necessary to add a capability of sharing semaphore synchronization between gecko(outside of wgpu). See Bug 1920763

Describe the solution you'd like

Add Global::queue_as_hal() like the following for accessing hal queue.

    pub unsafe fn queue_as_hal<A: HalApi, F: FnOnce(Option<&A::Queue>) -> R, R>(
        &self,
        id: QueueId,
        hal_queue_callback: F,
    ) -> R {
        profiling::scope!("Queue::as_hal");

        let queue = self.hub.queues.get(id);
        let hal_queue = queue.raw().as_any().downcast_ref();

        hal_queue_callback(hal_queue)
    }

And Queue::add_signal_semahore() adds signal semaphore, the semaphore is submitted by next Queue::submit().

impl Queue {
    pub fn add_signal_semahore(&self, semaphore: vk::Semaphore) {
        let mut signal_semaphores = self.signal_semaphores.lock();
        signal_semaphores.push(semaphore);
    }
}

Describe alternatives you've considered

Investigated to call Device::wait_for_submit() from a different thread. But it caused to block Device::wait_for_submit() calling thread several times for taking a lock.

Also investigated to use timeline semaphore in Fence.
Timeline fence seemed not work well with gl API GL_EXT_semaphore and GL_EXT_semaphore_fd.

It seems safer to use vk::Semaphore like chromium for signaling.

Additional context

Synchronization by using vk::Semaphore in gecko is tracked in Bug 1920763.