[14/22] mesa: implement buffer/texture barriers for semaphore signal/wait v2

Submitted by Andres Rodriguez on Dec. 22, 2017, 12:41 a.m.

Details

Message ID 20171222004157.28106-15-andresx7@gmail.com
State New
Headers show
Series "Add support for GL_EXT_semaphore" ( rev: 2 ) in Mesa

Not browsing as part of any series.

Commit Message

Andres Rodriguez Dec. 22, 2017, 12:41 a.m.
Make sure memory is accessible to the external client, for the specified
memory object, before the signal/after the wait.

v2: fixed flush order with respect to wait/signal emission

Signed-off-by: Andres Rodriguez <andresx7@gmail.com>
---
 src/mesa/main/dd.h                              | 14 ++++++-
 src/mesa/main/externalobjects.c                 | 38 +++++++++++++++---
 src/mesa/state_tracker/st_cb_semaphoreobjects.c | 53 +++++++++++++++++++++++--
 3 files changed, 95 insertions(+), 10 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index e43cf1c..6879587 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -1166,14 +1166,24 @@  struct dd_function_table {
     * server's command stream
     */
    void (*ServerWaitSemaphoreObject)(struct gl_context *ctx,
-                                     struct gl_semaphore_object *semObj);
+                                     struct gl_semaphore_object *semObj,
+                                     GLuint numBufferBarriers,
+                                     struct gl_buffer_object **bufObjs,
+                                     GLuint numTextureBarriers,
+                                     struct gl_texture_object **texObjs,
+                                     const GLenum *srcLayouts);
 
    /**
     * Introduce an operation to signal the semaphore object in the GL
     * server's command stream
     */
    void (*ServerSignalSemaphoreObject)(struct gl_context *ctx,
-                                       struct gl_semaphore_object *semObj);
+                                       struct gl_semaphore_object *semObj,
+                                       GLuint numBufferBarriers,
+                                       struct gl_buffer_object **bufObjs,
+                                       GLuint numTextureBarriers,
+                                       struct gl_texture_object **texObjs,
+                                       const GLenum *dstLayouts);
    /*@}*/
 
    /**
diff --git a/src/mesa/main/externalobjects.c b/src/mesa/main/externalobjects.c
index 26c1f27..e1e6df2 100644
--- a/src/mesa/main/externalobjects.c
+++ b/src/mesa/main/externalobjects.c
@@ -23,6 +23,7 @@ 
 
 #include "macros.h"
 #include "mtypes.h"
+#include "bufferobj.h"
 #include "context.h"
 #include "externalobjects.h"
 #include "teximage.h"
@@ -715,7 +716,8 @@  _mesa_WaitSemaphoreEXT(GLuint semaphore,
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_semaphore_object *semObj;
-
+   struct gl_buffer_object **bufObjs;
+   struct gl_texture_object **texObjs;
 
    if (!ctx->Extensions.EXT_semaphore) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glWaitSemaphoreEXT(unsupported)");
@@ -731,8 +733,20 @@  _mesa_WaitSemaphoreEXT(GLuint semaphore,
    FLUSH_VERTICES( ctx, 0 );
    FLUSH_CURRENT( ctx, 0 );
 
-   /* TODO: memory barriers and layout transitions */
-   ctx->Driver.ServerWaitSemaphoreObject(ctx, semObj);
+   bufObjs = alloca(sizeof(struct gl_buffer_object **) * numBufferBarriers);
+   for (unsigned i = 0; i < numBufferBarriers; i++) {
+      bufObjs[i] = _mesa_lookup_bufferobj(ctx, buffers[i]);
+   }
+
+   texObjs = alloca(sizeof(struct gl_texture_object **) * numTextureBarriers);
+   for (unsigned i = 0; i < numTextureBarriers; i++) {
+      texObjs[i] = _mesa_lookup_texture(ctx, textures[i]);
+   }
+
+   ctx->Driver.ServerWaitSemaphoreObject(ctx, semObj,
+                                         numBufferBarriers, bufObjs,
+                                         numTextureBarriers, texObjs,
+                                         srcLayouts);
 }
 
 void GLAPIENTRY
