mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
a/d3d: Add a fence waiting helper
This commit is contained in:
parent
3f777350e1
commit
903fd01272
|
@ -13,6 +13,7 @@
|
|||
#include "util/u_logging.h"
|
||||
#include "util/u_debug.h"
|
||||
#include "util/u_handles.h"
|
||||
#include "util/u_time.h"
|
||||
|
||||
#include "xrt/xrt_windows.h"
|
||||
|
||||
|
@ -24,6 +25,8 @@
|
|||
#include <inttypes.h>
|
||||
#include <memory>
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
|
||||
#define DEFAULT_CATCH(...) \
|
||||
catch (wil::ResultException const &e) \
|
||||
|
@ -93,4 +96,24 @@ try {
|
|||
}
|
||||
DEFAULT_CATCH(XRT_ERROR_ALLOCATION)
|
||||
|
||||
xrt_result_t
|
||||
waitOnFenceWithTimeout(wil::com_ptr<ID3D11Fence> fence,
|
||||
wil::unique_event_nothrow &event,
|
||||
uint64_t value,
|
||||
std::chrono::milliseconds timeout_ms)
|
||||
{
|
||||
DWORD dwTimeout = duration_cast<duration<DWORD, std::milli>>(timeout_ms).count();
|
||||
// Have to use this instead of ID3D11DeviceContext4::Wait because the latter has no timeout
|
||||
// parameter.
|
||||
fence->SetEventOnCompletion(value, event.get());
|
||||
if (value <= fence->GetCompletedValue()) {
|
||||
// oh we already reached this value.
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
if (event.wait(dwTimeout)) {
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
return XRT_TIMEOUT;
|
||||
}
|
||||
|
||||
} // namespace xrt::auxiliary::d3d
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <d3d11_4.h>
|
||||
#include <wil/com.h>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace xrt::auxiliary::d3d {
|
||||
|
||||
|
@ -40,4 +41,19 @@ createSharedFence(ID3D11Device5 &device,
|
|||
xrt_graphics_sync_handle_t *out_handle,
|
||||
wil::com_ptr<ID3D11Fence> &out_d3dfence);
|
||||
|
||||
/*!
|
||||
* Wait for a fence to be signaled with value equal or greater than @p value within @p timeout_ns nanoseconds.
|
||||
*
|
||||
* @param fence The fence to wait on.
|
||||
* @param event An event to use to wait. Please use a dedicated event for a single thread's calls to this function.
|
||||
* @param value The desired fence value
|
||||
* @param timeout_ms After this long, we may return early with @ref XRT_TIMEOUT even before the fence
|
||||
* reaches the value.
|
||||
*/
|
||||
xrt_result_t
|
||||
waitOnFenceWithTimeout(wil::com_ptr<ID3D11Fence> fence,
|
||||
wil::unique_event_nothrow &event,
|
||||
uint64_t value,
|
||||
std::chrono::milliseconds timeout_ms);
|
||||
|
||||
}; // namespace xrt::auxiliary::d3d
|
||||
|
|
Loading…
Reference in a new issue