summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/glthread.h
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2012-12-28 15:05:34 -0800
committerTimothy Arceri <[email protected]>2017-03-16 14:14:18 +1100
commitd8d81fbc31619f6ecf0a1b5ded22e5576e1d1739 (patch)
tree6c6ea69c5f728dd8feb29598a63d6e2ba18ec569 /src/mesa/main/glthread.h
parenta76a3cf664f93ca8a0a62281907a3f3342f44054 (diff)
mesa: Add infrastructure for a worker thread to process GL commands.
v2: Keep an allocated buffer around instead of checking for one at the start of every GL command. Inline the now-small space allocation function. v3: Remove duplicate !glthread->shutdown check, process remaining work before shutdown. v4: Fix leaks on destroy. V5: (Timothy Arceri) fix order of source files in makefile Acked-by: Timothy Arceri <[email protected]> Acked-by: Marek Olšák <[email protected]> Tested-by: Dieter Nützel <[email protected]> Tested-by: Mike Lothian <[email protected]>
Diffstat (limited to 'src/mesa/main/glthread.h')
-rw-r--r--src/mesa/main/glthread.h130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/mesa/main/glthread.h b/src/mesa/main/glthread.h
new file mode 100644
index 00000000000..c38fef32fa0
--- /dev/null
+++ b/src/mesa/main/glthread.h
@@ -0,0 +1,130 @@
+/*
+ * Copyright © 2012 Intel 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 _GLTHREAD_H
+#define _GLTHREAD_H
+
+#ifdef HAVE_PTHREAD
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <pthread.h>
+#include "main/mtypes.h"
+
+enum marshal_dispatch_cmd_id;
+
+/* Command size is a number of bytes stored in a short. */
+#define MARSHAL_MAX_CMD_SIZE 65535
+
+struct glthread_state
+{
+ /** The worker thread that asynchronously processes our GL commands. */
+ pthread_t thread;
+
+ /**
+ * Mutex used for synchronizing between the main thread and the worker
+ * thread.
+ */
+ pthread_mutex_t mutex;
+
+ /** Condvar used for waking the worker thread. */
+ pthread_cond_t new_work;
+
+ /** Condvar used for waking the main thread. */
+ pthread_cond_t work_done;
+
+ /** Used to tell the worker thread to quit */
+ bool shutdown;
+
+ /** Indicates that the worker thread is currently processing a batch */
+ bool busy;
+
+ /**
+ * Singly-linked list of command batches that are awaiting execution by
+ * a thread pool task. NULL if empty.
+ */
+ struct glthread_batch *batch_queue;
+
+ /**
+ * Tail pointer for appending batches to the end of batch_queue. If the
+ * queue is empty, this points to batch_queue.
+ */
+ struct glthread_batch **batch_queue_tail;
+
+ /**
+ * Batch containing commands that are being prepared for insertion into
+ * batch_queue. NULL if there are no such commands.
+ *
+ * Since this is only used by the main thread, it doesn't need the mutex to
+ * be accessed.
+ */
+ struct glthread_batch *batch;
+};
+
+/**
+ * A single batch of commands queued up for later execution by a thread pool
+ * task.
+ */
+struct glthread_batch
+{
+ /**
+ * Next batch of commands to execute after this batch, or NULL if this is
+ * the last set of commands queued. Protected by ctx->Marshal.Mutex.
+ */
+ struct glthread_batch *next;
+
+ /**
+ * Points to the first command in the batch.
+ */
+ uint8_t *buffer;
+
+ /**
+ * Amount of data used by batch commands, in bytes.
+ */
+ size_t used;
+};
+
+void _mesa_glthread_init(struct gl_context *ctx);
+void _mesa_glthread_destroy(struct gl_context *ctx);
+
+void _mesa_glthread_flush_batch(struct gl_context *ctx);
+void _mesa_glthread_finish(struct gl_context *ctx);
+
+#else /* HAVE_PTHREAD */
+
+static inline void
+_mesa_glthread_init(struct gl_context *ctx)
+{
+}
+
+static inline void
+_mesa_glthread_destroy(struct gl_context *ctx)
+{
+}
+
+static inline void
+_mesa_glthread_finish(struct gl_context *ctx)
+{
+}
+#endif /* !HAVE_PTHREAD */
+#endif /* _GLTHREAD_H*/