diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index a1a35b2f32..40fbf7f0fd 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -854,6 +854,23 @@ impl Global { hal_device_callback(hal_device) } + /// # Safety + /// + /// - The raw fence handle must not be manually destroyed + pub unsafe fn device_fence_as_hal) -> 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) -> R, R>( diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index daf14bf712..74cc09d6cd 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -1514,7 +1514,7 @@ impl crate::Device 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(), ) diff --git a/wgpu-hal/src/dx12/mod.rs b/wgpu-hal/src/dx12/mod.rs index 2d42d5faa1..e0cd1c15cf 100644 --- a/wgpu-hal/src/dx12/mod.rs +++ b/wgpu-hal/src/dx12/mod.rs @@ -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.