[Mesa-stable] [PATCH 1/2] gallium/drivers: Add threadsafe wrappers for pipe_context and pipe_screen

Tom Stellard thomas.stellard at amd.com
Tue May 12 11:07:43 PDT 2015


These wrappers can be used by state trackers to ensure threadsafe access
to pipe_context and pipe_screen objects.

CC: 10.5 <mesa-stable at lists.freedesktop.org
---
 src/gallium/SConscript                             |   1 +
 src/gallium/drivers/threadsafe/Makefile.am         |  11 +
 src/gallium/drivers/threadsafe/Makefile.sources    |   4 +
 src/gallium/drivers/threadsafe/SConscript          |  13 +
 src/gallium/drivers/threadsafe/threadsafe.h        |  39 +++
 .../drivers/threadsafe/threadsafe_context.c        | 275 +++++++++++++++++++++
 src/gallium/drivers/threadsafe/threadsafe_screen.c | 190 ++++++++++++++
 7 files changed, 533 insertions(+)
 create mode 100644 src/gallium/drivers/threadsafe/Makefile.am
 create mode 100644 src/gallium/drivers/threadsafe/Makefile.sources
 create mode 100644 src/gallium/drivers/threadsafe/SConscript
 create mode 100644 src/gallium/drivers/threadsafe/threadsafe.h
 create mode 100644 src/gallium/drivers/threadsafe/threadsafe_context.c
 create mode 100644 src/gallium/drivers/threadsafe/threadsafe_screen.c

diff --git a/src/gallium/SConscript b/src/gallium/SConscript
index eeb1c78..e6070b6 100644
--- a/src/gallium/SConscript
+++ b/src/gallium/SConscript
@@ -17,6 +17,7 @@ SConscript([
     'drivers/softpipe/SConscript',
     'drivers/svga/SConscript',
     'drivers/trace/SConscript',
+    'drivers/threadsafe/SConscript',
 ])
 
 #
diff --git a/src/gallium/drivers/threadsafe/Makefile.am b/src/gallium/drivers/threadsafe/Makefile.am
new file mode 100644
index 0000000..bab64bf
--- /dev/null
+++ b/src/gallium/drivers/threadsafe/Makefile.am
@@ -0,0 +1,11 @@
+include Makefile.sources
+include $(top_srcdir)/src/gallium/Automake.inc
+
+AM_CFLAGS = \
+	$(GALLIUM_DRIVER_CFLAGS)
+
+noinst_LTLIBRARIES = libthreadsafe.la
+
+libthreadsafe_la_SOURCES = $(C_SOURCES)
+
+EXTRA_DIST = SConscript
diff --git a/src/gallium/drivers/threadsafe/Makefile.sources b/src/gallium/drivers/threadsafe/Makefile.sources
new file mode 100644
index 0000000..694d754
--- /dev/null
+++ b/src/gallium/drivers/threadsafe/Makefile.sources
@@ -0,0 +1,4 @@
+C_SOURCES := \
+	threadsafe.h \
+	threadsafe_context.c \
+	threadsafe_screen.c
diff --git a/src/gallium/drivers/threadsafe/SConscript b/src/gallium/drivers/threadsafe/SConscript
new file mode 100644
index 0000000..bc3333e
--- /dev/null
+++ b/src/gallium/drivers/threadsafe/SConscript
@@ -0,0 +1,13 @@
+#######################################################################
+# SConscript for noop convenience library
+
+Import('*')
+
+env = env.Clone()
+
+threadsafe = env.ConvenienceLibrary(
+	target = 'threadsafe',
+	source = env.ParseSourceList('Makefile.sources', 'C_SOURCES')
+	) + extra
+
+Export('threadsafe')
diff --git a/src/gallium/drivers/threadsafe/threadsafe.h b/src/gallium/drivers/threadsafe/threadsafe.h
new file mode 100644
index 0000000..f49ff8c
--- /dev/null
+++ b/src/gallium/drivers/threadsafe/threadsafe.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2015 Advanced Micro Devices, Inc.
+ *
+ * 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.
+ *
+ * Authors: Tom Stellard <thomas.stellard at amd.com>
+ *
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct pipe_context;
+struct pipe_screen;
+
+struct pipe_context *pipe_threadsafe_context(struct pipe_context *ctx);
+struct pipe_screen *pipe_threadsafe_screen(struct pipe_screen *screen);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/src/gallium/drivers/threadsafe/threadsafe_context.c b/src/gallium/drivers/threadsafe/threadsafe_context.c
new file mode 100644
index 0000000..6ef2348
--- /dev/null
+++ b/src/gallium/drivers/threadsafe/threadsafe_context.c
@@ -0,0 +1,275 @@
+/*
+ * Copyright 2015 Advanced Micro Devices, Inc.
+ *
+ * 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.
+ *
+ * Authors: Tom Stellard <thomas.stellard at amd.com>
+ *
+ */
+
+#include <stdio.h>
+
+/**
+ * \file
+ *
+ * threadsafe_context is a wrapper around a pipe_context to make it thread
+ * safe.
+ *
+ * TODO: Implement all gallium functions.  Only the functions required by the
+ * clover state tracker have been implemented.
+ */
+
+#include "os/os_thread.h"
+#include "pipe/p_context.h"
+#include "util/u_memory.h"
+
+#include "threadsafe.h"
+
+
+
+struct threadsafe_context {
+   struct pipe_context base;
+   struct pipe_context *ctx;
+   pipe_mutex mutex;
+};
+
+static struct pipe_context *unwrap(struct pipe_context *ctx) {
+   if (!ctx)
+      return NULL;
+   struct threadsafe_context *ts_ctx = (struct threadsafe_context*)ctx;
+   return ts_ctx->ctx;
+}
+
+#define THREADSAFE_CALL_VOID(ctx, function) \
+   struct threadsafe_context *ts_ctx = (struct threadsafe_context*)(ctx); \
+   pipe_mutex_lock(ts_ctx->mutex); \
+   (unwrap(ctx)->function); \
+   pipe_mutex_unlock(ts_ctx->mutex);
+
+#define THREADSAFE_CALL_RET(ctx, return_type, function) \
+   struct threadsafe_context *ts_ctx = (struct threadsafe_context*)(ctx); \
+   pipe_mutex_lock(ts_ctx->mutex); \
+   return_type ret = (unwrap(ctx)->function); \
+   pipe_mutex_unlock(ts_ctx->mutex); \
+   return ret;
+
+
+static void threadsafe_destroy(struct pipe_context *ctx) {
+   THREADSAFE_CALL_VOID(ctx, destroy(unwrap(ctx)));
+   FREE(ctx);
+}
+
+static void *threadsafe_create_sampler_state(struct pipe_context *ctx,
+                                       const struct pipe_sampler_state *state) {
+   THREADSAFE_CALL_RET(ctx, void*, create_sampler_state(unwrap(ctx), state));
+}
+
+static struct pipe_query *threadsafe_create_query(struct pipe_context *ctx,
+                                                  unsigned query_type,
+                                                  unsigned index) {
+   THREADSAFE_CALL_RET(ctx, struct pipe_query*,
+      create_query(unwrap(ctx), query_type, index));
+}
+
+static void threadsafe_bind_compute_state(struct pipe_context *ctx,
+                                          void * state) {
+   THREADSAFE_CALL_VOID(ctx, bind_compute_state(unwrap(ctx), state));
+}
+
+static void threadsafe_bind_sampler_states(struct pipe_context *ctx,
+                                           unsigned shader, unsigned start_slot,
+                                           unsigned num_samplers,
+                                           void **samplers) {
+   THREADSAFE_CALL_VOID(ctx,
+      bind_sampler_states(unwrap(ctx), shader, start_slot, num_samplers,
+                          samplers));
+}
+
+static void threadsafe_set_sampler_views(struct pipe_context *ctx,
+                                         unsigned shader, unsigned start_slot,
+                                         unsigned num_views,
+                                         struct pipe_sampler_view ** views) {
+   THREADSAFE_CALL_VOID(ctx,
+      set_sampler_views(unwrap(ctx), shader, start_slot, num_views, views));
+}
+
+
+static void threadsafe_set_compute_resources(struct pipe_context *ctx,
+                                             unsigned start, unsigned count,
+                                             struct pipe_surface **resources) {
+   THREADSAFE_CALL_VOID(ctx,
+      set_compute_resources(unwrap(ctx), start, count, resources));
+}
+
+static void threadsafe_set_global_binding(struct pipe_context *ctx,
+                                          unsigned first, unsigned count,
+                                          struct pipe_resource **resources,
+                                          uint32_t **handles) {
+   THREADSAFE_CALL_VOID(ctx,
+      set_global_binding(unwrap(ctx), first, count, resources, handles));
+}
+
+static void threadsafe_launch_grid(struct pipe_context *ctx,
+                                   const uint *block_layout,
+                                   const uint *grid_layout,
+                                   uint32_t pc, const void *input) {
+   THREADSAFE_CALL_VOID(ctx,
+      launch_grid(unwrap(ctx), block_layout, grid_layout, pc, input));
+}
+
+static void threadsafe_delete_compute_state(struct pipe_context *ctx,
+                                            void *state) {
+   THREADSAFE_CALL_VOID(ctx, delete_compute_state(unwrap(ctx), state));
+}
+
+static void *threadsafe_create_compute_state(struct pipe_context *ctx,
+                                       const struct pipe_compute_state *state) {
+   THREADSAFE_CALL_RET(ctx, void*, create_compute_state(unwrap(ctx), state));
+}
+
+static void threadsafe_flush(struct pipe_context *ctx,
+                             struct pipe_fence_handle **fence,
+                             unsigned flags) {
+   THREADSAFE_CALL_VOID(ctx, flush(unwrap(ctx), fence, flags));
+}
+
+static struct pipe_sampler_view *threadsafe_create_sampler_view(
+                                      struct pipe_context *ctx,
+                                      struct pipe_resource *texture,
+                                      const struct pipe_sampler_view *templat) {
+   THREADSAFE_CALL_RET(ctx, struct pipe_sampler_view*,
+      create_sampler_view(unwrap(ctx), texture, templat));
+}
+
+static void threadsafe_resource_copy_region(struct pipe_context *ctx,
+                                 struct pipe_resource *dst,
+                                 unsigned dst_level,
+                                 unsigned dstx, unsigned dsty, unsigned dstz,
+                                 struct pipe_resource *src,
+                                 unsigned src_level,
+                                 const struct pipe_box *src_box) {
+   THREADSAFE_CALL_VOID(ctx,
+      resource_copy_region(unwrap(ctx), dst, dst_level, dstx, dsty, dstz, src,
+                           src_level, src_box));
+}
+
+static void threadsafe_sampler_view_destroy(struct pipe_context *ctx,
+                                            struct pipe_sampler_view *view) {
+   THREADSAFE_CALL_VOID(ctx, sampler_view_destroy(unwrap(ctx), view));
+}
+
+static struct pipe_surface *threadsafe_create_surface(struct pipe_context *ctx,
+                                           struct pipe_resource *resource,
+                                           const struct pipe_surface *templat) {
+   THREADSAFE_CALL_RET(ctx, struct pipe_surface*,
+      create_surface(unwrap(ctx), resource, templat));
+}
+
+
+static void threadsafe_surface_destroy(struct pipe_context *ctx,
+                                       struct pipe_surface *surface) {
+   THREADSAFE_CALL_VOID(ctx, surface_destroy(unwrap(ctx), surface));
+}
+
+static void threadsafe_transfer_inline_write(struct pipe_context *ctx,
+                                             struct pipe_resource *resource,
+                                             unsigned level, unsigned usage,
+                                             const struct pipe_box *pipe_box,
+                                             const void *data,
+                                             unsigned stride,
+                                             unsigned layer_stride) {
+   THREADSAFE_CALL_VOID(ctx,
+      transfer_inline_write(unwrap(ctx), resource, level, usage, pipe_box, data,
+                            stride, layer_stride));
+}
+
+static void *threadsafe_transfer_map(struct pipe_context *ctx,
+                                     struct pipe_resource *resource,
+                                     unsigned level,
+                                     unsigned usage,
+                                     const struct pipe_box *box,
+                                     struct pipe_transfer **out_transfer) {
+   THREADSAFE_CALL_RET(ctx, void*,
+      transfer_map(unwrap(ctx), resource, level, usage, box, out_transfer));
+}
+
+static void threadsafe_transfer_unmap(struct pipe_context *ctx,
+                                      struct pipe_transfer *transfer) {
+   THREADSAFE_CALL_VOID(ctx, transfer_unmap(unwrap(ctx), transfer));
+}
+
+static void threadsafe_delete_sampler_state(struct pipe_context *ctx,
+                                            void *state) {
+   THREADSAFE_CALL_VOID(ctx, delete_sampler_state(unwrap(ctx), state));
+}
+
+static void threadsafe_end_query(struct pipe_context *ctx,
+                                 struct pipe_query *q) {
+   THREADSAFE_CALL_VOID(ctx, end_query(unwrap(ctx), q));
+}
+
+static void threadsafe_destroy_query(struct pipe_context *ctx,
+                                     struct pipe_query *q) {
+   THREADSAFE_CALL_VOID(ctx, destroy_query(unwrap(ctx), q));
+}
+
+static boolean threadsafe_get_query_result(struct pipe_context *ctx,
+                                           struct pipe_query *q,
+                                           boolean wait,
+                                           union pipe_query_result *result) {
+   THREADSAFE_CALL_RET(ctx, boolean,
+      get_query_result(unwrap(ctx), q, wait, result));
+}
+
+#define INIT_FUNCTION(name) \
+   ts_ctx->base.name = threadsafe_ ## name;
+
+struct pipe_context *pipe_threadsafe_context(struct pipe_context *ctx) {
+   struct threadsafe_context *ts_ctx = CALLOC_STRUCT(threadsafe_context);
+
+   ts_ctx->ctx = ctx;
+   pipe_mutex_init(ts_ctx->mutex);
+
+   INIT_FUNCTION(destroy);
+   INIT_FUNCTION(create_query);
+   INIT_FUNCTION(bind_compute_state);
+   INIT_FUNCTION(bind_sampler_states);
+   INIT_FUNCTION(set_sampler_views);
+   INIT_FUNCTION(set_compute_resources);
+   INIT_FUNCTION(set_global_binding);
+   INIT_FUNCTION(launch_grid);
+   INIT_FUNCTION(delete_compute_state);
+   INIT_FUNCTION(create_compute_state);
+   INIT_FUNCTION(flush);
+   INIT_FUNCTION(create_sampler_view);
+   INIT_FUNCTION(resource_copy_region);
+   INIT_FUNCTION(sampler_view_destroy);
+   INIT_FUNCTION(create_surface);
+   INIT_FUNCTION(surface_destroy);
+   INIT_FUNCTION(transfer_inline_write);
+   INIT_FUNCTION(transfer_map);
+   INIT_FUNCTION(transfer_unmap);
+   INIT_FUNCTION(create_sampler_state);
+   INIT_FUNCTION(delete_sampler_state);
+   INIT_FUNCTION(end_query);
+   INIT_FUNCTION(destroy_query);
+   INIT_FUNCTION(get_query_result);
+   return &ts_ctx->base;
+}
diff --git a/src/gallium/drivers/threadsafe/threadsafe_screen.c b/src/gallium/drivers/threadsafe/threadsafe_screen.c
new file mode 100644
index 0000000..11f48b7
--- /dev/null
+++ b/src/gallium/drivers/threadsafe/threadsafe_screen.c
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2015 Advanced Micro Devices, Inc.
+ *
+ * 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.
+ *
+ * Authors: Tom Stellard <thomas.stellard at amd.com>
+ *
+ */
+
+#include <stdio.h>
+
+
+/**
+ * \file
+ *
+ * threadsafe_screen is a wrapper around a pipe_screen to make it thread
+ * safe.
+ *
+ * TODO: Implement all gallium functions.  Only the functions required by the
+ * clover state tracker have been implemented.
+ */
+
+#include "os/os_thread.h"
+#include "pipe/p_context.h"
+#include "pipe/p_screen.h"
+#include "util/u_memory.h"
+
+#include "threadsafe.h"
+
+struct threadsafe_screen {
+   struct pipe_screen base;
+   struct pipe_screen *screen;
+   pipe_mutex mutex;
+};
+
+static struct pipe_screen *unwrap(struct pipe_screen *screen) {
+   if (!screen)
+      return NULL;
+   struct threadsafe_screen *ts_screen = (struct threadsafe_screen*)screen;
+   return ts_screen->screen;
+}
+
+#define THREADSAFE_CALL_VOID(screen, function) \
+   struct threadsafe_screen *ts_screen = (struct threadsafe_screen*)(screen); \
+   pipe_mutex_lock(ts_screen->mutex); \
+   (unwrap(screen)->function); \
+   pipe_mutex_unlock(ts_screen->mutex);
+
+#define THREADSAFE_CALL_RET(screen, return_type, function) \
+   struct threadsafe_screen *ts_screen = (struct threadsafe_screen*)(screen); \
+   pipe_mutex_lock(ts_screen->mutex); \
+   return_type ret = (unwrap(screen)->function); \
+   pipe_mutex_unlock(ts_screen->mutex); \
+   return ret;
+
+static struct pipe_context *threadsafe_context_create(
+                                                     struct pipe_screen *screen,
+                                                     void *priv) {
+   struct threadsafe_screen *ts_screen = (struct threadsafe_screen*)(screen);
+   struct pipe_context *ctx;
+
+   pipe_mutex_lock(ts_screen->mutex);
+   ctx = unwrap(screen)->context_create(unwrap(screen), priv);
+   ctx = pipe_threadsafe_context(ctx);
+   ctx->screen = screen;
+   pipe_mutex_unlock(ts_screen->mutex);
+   return ctx;
+}
+
+static void threadsafe_destroy(struct pipe_screen *screen) {
+   THREADSAFE_CALL_VOID(screen, destroy(unwrap(screen)));
+   FREE(screen);
+}
+
+static boolean threadsafe_is_format_supported(struct pipe_screen *screen,
+                                              enum pipe_format format,
+                                              enum pipe_texture_target target,
+                                              unsigned sample_count,
+                                              unsigned bindings) {
+   THREADSAFE_CALL_RET(screen, boolean,
+                       is_format_supported(unwrap(screen), format, target,
+                                           sample_count, bindings));
+}
+
+
+static struct pipe_resource *threadsafe_resource_create(
+                                          struct pipe_screen *screen,
+                                          const struct pipe_resource *templat) {
+   THREADSAFE_CALL_RET(screen, struct pipe_resource*,
+                       resource_create(unwrap(screen), templat));
+}
+
+static void threadsafe_resource_destroy(struct pipe_screen *screen,
+                                        struct pipe_resource *pt) {
+   THREADSAFE_CALL_VOID(screen, resource_destroy(unwrap(screen), pt));
+}
+
+static int threadsafe_get_compute_param(struct pipe_screen *screen,
+                                        enum pipe_compute_cap param,
+                                        void *param_value) {
+   THREADSAFE_CALL_RET(screen, int,
+                       get_compute_param(unwrap(screen), param, param_value));
+}
+
+static int threadsafe_get_param(struct pipe_screen *screen,
+                                enum pipe_cap param) {
+   THREADSAFE_CALL_RET(screen, int,
+                       get_param(unwrap(screen), param));
+}
+
+static const char* threadsafe_get_name(struct pipe_screen *screen) {
+   THREADSAFE_CALL_RET(screen, const char*, get_name(unwrap(screen)));
+}
+
+static const char* threadsafe_get_device_vendor(struct pipe_screen *screen) {
+   THREADSAFE_CALL_RET(screen, const char*, get_device_vendor(unwrap(screen)));
+}
+
+static int threadsafe_get_shader_param(struct pipe_screen *screen,
+                                       unsigned shader,
+                                       enum pipe_shader_cap param) {
+   THREADSAFE_CALL_RET(screen, int,
+                       get_shader_param(unwrap(screen), shader, param));
+}
+
+static void threadsafe_fence_reference(struct pipe_screen *screen,
+                                       struct pipe_fence_handle **ptr,
+                                       struct pipe_fence_handle *fence) {
+   THREADSAFE_CALL_VOID(screen, fence_reference(unwrap(screen), ptr, fence));
+}
+
+static uint64_t threadsafe_get_timestamp(struct pipe_screen *screen) {
+   THREADSAFE_CALL_RET(screen, uint64_t, get_timestamp(unwrap(screen)));
+}
+
+static boolean threadsafe_fence_signalled(struct pipe_screen *screen,
+                                          struct pipe_fence_handle *fence) {
+   THREADSAFE_CALL_RET(screen, boolean, fence_signalled(unwrap(screen), fence));
+}
+
+static boolean threadsafe_fence_finish(struct pipe_screen *screen,
+                                       struct pipe_fence_handle *fence,
+                                       uint64_t timeout) {
+   THREADSAFE_CALL_RET(screen, boolean,
+                       fence_finish(unwrap(screen), fence, timeout));
+}
+
+#define INIT_FUNCTION(name) \
+   ts_screen->base.name = threadsafe_ ## name;
+
+struct pipe_screen *pipe_threadsafe_screen(struct pipe_screen *screen) {
+   struct threadsafe_screen *ts_screen = CALLOC_STRUCT(threadsafe_screen);
+
+   ts_screen->screen = screen;
+   pipe_mutex_init(ts_screen->mutex);
+
+   INIT_FUNCTION(context_create);
+   INIT_FUNCTION(destroy);
+   INIT_FUNCTION(is_format_supported);
+   INIT_FUNCTION(resource_create);
+   INIT_FUNCTION(resource_destroy);
+   INIT_FUNCTION(get_compute_param);
+   INIT_FUNCTION(get_param);
+   INIT_FUNCTION(get_name);
+   INIT_FUNCTION(get_device_vendor);
+   INIT_FUNCTION(get_shader_param);
+   INIT_FUNCTION(fence_reference);
+   INIT_FUNCTION(get_timestamp);
+   INIT_FUNCTION(fence_signalled);
+   INIT_FUNCTION(fence_finish);
+
+   return &ts_screen->base;
+}
-- 
2.0.4



More information about the mesa-stable mailing list