Monado OpenXR Runtime
d3d_d3d11_fence.hpp
Go to the documentation of this file.
1 // Copyright 2020-2022, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief D3D11-backed fence (timeline semaphore) creation routine.
6  * @author Rylie Pavlik <rylie.pavlik@collabora.com>
7  * @ingroup aux_d3d
8  */
9 
10 #pragma once
11 
12 #include "xrt/xrt_compositor.h"
13 
14 #include <Unknwn.h>
15 #include <d3d11_4.h>
16 #include <wil/com.h>
17 
18 #include <chrono>
19 
20 namespace xrt::auxiliary::d3d::d3d11 {
21 
22 /**
23  * Allocate a fence (ID3D11Fence) that has a corresponding native handle.
24  *
25  * D3D fences are roughly equivalent to Vulkan timeline semaphores.
26  *
27  * @param device A D3D device to allocate with.
28  * @param share_cross_adapter True if the fence should be shared across adapters, not only across ID3D11Device
29  * instances.
30  * @param[out] out_handle A graphics sync handle to populate
31  * @param[out] out_d3dfence A COM pointer to the D3D11 fence to populate
32  *
33  * @return xrt_result_t, one of:
34  * - @ref XRT_SUCCESS
35  * - @ref XRT_ERROR_ALLOCATION
36  * - @ref XRT_ERROR_D3D11
37  */
39 createSharedFence(ID3D11Device5 &device,
40  bool share_cross_adapter,
41  xrt_graphics_sync_handle_t *out_handle,
42  wil::com_ptr<ID3D11Fence> &out_d3dfence);
43 
44 /*!
45  * Wait for a fence to be signaled with value equal or greater than @p value within @p timeout_ns nanoseconds.
46  *
47  * @param fence The fence to wait on.
48  * @param event An event to use to wait. Please use a dedicated event for a single thread's calls to this function.
49  * @param value The desired fence value
50  * @param timeout_ms After this long, we may return early with @ref XRT_TIMEOUT even before the fence
51  * reaches the value.
52  */
54 waitOnFenceWithTimeout(wil::com_ptr<ID3D11Fence> fence,
55  wil::unique_event_nothrow &event,
56  uint64_t value,
57  std::chrono::milliseconds timeout_ms);
58 
59 }; // namespace xrt::auxiliary::d3d::d3d11
xrt_result_t createSharedFence(ID3D11Device5 &device, bool share_cross_adapter, xrt_graphics_sync_handle_t *out_handle, wil::com_ptr< ID3D11Fence > &out_d3dfence)
Allocate a fence (ID3D11Fence) that has a corresponding native handle.
Definition: d3d_d3d11_fence.cpp:52
xrt_result_t waitOnFenceWithTimeout(wil::com_ptr< ID3D11Fence > fence, wil::unique_event_nothrow &event, uint64_t value, std::chrono::milliseconds timeout_ms)
Wait for a fence to be signaled with value equal or greater than value within timeout_ns nanoseconds.
Definition: d3d_d3d11_fence.cpp:100
enum xrt_result xrt_result_t
Result type used across Monado.
A very simple implementation of a fence primitive.
Definition: comp_sync.c:36
Header declaring XRT graphics interfaces.
int xrt_graphics_sync_handle_t
The type underlying synchronization primitives (semaphores, etc) shared between compositor clients an...
Definition: xrt_handles.h:348