@@ -745,6 +759,8 @@  _mesa_SignalSemaphoreEXT(GLuint semaphore,
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_semaphore_object *semObj;
+   struct gl_buffer_object **bufObjs;
+   struct gl_texture_object **texObjs;
 
    if (!ctx->Extensions.EXT_semaphore) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glSignalSemaphoreEXT(unsupported)");
@@ -760,8 +776,20 @@  _mesa_SignalSemaphoreEXT(GLuint semaphore,
    FLUSH_VERTICES( ctx, 0 );
    FLUSH_CURRENT( ctx, 0 );
 
-   /* TODO: memory barriers and layout transitions */
-   ctx->Driver.ServerSignalSemaphoreObject(ctx, semObj);
+   bufObjs = alloca(sizeof(struct gl_buffer_object **) * numBufferBarriers);
+   for (unsigned i = 0; i < numBufferBarriers; i++) {
+      bufObjs[i] = _mesa_lookup_bufferobj(ctx, buffers[i]);
+   }
+
+   texObjs = alloca(sizeof(struct gl_texture_object **) * numTextureBarriers);
+   for (unsigned i = 0; i < numTextureBarriers; i++) {
+      texObjs[i] = _mesa_lookup_texture(ctx, textures[i]);
+   }
+
+   ctx->Driver.ServerSignalSemaphoreObject(ctx, semObj,
+                                           numBufferBarriers, bufObjs,
+                                           numTextureBarriers, texObjs,
+                                           dstLayouts);
 }
 
 void GLAPIENTRY
diff --git a/src/mesa/state_tracker/st_cb_semaphoreobjects.c b/src/mesa/state_tracker/st_cb_semaphoreobjects.c
index b1aec14..f53fe4d 100644
--- a/src/mesa/state_tracker/st_cb_semaphoreobjects.c
+++ b/src/mesa/state_tracker/st_cb_semaphoreobjects.c
@@ -6,6 +6,8 @@ 
 #include "main/externalobjects.h"
 
 #include "st_context.h"
+#include "st_texture.h"
+#include "st_cb_bufferobjects.h"
 #include "st_cb_semaphoreobjects.h"
 
 #include "state_tracker/drm_driver.h"
@@ -50,24 +52,69 @@  st_import_semaphoreobj_fd(struct gl_context *ctx,
 
 static void
 st_server_wait_semaphore(struct gl_context *ctx,
-                         struct gl_semaphore_object *semObj)
+                         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 st_buffer_object *bufObj;
+   struct st_texture_object *texObj;
 
    pipe->semaphore_server_sync(pipe, st_obj->fence);
+
+   for (unsigned i = 0; i < numBufferBarriers; i++) {
+      if (!bufObjs[i])
+         continue;
+
+      bufObj = st_buffer_object(bufObjs[i]);
+      pipe->flush_resource(pipe, bufObj->buffer);
+   }
+
+   for (unsigned i = 0; i < numTextureBarriers; i++) {
+      if (!texObjs[i])
+         continue;
+
+      texObj = st_texture_object(texObjs[i]);
+      pipe->flush_resource(pipe, texObj->pt);
+   }
 }
 
 static void
 st_server_signal_semaphore(struct gl_context *ctx,
-                           struct gl_semaphore_object *semObj)
+                           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 st_buffer_object *bufObj;
+   struct st_texture_object *texObj;
+
+   for (unsigned i = 0; i < numBufferBarriers; i++) {
+      if (!bufObjs[i])
+         continue;
+
+      bufObj = st_buffer_object(bufObjs[i]);
+      pipe->flush_resource(pipe, bufObj->buffer);
+   }
+
+   for (unsigned i = 0; i < numTextureBarriers; i++) {
+      if (!texObjs[i])
+         continue;
+
+      texObj = st_texture_object(texObjs[i]);
+      pipe->flush_resource(pipe, texObj->pt);
+   }
 
-   /**TODO FIXME */
    pipe->semaphore_server_signal(pipe, st_obj->fence);
 }