From c191c9a4669b64f36c36e956fc1249a422f2629c Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 18 Dec 2020 15:04:00 +0000 Subject: [PATCH] ipc: Support sending sync handles on layer_commit --- src/xrt/ipc/client/ipc_client_compositor.c | 25 +++++++++++++++++++--- src/xrt/ipc/server/ipc_server_handler.c | 19 +++++++++++++++- src/xrt/ipc/shared/proto.json | 1 + 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/xrt/ipc/client/ipc_client_compositor.c b/src/xrt/ipc/client/ipc_client_compositor.c index 01abb3ec1..bc6c4086a 100644 --- a/src/xrt/ipc/client/ipc_client_compositor.c +++ b/src/xrt/ipc/client/ipc_client_compositor.c @@ -28,6 +28,10 @@ #include #include +#ifdef XRT_GRAPHICS_SYNC_HANDLE_IS_FD +#include +#endif + /* * @@ -616,7 +620,7 @@ ipc_compositor_layer_commit(struct xrt_compositor *xc, { struct ipc_client_compositor *icc = ipc_client_compositor(xc); - assert(!xrt_graphics_sync_handle_is_valid(sync_handle)); + bool valid_sync = xrt_graphics_sync_handle_is_valid(sync_handle); struct ipc_shared_memory *ism = icc->ipc_c->ism; struct ipc_layer_slot *slot = &ism->slots[icc->layers.slot_id]; @@ -624,12 +628,27 @@ ipc_compositor_layer_commit(struct xrt_compositor *xc, // Last bit of data to put in the shared memory area. slot->num_layers = icc->layers.num_layers; - IPC_CALL_CHK(ipc_call_compositor_layer_sync( - icc->ipc_c, frame_id, icc->layers.slot_id, &icc->layers.slot_id)); + IPC_CALL_CHK(ipc_call_compositor_layer_sync( // + icc->ipc_c, // + frame_id, // + icc->layers.slot_id, // + &sync_handle, // + valid_sync ? 1 : 0, // + &icc->layers.slot_id)); // // Reset. icc->layers.num_layers = 0; +#ifdef XRT_GRAPHICS_SYNC_HANDLE_IS_FD + // Need to consume this handle. + if (valid_sync) { + close(sync_handle); + sync_handle = XRT_GRAPHICS_SYNC_HANDLE_INVALID; + } +#else +#error "Not yet implemented for this platform" +#endif + return res; } diff --git a/src/xrt/ipc/server/ipc_server_handler.c b/src/xrt/ipc/server/ipc_server_handler.c index 222204922..f377efc72 100644 --- a/src/xrt/ipc/server/ipc_server_handler.c +++ b/src/xrt/ipc/server/ipc_server_handler.c @@ -14,6 +14,10 @@ #include "server/ipc_server.h" #include "ipc_server_generated.h" +#ifdef XRT_GRAPHICS_SYNC_HANDLE_IS_FD +#include +#endif + /* * @@ -183,11 +187,24 @@ xrt_result_t ipc_handle_compositor_layer_sync(volatile struct ipc_client_state *ics, int64_t frame_id, uint32_t slot_id, - uint32_t *out_free_slot_id) + uint32_t *out_free_slot_id, + const xrt_graphics_sync_handle_t *handles, + const uint32_t num_handles) { struct ipc_shared_memory *ism = ics->server->ism; struct ipc_layer_slot *slot = &ism->slots[slot_id]; + for (uint32_t i = 0; i < num_handles; i++) { + if (!xrt_graphics_sync_handle_is_valid(handles[i])) { + continue; + } +#ifdef XRT_GRAPHICS_SYNC_HANDLE_IS_FD + close(handles[i]); +#else +#error "Need port to transport these graphics buffers" +#endif + } + // Copy current slot data to our state. ics->render_state = *slot; ics->rendering_state = true; diff --git a/src/xrt/ipc/shared/proto.json b/src/xrt/ipc/shared/proto.json index dbbcdcc95..a9e5f38c4 100644 --- a/src/xrt/ipc/shared/proto.json +++ b/src/xrt/ipc/shared/proto.json @@ -99,6 +99,7 @@ {"name": "frame_id", "type": "int64_t"}, {"name": "slot_id", "type": "uint32_t"} ], + "in_handles": {"type": "xrt_graphics_sync_handle_t"}, "out": [ {"name": "free_slot_id", "type": "uint32_t"} ]