[Mesa-dev] [PATCH 03/17] mesa: add support for semaphore object creation/import/delete

Marek Olšák maraeo at gmail.com
Fri Nov 3 17:30:12 UTC 2017


On Thu, Nov 2, 2017 at 4:57 AM, Andres Rodriguez <andresx7 at gmail.com> wrote:
> Used by EXT_semmaphore and EXT_semaphore_fd
>
> Signed-off-by: Andres Rodriguez <andresx7 at gmail.com>
> ---
>  src/mesa/drivers/common/driverfuncs.c |   3 +
>  src/mesa/main/dd.h                    |  34 +++++++
>  src/mesa/main/externalobjects.c       | 161 +++++++++++++++++++++++++++++++++-
>  src/mesa/main/externalobjects.h       |  34 ++++++-
>  src/mesa/main/mtypes.h                |   7 ++
>  src/mesa/main/shared.c                |  17 ++++
>  6 files changed, 254 insertions(+), 2 deletions(-)
>
> diff --git a/src/mesa/drivers/common/driverfuncs.c b/src/mesa/drivers/common/driverfuncs.c
> index ddb4bb6..1ab1b5d 100644
> --- a/src/mesa/drivers/common/driverfuncs.c
> +++ b/src/mesa/drivers/common/driverfuncs.c
> @@ -170,6 +170,9 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
>     /* memory objects */
>     _mesa_init_memory_object_functions(driver);
>
> +   /* semaphore objects */
> +   _mesa_init_semaphore_object_functions(driver);
> +
>     driver->NewFramebuffer = _mesa_new_framebuffer;
>     driver->NewRenderbuffer = _swrast_new_soft_renderbuffer;
>     driver->MapRenderbuffer = _swrast_map_soft_renderbuffer;
> diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
> index da03b2e..b089219 100644
> --- a/src/mesa/main/dd.h
> +++ b/src/mesa/main/dd.h
> @@ -1126,6 +1126,40 @@ struct dd_function_table {
>                                  GLuint64 size,
>                                  int fd);
>     /*@}*/
> +
> +   /**
> +    * \name GL_EXT_semaphore interface
> +    */
> +   /*@{*/
> +  /**
> +    * Called to allocate a new semaphore object. Drivers will usually
> +    * allocate/return a subclass of gl_semaphore_object.
> +    */
> +   struct gl_semaphore_object * (*NewSemaphoreObject)(struct gl_context *ctx,
> +                                                      GLuint name);
> +   /**
> +    * Called to delete/free a semaphore object. Drivers should free the
> +    * object and any associated resources.
> +    */
> +   void (*DeleteSemaphoreObject)(struct gl_context *ctx,
> +                                 struct gl_semaphore_object *semObj);
> +   /*@}*/
> +
> +   /**
> +    * \name GL_EXT_semaphore_fd interface
> +    */
> +   /*@{*/
> +   /**
> +    * Called to import a semaphore object. The caller relinquishes ownership
> +    * of fd after the call returns.
> +    *
> +    * Accessing fd after ImportSemaphoreFd returns results in undefined
> +    * behaviour. This is consistent with EXT_semaphore_fd.
> +    */
> +   void (*ImportSemaphoreFd)(struct gl_context *ctx,
> +                                struct gl_semaphore_object *semObj,
> +                                int fd);
> +   /*@}*/
>  };
>
>
> diff --git a/src/mesa/main/externalobjects.c b/src/mesa/main/externalobjects.c
> index e70280c..30f5248 100644
> --- a/src/mesa/main/externalobjects.c
> +++ b/src/mesa/main/externalobjects.c
> @@ -547,22 +547,153 @@ _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;
> +
> +
> +/**
> + * Allocate and initialize a new semaphore object.  But don't put it into the
> + * semaphore object hash table.
> + *
> + * Called via ctx->Driver.NewSemaphoreObject, unless overridden by a device
> + * driver.
> + *
> + * \return pointer to new semaphore object.
> + */
> +static struct gl_semaphore_object *
> +_mesa_new_semaphore_object(struct gl_context *ctx, GLuint name)
> +{
> +   struct gl_semaphore_object *obj = MALLOC_STRUCT(gl_semaphore_object);
> +   if (!obj)
> +      return NULL;
> +
> +   _mesa_initialize_semaphore_object(ctx, obj, name);
> +   return obj;
> +}
> +
> +/**
> + * 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)
> +{
> +   free(semObj);
> +}
> +
> +void
> +_mesa_init_semaphore_object_functions(struct dd_function_table *driver)
> +{
> +   driver->NewSemaphoreObject = _mesa_new_semaphore_object;
> +   driver->DeleteSemaphoreObject = _mesa_delete_semaphore_object;

It's not necessary to set dummy callbacks. Keeping NULL is OK.

Marek


More information about the mesa-dev mailing list