mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-07 21:40:20 +01:00
d3d12: Support Linux eventfds for fences
Acked-by: Erik Faye-Lund <erik.faye-lund@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7937>
This commit is contained in:
parent
ee4c80f77d
commit
0b60d6a24d
2 changed files with 53 additions and 7 deletions
|
|
@ -28,11 +28,58 @@
|
||||||
|
|
||||||
#include "util/u_memory.h"
|
#include "util/u_memory.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
static void
|
||||||
|
close_event(HANDLE event, int fd)
|
||||||
|
{
|
||||||
|
if (event)
|
||||||
|
CloseHandle(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static HANDLE
|
||||||
|
create_event(int *fd)
|
||||||
|
{
|
||||||
|
*fd = -1;
|
||||||
|
return CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
return WaitForSingleObject(event, timeout_ms) == WAIT_OBJECT_0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#include <sys/eventfd.h>
|
||||||
|
#include <poll.h>
|
||||||
|
#include <util/libsync.h>
|
||||||
|
|
||||||
|
static void
|
||||||
|
close_event(HANDLE event, int fd)
|
||||||
|
{
|
||||||
|
if (fd != -1)
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static HANDLE
|
||||||
|
create_event(int *fd)
|
||||||
|
{
|
||||||
|
*fd = eventfd(0, 0);
|
||||||
|
return (HANDLE)(size_t)*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;
|
||||||
|
return sync_wait(event_fd, timeout_ms);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy_fence(struct d3d12_fence *fence)
|
destroy_fence(struct d3d12_fence *fence)
|
||||||
{
|
{
|
||||||
if (fence->event)
|
close_event(fence->event, fence->event_fd);
|
||||||
CloseHandle(fence->event);
|
|
||||||
FREE(fence);
|
FREE(fence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,7 +94,7 @@ d3d12_create_fence(struct d3d12_screen *screen, struct d3d12_context *ctx)
|
||||||
|
|
||||||
ret->cmdqueue_fence = ctx->cmdqueue_fence;
|
ret->cmdqueue_fence = ctx->cmdqueue_fence;
|
||||||
ret->value = ++ctx->fence_value;
|
ret->value = ++ctx->fence_value;
|
||||||
ret->event = CreateEvent(NULL, FALSE, FALSE, NULL);
|
ret->event = create_event(&ret->event_fd);
|
||||||
if (FAILED(ctx->cmdqueue_fence->SetEventOnCompletion(ret->value, ret->event)))
|
if (FAILED(ctx->cmdqueue_fence->SetEventOnCompletion(ret->value, ret->event)))
|
||||||
goto fail;
|
goto fail;
|
||||||
if (FAILED(screen->cmdqueue->Signal(ctx->cmdqueue_fence, ret->value)))
|
if (FAILED(screen->cmdqueue->Signal(ctx->cmdqueue_fence, ret->value)))
|
||||||
|
|
@ -85,10 +132,8 @@ d3d12_fence_finish(struct d3d12_fence *fence, uint64_t timeout_ns)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
bool complete = fence->cmdqueue_fence->GetCompletedValue() >= fence->value;
|
bool complete = fence->cmdqueue_fence->GetCompletedValue() >= fence->value;
|
||||||
if (!complete && timeout_ns) {
|
if (!complete && timeout_ns)
|
||||||
DWORD timeout_ms = (timeout_ns == PIPE_TIMEOUT_INFINITE) ? INFINITE : timeout_ns / 1000000;
|
complete = wait_event(fence->event, fence->event_fd, timeout_ns);
|
||||||
complete = WaitForSingleObject(fence->event, timeout_ms) == WAIT_OBJECT_0;
|
|
||||||
}
|
|
||||||
|
|
||||||
fence->signaled = complete;
|
fence->signaled = complete;
|
||||||
return complete;
|
return complete;
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ struct d3d12_fence {
|
||||||
struct pipe_reference reference;
|
struct pipe_reference reference;
|
||||||
ID3D12Fence *cmdqueue_fence;
|
ID3D12Fence *cmdqueue_fence;
|
||||||
HANDLE event;
|
HANDLE event;
|
||||||
|
int event_fd;
|
||||||
uint64_t value;
|
uint64_t value;
|
||||||
bool signaled;
|
bool signaled;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue