{
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;
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;
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);
_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");
}
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
/** 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];
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:
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);
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 ||
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;
}
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 ||
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 ||
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);
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;
_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;
_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;
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;
#include "c11/threads.h"
#include "main/glheader.h"
+#include "main/glthread.h"
#include "main/menums.h"
#include "main/config.h"
#include "glapi/glapi.h"
/*@}*/
- struct glthread_state *GLThread;
+ struct glthread_state GLThread;
struct gl_config Visual;
struct gl_framebuffer *DrawBuffer; /**< buffer for writing */
* 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]);
}
}