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 dx12 on Windows #4900

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading