[Mesa-dev] [PATCH 10/22] mesa/st: add support for semaphore object create/import/delete

Andres Rodriguez andresx7 at gmail.com
Fri Dec 22 00:41:45 UTC 2017


Add basic semaphore object operations.

Signed-off-by: Andres Rodriguez <andresx7 at gmail.com>
---
 src/mesa/Makefile.sources                       |  2 +
 src/mesa/meson.build                            |  2 +
 src/mesa/state_tracker/st_cb_semaphoreobjects.c | 55 +++++++++++++++++++++++++
 src/mesa/state_tracker/st_cb_semaphoreobjects.h | 25 +++++++++++
 src/mesa/state_tracker/st_context.c             |  2 +
 5 files changed, 86 insertions(+)
 create mode 100644 src/mesa/state_tracker/st_cb_semaphoreobjects.c
 create mode 100644 src/mesa/state_tracker/st_cb_semaphoreobjects.h

diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
index 53fa486..2e89da4 100644
--- a/src/mesa/Makefile.sources
+++ b/src/mesa/Makefile.sources
@@ -485,6 +485,8 @@ STATETRACKER_FILES = \
 	state_tracker/st_cb_rasterpos.h \
 	state_tracker/st_cb_readpixels.c \
 	state_tracker/st_cb_readpixels.h \
+	state_tracker/st_cb_semaphoreobjects.c \
+	state_tracker/st_cb_semaphoreobjects.h \
 	state_tracker/st_cb_strings.c \
 	state_tracker/st_cb_strings.h \
 	state_tracker/st_cb_syncobj.c \
diff --git a/src/mesa/meson.build b/src/mesa/meson.build
index ab6bc27..a047396 100644
--- a/src/mesa/meson.build
+++ b/src/mesa/meson.build
@@ -536,6 +536,8 @@ files_libmesa_gallium = files(
   'state_tracker/st_cb_readpixels.h',
   'state_tracker/st_cb_strings.c',
   'state_tracker/st_cb_strings.h',
+  'state_tracker/st_cb_semaphoreobjects.c',
+  'state_tracker/st_cb_semaphoreobjects.h',
   'state_tracker/st_cb_syncobj.c',
   'state_tracker/st_cb_syncobj.h',
   'state_tracker/st_cb_texturebarrier.c',
diff --git a/src/mesa/state_tracker/st_cb_semaphoreobjects.c b/src/mesa/state_tracker/st_cb_semaphoreobjects.c
new file mode 100644
index 0000000..d7ea2ef
--- /dev/null
+++ b/src/mesa/state_tracker/st_cb_semaphoreobjects.c
@@ -0,0 +1,55 @@
+#include "main/imports.h"
+#include "main/mtypes.h"
+
+#include "main/externalobjects.h"
+
+#include "st_context.h"
+#include "st_cb_semaphoreobjects.h"
+
+#include "state_tracker/drm_driver.h"
+#include "pipe/p_context.h"
+#include "pipe/p_screen.h"
+
+static struct gl_semaphore_object *
+st_semaphoreobj_alloc(struct gl_context *ctx, GLuint name)
+{
+   struct st_semaphore_object *st_obj = ST_CALLOC_STRUCT(st_semaphore_object);
+   if (!st_obj)
+      return NULL;
+
+   _mesa_initialize_semaphore_object(ctx, &st_obj->Base, name);
+   return &st_obj->Base;
+}
+
+static void
+st_semaphoreobj_free(struct gl_context *ctx,
+                     struct gl_semaphore_object *semObj)
+{
+   _mesa_delete_semaphore_object(ctx, semObj);
+}
+
+
+static void
+st_import_semaphoreobj_fd(struct gl_context *ctx,
+                       struct gl_semaphore_object *semObj,
+                       int fd)
+{
+   struct st_semaphore_object *st_obj = st_semaphore_object(semObj);
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
+
+   pipe->create_semaphore_fd(pipe, &st_obj->fence, fd, PIPE_FD_TYPE_SYNCOBJ);
+
+#if !defined(_WIN32)
+   /* We own fd, but we no longer need it. So get rid of it */
+   close(fd);
+#endif
+}
+
+void
+st_init_semaphoreobject_functions(struct dd_function_table *functions)
+{
+   functions->NewSemaphoreObject = st_semaphoreobj_alloc;
+   functions->DeleteSemaphoreObject = st_semaphoreobj_free;
+   functions->ImportSemaphoreFd = st_import_semaphoreobj_fd;
+}
diff --git a/src/mesa/state_tracker/st_cb_semaphoreobjects.h b/src/mesa/state_tracker/st_cb_semaphoreobjects.h
new file mode 100644
index 0000000..43f774b
--- /dev/null
+++ b/src/mesa/state_tracker/st_cb_semaphoreobjects.h
@@ -0,0 +1,25 @@
+#ifndef ST_CB_SEMAPHOREOBJECTS_H
+#define ST_CB_SEMAPHOREOBJECTS_H
+
+#include "main/compiler.h"
+#include "main/mtypes.h"
+
+struct dd_function_table;
+struct pipe_screen;
+
+struct st_semaphore_object
+{
+   struct gl_semaphore_object Base;
+   struct pipe_semaphore_handle *fence;
+};
+
+static inline struct st_semaphore_object *
+st_semaphore_object(struct gl_semaphore_object *obj)
+{
+   return (struct st_semaphore_object *)obj;
+}
+
+extern void
+st_init_semaphoreobject_functions(struct dd_function_table *functions);
+
+#endif
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 7564a53..75f5815 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -60,6 +60,7 @@
 #include "st_cb_program.h"
 #include "st_cb_queryobj.h"
 #include "st_cb_readpixels.h"
+#include "st_cb_semaphoreobjects.h"
 #include "st_cb_texture.h"
 #include "st_cb_xformfb.h"
 #include "st_cb_flush.h"
@@ -739,6 +740,7 @@ st_init_driver_functions(struct pipe_screen *screen,
    st_init_query_functions(functions);
    st_init_cond_render_functions(functions);
    st_init_readpixels_functions(functions);
+   st_init_semaphoreobject_functions(functions);
    st_init_texture_functions(functions);
    st_init_texture_barrier_functions(functions);
    st_init_flush_functions(screen, functions);
-- 
2.9.3



More information about the mesa-dev mailing list