Skip to content

Commit

Permalink
add as_hal for Queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Pabst committed Feb 19, 2025
1 parent b5e32ce commit 7948059
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ keywords = ["graphics"]
license = "MIT OR Apache-2.0"
homepage = "https://wgpu.rs/"
repository = "https://github.com/gfx-rs/wgpu"
version = "24.0.0"
version = "24.0.1"
authors = ["gfx-rs developers"]

[workspace.dependencies]
Expand Down
4 changes: 4 additions & 0 deletions wgpu-hal/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ impl Queue {
timestamp_period,
}
}

pub fn as_raw(&self) -> parking_lot::MutexGuard<'_, metal::CommandQueue> {
self.raw.lock()
}
}

pub struct Device {
Expand Down
22 changes: 22 additions & 0 deletions wgpu/src/api/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,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<A: wgc::hal_api::HalApi, F: FnOnce(Option<&A::Queue>) -> 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::<A, F, R>(core_queue, hal_queue_callback)
}
} else {
hal_queue_callback(None)
}
}
}
8 changes: 8 additions & 0 deletions wgpu/src/backend/wgpu_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ impl ContextWgpuCore {

format!("Validation Error\n\nCaused by:\n{output}")
}

pub unsafe fn queue_as_hal<A: wgc::hal_api::HalApi, F: FnOnce(Option<&A::Queue>) -> R, R>(
&self,
queue: &CoreQueue,
hal_queue_callback: F,
) -> R {
unsafe { self.0.queue_as_hal::<A, F, R>(queue.id, hal_queue_callback) }
}
}

fn map_buffer_copy_view(view: crate::TexelCopyBufferInfo<'_>) -> wgc::command::TexelCopyBufferInfo {
Expand Down

0 comments on commit 7948059

Please sign in to comment.