glthread: add ctx->GLThread.draw_always_async to simplify draw checking

This just precomputes 3 terms of the condition to draw asynchronously.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20624>
This commit is contained in:
Marek Olšák 2022-12-26 03:57:20 -05:00
parent 15aaef4d36
commit 3b897719e6
5 changed files with 38 additions and 13 deletions

View file

@ -1156,7 +1156,7 @@
</function> </function>
<function name="Begin" deprecated="3.1" exec="beginend" <function name="Begin" deprecated="3.1" exec="beginend"
marshal_call_after="ctx->GLThread.inside_begin_end = true;"> marshal_call_after="_mesa_glthread_Begin(ctx);">
<param name="mode" type="GLenum"/> <param name="mode" type="GLenum"/>
<glx rop="4"/> <glx rop="4"/>
</function> </function>
@ -1371,7 +1371,7 @@
</function> </function>
<function name="End" deprecated="3.1" exec="beginend" <function name="End" deprecated="3.1" exec="beginend"
marshal_call_after="ctx->GLThread.inside_begin_end = false;"> marshal_call_after="_mesa_glthread_End(ctx);">
<glx rop="23"/> <glx rop="23"/>
</function> </function>

View file

@ -214,6 +214,8 @@ _mesa_glthread_init(struct gl_context *ctx)
/* glthread takes over all L3 pinning */ /* glthread takes over all L3 pinning */
ctx->st->pin_thread_counter = ST_L3_PINNING_DISABLED; ctx->st->pin_thread_counter = ST_L3_PINNING_DISABLED;
_mesa_glthread_update_draw_always_async(ctx);
/* Execute the thread initialization function in the thread. */ /* Execute the thread initialization function in the thread. */
struct util_queue_fence fence; struct util_queue_fence fence;
util_queue_fence_init(&fence); util_queue_fence_init(&fence);

View file

@ -186,6 +186,7 @@ struct glthread_state
/** Whether GLThread is enabled. */ /** Whether GLThread is enabled. */
bool enabled; bool enabled;
bool inside_begin_end; bool inside_begin_end;
bool draw_always_async;
/** Display lists. */ /** Display lists. */
GLenum16 ListMode; /**< Zero if not inside display list, else list mode. */ GLenum16 ListMode; /**< Zero if not inside display list, else list mode. */

View file

@ -467,9 +467,7 @@ draw_arrays(GLenum mode, GLint first, GLsizei count, GLsizei instance_count,
* for possible GL errors. * for possible GL errors.
*/ */
if (!user_buffer_mask || count <= 0 || instance_count <= 0 || if (!user_buffer_mask || count <= 0 || instance_count <= 0 ||
/* This will just generate GL_INVALID_OPERATION, as it should. */ ctx->GLThread.draw_always_async) {
ctx->GLThread.inside_begin_end ||
(!compiled_into_dlist && ctx->GLThread.ListMode)) {
draw_arrays_async(ctx, mode, first, count, instance_count, baseinstance); draw_arrays_async(ctx, mode, first, count, instance_count, baseinstance);
return; return;
} }
@ -543,7 +541,7 @@ _mesa_marshal_MultiDrawArrays(GLenum mode, const GLint *first,
struct glthread_attrib_binding buffers[VERT_ATTRIB_MAX]; struct glthread_attrib_binding buffers[VERT_ATTRIB_MAX];
unsigned user_buffer_mask = unsigned user_buffer_mask =
ctx->API == API_OPENGL_CORE || draw_count <= 0 || ctx->API == API_OPENGL_CORE || draw_count <= 0 ||
ctx->GLThread.inside_begin_end ? 0 : get_user_buffer_mask(ctx); ctx->GLThread.draw_always_async ? 0 : get_user_buffer_mask(ctx);
if (user_buffer_mask) { if (user_buffer_mask) {
unsigned min_index = ~0; unsigned min_index = ~0;
@ -879,12 +877,9 @@ draw_elements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
* This is also an error path. Zero counts should still call the driver * This is also an error path. Zero counts should still call the driver
* for possible GL errors. * for possible GL errors.
*/ */
if (count <= 0 || instance_count <= 0 || if (ctx->GLThread.draw_always_async || count <= 0 || instance_count <= 0 ||
!is_index_type_valid(type) || !is_index_type_valid(type) ||
(!user_buffer_mask && !has_user_indices) || (!user_buffer_mask && !has_user_indices)) {
/* This will just generate GL_INVALID_OPERATION, as it should. */
ctx->GLThread.inside_begin_end ||
(!compiled_into_dlist && ctx->GLThread.ListMode)) {
draw_elements_async(ctx, mode, count, type, indices, instance_count, draw_elements_async(ctx, mode, count, type, indices, instance_count,
basevertex, baseinstance); basevertex, baseinstance);
return; return;
@ -1122,7 +1117,7 @@ _mesa_marshal_MultiDrawElementsBaseVertex(GLenum mode, const GLsizei *count,
* a GL error, we don't upload anything. * a GL error, we don't upload anything.
*/ */
if (draw_count > 0 && is_index_type_valid(type) && if (draw_count > 0 && is_index_type_valid(type) &&
!ctx->GLThread.inside_begin_end) { !ctx->GLThread.draw_always_async) {
user_buffer_mask = ctx->API == API_OPENGL_CORE ? 0 : get_user_buffer_mask(ctx); user_buffer_mask = ctx->API == API_OPENGL_CORE ? 0 : get_user_buffer_mask(ctx);
has_user_indices = vao->CurrentElementBufferName == 0; has_user_indices = vao->CurrentElementBufferName == 0;
} }

View file

@ -142,6 +142,16 @@ _mesa_glthread_has_non_vbo_vertices_or_indices_or_indirect(const struct gl_conte
(vao->UserPointerMask & vao->BufferEnabled)); (vao->UserPointerMask & vao->BufferEnabled));
} }
static inline void
_mesa_glthread_update_draw_always_async(struct gl_context *ctx)
{
/* Executing erroneous cases will just generate GL_INVALID_OPERATION. */
ctx->GLThread.draw_always_async =
ctx->API == API_OPENGL_CORE ||
ctx->GLThread.inside_begin_end ||
ctx->GLThread.ListMode;
}
static inline unsigned static inline unsigned
_mesa_buffer_enum_to_count(GLenum buffer) _mesa_buffer_enum_to_count(GLenum buffer)
{ {
@ -879,8 +889,10 @@ _mesa_glthread_CallLists(struct gl_context *ctx, GLsizei n, GLenum type,
static inline void static inline void
_mesa_glthread_NewList(struct gl_context *ctx, GLuint list, GLenum mode) _mesa_glthread_NewList(struct gl_context *ctx, GLuint list, GLenum mode)
{ {
if (!ctx->GLThread.ListMode) if (!ctx->GLThread.ListMode) {
ctx->GLThread.ListMode = MIN2(mode, 0xffff); ctx->GLThread.ListMode = MIN2(mode, 0xffff);
_mesa_glthread_update_draw_always_async(ctx);
}
} }
static inline void static inline void
@ -890,6 +902,7 @@ _mesa_glthread_EndList(struct gl_context *ctx)
return; return;
ctx->GLThread.ListMode = 0; ctx->GLThread.ListMode = 0;
_mesa_glthread_update_draw_always_async(ctx);
/* Track the last display list change. */ /* Track the last display list change. */
p_atomic_set(&ctx->GLThread.LastDListChangeBatchIndex, ctx->GLThread.next); p_atomic_set(&ctx->GLThread.LastDListChangeBatchIndex, ctx->GLThread.next);
@ -938,4 +951,18 @@ _mesa_glthread_DeleteFramebuffers(struct gl_context *ctx, GLsizei n,
} }
} }
static inline void
_mesa_glthread_Begin(struct gl_context *ctx)
{
ctx->GLThread.inside_begin_end = true;
_mesa_glthread_update_draw_always_async(ctx);
}
static inline void
_mesa_glthread_End(struct gl_context *ctx)
{
ctx->GLThread.inside_begin_end = false;
_mesa_glthread_update_draw_always_async(ctx);
}
#endif /* MARSHAL_H */ #endif /* MARSHAL_H */