mesa/glthread: pass the function name to _mesa_glthread_restore_dispatch
[mesa.git] / src / mesa / main / glthread.h
index 98ae11509a66061cec0e225125e2bfd4b8ab277b..59cb95feb4a0bc4a09c0ac3de757c12423e49a19 100644 (file)
 #ifndef _GLTHREAD_H
 #define _GLTHREAD_H
 
-#ifdef HAVE_PTHREAD
+/* The size of one batch and the maximum size of one call.
+ *
+ * This should be as low as possible, so that:
+ * - multiple synchronizations within a frame don't slow us down much
+ * - a smaller number of calls per frame can still get decent parallelism
+ * - the memory footprint of the queue is low, and with that comes a lower
+ *   chance of experiencing CPU cache thrashing
+ * but it should be high enough so that u_queue overhead remains negligible.
+ */
+#define MARSHAL_MAX_CMD_SIZE (8 * 1024)
+
+/* 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 8
 
 #include <inttypes.h>
 #include <stdbool.h>
-#include <pthread.h>
-#include "main/mtypes.h"
+#include "util/u_queue.h"
 
 enum marshal_dispatch_cmd_id;
+struct gl_context;
 
-/* Command size is a number of bytes stored in a short. */
-#define MARSHAL_MAX_CMD_SIZE 65535
-
-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;
-
-   /**
-    * Mutex used for synchronizing between the main thread and the worker
-    * thread.
-    */
-   pthread_mutex_t mutex;
+   /** Batch fence for waiting for the execution to finish. */
+   struct util_queue_fence fence;
 
-   /** Condvar used for waking the worker thread. */
-   pthread_cond_t new_work;
+   /** The worker thread will access the context with this. */
+   struct gl_context *ctx;
 
-   /** 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;
+   /** This is sent to the driver for framebuffer overlay / HUD. */
+   struct util_queue_monitoring stats;
 
-   /**
-    * 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;
+   /** The ring of batches in memory. */
+   struct glthread_batch batches[MARSHAL_MAX_BATCHES];
 
-   /**
-    * 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 last submitted batch. */
+   unsigned last;
 
-/**
- * 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;
+   /** Index of the batch being filled and about to be submitted. */
+   unsigned next;
 
    /**
-    * Amount of data used by batch commands, in bytes.
+    * Tracks on the main thread side whether the current vertex array binding
+    * is in a VBO.
     */
-   size_t used;
+   bool vertex_array_is_vbo;
 
    /**
-    * Data contained in the command buffer.
+    * Tracks on the main thread side whether the current element array (index
+    * buffer) binding is in a VBO.
     */
-   uint8_t buffer[MARSHAL_MAX_CMD_SIZE];
+   bool element_array_is_vbo;
 };
 
 void _mesa_glthread_init(struct gl_context *ctx);
 void _mesa_glthread_destroy(struct gl_context *ctx);
 
+void _mesa_glthread_restore_dispatch(struct gl_context *ctx, const char *func);
 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*/