Module: Mesa
Branch: main
Commit: adf0dc7801c8ac6e20abf26a2a07ebbd463c3a29
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=adf0dc7801c8ac6e20abf26a2a07ebbd463c3a29

Author: Dave Airlie <[email protected]>
Date:   Thu Dec  9 14:37:51 2021 +1000

mesa/st: merge semaphore objects from st into mesa

Take all the semaphore objects code from state tracker and merge it
into mesa.

Acked-by: Marek Olšák <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14327>

---

 src/mesa/main/externalobjects.c                 | 151 ++++++++++++++++++----
 src/mesa/main/externalobjects.h                 |   4 -
 src/mesa/main/mtypes.h                          |   1 +
 src/mesa/main/shared.c                          |   3 +-
 src/mesa/meson.build                            |   2 -
 src/mesa/state_tracker/st_cb_semaphoreobjects.c | 164 ------------------------
 src/mesa/state_tracker/st_cb_semaphoreobjects.h |  73 -----------
 7 files changed, 129 insertions(+), 269 deletions(-)

diff --git a/src/mesa/main/externalobjects.c b/src/mesa/main/externalobjects.c
index f777f468bbd..0b34df873eb 100644
--- a/src/mesa/main/externalobjects.c
+++ b/src/mesa/main/externalobjects.c
@@ -36,8 +36,12 @@
 #include "pipe/p_context.h"
 #include "pipe/p_screen.h"
 #include "api_exec_decl.h"
-#include "state_tracker/st_cb_semaphoreobjects.h"
 
+#include "state_tracker/st_cb_bitmap.h"
+#include "state_tracker/st_texture.h"
+
+struct st_context;
+struct st_texture_object;
 #include "frontend/drm_driver.h"
 #ifdef HAVE_LIBDRM
 #include "drm-uapi/drm_fourcc.h"
@@ -586,6 +590,117 @@ _mesa_TextureStorageMem1DEXT(GLuint texture,
                          memory, offset, "glTextureStorageMem1DEXT");
 }
 
