aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/main/externalobjects.c
diff options
context:
space:
mode:
authorAndres Rodriguez <[email protected]>2017-10-06 17:17:54 -0400
committerAndres Rodriguez <[email protected]>2018-01-30 15:13:49 -0500
commit67d5d08682c4975a025182a7bf58a4768753e677 (patch)
treebfca34272dd4eee12b89e32dfedbe4169b8d1df7 /src/mesa/main/externalobjects.c
parent8e635f7d65752cd5af362036fd50ff3957275510 (diff)
mesa: add support for semaphore object creation/import/delete v3
Used by EXT_semmaphore and EXT_semaphore_fd v2: Removed unnecessary dummy callback initialization v3: Fixed attempting to free the DummySemaphoreObject Signed-off-by: Andres Rodriguez <[email protected]> Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/mesa/main/externalobjects.c')
-rw-r--r--src/mesa/main/externalobjects.c134
1 files changed, 133 insertions, 1 deletions
diff --git a/src/mesa/main/externalobjects.c b/src/mesa/main/externalobjects.c
index 4e9f8f87ab4..8b5ecb2cd8a 100644
--- a/src/mesa/main/externalobjects.c
+++ b/src/mesa/main/externalobjects.c
@@ -545,22 +545,126 @@ _mesa_TextureStorageMem1DEXT(GLuint texture,
memory, offset, "glTextureStorageMem1DEXT");
}
+/**
+ * Used as a placeholder for semaphore objects between glGenSemaphoresEXT()
+ * and glImportSemaphoreFdEXT(), so that glIsSemaphoreEXT() can work correctly.
+ */
+static struct gl_semaphore_object DummySemaphoreObject;
+
+/**
+ * Delete a semaphore object. Called via ctx->Driver.DeleteSemaphore().
+ * Not removed from hash table here.
+ */
+void
+_mesa_delete_semaphore_object(struct gl_context *ctx,
+ struct gl_semaphore_object *semObj)
+{
+ if (semObj != &DummySemaphoreObject)
+ free(semObj);
+}
+
+/**
+ * Initialize a semaphore object to default values.
+ */
+void
+_mesa_initialize_semaphore_object(struct gl_context *ctx,
+ struct gl_semaphore_object *obj,
+ GLuint name)
+{
+ memset(obj, 0, sizeof(struct gl_semaphore_object));
+ obj->Name = name;
+}
+
void GLAPIENTRY
_mesa_GenSemaphoresEXT(GLsizei n, GLuint *semaphores)
{
+ GET_CURRENT_CONTEXT(ctx);
+
+ const char *func = "glGenSemaphoresEXT";
+
+ if (MESA_VERBOSE & (VERBOSE_API))
+ _mesa_debug(ctx, "%s(%d, %p)", func, n, semaphores);
+ if (!ctx->Extensions.EXT_semaphore) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
+ return;
+ }
+
+ if (n < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(n < 0)", func);
+ return;
+ }
+
+ if (!semaphores)
+ return;
+
+ _mesa_HashLockMutex(ctx->Shared->SemaphoreObjects);
+ GLuint first = _mesa_HashFindFreeKeyBlock(ctx->Shared->SemaphoreObjects, n);
+ if (first) {
+ for (GLsizei i = 0; i < n; i++) {
+ semaphores[i] = first + i;
+ _mesa_HashInsertLocked(ctx->Shared->SemaphoreObjects,
+ semaphores[i], &DummySemaphoreObject);
+ }
+ }
+
+ _mesa_HashUnlockMutex(ctx->Shared->SemaphoreObjects);
}
void GLAPIENTRY
_mesa_DeleteSemaphoresEXT(GLsizei n, const GLuint *semaphores)
{
+ GET_CURRENT_CONTEXT(ctx);
+
+ const char *func = "glDeleteSemaphoresEXT";
+
+ if (MESA_VERBOSE & (VERBOSE_API)) {
+ _mesa_debug(ctx, "%s(%d, %p)\n", func, n, semaphores);
+ }
+
+ if (!ctx->Extensions.EXT_semaphore) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
+ return;
+ }
+ if (n < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(n < 0)", func);
+ return;
+ }
+
+ if (!semaphores)
+ return;
+
+ _mesa_HashLockMutex(ctx->Shared->SemaphoreObjects);
+ for (GLint i = 0; i < n; i++) {
+ if (semaphores[i] > 0) {
+ struct gl_semaphore_object *delObj
+ = _mesa_lookup_semaphore_object_locked(ctx, semaphores[i]);
+
+ if (delObj) {
+ _mesa_HashRemoveLocked(ctx->Shared->SemaphoreObjects,
+ semaphores[i]);
+ ctx->Driver.DeleteSemaphoreObject(ctx, delObj);
+ }
+ }
+ }
+ _mesa_HashUnlockMutex(ctx->Shared->SemaphoreObjects);
}
GLboolean GLAPIENTRY
_mesa_IsSemaphoreEXT(GLuint semaphore)
{
- return GL_FALSE;
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (!ctx->Extensions.EXT_semaphore) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glIsSemaphoreEXT(unsupported)");
+ return GL_FALSE;
+ }
+
+ struct gl_semaphore_object *obj =
+ _mesa_lookup_semaphore_object(ctx, semaphore);
+
+ return obj ? GL_TRUE : GL_FALSE;
}
void GLAPIENTRY
@@ -634,5 +738,33 @@ _mesa_ImportSemaphoreFdEXT(GLuint semaphore,
GLenum handleType,
GLint fd)
{
+ GET_CURRENT_CONTEXT(ctx);
+
+ const char *func = "glImportSemaphoreFdEXT";
+
+ if (!ctx->Extensions.EXT_semaphore_fd) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
+ return;
+ }
+
+ if (handleType != GL_HANDLE_TYPE_OPAQUE_FD_EXT) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(handleType=%u)", func, handleType);
+ return;
+ }
+
+ struct gl_semaphore_object *semObj = _mesa_lookup_semaphore_object(ctx,
+ semaphore);
+ if (!semObj)
+ return;
+
+ if (semObj == &DummySemaphoreObject) {
+ semObj = ctx->Driver.NewSemaphoreObject(ctx, semaphore);
+ if (!semObj) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
+ return;
+ }
+ _mesa_HashInsert(ctx->Shared->SemaphoreObjects, semaphore, semObj);
+ }
+ ctx->Driver.ImportSemaphoreFd(ctx, semObj, fd);
}