From c41ac0682ef6bb4945677265ee612e24b78431ca Mon Sep 17 00:00:00 2001 From: Qiang Yu Date: Fri, 13 May 2022 17:34:14 +0800 Subject: [PATCH] mesa: add HWSelectModeBeginEnd dispatch table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Used when in glBegin/End section and HW GL_RENDER mode. Reviewed-by: Marek Olšák Signed-off-by: Qiang Yu Part-of: --- src/mesa/main/context.c | 1 + src/mesa/main/feedback.c | 9 +++++++++ src/mesa/main/mtypes.h | 5 +++++ src/mesa/vbo/vbo.h | 3 +++ src/mesa/vbo/vbo_exec_api.c | 40 ++++++++++++++++++++++++++++++++++--- src/mesa/vbo/vbo_noop.c | 5 +++++ 6 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 6685c19c657..8a8193c521d 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -1168,6 +1168,7 @@ _mesa_free_context_data(struct gl_context *ctx, bool destroy_debug_output) free(ctx->Save); free(ctx->ContextLost); free(ctx->MarshalExec); + free(ctx->HWSelectModeBeginEnd); /* Shared context state (display lists, textures, etc) */ _mesa_reference_shared_state(ctx, &ctx->Shared, NULL); diff --git a/src/mesa/main/feedback.c b/src/mesa/main/feedback.c index 34e6a82aea6..e6d925b274d 100644 --- a/src/mesa/main/feedback.c +++ b/src/mesa/main/feedback.c @@ -230,6 +230,15 @@ alloc_select_resource(struct gl_context *ctx) if (!ctx->Const.HardwareAcceleratedSelect) return; + if (!ctx->HWSelectModeBeginEnd) { + ctx->HWSelectModeBeginEnd = _mesa_alloc_dispatch_table(false); + if (!ctx->HWSelectModeBeginEnd) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "Cannot allocate HWSelectModeBeginEnd"); + return; + } + vbo_install_hw_select_begin_end(ctx); + } + if (!s->SaveBuffer) { s->SaveBuffer = malloc(NAME_STACK_BUFFER_SIZE); if (!s->SaveBuffer) { diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 5db4417f665..4fa389d7e00 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -3255,6 +3255,11 @@ struct gl_context * display list). Only valid functions between those two are set. */ struct _glapi_table *BeginEnd; + /** + * Same as BeginEnd except vertex postion set functions. Used when + * HW GL_SELECT mode instead of BeginEnd. + */ + struct _glapi_table *HWSelectModeBeginEnd; /** * Dispatch table for when a graphics reset has happened. */ diff --git a/src/mesa/vbo/vbo.h b/src/mesa/vbo/vbo.h index 2fcbfc577b1..9e47b49d216 100644 --- a/src/mesa/vbo/vbo.h +++ b/src/mesa/vbo/vbo.h @@ -190,6 +190,9 @@ _vbo_DestroyContext(struct gl_context *ctx); void vbo_install_exec_vtxfmt(struct gl_context *ctx); +void +vbo_install_hw_select_begin_end(struct gl_context *ctx); + void vbo_install_exec_vtxfmt_noop(struct gl_context *ctx); diff --git a/src/mesa/vbo/vbo_exec_api.c b/src/mesa/vbo/vbo_exec_api.c index 806cd6c60f8..f7ee3baa49b 100644 --- a/src/mesa/vbo/vbo_exec_api.c +++ b/src/mesa/vbo/vbo_exec_api.c @@ -477,7 +477,7 @@ is_vertex_position(const struct gl_context *ctx, GLuint index) * \param C cast type (uint32_t or uint64_t) * \param V0, V1, v2, V3 attribute value */ -#define ATTR_UNION(A, N, T, C, V0, V1, V2, V3) \ +#define ATTR_UNION_BASE(A, N, T, C, V0, V1, V2, V3) \ do { \ struct vbo_exec_context *exec = &vbo_context(ctx)->exec; \ int sz = (sizeof(C) / sizeof(GLfloat)); \ @@ -563,6 +563,9 @@ do { \ #define TAG(x) _mesa_##x #define SUPPRESS_STATIC +#define ATTR_UNION(A, N, T, C, V0, V1, V2, V3) \ + ATTR_UNION_BASE(A, N, T, C, V0, V1, V2, V3) + #include "vbo_attrib_tmp.h" @@ -842,7 +845,8 @@ _mesa_Begin(GLenum mode) ctx->Driver.CurrentExecPrimitive = mode; - ctx->Exec = ctx->BeginEnd; + ctx->Exec = _mesa_hw_select_enabled(ctx) ? + ctx->HWSelectModeBeginEnd : ctx->BeginEnd; /* We may have been called from a display list, in which case we should * leave dlist.c's dispatch table in place. @@ -908,7 +912,8 @@ _mesa_End(void) if (ctx->GLThread.enabled) { ctx->CurrentServerDispatch = ctx->Exec; - } else if (ctx->CurrentClientDispatch == ctx->BeginEnd) { + } else if (ctx->CurrentClientDispatch == ctx->BeginEnd || + ctx->CurrentClientDispatch == ctx->HWSelectModeBeginEnd) { ctx->CurrentClientDispatch = ctx->CurrentServerDispatch = ctx->Exec; _glapi_set_dispatch(ctx->CurrentClientDispatch); } @@ -1215,3 +1220,32 @@ _es_Materialf(GLenum face, GLenum pname, GLfloat param) p[1] = p[2] = p[3] = 0.0F; _mesa_Materialfv(face, pname, p); } + +#undef TAG +#undef SUPPRESS_STATIC +#define TAG(x) _hw_select_##x +/* filter out none vertex api */ +#define HW_SELECT_MODE + +#undef ATTR_UNION +#define ATTR_UNION(A, N, T, C, V0, V1, V2, V3) \ + do { \ + if ((A) == 0) { \ + /* TODO: insert name stack attr. */ \ + } \ + ATTR_UNION_BASE(A, N, T, C, V0, V1, V2, V3); \ + } while (0) + +#include "vbo_attrib_tmp.h" + +void +vbo_install_hw_select_begin_end(struct gl_context *ctx) +{ + int numEntries = MAX2(_gloffset_COUNT, _glapi_get_dispatch_table_size()); + memcpy(ctx->HWSelectModeBeginEnd, ctx->BeginEnd, numEntries * sizeof(_glapi_proc)); + +#undef NAME +#define NAME(x) _hw_select_##x + struct _glapi_table *tab = ctx->HWSelectModeBeginEnd; + #include "api_hw_select_init.h" +} diff --git a/src/mesa/vbo/vbo_noop.c b/src/mesa/vbo/vbo_noop.c index f4b6120d096..9ed773d3bc5 100644 --- a/src/mesa/vbo/vbo_noop.c +++ b/src/mesa/vbo/vbo_noop.c @@ -134,6 +134,11 @@ vbo_install_exec_vtxfmt_noop(struct gl_context *ctx) tab = ctx->BeginEnd; #include "api_vtxfmt_init.h" } + + if (ctx->HWSelectModeBeginEnd) { + tab = ctx->HWSelectModeBeginEnd; + #include "api_vtxfmt_init.h" + } }