From acfefc1f14792ae632c8b764b6ab99cf9cd36b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sun, 7 Jan 2024 13:43:26 -0500 Subject: [PATCH] glthread: add no_error variants of glDrawArrays* The main motivation is that no_error allows us to drop count==0 draws at the beginning of the marshal function, instead of forwarding them to the frontend thread. Such draws are plentiful with Viewperf. Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mapi/glapi/gen/ARB_base_instance.xml | 2 +- src/mapi/glapi/gen/ARB_draw_instanced.xml | 3 +- src/mapi/glapi/gen/gl_API.xml | 2 +- src/mesa/main/glthread_draw.c | 48 ++++++++++++++++++----- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/mapi/glapi/gen/ARB_base_instance.xml b/src/mapi/glapi/gen/ARB_base_instance.xml index d6c17c155b9..768b1447870 100644 --- a/src/mapi/glapi/gen/ARB_base_instance.xml +++ b/src/mapi/glapi/gen/ARB_base_instance.xml @@ -9,7 +9,7 @@ + marshal_struct="public" marshal_no_error="true"> diff --git a/src/mapi/glapi/gen/ARB_draw_instanced.xml b/src/mapi/glapi/gen/ARB_draw_instanced.xml index 5418fd62917..cadf9f53846 100644 --- a/src/mapi/glapi/gen/ARB_draw_instanced.xml +++ b/src/mapi/glapi/gen/ARB_draw_instanced.xml @@ -8,7 +8,8 @@ - + diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml index 6f5d68f6cf3..ca141aa2bfc 100644 --- a/src/mapi/glapi/gen/gl_API.xml +++ b/src/mapi/glapi/gen/gl_API.xml @@ -3211,7 +3211,7 @@ + marshal_struct="public" marshal_no_error="true"> diff --git a/src/mesa/main/glthread_draw.c b/src/mesa/main/glthread_draw.c index 99946dd30a2..8c48aef859d 100644 --- a/src/mesa/main/glthread_draw.c +++ b/src/mesa/main/glthread_draw.c @@ -406,10 +406,16 @@ get_user_buffer_mask(struct gl_context *ctx) static ALWAYS_INLINE void draw_arrays(GLuint drawid, GLenum mode, GLint first, GLsizei count, GLsizei instance_count, GLuint baseinstance, - bool compiled_into_dlist) + bool compiled_into_dlist, bool no_error) { GET_CURRENT_CONTEXT(ctx); + /* The main benefit of no_error is that we can discard no-op draws + * immediately. + */ + if (no_error && (count <= 0 || instance_count <= 0)) + return; + if (unlikely(compiled_into_dlist && ctx->GLThread.ListMode)) { _mesa_glthread_finish_before(ctx, "DrawArrays"); /* Use the function that's compiled into a display list. */ @@ -425,11 +431,12 @@ draw_arrays(GLuint drawid, GLenum mode, GLint first, GLsizei count, * This is also an error path. Zero counts should still call the driver * for possible GL errors. */ - if (!user_buffer_mask || count <= 0 || instance_count <= 0 || - /* This will just generate GL_INVALID_OPERATION, as it should. */ - ctx->GLThread.inside_begin_end || - ctx->Dispatch.Current == ctx->Dispatch.ContextLost || - ctx->GLThread.ListMode) { + if (!user_buffer_mask || + (!no_error && + (count <= 0 || instance_count <= 0 || /* GL_INVALID_VALUE / no-op */ + ctx->GLThread.inside_begin_end || /* GL_INVALID_OPERATION */ + ctx->Dispatch.Current == ctx->Dispatch.ContextLost || /* GL_INVALID_OPERATION */ + ctx->GLThread.ListMode))) { /* GL_INVALID_OPERATION */ if (instance_count == 1 && baseinstance == 0 && drawid == 0) { int cmd_size = sizeof(struct marshal_cmd_DrawArrays); struct marshal_cmd_DrawArrays *cmd = @@ -1269,7 +1276,7 @@ lower_draw_arrays_indirect(struct gl_context *ctx, GLenum mode, params[i * stride / 4 + 2], params[i * stride / 4 + 0], params[i * stride / 4 + 1], - params[i * stride / 4 + 3], false); + params[i * stride / 4 + 3], false, false); } unmap_draw_indirect_params(ctx); @@ -1600,14 +1607,27 @@ _mesa_marshal_MultiDrawElementsIndirectCountARB(GLenum mode, GLenum type, void GLAPIENTRY _mesa_marshal_DrawArrays(GLenum mode, GLint first, GLsizei count) { - draw_arrays(0, mode, first, count, 1, 0, true); + draw_arrays(0, mode, first, count, 1, 0, true, false); +} + +void GLAPIENTRY +_mesa_marshal_DrawArrays_no_error(GLenum mode, GLint first, GLsizei count) +{ + draw_arrays(0, mode, first, count, 1, 0, true, true); } void GLAPIENTRY _mesa_marshal_DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instance_count) { - draw_arrays(0, mode, first, count, instance_count, 0, false); + draw_arrays(0, mode, first, count, instance_count, 0, false, false); +} + +void GLAPIENTRY +_mesa_marshal_DrawArraysInstanced_no_error(GLenum mode, GLint first, GLsizei count, + GLsizei instance_count) +{ + draw_arrays(0, mode, first, count, instance_count, 0, false, true); } void GLAPIENTRY @@ -1615,7 +1635,15 @@ _mesa_marshal_DrawArraysInstancedBaseInstance(GLenum mode, GLint first, GLsizei count, GLsizei instance_count, GLuint baseinstance) { - draw_arrays(0, mode, first, count, instance_count, baseinstance, false); + draw_arrays(0, mode, first, count, instance_count, baseinstance, false, false); +} + +void GLAPIENTRY +_mesa_marshal_DrawArraysInstancedBaseInstance_no_error(GLenum mode, GLint first, + GLsizei count, GLsizei instance_count, + GLuint baseinstance) +{ + draw_arrays(0, mode, first, count, instance_count, baseinstance, false, true); } void GLAPIENTRY