glthread: make glGetActiveUniform return without syncing

We just need to track glLinkProgram and glDeleteProgram.

Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7053>
This commit is contained in:
Marek Olšák 2020-10-03 16:11:07 -04:00 committed by Marge Bot
parent 5f820b38d4
commit b8684672ff
4 changed files with 61 additions and 4 deletions

View File

@ -5353,7 +5353,8 @@
<glx ignore="true"/>
</function>
<function name="DeleteProgram" es2="2.0">
<function name="DeleteProgram" es2="2.0"
marshal_call_after="_mesa_glthread_ProgramChanged(ctx);">
<param name="program" type="GLuint"/>
<glx ignore="true"/>
</function>
@ -5394,7 +5395,7 @@
<glx ignore="true"/>
</function>
<function name="GetActiveUniform" es2="2.0">
<function name="GetActiveUniform" es2="2.0" marshal="custom">
<param name="program" type="GLuint"/>
<param name="index" type="GLuint"/>
<param name="bufSize" type="GLsizei"/>
@ -5523,7 +5524,8 @@
<glx ignore="true"/>
</function>
<function name="LinkProgram" es2="2.0" no_error="true">
<function name="LinkProgram" es2="2.0" no_error="true"
marshal_call_after="_mesa_glthread_ProgramChanged(ctx);">
<param name="program" type="GLuint"/>
<glx ignore="true"/>
</function>
@ -7701,7 +7703,8 @@
<type name="charARB" size="1" glx_name="CARD8"/>
<type name="handleARB" size="4" glx_name="CARD32"/>
<function name="DeleteObjectARB">
<function name="DeleteObjectARB"
marshal_call_after="_mesa_glthread_ProgramChanged(ctx);">
<param name="obj" type="GLhandleARB"/>
<glx ignore="true"/>
</function>

View File

@ -62,6 +62,10 @@ glthread_unmarshal_batch(void *job, int thread_index)
assert(pos == used);
batch->used = 0;
unsigned batch_index = batch - ctx->GLThread.batches;
/* Atomically set this to -1 if it's equal to batch_index. */
p_atomic_cmpxchg(&ctx->GLThread.LastProgramChangeBatch, batch_index, -1);
}
static void

View File

@ -182,6 +182,12 @@ struct glthread_state
/** Currently-bound buffer object IDs. */
GLuint CurrentArrayBufferName;
GLuint CurrentDrawIndirectBufferName;
/**
* The batch index of the last occurence of glLinkProgram or
* glDeleteProgram or -1 if there is no such enqueued call.
*/
int LastProgramChangeBatch;
};
void _mesa_glthread_init(struct gl_context *ctx);
@ -255,6 +261,7 @@ void _mesa_glthread_PopClientAttrib(struct gl_context *ctx);
void _mesa_glthread_ClientAttribDefault(struct gl_context *ctx, GLbitfield mask);
void _mesa_glthread_InterleavedArrays(struct gl_context *ctx, GLenum format,
GLsizei stride, const GLvoid *pointer);
void _mesa_glthread_ProgramChanged(struct gl_context *ctx);
#ifdef __cplusplus
}

View File

@ -23,6 +23,7 @@
#include "glthread_marshal.h"
#include "dispatch.h"
#include "uniforms.h"
struct marshal_cmd_ShaderSource
{
@ -113,3 +114,45 @@ _mesa_marshal_ShaderSource(GLuint shader, GLsizei count,
}
free(length_tmp);
}
void
_mesa_glthread_ProgramChanged(struct gl_context *ctx)
{
struct glthread_state *glthread = &ctx->GLThread;
/* Track the last change. */
p_atomic_set(&glthread->LastProgramChangeBatch, glthread->next);
_mesa_glthread_flush_batch(ctx);
}
void
_mesa_unmarshal_GetActiveUniform(struct gl_context *ctx,
const struct marshal_cmd_GetActiveUniform *cmd)
{
unreachable("never executed");
}
void GLAPIENTRY
_mesa_marshal_GetActiveUniform(GLuint program, GLuint index, GLsizei bufSize,
GLsizei *length, GLint *size, GLenum *type,
GLchar * name)
{
GET_CURRENT_CONTEXT(ctx);
/* Wait for the last glLinkProgram call. */
int batch = p_atomic_read(&ctx->GLThread.LastProgramChangeBatch);
if (batch != -1) {
util_queue_fence_wait(&ctx->GLThread.batches[batch].fence);
assert(p_atomic_read(&ctx->GLThread.LastProgramChangeBatch) == -1);
}
/* We can execute glGetActiveUniform without syncing if we are sync'd to
* the last calls of glLinkProgram and glDeleteProgram because shader
* object IDs and their contents are immutable after those calls and
* also thread-safe because they are shared between contexts.
* glCreateShaderProgram calls glLinkProgram internally and it always
* syncs, so it doesn't need any handling.
*/
_mesa_GetActiveUniform_impl(program, index, bufSize, length, size, type,
name, true);
}