Skip to content

Commit

Permalink
Support Device fence sharing with dx12 on Windows (#4900)
Browse files Browse the repository at this point in the history
Co-authored-by: Sotaro Ikeda <you@example.com>
  • Loading branch information
sotaroikeda and Sotaro Ikeda authored Dec 20, 2023
1 parent 56d9d32 commit 1d6c7a0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
17 changes: 17 additions & 0 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,23 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
hal_device_callback(hal_device)
}

/// # Safety
///
/// - The raw fence handle must not be manually destroyed
pub unsafe fn device_fence_as_hal<A: HalApi, F: FnOnce(Option<&A::Fence>) -> R, R>(
&self,
id: DeviceId,
hal_fence_callback: F,
) -> R {
profiling::scope!("Device::fence_as_hal");

let hub = A::hub(self);
let device = hub.devices.try_get(id).ok().flatten();
let hal_fence = device.as_ref().map(|device| device.fence.read());

hal_fence_callback(hal_fence.as_deref().unwrap().as_ref())
}

/// # Safety
/// - The raw surface handle must not be manually destroyed
pub unsafe fn surface_as_hal<A: HalApi, F: FnOnce(Option<&A::Surface>) -> R, R>(
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/dx12/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@ impl crate::Device<super::Api> for super::Device {
let hr = unsafe {
self.raw.CreateFence(
0,
d3d12_ty::D3D12_FENCE_FLAG_NONE,
d3d12_ty::D3D12_FENCE_FLAG_SHARED,
&d3d12_ty::ID3D12Fence::uuidof(),
raw.mut_void(),
)
Expand Down
6 changes: 6 additions & 0 deletions wgpu-hal/src/dx12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,12 @@ pub struct Fence {
unsafe impl Send for Fence {}
unsafe impl Sync for Fence {}

impl Fence {
pub fn raw_fence(&self) -> &d3d12::Fence {
&self.raw
}
}

#[derive(Debug)]
pub struct BindGroupLayout {
/// Sorted list of entries.
Expand Down

0 comments on commit 1d6c7a0

Please sign in to comment.