diff options
-rw-r--r-- | src/mesa/main/glthread.c | 27 | ||||
-rw-r--r-- | src/mesa/main/glthread.h | 3 | ||||
-rw-r--r-- | src/mesa/main/glthread_bufferobj.c | 2 | ||||
-rw-r--r-- | src/mesa/main/glthread_marshal.h | 10 | ||||
-rw-r--r-- | src/mesa/main/glthread_varray.c | 10 | ||||
-rw-r--r-- | src/mesa/main/mtypes.h | 3 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_manager.c | 4 |
7 files changed, 29 insertions, 30 deletions
diff --git a/src/mesa/main/glthread.c b/src/mesa/main/glthread.c index 92cac5ee401..5d50e138150 100644 --- a/src/mesa/main/glthread.c +++ b/src/mesa/main/glthread.c @@ -68,28 +68,25 @@ glthread_thread_initialization(void *job, int thread_index) { 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); - free(glthread); return; } glthread->CurrentVAO = &glthread->DefaultVAO; @@ -98,7 +95,6 @@ _mesa_glthread_init(struct gl_context *ctx) if (!ctx->MarshalExec) { _mesa_DeleteHashTable(glthread->VAOs); util_queue_destroy(&glthread->queue); - free(glthread); return; } @@ -107,9 +103,9 @@ _mesa_glthread_init(struct gl_context *ctx) 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; @@ -129,9 +125,9 @@ free_vao(GLuint key, void *data, void *userData) 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); @@ -143,8 +139,7 @@ _mesa_glthread_destroy(struct gl_context *ctx) _mesa_HashDeleteAll(glthread->VAOs, free_vao, NULL); _mesa_DeleteHashTable(glthread->VAOs); - free(glthread); - ctx->GLThread = NULL; + ctx->GLThread.enabled = false; _mesa_glthread_restore_dispatch(ctx, "destroy"); } @@ -177,8 +172,8 @@ _mesa_glthread_disable(struct gl_context *ctx, const char *func) 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]; @@ -213,8 +208,8 @@ _mesa_glthread_flush_batch(struct gl_context *ctx) 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 diff --git a/src/mesa/main/glthread.h b/src/mesa/main/glthread.h index d8e9c3da84a..0d48438b9bd 100644 --- a/src/mesa/main/glthread.h +++ b/src/mesa/main/glthread.h @@ -86,6 +86,9 @@ struct glthread_state /** This is sent to the driver for framebuffer overlay / HUD. */ struct util_queue_monitoring stats; + /** Whether GLThread is enabled. */ + bool enabled; + /** The ring of batches in memory. */ struct glthread_batch batches[MARSHAL_MAX_BATCHES]; diff --git a/src/mesa/main/glthread_bufferobj.c b/src/mesa/main/glthread_bufferobj.c index b5df4569ac5..872bcbc69b8 100644 --- a/src/mesa/main/glthread_bufferobj.c +++ b/src/mesa/main/glthread_bufferobj.c @@ -50,7 +50,7 @@ void _mesa_glthread_BindBuffer(struct gl_context *ctx, GLenum target, GLuint buffer) { - struct glthread_state *glthread = ctx->GLThread; + struct glthread_state *glthread = &ctx->GLThread; switch (target) { case GL_ARRAY_BUFFER: diff --git a/src/mesa/main/glthread_marshal.h b/src/mesa/main/glthread_marshal.h index 2b6d8f92389..e3781b0437f 100644 --- a/src/mesa/main/glthread_marshal.h +++ b/src/mesa/main/glthread_marshal.h @@ -56,7 +56,7 @@ _mesa_glthread_allocate_command(struct gl_context *ctx, uint16_t cmd_id, int size) { - struct glthread_state *glthread = ctx->GLThread; + struct glthread_state *glthread = &ctx->GLThread; struct glthread_batch *next = &glthread->batches[glthread->next]; struct marshal_cmd_base *cmd_base; const int aligned_size = ALIGN(size, 8); @@ -80,7 +80,7 @@ _mesa_glthread_allocate_command(struct gl_context *ctx, static inline bool _mesa_glthread_is_non_vbo_draw_elements(const struct gl_context *ctx) { - struct glthread_state *glthread = ctx->GLThread; + const struct glthread_state *glthread = &ctx->GLThread; return ctx->API != API_OPENGL_CORE && (glthread->CurrentVAO->IndexBufferIsUserPointer || @@ -90,7 +90,7 @@ _mesa_glthread_is_non_vbo_draw_elements(const struct gl_context *ctx) static inline bool _mesa_glthread_is_non_vbo_draw_arrays(const struct gl_context *ctx) { - struct glthread_state *glthread = ctx->GLThread; + const struct glthread_state *glthread = &ctx->GLThread; return ctx->API != API_OPENGL_CORE && glthread->CurrentVAO->HasUserPointer; } @@ -98,7 +98,7 @@ _mesa_glthread_is_non_vbo_draw_arrays(const struct gl_context *ctx) static inline bool _mesa_glthread_is_non_vbo_draw_arrays_indirect(const struct gl_context *ctx) { - struct glthread_state *glthread = ctx->GLThread; + const struct glthread_state *glthread = &ctx->GLThread; return ctx->API != API_OPENGL_CORE && (!glthread->draw_indirect_buffer_is_vbo || @@ -108,7 +108,7 @@ _mesa_glthread_is_non_vbo_draw_arrays_indirect(const struct gl_context *ctx) static inline bool _mesa_glthread_is_non_vbo_draw_elements_indirect(const struct gl_context *ctx) { - struct glthread_state *glthread = ctx->GLThread; + const struct glthread_state *glthread = &ctx->GLThread; return ctx->API != API_OPENGL_CORE && (!glthread->draw_indirect_buffer_is_vbo || diff --git a/src/mesa/main/glthread_varray.c b/src/mesa/main/glthread_varray.c index 7a261552202..d246d2d4253 100644 --- a/src/mesa/main/glthread_varray.c +++ b/src/mesa/main/glthread_varray.c @@ -42,7 +42,7 @@ static struct glthread_vao * lookup_vao(struct gl_context *ctx, GLuint id) { - struct glthread_state *glthread = ctx->GLThread; + struct glthread_state *glthread = &ctx->GLThread; struct glthread_vao *vao; assert(id != 0); @@ -64,7 +64,7 @@ lookup_vao(struct gl_context *ctx, GLuint id) void _mesa_glthread_BindVertexArray(struct gl_context *ctx, GLuint id) { - struct glthread_state *glthread = ctx->GLThread; + struct glthread_state *glthread = &ctx->GLThread; if (id == 0) { glthread->CurrentVAO = &glthread->DefaultVAO; @@ -80,7 +80,7 @@ void _mesa_glthread_DeleteVertexArrays(struct gl_context *ctx, GLsizei n, const GLuint *ids) { - struct glthread_state *glthread = ctx->GLThread; + struct glthread_state *glthread = &ctx->GLThread; if (!ids) return; @@ -114,7 +114,7 @@ void _mesa_glthread_GenVertexArrays(struct gl_context *ctx, GLsizei n, GLuint *arrays) { - struct glthread_state *glthread = ctx->GLThread; + struct glthread_state *glthread = &ctx->GLThread; if (!arrays) return; @@ -137,7 +137,7 @@ _mesa_glthread_GenVertexArrays(struct gl_context *ctx, void _mesa_glthread_AttribPointer(struct gl_context *ctx) { - struct glthread_state *glthread = ctx->GLThread; + struct glthread_state *glthread = &ctx->GLThread; if (!glthread->vertex_array_is_vbo) glthread->CurrentVAO->HasUserPointer = true; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index f267bb723ca..12884170c24 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -39,6 +39,7 @@ #include "c11/threads.h" #include "main/glheader.h" +#include "main/glthread.h" #include "main/menums.h" #include "main/config.h" #include "glapi/glapi.h" @@ -4904,7 +4905,7 @@ struct gl_context /*@}*/ - struct glthread_state *GLThread; + struct glthread_state GLThread; struct gl_config Visual; struct gl_framebuffer *DrawBuffer; /**< buffer for writing */ diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c index 99404015c32..79aa778a14c 100644 --- a/src/mesa/state_tracker/st_manager.c +++ b/src/mesa/state_tracker/st_manager.c @@ -827,8 +827,8 @@ st_start_thread(struct st_context_iface *stctxi) * If glthread is disabled, st_draw.c re-pins driver threads regularly * based on the location of the app thread. */ - struct glthread_state *glthread = st->ctx->GLThread; - if (glthread && st->pipe->set_context_param) { + struct glthread_state *glthread = &st->ctx->GLThread; + if (glthread->enabled && st->pipe->set_context_param) { util_pin_driver_threads_to_random_L3(st->pipe, &glthread->queue.threads[0]); } } |