#include "main/mtypes.h"
#include "main/glthread.h"
-#include "main/marshal.h"
+#include "main/glthread_marshal.h"
+#include "main/hash.h"
#include "util/u_atomic.h"
#include "util/u_thread.h"
{
struct gl_context *ctx = (struct gl_context*)job;
- ctx->Driver.SetBackgroundContext(ctx, &ctx->GLThread->stats);
+ ctx->Driver.SetBackgroundContext(ctx, &ctx->GLThread.stats);
_glapi_set_context(ctx);
}
void
_mesa_glthread_init(struct gl_context *ctx)
{
- struct glthread_state *glthread = calloc(1, sizeof(*glthread));
+ struct glthread_state *glthread = &ctx->GLThread;
- if (!glthread)
- return;
+ assert(!glthread->enabled);
if (!util_queue_init(&glthread->queue, "gl", MARSHAL_MAX_BATCHES - 2,
1, 0)) {
- free(glthread);
return;
}
+ glthread->VAOs = _mesa_NewHashTable();
+ if (!glthread->VAOs) {
+ util_queue_destroy(&glthread->queue);
+ return;
+ }
+ glthread->CurrentVAO = &glthread->DefaultVAO;
+
ctx->MarshalExec = _mesa_create_marshal_table(ctx);
if (!ctx->MarshalExec) {
+ _mesa_DeleteHashTable(glthread->VAOs);
util_queue_destroy(&glthread->queue);
- free(glthread);
return;
}
util_queue_fence_init(&glthread->batches[i].fence);
}
+ glthread->enabled = true;
glthread->stats.queue = &glthread->queue;
ctx->CurrentClientDispatch = ctx->MarshalExec;
- ctx->GLThread = glthread;
/* Execute the thread initialization function in the thread. */
struct util_queue_fence fence;
util_queue_fence_destroy(&fence);
}
+static void
+free_vao(GLuint key, void *data, void *userData)
+{
+ free(data);
+}
+
void
_mesa_glthread_destroy(struct gl_context *ctx)
{
- struct glthread_state *glthread = ctx->GLThread;
+ struct glthread_state *glthread = &ctx->GLThread;
- if (!glthread)
+ if (!glthread->enabled)
return;
_mesa_glthread_finish(ctx);
for (unsigned i = 0; i < MARSHAL_MAX_BATCHES; i++)
util_queue_fence_destroy(&glthread->batches[i].fence);
- free(glthread);
- ctx->GLThread = NULL;
+ _mesa_HashDeleteAll(glthread->VAOs, free_vao, NULL);
+ _mesa_DeleteHashTable(glthread->VAOs);
+
+ ctx->GLThread.enabled = false;
_mesa_glthread_restore_dispatch(ctx, "destroy");
}
void
_mesa_glthread_flush_batch(struct gl_context *ctx)
{
- struct glthread_state *glthread = ctx->GLThread;
- if (!glthread)
+ struct glthread_state *glthread = &ctx->GLThread;
+ if (!glthread->enabled)
return;
struct glthread_batch *next = &glthread->batches[glthread->next];
void
_mesa_glthread_finish(struct gl_context *ctx)
{
- struct glthread_state *glthread = ctx->GLThread;
- if (!glthread)
+ struct glthread_state *glthread = &ctx->GLThread;
+ if (!glthread->enabled)
return;
/* If this is called from the worker thread, then we've hit a path that
_mesa_glthread_finish_before(struct gl_context *ctx, const char *func)
{
_mesa_glthread_finish(ctx);
- debug_print_sync_fallback(func);
+
+ /* Uncomment this if you want to know where glthread syncs. */
+ /*printf("fallback to sync: %s\n", func);*/
}