[Mesa-dev] [PATCH 07/17] mesa/st: add support for semaphore object create/import/delete
Andres Rodriguez
andresx7 at gmail.com
Thu Nov 2 03:57:10 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 | 56 +++++++++++++++++++++++++
src/mesa/state_tracker/st_cb_semaphoreobjects.h | 25 +++++++++++
src/mesa/state_tracker/st_context.c | 2 +
5 files changed, 87 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 6da1e3f..e4582ee 100644
--- a/src/mesa/Makefile.sources
+++ b/src/mesa/Makefile.sources
@@ -481,6 +481,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 20d06aa..a2e89a2 100644
--- a/src/mesa/meson.build
+++ b/src/mesa/meson.build
@@ -537,6 +537,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..47ece47
--- /dev/null
+++ b/src/mesa/state_tracker/st_cb_semaphoreobjects.c
@@ -0,0 +1,56 @@
+#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;
+ struct pipe_screen *screen = pipe->screen;
+
+ st_obj->semaphore = screen->semobj_create_from_fd(screen, fd);
+
+#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..2301651
--- /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_object *semaphore;
+};
+
+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 5d8dd8b..ddee38c 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"
@@ -715,6 +716,7 @@ void 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