From 9bdfee3a470a535ebe31074651fbacf680bcea6a Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 18 Jul 2005 12:31:24 +0000 Subject: Wrap every place that accesses a dispatch table with a macro. A new script- generated file, called src/mesa/glapi/dispatch.h, is added. This file contains three macros for each API function. It contains a GET, a SET, and a CALL. Each of the macros take a pointer to the context and a pointer to the dispatch table. In several threads on mesa3d-dev we discussed replacing _glapi_add_entrypoint with a new function called _glapi_add_dispatch. For this discussion, the important difference between the two is that the caller of _glapi_add_dispatch does *not* know what the dispatch offset will be at compile time. Because of this callers need to track the dispatch offset returned by _glapi_add_dispatch. http://marc.theaimsgroup.com/?t=111947074700001&r=1&w=2 The downside is that driver code then has to access the dispatch table two different ways. It accesses it using structure tags (e.g., exec->Begin) for functions with fixed offsets and via a remap table (e.g., exec[ remap->NewExtensionFunction ]) for functions without fixed offsets. Yuck! Using the macros allows both types of functions to be accessed identically. If a driver needs to set a pointer for Begin, it does 'SET_Begin(ctx, exec, my_begin_function)'. If it needs to set a pointer for NewExtensionFunction, it does 'SET_NewExtensionFunction(ctx, exec, my_NewExtensionFunction_function)'. Furthermore, if at some point in the future a static offset is assigned for NewExtensionFunction, only the macros need to change (instead of every single place that accesses a table for that function). This code differs slightly from the originally posted patches in that the CALL, GET, and SET marcos no longer take a context pointer as a parameter. Brian Paul had suggested that the remap table could be stored as a global since it would be set at CreateScreen time and would be constant for all contexts. This change reflects that feedback. http://marc.theaimsgroup.com/?t=112087194700001&r=1&w=2 --- src/mesa/tnl/t_array_api.c | 13 +++++------ src/mesa/tnl/t_save_api.c | 39 +++++++++++++++++---------------- src/mesa/tnl/t_save_loopback.c | 49 +++++++++++++++++++++--------------------- src/mesa/tnl/t_vtx_api.c | 4 +++- src/mesa/tnl/t_vtx_eval.c | 9 ++++---- 5 files changed, 60 insertions(+), 54 deletions(-) (limited to 'src/mesa/tnl') diff --git a/src/mesa/tnl/t_array_api.c b/src/mesa/tnl/t_array_api.c index c8cd22f0c68..1ad77c5a99b 100644 --- a/src/mesa/tnl/t_array_api.c +++ b/src/mesa/tnl/t_array_api.c @@ -43,6 +43,7 @@ #include "t_save_api.h" #include "t_context.h" #include "t_pipeline.h" +#include "dispatch.h" static void fallback_drawarrays( GLcontext *ctx, GLenum mode, GLint start, GLsizei count ) @@ -52,10 +53,10 @@ static void fallback_drawarrays( GLcontext *ctx, GLenum mode, GLint start, assert(!ctx->CompileFlag); assert(ctx->Driver.CurrentExecPrimitive == GL_POLYGON+1); - GL_CALL(Begin)(mode); + CALL_Begin(GET_DISPATCH(), (mode)); for (i = 0; i < count; i++) - GL_CALL(ArrayElement)( start + i ); - GL_CALL(End)(); + CALL_ArrayElement(GET_DISPATCH(), ( start + i )); + CALL_End(GET_DISPATCH(), ()); } @@ -69,11 +70,11 @@ static void fallback_drawelements( GLcontext *ctx, GLenum mode, GLsizei count, /* Here, indices will already reflect the buffer object if active */ - GL_CALL(Begin)(mode); + CALL_Begin(GET_DISPATCH(), (mode)); for (i = 0 ; i < count ; i++) { - GL_CALL(ArrayElement)( indices[i] ); + CALL_ArrayElement(GET_DISPATCH(), ( indices[i] )); } - GL_CALL(End)(); + CALL_End(GET_DISPATCH(), ()); } diff --git a/src/mesa/tnl/t_save_api.c b/src/mesa/tnl/t_save_api.c index dcc8850bec0..b3637cf8d9b 100644 --- a/src/mesa/tnl/t_save_api.c +++ b/src/mesa/tnl/t_save_api.c @@ -77,6 +77,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #include "api_arrayelt.h" #include "vtxfmt.h" #include "t_save_api.h" +#include "dispatch.h" /* * NOTE: Old 'parity' issue is gone, but copying can still be @@ -1212,56 +1213,56 @@ static void GLAPIENTRY _save_EvalCoord1f( GLfloat u ) { GET_CURRENT_CONTEXT(ctx); FALLBACK(ctx); - ctx->Save->EvalCoord1f( u ); + CALL_EvalCoord1f(ctx->Save, ( u )); } static void GLAPIENTRY _save_EvalCoord1fv( const GLfloat *v ) { GET_CURRENT_CONTEXT(ctx); FALLBACK(ctx); - ctx->Save->EvalCoord1fv( v ); + CALL_EvalCoord1fv(ctx->Save, ( v )); } static void GLAPIENTRY _save_EvalCoord2f( GLfloat u, GLfloat v ) { GET_CURRENT_CONTEXT(ctx); FALLBACK(ctx); - ctx->Save->EvalCoord2f( u, v ); + CALL_EvalCoord2f(ctx->Save, ( u, v )); } static void GLAPIENTRY _save_EvalCoord2fv( const GLfloat *v ) { GET_CURRENT_CONTEXT(ctx); FALLBACK(ctx); - ctx->Save->EvalCoord2fv( v ); + CALL_EvalCoord2fv(ctx->Save, ( v )); } static void GLAPIENTRY _save_EvalPoint1( GLint i ) { GET_CURRENT_CONTEXT(ctx); FALLBACK(ctx); - ctx->Save->EvalPoint1( i ); + CALL_EvalPoint1(ctx->Save, ( i )); } static void GLAPIENTRY _save_EvalPoint2( GLint i, GLint j ) { GET_CURRENT_CONTEXT(ctx); FALLBACK(ctx); - ctx->Save->EvalPoint2( i, j ); + CALL_EvalPoint2(ctx->Save, ( i, j )); } static void GLAPIENTRY _save_CallList( GLuint l ) { GET_CURRENT_CONTEXT(ctx); FALLBACK(ctx); - ctx->Save->CallList( l ); + CALL_CallList(ctx->Save, ( l )); } static void GLAPIENTRY _save_CallLists( GLsizei n, GLenum type, const GLvoid *v ) { GET_CURRENT_CONTEXT(ctx); FALLBACK(ctx); - ctx->Save->CallLists( n, type, v ); + CALL_CallLists(ctx->Save, ( n, type, v )); } @@ -1383,11 +1384,11 @@ static void GLAPIENTRY _save_OBE_Rectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfl { GET_CURRENT_CONTEXT(ctx); _save_NotifyBegin( ctx, GL_QUADS | PRIM_WEAK ); - GL_CALL(Vertex2f)( x1, y1 ); - GL_CALL(Vertex2f)( x2, y1 ); - GL_CALL(Vertex2f)( x2, y2 ); - GL_CALL(Vertex2f)( x1, y2 ); - GL_CALL(End)(); + CALL_Vertex2f(GET_DISPATCH(), ( x1, y1 )); + CALL_Vertex2f(GET_DISPATCH(), ( x2, y1 )); + CALL_Vertex2f(GET_DISPATCH(), ( x2, y2 )); + CALL_Vertex2f(GET_DISPATCH(), ( x1, y2 )); + CALL_End(GET_DISPATCH(), ()); } @@ -1401,8 +1402,8 @@ static void GLAPIENTRY _save_OBE_DrawArrays(GLenum mode, GLint start, GLsizei co _save_NotifyBegin( ctx, mode | PRIM_WEAK ); for (i = 0; i < count; i++) - GL_CALL(ArrayElement)(start + i); - GL_CALL(End)(); + CALL_ArrayElement(GET_DISPATCH(), (start + i)); + CALL_End(GET_DISPATCH(), ()); } @@ -1420,22 +1421,22 @@ static void GLAPIENTRY _save_OBE_DrawElements(GLenum mode, GLsizei count, GLenum switch (type) { case GL_UNSIGNED_BYTE: for (i = 0 ; i < count ; i++) - GL_CALL(ArrayElement)( ((GLubyte *)indices)[i] ); + CALL_ArrayElement(GET_DISPATCH(), ( ((GLubyte *)indices)[i] )); break; case GL_UNSIGNED_SHORT: for (i = 0 ; i < count ; i++) - GL_CALL(ArrayElement)( ((GLushort *)indices)[i] ); + CALL_ArrayElement(GET_DISPATCH(), ( ((GLushort *)indices)[i] )); break; case GL_UNSIGNED_INT: for (i = 0 ; i < count ; i++) - GL_CALL(ArrayElement)( ((GLuint *)indices)[i] ); + CALL_ArrayElement(GET_DISPATCH(), ( ((GLuint *)indices)[i] )); break; default: _mesa_error( ctx, GL_INVALID_ENUM, "glDrawElements(type)" ); break; } - GL_CALL(End)(); + CALL_End(GET_DISPATCH(), ()); } static void GLAPIENTRY _save_OBE_DrawRangeElements(GLenum mode, diff --git a/src/mesa/tnl/t_save_loopback.c b/src/mesa/tnl/t_save_loopback.c index 2dae9c60932..7b2e4a43203 100644 --- a/src/mesa/tnl/t_save_loopback.c +++ b/src/mesa/tnl/t_save_loopback.c @@ -35,6 +35,7 @@ #include "mtypes.h" #include "t_context.h" #include "t_save_api.h" +#include "dispatch.h" /* If someone compiles a display list like: * glBegin(Triangles) @@ -70,22 +71,22 @@ typedef void (*attr_func)( GLcontext *ctx, GLint target, const GLfloat * ); /* Wrapper functions in case glVertexAttrib*fvNV doesn't exist */ static void VertexAttrib1fvNV(GLcontext *ctx, GLint target, const GLfloat *v) { - ctx->Exec->VertexAttrib1fvNV(target, v); + CALL_VertexAttrib1fvNV(ctx->Exec, (target, v)); } static void VertexAttrib2fvNV(GLcontext *ctx, GLint target, const GLfloat *v) { - ctx->Exec->VertexAttrib2fvNV(target, v); + CALL_VertexAttrib2fvNV(ctx->Exec, (target, v)); } static void VertexAttrib3fvNV(GLcontext *ctx, GLint target, const GLfloat *v) { - ctx->Exec->VertexAttrib3fvNV(target, v); + CALL_VertexAttrib3fvNV(ctx->Exec, (target, v)); } static void VertexAttrib4fvNV(GLcontext *ctx, GLint target, const GLfloat *v) { - ctx->Exec->VertexAttrib4fvNV(target, v); + CALL_VertexAttrib4fvNV(ctx->Exec, (target, v)); } static attr_func vert_attrfunc[4] = { @@ -98,22 +99,22 @@ static attr_func vert_attrfunc[4] = { static void VertexAttrib1fvARB(GLcontext *ctx, GLint target, const GLfloat *v) { - ctx->Exec->VertexAttrib1fvARB(target, v); + CALL_VertexAttrib1fvARB(ctx->Exec, (target, v)); } static void VertexAttrib2fvARB(GLcontext *ctx, GLint target, const GLfloat *v) { - ctx->Exec->VertexAttrib2fvARB(target, v); + CALL_VertexAttrib2fvARB(ctx->Exec, (target, v)); } static void VertexAttrib3fvARB(GLcontext *ctx, GLint target, const GLfloat *v) { - ctx->Exec->VertexAttrib3fvARB(target, v); + CALL_VertexAttrib3fvARB(ctx->Exec, (target, v)); } static void VertexAttrib4fvARB(GLcontext *ctx, GLint target, const GLfloat *v) { - ctx->Exec->VertexAttrib4fvARB(target, v); + CALL_VertexAttrib4fvARB(ctx->Exec, (target, v)); } static attr_func vert_attrfunc_arb[4] = { @@ -133,10 +134,10 @@ static void mat_attr1fv( GLcontext *ctx, GLint target, const GLfloat *v ) { switch (target) { case _TNL_ATTRIB_MAT_FRONT_SHININESS: - ctx->Exec->Materialfv( GL_FRONT, GL_SHININESS, v ); + CALL_Materialfv(ctx->Exec, ( GL_FRONT, GL_SHININESS, v )); break; case _TNL_ATTRIB_MAT_BACK_SHININESS: - ctx->Exec->Materialfv( GL_BACK, GL_SHININESS, v ); + CALL_Materialfv(ctx->Exec, ( GL_BACK, GL_SHININESS, v )); break; } } @@ -146,10 +147,10 @@ static void mat_attr3fv( GLcontext *ctx, GLint target, const GLfloat *v ) { switch (target) { case _TNL_ATTRIB_MAT_FRONT_INDEXES: - ctx->Exec->Materialfv( GL_FRONT, GL_COLOR_INDEXES, v ); + CALL_Materialfv(ctx->Exec, ( GL_FRONT, GL_COLOR_INDEXES, v )); break; case _TNL_ATTRIB_MAT_BACK_INDEXES: - ctx->Exec->Materialfv( GL_BACK, GL_COLOR_INDEXES, v ); + CALL_Materialfv(ctx->Exec, ( GL_BACK, GL_COLOR_INDEXES, v )); break; } } @@ -159,28 +160,28 @@ static void mat_attr4fv( GLcontext *ctx, GLint target, const GLfloat *v ) { switch (target) { case _TNL_ATTRIB_MAT_FRONT_EMISSION: - ctx->Exec->Materialfv( GL_FRONT, GL_EMISSION, v ); + CALL_Materialfv(ctx->Exec, ( GL_FRONT, GL_EMISSION, v )); break; case _TNL_ATTRIB_MAT_BACK_EMISSION: - ctx->Exec->Materialfv( GL_BACK, GL_EMISSION, v ); + CALL_Materialfv(ctx->Exec, ( GL_BACK, GL_EMISSION, v )); break; case _TNL_ATTRIB_MAT_FRONT_AMBIENT: - ctx->Exec->Materialfv( GL_FRONT, GL_AMBIENT, v ); + CALL_Materialfv(ctx->Exec, ( GL_FRONT, GL_AMBIENT, v )); break; case _TNL_ATTRIB_MAT_BACK_AMBIENT: - ctx->Exec->Materialfv( GL_BACK, GL_AMBIENT, v ); + CALL_Materialfv(ctx->Exec, ( GL_BACK, GL_AMBIENT, v )); break; case _TNL_ATTRIB_MAT_FRONT_DIFFUSE: - ctx->Exec->Materialfv( GL_FRONT, GL_DIFFUSE, v ); + CALL_Materialfv(ctx->Exec, ( GL_FRONT, GL_DIFFUSE, v )); break; case _TNL_ATTRIB_MAT_BACK_DIFFUSE: - ctx->Exec->Materialfv( GL_BACK, GL_DIFFUSE, v ); + CALL_Materialfv(ctx->Exec, ( GL_BACK, GL_DIFFUSE, v )); break; case _TNL_ATTRIB_MAT_FRONT_SPECULAR: - ctx->Exec->Materialfv( GL_FRONT, GL_SPECULAR, v ); + CALL_Materialfv(ctx->Exec, ( GL_FRONT, GL_SPECULAR, v )); break; case _TNL_ATTRIB_MAT_BACK_SPECULAR: - ctx->Exec->Materialfv( GL_BACK, GL_SPECULAR, v ); + CALL_Materialfv(ctx->Exec, ( GL_BACK, GL_SPECULAR, v )); break; } } @@ -197,13 +198,13 @@ static attr_func mat_attrfunc[4] = { static void index_attr1fv(GLcontext *ctx, GLint target, const GLfloat *v) { (void) target; - ctx->Exec->Indexf(v[0]); + CALL_Indexf(ctx->Exec, (v[0])); } static void edgeflag_attr1fv(GLcontext *ctx, GLint target, const GLfloat *v) { (void) target; - ctx->Exec->EdgeFlag((GLboolean)(v[0] == 1.0)); + CALL_EdgeFlag(ctx->Exec, ((GLboolean)(v[0] == 1.0))); } struct loopback_attr { @@ -228,7 +229,7 @@ static void loopback_prim( GLcontext *ctx, GLuint k; if (prim->mode & PRIM_BEGIN) { - GL_CALL(Begin)( prim->mode & PRIM_MODE_MASK ); + CALL_Begin(GET_DISPATCH(), ( prim->mode & PRIM_MODE_MASK )); } else { assert(i == 0); @@ -253,7 +254,7 @@ static void loopback_prim( GLcontext *ctx, } if (prim->mode & PRIM_END) { - GL_CALL(End)(); + CALL_End(GET_DISPATCH(), ()); } else { assert (i == list->prim_count-1); diff --git a/src/mesa/tnl/t_vtx_api.c b/src/mesa/tnl/t_vtx_api.c index 129b19c5f96..fa9e04ad336 100644 --- a/src/mesa/tnl/t_vtx_api.c +++ b/src/mesa/tnl/t_vtx_api.c @@ -43,6 +43,8 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #include "t_vtx_api.h" #include "simple_list.h" +#include "dispatch.h" + static void reset_attrfv( TNLcontext *tnl ); static tnl_attrfv_func choose[_TNL_MAX_ATTR_CODEGEN+1][4]; /* +1 for ERROR_ATTRIB */ @@ -749,7 +751,7 @@ static void GLAPIENTRY _tnl_Begin( GLenum mode ) if (!(tnl->Driver.NotifyBegin && tnl->Driver.NotifyBegin( ctx, mode ))) - ctx->Exec->Begin(mode); + CALL_Begin(ctx->Exec, (mode)); return; } diff --git a/src/mesa/tnl/t_vtx_eval.c b/src/mesa/tnl/t_vtx_eval.c index 3b09bd29f59..d948e700b0d 100644 --- a/src/mesa/tnl/t_vtx_eval.c +++ b/src/mesa/tnl/t_vtx_eval.c @@ -31,6 +31,7 @@ #include "macros.h" #include "math/m_eval.h" #include "t_vtx_api.h" +#include "dispatch.h" static void clear_active_eval1( TNLcontext *tnl, GLuint attr ) @@ -165,9 +166,9 @@ void _tnl_do_EvalCoord1f(GLcontext* ctx, GLfloat u) map->Order); if (tnl->vtx.eval.map1[0].sz == 4) - GL_CALL(Vertex4fv)( vertex ); + CALL_Vertex4fv(GET_DISPATCH(), ( vertex )); else - GL_CALL(Vertex3fv)( vertex ); + CALL_Vertex3fv(GET_DISPATCH(), ( vertex )); } } @@ -244,9 +245,9 @@ void _tnl_do_EvalCoord2f( GLcontext* ctx, GLfloat u, GLfloat v ) } if (tnl->vtx.attrsz[0] == 4) - GL_CALL(Vertex4fv)( vertex ); + CALL_Vertex4fv(GET_DISPATCH(), ( vertex )); else - GL_CALL(Vertex3fv)( vertex ); + CALL_Vertex3fv(GET_DISPATCH(), ( vertex )); } } -- cgit v1.2.3