diff --git a/src/gallium/drivers/d3d12/d3d12_fence.cpp b/src/gallium/drivers/d3d12/d3d12_fence.cpp index e3b39dd584f..b00d2ffae6c 100644 --- a/src/gallium/drivers/d3d12/d3d12_fence.cpp +++ b/src/gallium/drivers/d3d12/d3d12_fence.cpp @@ -28,6 +28,9 @@ #include "util/u_memory.h" +constexpr uint64_t NsPerMs = 1000000; +constexpr uint64_t MaxTimeoutInNs = (uint64_t)UINT_MAX * NsPerMs; + #ifdef _WIN32 static void close_event(HANDLE event, int fd) @@ -46,7 +49,7 @@ create_event(int *fd) static bool wait_event(HANDLE event, int event_fd, uint64_t timeout_ns) { - DWORD timeout_ms = (timeout_ns == PIPE_TIMEOUT_INFINITE) ? INFINITE : timeout_ns / 1000000; + DWORD timeout_ms = (timeout_ns == PIPE_TIMEOUT_INFINITE || timeout_ns > MaxTimeoutInNs) ? INFINITE : timeout_ns / NsPerMs; return WaitForSingleObject(event, timeout_ms) == WAIT_OBJECT_0; } #else @@ -71,7 +74,7 @@ create_event(int *fd) static bool wait_event(HANDLE event, int event_fd, uint64_t timeout_ns) { - int timeout_ms = (timeout_ns == PIPE_TIMEOUT_INFINITE) ? -1 : timeout_ns / 1000000; + int timeout_ms = (timeout_ns == PIPE_TIMEOUT_INFINITE || timeout_ns > MaxTimeoutInNs) ? -1 : timeout_ns / NsPerMs; return sync_wait(event_fd, timeout_ms) == 0; } #endif