mesa: put gl_thread_state inside gl_context to remove pointer indirection
authorMarek Olšák <marek.olsak@amd.com>
Fri, 6 Mar 2020 19:54:50 +0000 (14:54 -0500)
committerMarek Olšák <marek.olsak@amd.com>
Sat, 21 Mar 2020 03:01:13 +0000 (23:01 -0400)
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4124>

src/mesa/main/glthread.c
src/mesa/main/glthread.h
src/mesa/main/glthread_bufferobj.c
src/mesa/main/glthread_marshal.h
src/mesa/main/glthread_varray.c
src/mesa/main/mtypes.h
src/mesa/state_tracker/st_manager.c

index 92cac5ee401c32f57c16dbf78daff6f705aaa8f1..5d50e138150dd6fe87d2475f2a0247d046c7dbe8 100644 (file)
@@ -68,28 +68,25 @@ glthread_thread_initialization(void *job, int thread_index)
 {
    struct gl_context *ctx = (struct gl_context*)job;
 
 {
    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)
 {
    _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)) {
 
    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->VAOs = _mesa_NewHashTable();
    if (!glthread->VAOs) {
       util_queue_destroy(&glthread->queue);
-      free(glthread);
       return;
    }
    glthread->CurrentVAO = &glthread->DefaultVAO;
       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);
    if (!ctx->MarshalExec) {
       _mesa_DeleteHashTable(glthread->VAOs);
       util_queue_destroy(&glthread->queue);
-      free(glthread);
       return;
    }
 
       return;
    }
 
@@ -107,9 +103,9 @@ _mesa_glthread_init(struct gl_context *ctx)
       util_queue_fence_init(&glthread->batches[i].fence);
    }
 
       util_queue_fence_init(&glthread->batches[i].fence);
    }
 
+   glthread->enabled = true;
    glthread->stats.queue = &glthread->queue;
    ctx->CurrentClientDispatch = ctx->MarshalExec;
    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;
 
    /* 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)
 {
 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);
       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);
 
    _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");
 }
 
    _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)
 {
 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];
       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)
 {
 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
       return;
 
    /* If this is called from the worker thread, then we've hit a path that
index d8e9c3da84a77c4dd09153273d7d10adc2c93171..0d48438b9bdfb1bd5a48a5fc4a6289840c7300e4 100644 (file)
@@ -86,6 +86,9 @@ struct glthread_state
    /** This is sent to the driver for framebuffer overlay / HUD. */
    struct util_queue_monitoring stats;
 
    /** 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];
 
    /** The ring of batches in memory. */
    struct glthread_batch batches[MARSHAL_MAX_BATCHES];
 
index b5df4569ac5ad55eeabd61510d64fd0428bb76fa..872bcbc69b88480716f33fecda9d8299db2222ed 100644 (file)
@@ -50,7 +50,7 @@
 void
 _mesa_glthread_BindBuffer(struct gl_context *ctx, GLenum target, GLuint buffer)
 {
 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:
 
    switch (target) {
    case GL_ARRAY_BUFFER:
index 2b6d8f923896f67423ff61aeb3214943a0197c34..e3781b0437fe909a2929badcaf7685bf45389521 100644 (file)
@@ -56,7 +56,7 @@ _mesa_glthread_allocate_command(struct gl_context *ctx,
                                 uint16_t cmd_id,
                                 int size)
 {
                                 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);
    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)
 {
 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 ||
 
    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)
 {
 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;
 }
 
    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)
 {
 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 ||
 
    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)
 {
 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 ||
 
    return ctx->API != API_OPENGL_CORE &&
           (!glthread->draw_indirect_buffer_is_vbo ||
index 7a261552202f8653e33f1b3811d64104b92baf9f..d246d2d4253b936f2765a21024803e5421e285f3 100644 (file)
@@ -42,7 +42,7 @@
 static struct glthread_vao *
 lookup_vao(struct gl_context *ctx, GLuint id)
 {
 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);
    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)
 {
 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;
 
    if (id == 0) {
       glthread->CurrentVAO = &glthread->DefaultVAO;
@@ -80,7 +80,7 @@ void
 _mesa_glthread_DeleteVertexArrays(struct gl_context *ctx,
                                   GLsizei n, const GLuint *ids)
 {
 _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;
 
    if (!ids)
       return;
@@ -114,7 +114,7 @@ void
 _mesa_glthread_GenVertexArrays(struct gl_context *ctx,
                                GLsizei n, GLuint *arrays)
 {
 _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;
 
    if (!arrays)
       return;
@@ -137,7 +137,7 @@ _mesa_glthread_GenVertexArrays(struct gl_context *ctx,
 void
 _mesa_glthread_AttribPointer(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;
 
    if (!glthread->vertex_array_is_vbo)
       glthread->CurrentVAO->HasUserPointer = true;
index f267bb723caa7d775b992ecaf9a399534b983e60..12884170c242ff34dae5dc2e0371425dde83c6a9 100644 (file)
@@ -39,6 +39,7 @@
 #include "c11/threads.h"
 
 #include "main/glheader.h"
 #include "c11/threads.h"
 
 #include "main/glheader.h"
+#include "main/glthread.h"
 #include "main/menums.h"
 #include "main/config.h"
 #include "glapi/glapi.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 */
 
    struct gl_config Visual;
    struct gl_framebuffer *DrawBuffer;  /**< buffer for writing */
index 99404015c32da5582ee5be118dacc579d1805511..79aa778a14ca428c6ed906de9780df9b0f2003df 100644 (file)
@@ -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.
     */
     * 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]);
    }
 }
       util_pin_driver_threads_to_random_L3(st->pipe, &glthread->queue.threads[0]);
    }
 }