st/mesa: implement ARB_sync
authorMarek Olšák <maraeo@gmail.com>
Sat, 5 Mar 2011 19:32:28 +0000 (20:32 +0100)
committerMarek Olšák <maraeo@gmail.com>
Tue, 8 Mar 2011 22:52:37 +0000 (23:52 +0100)
The ServerWaitSync implementation matches Intel's driver.

The extension is advertised when pipe_screen::fence_finish is set.

src/mesa/SConscript
src/mesa/sources.mak
src/mesa/state_tracker/st_cb_syncobj.c [new file with mode: 0644]
src/mesa/state_tracker/st_cb_syncobj.h [new file with mode: 0644]
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_extensions.c

index 7e8bb2486c324674aa3659081ac2f8f48f3e1bf0..f797d62dc0e6a93a2f92255a316ef4e09f797e4a 100644 (file)
@@ -197,6 +197,7 @@ statetracker_sources = [
     'state_tracker/st_cb_queryobj.c',
     'state_tracker/st_cb_rasterpos.c',
     'state_tracker/st_cb_readpixels.c',
+    'state_tracker/st_cb_syncobj.c',
     'state_tracker/st_cb_strings.c',
     'state_tracker/st_cb_texture.c',
     'state_tracker/st_cb_viewport.c',
index ae92e4da9409939fc24fbcb091fd155852235480..95330947a83680412744ddad7ecd82d06527d6f5 100644 (file)
@@ -215,6 +215,7 @@ STATETRACKER_SOURCES = \
        state_tracker/st_cb_queryobj.c \
        state_tracker/st_cb_rasterpos.c \
        state_tracker/st_cb_readpixels.c \
+       state_tracker/st_cb_syncobj.c \
        state_tracker/st_cb_strings.c \
        state_tracker/st_cb_texture.c \
        state_tracker/st_cb_viewport.c \
diff --git a/src/mesa/state_tracker/st_cb_syncobj.c b/src/mesa/state_tracker/st_cb_syncobj.c
new file mode 100644 (file)
index 0000000..69a8678
--- /dev/null
@@ -0,0 +1,122 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Marek Olšák <maraeo@gmail.com>
+ * All Rights Reserved.
+ *
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL AUTHORS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+ /*
+  * Authors:
+  *   Marek Olšák <maraeo@gmail.com>
+  */
+
+#include "main/glheader.h"
+#include "main/macros.h"
+#include "pipe/p_context.h"
+#include "pipe/p_screen.h"
+#include "st_context.h"
+#include "st_cb_syncobj.h"
+
+struct st_sync_object {
+   struct gl_sync_object b;
+
+   struct pipe_fence_handle *fence;
+};
+
+
+static struct gl_sync_object * st_new_sync_object(struct gl_context *ctx,
+                                                  GLenum type)
+{
+   if (type == GL_SYNC_FENCE)
+      return (struct gl_sync_object*)CALLOC_STRUCT(st_sync_object);
+   else
+      return NULL;
+}
+
+static void st_delete_sync_object(struct gl_context *ctx,
+                                  struct gl_sync_object *obj)
+{
+   struct pipe_screen *screen = st_context(ctx)->pipe->screen;
+   struct st_sync_object *so = (struct st_sync_object*)obj;
+
+   screen->fence_reference(screen, &so->fence, NULL);
+   FREE(so);
+}
+
+static void st_fence_sync(struct gl_context *ctx, struct gl_sync_object *obj,
+                          GLenum condition, GLbitfield flags)
+{
+   struct pipe_context *pipe = st_context(ctx)->pipe;
+   struct st_sync_object *so = (struct st_sync_object*)obj;
+
+   assert(condition == GL_SYNC_GPU_COMMANDS_COMPLETE && flags == 0);
+   assert(so->fence == NULL);
+
+   pipe->flush(pipe, 0, &so->fence);
+}
+
+static void st_check_sync(struct gl_context *ctx, struct gl_sync_object *obj)
+{
+   struct pipe_screen *screen = st_context(ctx)->pipe->screen;
+   struct st_sync_object *so = (struct st_sync_object*)obj;
+
+   if (so->fence && screen->fence_signalled(screen, so->fence, 0) == 0) {
+      screen->fence_reference(screen, &so->fence, NULL);
+      so->b.StatusFlag = GL_TRUE;
+   }
+}
+
+static void st_client_wait_sync(struct gl_context *ctx,
+                                struct gl_sync_object *obj,
+                                GLbitfield flags, GLuint64 timeout)
+{
+   struct pipe_screen *screen = st_context(ctx)->pipe->screen;
+   struct st_sync_object *so = (struct st_sync_object*)obj;
+
+   /* We don't care about GL_SYNC_FLUSH_COMMANDS_BIT, because flush is
+    * already called when creating a fence. */
+
+   if (so->fence) {
+      screen->fence_finish(screen, so->fence, 0);
+      screen->fence_reference(screen, &so->fence, NULL);
+      so->b.StatusFlag = GL_TRUE;
+   }
+}
+
+static void st_server_wait_sync(struct gl_context *ctx,
+                                struct gl_sync_object *obj,
+                                GLbitfield flags, GLuint64 timeout)
+{
+   /* NO-OP.
+    * Neither Gallium nor DRM interfaces support blocking on the GPU. */
+}
+
+void st_init_syncobj_functions(struct dd_function_table *functions)
+{
+   functions->NewSyncObject = st_new_sync_object;
+   functions->FenceSync = st_fence_sync;
+   functions->DeleteSyncObject = st_delete_sync_object;
+   functions->CheckSync = st_check_sync;
+   functions->ClientWaitSync = st_client_wait_sync;
+   functions->ServerWaitSync = st_server_wait_sync;
+}
diff --git a/src/mesa/state_tracker/st_cb_syncobj.h b/src/mesa/state_tracker/st_cb_syncobj.h
new file mode 100644 (file)
index 0000000..c254684
--- /dev/null
@@ -0,0 +1,38 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Marek Olšák <maraeo@gmail.com>
+ * All Rights Reserved.
+ *
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL AUTHORS AND/OR ITS SUPPLIERS 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_SYNCOBJ_H
+#define ST_CB_SYNCOBJ_H
+
+
+struct dd_function_table;
+
+extern void
+st_init_syncobj_functions(struct dd_function_table *functions);
+
+
+#endif /* ST_CB_SYNCOBJ_H */
index 7a19f35bbf5418a24cbbf406c2a1fdb8e540c718..60972e07de87a35d8cdcb03bb454c8a87b75044f 100644 (file)
@@ -51,6 +51,7 @@
 #include "st_cb_texture.h"
 #include "st_cb_xformfb.h"
 #include "st_cb_flush.h"
+#include "st_cb_syncobj.h"
 #include "st_cb_strings.h"
 #include "st_cb_viewport.h"
 #include "st_atom.h"
@@ -292,6 +293,7 @@ void st_init_driver_functions(struct dd_function_table *functions)
    st_init_viewport_functions(functions);
 
    st_init_xformfb_functions(functions);
+   st_init_syncobj_functions(functions);
 
    functions->UpdateState = st_invalidate_state;
 }
index d96985a3747d2db31a7df83264c5a857a4c987d2..aaa1658f4a0b712c6b9e63fb89a8f088e6e97f48 100644 (file)
@@ -518,4 +518,8 @@ void st_init_extensions(struct st_context *st)
    if (screen->get_param(screen, PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR)) {
       ctx->Extensions.ARB_instanced_arrays = GL_TRUE;
    }
+
+   if (screen->fence_finish) {
+      ctx->Extensions.ARB_sync = GL_TRUE;
+   }
 }