summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/glthread.h
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2017-06-21 13:53:23 +0200
committerMarek Olšák <[email protected]>2017-06-26 02:17:03 +0200
commitd1513edaa00b476f87c4dd397c3746f17f19196a (patch)
tree08c8f018f0eaa7d74085fc47f119cf859b730c48 /src/mesa/main/glthread.h
parent1e37a5054b1f47a0e95183bd99b8c6a3a8be4725 (diff)
mesa/glthread: switch to u_queue and redesign the batch management
This mirrors exactly how u_threaded_context works. If you understand this, you also understand u_threaded_context. Reviewed-by: Timothy Arceri <[email protected]>
Diffstat (limited to 'src/mesa/main/glthread.h')
-rw-r--r--src/mesa/main/glthread.h88
1 files changed, 30 insertions, 58 deletions
diff --git a/src/mesa/main/glthread.h b/src/mesa/main/glthread.h
index 07bed380cbf..5b938fdeef9 100644
--- a/src/mesa/main/glthread.h
+++ b/src/mesa/main/glthread.h
@@ -29,55 +29,50 @@
/* Command size is a number of bytes stored in a short. */
#define MARSHAL_MAX_CMD_SIZE 65535
+/* The number of batch slots in memory.
+ *
+ * One batch is being executed, one batch is being filled, the rest are
+ * waiting batches. There must be at least 1 slot for a waiting batch,
+ * so the minimum number of batches is 3.
+ */
+#define MARSHAL_MAX_BATCHES 4
+
#include <inttypes.h>
#include <stdbool.h>
#include <pthread.h>
+#include "util/u_queue.h"
enum marshal_dispatch_cmd_id;
-struct glthread_state
+/** A single batch of commands queued up for execution. */
+struct glthread_batch
{
- /** The worker thread that asynchronously processes our GL commands. */
- pthread_t thread;
+ /** Batch fence for waiting for the execution to finish. */
+ struct util_queue_fence fence;
- /**
- * Mutex used for synchronizing between the main thread and the worker
- * thread.
- */
- pthread_mutex_t mutex;
+ /** The worker thread will access the context with this. */
+ struct gl_context *ctx;
- /** Condvar used for waking the worker thread. */
- pthread_cond_t new_work;
-
- /** Condvar used for waking the main thread. */
- pthread_cond_t work_done;
+ /** Amount of data used by batch commands, in bytes. */
+ size_t used;
- /** Used to tell the worker thread to quit */
- bool shutdown;
+ /** Data contained in the command buffer. */
+ uint8_t buffer[MARSHAL_MAX_CMD_SIZE];
+};
- /** Indicates that the worker thread is currently processing a batch */
- bool busy;
+struct glthread_state
+{
+ /** Multithreaded queue. */
+ struct util_queue queue;
- /**
- * Singly-linked list of command batches that are awaiting execution by
- * a thread pool task. NULL if empty.
- */
- struct glthread_batch *batch_queue;
+ /** The ring of batches in memory. */
+ struct glthread_batch batches[MARSHAL_MAX_BATCHES];
- /**
- * 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;
+ /** Index of the last submitted batch. */
+ unsigned last;
- /**
- * 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;
+ /** Index of the batch being filled and about to be submitted. */
+ unsigned next;
/**
* Tracks on the main thread side whether the current vertex array binding
@@ -92,29 +87,6 @@ struct glthread_state
bool element_array_is_vbo;
};
-/**
- * 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;
-
- /**
- * Amount of data used by batch commands, in bytes.
- */
- size_t used;
-
- /**
- * Data contained in the command buffer.
- */
- uint8_t buffer[MARSHAL_MAX_CMD_SIZE];
-};
-
void _mesa_glthread_init(struct gl_context *ctx);
void _mesa_glthread_destroy(struct gl_context *ctx);