diff --git a/wgpu-hal/src/dx12/mod.rs b/wgpu-hal/src/dx12/mod.rs index 2739c1677c..1df4886028 100644 --- a/wgpu-hal/src/dx12/mod.rs +++ b/wgpu-hal/src/dx12/mod.rs @@ -670,6 +670,12 @@ pub struct Queue { temp_lists: Mutex>>, } +impl Queue { + pub fn as_raw(&self) -> &Direct3D12::ID3D12CommandQueue { + &self.raw + } +} + unsafe impl Send for Queue {} unsafe impl Sync for Queue {} diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index d97d67576b..f8b04591a7 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -362,6 +362,10 @@ impl Queue { timestamp_period, } } + + pub fn as_raw(&self) -> &Arc> { + &self.raw + } } pub struct Device { diff --git a/wgpu-hal/src/vulkan/mod.rs b/wgpu-hal/src/vulkan/mod.rs index 8c93c38332..ef349c7b26 100644 --- a/wgpu-hal/src/vulkan/mod.rs +++ b/wgpu-hal/src/vulkan/mod.rs @@ -773,6 +773,12 @@ pub struct Queue { signal_semaphores: Mutex<(Vec, Vec)>, } +impl Queue { + pub fn as_raw(&self) -> vk::Queue { + self.raw + } +} + impl Drop for Queue { fn drop(&mut self) { unsafe { self.relay_semaphores.lock().destroy(&self.device.raw) }; diff --git a/wgpu/src/api/queue.rs b/wgpu/src/api/queue.rs index 38546a1715..bb0621950e 100644 --- a/wgpu/src/api/queue.rs +++ b/wgpu/src/api/queue.rs @@ -260,4 +260,26 @@ impl Queue { pub fn on_submitted_work_done(&self, callback: impl FnOnce() + Send + 'static) { self.inner.on_submitted_work_done(Box::new(callback)); } + + /// Returns the inner hal Queue using a callback. The hal queue will be `None` if the + /// backend type argument does not match with this wgpu Queue + /// + /// # Safety + /// + /// - The raw handle obtained from the hal Queue must not be manually destroyed + #[cfg(wgpu_core)] + pub unsafe fn as_hal) -> R, R>( + &self, + hal_queue_callback: F, + ) -> R { + if let Some(core_queue) = self.inner.as_core_opt() { + unsafe { + core_queue + .context + .queue_as_hal::(core_queue, hal_queue_callback) + } + } else { + hal_queue_callback(None) + } + } } diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 1d1207da29..2a8925f47a 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -367,6 +367,14 @@ impl ContextWgpuCore { format!("Validation Error\n\nCaused by:\n{output}") } + + pub unsafe fn queue_as_hal) -> R, R>( + &self, + queue: &CoreQueue, + hal_queue_callback: F, + ) -> R { + unsafe { self.0.queue_as_hal::(queue.id, hal_queue_callback) } + } } fn map_buffer_copy_view(view: crate::TexelCopyBufferInfo<'_>) -> wgc::command::TexelCopyBufferInfo {