Support Device fence sharing with dx12 on Windows (#4900)

Co-authored-by: Sotaro Ikeda <you@example.com>
This commit is contained in:
sotaroikeda
2023-12-21 03:33:47 +09:00
committed by GitHub
parent 56d9d32a07
commit 1d6c7a0263
3 changed files with 24 additions and 1 deletions

View File

@@ -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>(

View File

@@ -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(),
)

View File

@@ -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.