+static struct gl_semaphore_object *
+semaphoreobj_alloc(struct gl_context *ctx, GLuint name)
+{
+   struct gl_semaphore_object *obj = CALLOC_STRUCT(gl_semaphore_object);
+   if (!obj)
+      return NULL;
+
+   obj->Name = name;
+   return obj;
+}
+
+static void
+import_semaphoreobj_fd(struct gl_context *ctx,
+                          struct gl_semaphore_object *semObj,
+                          int fd)
+{
+   struct pipe_context *pipe = ctx->pipe;
+
+   pipe->create_fence_fd(pipe, &semObj->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
+}
+
+static void
+server_wait_semaphore(struct gl_context *ctx,
+                      struct gl_semaphore_object *semObj,
+                      GLuint numBufferBarriers,
+                      struct gl_buffer_object **bufObjs,
+                      GLuint numTextureBarriers,
+                      struct gl_texture_object **texObjs,
+                      const GLenum *srcLayouts)
+{
+   struct st_context *st = ctx->st;
+   struct pipe_context *pipe = ctx->pipe;
+   struct gl_buffer_object *bufObj;
+   struct st_texture_object *texObj;
+
+   /* The driver is allowed to flush during fence_server_sync, be prepared */
+   st_flush_bitmap_cache(st);
+   pipe->fence_server_sync(pipe, semObj->fence);
+
+   /**
+    * According to the EXT_external_objects spec, the memory operations must
+    * follow the wait. This is to make sure the flush is executed after the
+    * other party is done modifying the memory.
+    *
+    * Relevant excerpt from section "4.2.3 Waiting for Semaphores":
+    *
+    * Following completion of the semaphore wait operation, memory will also be
+    * made visible in the specified buffer and texture objects.
+    *
+    */
+   for (unsigned i = 0; i < numBufferBarriers; i++) {
+      if (!bufObjs[i])
+         continue;
+
+      bufObj = bufObjs[i];
+      if (bufObj->buffer)
+         pipe->flush_resource(pipe, bufObj->buffer);
+   }
+
+   for (unsigned i = 0; i < numTextureBarriers; i++) {
+      if (!texObjs[i])
+         continue;
+
+      texObj = st_texture_object(texObjs[i]);
+      if (texObj->pt)
+         pipe->flush_resource(pipe, texObj->pt);
+   }
+}
+
+static void
+server_signal_semaphore(struct gl_context *ctx,
+                        struct gl_semaphore_object *semObj,
+                        GLuint numBufferBarriers,
+                        struct gl_buffer_object **bufObjs,
+                        GLuint numTextureBarriers,
+                        struct gl_texture_object **texObjs,
+                        const GLenum *dstLayouts)
+{
+   struct st_context *st = ctx->st;
+   struct pipe_context *pipe = ctx->pipe;
+   struct gl_buffer_object *bufObj;
+   struct st_texture_object *texObj;
+
+   for (unsigned i = 0; i < numBufferBarriers; i++) {
+      if (!bufObjs[i])
+         continue;
+
+      bufObj = bufObjs[i];
+      if (bufObj->buffer)
+         pipe->flush_resource(pipe, bufObj->buffer);
+   }
+
+   for (unsigned i = 0; i < numTextureBarriers; i++) {
+      if (!texObjs[i])
+         continue;
+
+      texObj = st_texture_object(texObjs[i]);
+      if (texObj->pt)
+         pipe->flush_resource(pipe, texObj->pt);
+   }
+
+   /* The driver is allowed to flush during fence_server_signal, be prepared */
+   st_flush_bitmap_cache(st);
+   pipe->fence_server_signal(pipe, semObj->fence);
+}
+
 /**
  * Used as a placeholder for semaphore objects between glGenSemaphoresEXT()
  * and glImportSemaphoreFdEXT(), so that glIsSemaphoreEXT() can work correctly.
@@ -604,18 +719,6 @@ _mesa_delete_semaphore_object(struct gl_context *ctx,
       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)
 {
@@ -683,7 +786,7 @@ _mesa_DeleteSemaphoresEXT(GLsizei n, const GLuint 
*semaphores)
          if (delObj) {
             _mesa_HashRemoveLocked(ctx->Shared->SemaphoreObjects,
                                    semaphores[i]);
-            st_semaphoreobj_free(ctx, delObj);
+            _mesa_delete_semaphore_object(ctx, delObj);
          }
       }
    }
@@ -794,10 +897,10 @@ _mesa_WaitSemaphoreEXT(GLuint semaphore,
       texObjs[i] = _mesa_lookup_texture(ctx, textures[i]);
    }
 
-   st_server_wait_semaphore(ctx, semObj,
-                            numBufferBarriers, bufObjs,
-                            numTextureBarriers, texObjs,
-                            srcLayouts);
+   server_wait_semaphore(ctx, semObj,
+                         numBufferBarriers, bufObjs,
+                         numTextureBarriers, texObjs,
+                         srcLayouts);
 
 end:
    free(bufObjs);
@@ -854,10 +957,10 @@ _mesa_SignalSemaphoreEXT(GLuint semaphore,
       texObjs[i] = _mesa_lookup_texture(ctx, textures[i]);
    }
 
-   st_server_signal_semaphore(ctx, semObj,
-                              numBufferBarriers, bufObjs,
-                              numTextureBarriers, texObjs,
-                              dstLayouts);
+   server_signal_semaphore(ctx, semObj,
+                           numBufferBarriers, bufObjs,
+                           numTextureBarriers, texObjs,
+                           dstLayouts);
 
 end:
    free(bufObjs);
@@ -917,7 +1020,7 @@ _mesa_ImportSemaphoreFdEXT(GLuint semaphore,
       return;
 
    if (semObj == &DummySemaphoreObject) {
-      semObj = st_semaphoreobj_alloc(ctx, semaphore);
+      semObj = semaphoreobj_alloc(ctx, semaphore);
       if (!semObj) {
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
          return;
@@ -925,5 +1028,5 @@ _mesa_ImportSemaphoreFdEXT(GLuint semaphore,
       _mesa_HashInsert(ctx->Shared->SemaphoreObjects, semaphore, semObj, true);
    }
 
-   st_import_semaphoreobj_fd(ctx, semObj, fd);
+   import_semaphoreobj_fd(ctx, semObj, fd);
 }
diff --git a/src/mesa/main/externalobjects.h b/src/mesa/main/externalobjects.h
index d9379862e8a..1bb04814a8a 100644
--- a/src/mesa/main/externalobjects.h
+++ b/src/mesa/main/externalobjects.h
@@ -82,10 +82,6 @@ _mesa_delete_memory_object(struct gl_context *ctx,
                            struct gl_memory_object *semObj);
 
 extern void
-_mesa_initialize_semaphore_object(struct gl_context *ctx,
-                                  struct gl_semaphore_object *obj,
-                                  GLuint name);
-extern void
 _mesa_delete_semaphore_object(struct gl_context *ctx,
                               struct gl_semaphore_object *semObj);
 
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 5dc986d59af..ab0db99c6f0 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2879,6 +2879,7 @@ struct gl_memory_object
 struct gl_semaphore_object
 {
    GLuint Name;            /**< hash table ID/name */
+   struct pipe_fence_handle *fence;
 };
 
 /**
diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c
index d2cef0e59a8..473fc754655 100644
--- a/src/mesa/main/shared.c
+++ b/src/mesa/main/shared.c
@@ -46,7 +46,6 @@
 #include "util/set.h"
 #include "util/u_memory.h"
 
-#include "state_tracker/st_cb_semaphoreobjects.h"
 #include "state_tracker/st_cb_texture.h"
 #include "state_tracker/st_cb_program.h"
 
@@ -329,7 +328,7 @@ delete_semaphore_object_cb(void *data, void *userData)
 {
    struct gl_semaphore_object *semObj = (struct gl_semaphore_object *) data;
    struct gl_context *ctx = (struct gl_context *) userData;
-   st_semaphoreobj_free(ctx, semObj);
+   _mesa_delete_semaphore_object(ctx, semObj);
 }
 
 /**
diff --git a/src/mesa/meson.build b/src/mesa/meson.build
index 85f7688992e..978a2fcae5a 100644
--- a/src/mesa/meson.build
+++ b/src/mesa/meson.build
@@ -356,8 +356,6 @@ files_libmesa = 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_syncobj.c',
   'state_tracker/st_cb_syncobj.h',
   'state_tracker/st_cb_texture.c',
diff --git a/src/mesa/state_tracker/st_cb_semaphoreobjects.c 
b/src/mesa/state_tracker/st_cb_semaphoreobjects.c
deleted file mode 100644
index 419ac6ad999..00000000000
--- a/src/mesa/state_tracker/st_cb_semaphoreobjects.c
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Copyright © 2017 Valve Corporation.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-
-#include "main/mtypes.h"
-#include "main/context.h"
-
-#include "main/externalobjects.h"
-
-#include "util/u_memory.h"
-
-#include "st_context.h"
-#include "st_texture.h"
-#include "st_util.h"
-#include "st_cb_bitmap.h"
-#include "st_cb_semaphoreobjects.h"
-
-#include "frontend/drm_driver.h"
-#include "pipe/p_context.h"
-#include "pipe/p_screen.h"
-
-struct gl_semaphore_object *
-st_semaphoreobj_alloc(struct gl_context *ctx, GLuint name)
-{
-   struct st_semaphore_object *st_obj = CALLOC_STRUCT(st_semaphore_object);
-   if (!st_obj)
-      return NULL;
-
-   _mesa_initialize_semaphore_object(ctx, &st_obj->Base, name);
-   return &st_obj->Base;
-}
-
-void
-st_semaphoreobj_free(struct gl_context *ctx,
-                     struct gl_semaphore_object *semObj)
-{
-   _mesa_delete_semaphore_object(ctx, semObj);
-}
-
-
-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_fence_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_server_wait_semaphore(struct gl_context *ctx,
-                         struct gl_semaphore_object *semObj,
-                         GLuint numBufferBarriers,
-                         struct gl_buffer_object **bufObjs,
-                         GLuint numTextureBarriers,
-                         struct gl_texture_object **texObjs,
-                         const GLenum *srcLayouts)
-{
-   struct st_semaphore_object *st_obj = st_semaphore_object(semObj);
-   struct st_context *st = st_context(ctx);
-   struct pipe_context *pipe = st->pipe;
-   struct gl_buffer_object *bufObj;
-   struct st_texture_object *texObj;
-
-   /* The driver is allowed to flush during fence_server_sync, be prepared */
-   st_flush_bitmap_cache(st);
-   pipe->fence_server_sync(pipe, st_obj->fence);
-
-   /**
-    * According to the EXT_external_objects spec, the memory operations must
-    * follow the wait. This is to make sure the flush is executed after the
-    * other party is done modifying the memory.
-    *
-    * Relevant excerpt from section "4.2.3 Waiting for Semaphores":
-    *
-    * Following completion of the semaphore wait operation, memory will also be
-    * made visible in the specified buffer and texture objects.
-    *
-    */
-   for (unsigned i = 0; i < numBufferBarriers; i++) {
-      if (!bufObjs[i])
-         continue;
-
-      bufObj = bufObjs[i];
-      if (bufObj->buffer)
-         pipe->flush_resource(pipe, bufObj->buffer);
-   }
-
-   for (unsigned i = 0; i < numTextureBarriers; i++) {
-      if (!texObjs[i])
-         continue;
-
-      texObj = st_texture_object(texObjs[i]);
-      if (texObj->pt)
-         pipe->flush_resource(pipe, texObj->pt);
-   }
-}
-
-void
-st_server_signal_semaphore(struct gl_context *ctx,
-                           struct gl_semaphore_object *semObj,
-                           GLuint numBufferBarriers,
-                           struct gl_buffer_object **bufObjs,
-                           GLuint numTextureBarriers,
-                           struct gl_texture_object **texObjs,
-                           const GLenum *dstLayouts)
-{
-   struct st_semaphore_object *st_obj = st_semaphore_object(semObj);
-   struct st_context *st = st_context(ctx);
-   struct pipe_context *pipe = st->pipe;
-   struct gl_buffer_object *bufObj;
-   struct st_texture_object *texObj;
-
-   for (unsigned i = 0; i < numBufferBarriers; i++) {
-      if (!bufObjs[i])
-         continue;
-
-      bufObj = bufObjs[i];
-      if (bufObj->buffer)
-         pipe->flush_resource(pipe, bufObj->buffer);
-   }
-
-   for (unsigned i = 0; i < numTextureBarriers; i++) {
-      if (!texObjs[i])
-         continue;
-
-      texObj = st_texture_object(texObjs[i]);
-      if (texObj->pt)
-         pipe->flush_resource(pipe, texObj->pt);
-   }
-
-   /* The driver is allowed to flush during fence_server_signal, be prepared */
-   st_flush_bitmap_cache(st);
-   pipe->fence_server_signal(pipe, st_obj->fence);
-}
-
diff --git a/src/mesa/state_tracker/st_cb_semaphoreobjects.h 
b/src/mesa/state_tracker/st_cb_semaphoreobjects.h
deleted file mode 100644
index 3f7a25b7337..00000000000
--- a/src/mesa/state_tracker/st_cb_semaphoreobjects.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright © 2017 Valve Corporation.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef ST_CB_SEMAPHOREOBJECTS_H
-#define ST_CB_SEMAPHOREOBJECTS_H
-
-#include "util/compiler.h"
-#include "main/mtypes.h"
-
-struct dd_function_table;
-struct pipe_screen;
-
-struct st_semaphore_object
-{
-   struct gl_semaphore_object Base;
-   struct pipe_fence_handle *fence;
-};
-
-static inline struct st_semaphore_object *
-st_semaphore_object(struct gl_semaphore_object *obj)
-{
-   return (struct st_semaphore_object *)obj;
-}
-
-struct gl_semaphore_object *
-st_semaphoreobj_alloc(struct gl_context *ctx, GLuint name);
-void
-st_semaphoreobj_free(struct gl_context *ctx,
-                     struct gl_semaphore_object *semObj);
-
-void
-st_import_semaphoreobj_fd(struct gl_context *ctx,
-                          struct gl_semaphore_object *semObj,
-                          int fd);
-
-void
-st_server_wait_semaphore(struct gl_context *ctx,
-                         struct gl_semaphore_object *semObj,
-                         GLuint numBufferBarriers,
-                         struct gl_buffer_object **bufObjs,
-                         GLuint numTextureBarriers,
-                         struct gl_texture_object **texObjs,
-                         const GLenum *srcLayouts);
-
-void
-st_server_signal_semaphore(struct gl_context *ctx,
-                           struct gl_semaphore_object *semObj,
-                           GLuint numBufferBarriers,
-                           struct gl_buffer_object **bufObjs,
-                           GLuint numTextureBarriers,
-                           struct gl_texture_object **texObjs,
-                           const GLenum *dstLayouts);
-#endif

Reply via email to