mesa: put gl_thread_state inside gl_context to remove pointer indirection

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4124>
This commit is contained in:
Marek Olšák
2020-03-06 14:54:50 -05:00
parent 8a4114b929
commit 15b0719ae2
7 changed files with 29 additions and 30 deletions

View File

@@ -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

View File

@@ -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];

View File

@@ -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:

View File

@@ -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 ||

View File

@@ -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;

View File

@@ -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 */

View 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.
*/
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]);
}
}