diff options
-rw-r--r-- | src/mesa/main/api_exec.c | 1 | ||||
-rw-r--r-- | src/mesa/main/api_noop.c | 15 | ||||
-rw-r--r-- | src/mesa/main/api_noop.h | 4 | ||||
-rw-r--r-- | src/mesa/main/dd.h | 6 | ||||
-rw-r--r-- | src/mesa/main/dlist.c | 14 | ||||
-rw-r--r-- | src/mesa/main/varray.c | 18 | ||||
-rw-r--r-- | src/mesa/main/vtxfmt.c | 1 | ||||
-rw-r--r-- | src/mesa/main/vtxfmt_tmp.h | 12 | ||||
-rw-r--r-- | src/mesa/vbo/vbo_exec_array.c | 157 | ||||
-rw-r--r-- | src/mesa/vbo/vbo_save_api.c | 5 |
10 files changed, 200 insertions, 33 deletions
diff --git a/src/mesa/main/api_exec.c b/src/mesa/main/api_exec.c index 199550b35d3..cbf48615bf4 100644 --- a/src/mesa/main/api_exec.c +++ b/src/mesa/main/api_exec.c @@ -529,7 +529,6 @@ _mesa_init_exec_table(struct _glapi_table *exec) /* 148. GL_EXT_multi_draw_arrays */ #if _HAVE_FULL_GL SET_MultiDrawArraysEXT(exec, _mesa_MultiDrawArraysEXT); - SET_MultiDrawElementsEXT(exec, _mesa_MultiDrawElementsEXT); #endif /* 173. GL_INGR_blend_func_separate */ diff --git a/src/mesa/main/api_noop.c b/src/mesa/main/api_noop.c index 66f9c4e6bdb..09ba7e50622 100644 --- a/src/mesa/main/api_noop.c +++ b/src/mesa/main/api_noop.c @@ -772,6 +772,20 @@ _mesa_noop_DrawRangeElements(GLenum mode, CALL_DrawElements(GET_DISPATCH(), (mode, count, type, indices)); } +/* GL_EXT_multi_draw_arrays */ +void GLAPIENTRY +_mesa_noop_MultiDrawElements(GLenum mode, const GLsizei *count, GLenum type, + const GLvoid **indices, GLsizei primcount) +{ + GLsizei i; + + for (i = 0; i < primcount; i++) { + if (count[i] > 0) { + CALL_DrawElements(GET_DISPATCH(), (mode, count[i], type, indices[i])); + } + } +} + /* * Eval Mesh */ @@ -980,6 +994,7 @@ _mesa_noop_vtxfmt_init( GLvertexformat *vfmt ) vfmt->DrawArrays = _mesa_noop_DrawArrays; vfmt->DrawElements = _mesa_noop_DrawElements; vfmt->DrawRangeElements = _mesa_noop_DrawRangeElements; + vfmt->MultiDrawElementsEXT = _mesa_noop_MultiDrawElements; vfmt->EvalMesh1 = _mesa_noop_EvalMesh1; vfmt->EvalMesh2 = _mesa_noop_EvalMesh2; } diff --git a/src/mesa/main/api_noop.h b/src/mesa/main/api_noop.h index 8bf46608001..a7956d00b3b 100644 --- a/src/mesa/main/api_noop.h +++ b/src/mesa/main/api_noop.h @@ -40,6 +40,10 @@ _mesa_noop_EvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2); extern void GLAPIENTRY _mesa_noop_Materialfv(GLenum face, GLenum pname, const GLfloat *param); +extern void GLAPIENTRY +_mesa_noop_MultiDrawElements(GLenum mode, const GLsizei *count, GLenum type, + const GLvoid **indices, GLsizei primcount); + extern void _mesa_noop_vtxfmt_init(GLvertexformat *vfmt); diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h index 1d92e510a4d..f02e868d4a7 100644 --- a/src/mesa/main/dd.h +++ b/src/mesa/main/dd.h @@ -1150,7 +1150,11 @@ typedef struct { void (GLAPIENTRYP DrawRangeElements)( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices ); - /*@}*/ + void (GLAPIENTRYP MultiDrawElementsEXT)( GLenum mode, const GLsizei *count, + GLenum type, + const GLvoid **indices, + GLsizei primcount); + /*@}*/ /** * \name Eval diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c index 9b68b3e1162..8cff9ea64a0 100644 --- a/src/mesa/main/dlist.c +++ b/src/mesa/main/dlist.c @@ -7751,18 +7751,6 @@ exec_MultiDrawArraysEXT(GLenum mode, GLint * first, CALL_MultiDrawArraysEXT(ctx->Exec, (mode, first, count, primcount)); } -/* GL_EXT_multi_draw_arrays */ -static void GLAPIENTRY -exec_MultiDrawElementsEXT(GLenum mode, const GLsizei * count, - GLenum type, const GLvoid ** indices, - GLsizei primcount) -{ - GET_CURRENT_CONTEXT(ctx); - FLUSH_VERTICES(ctx, 0); - CALL_MultiDrawElementsEXT(ctx->Exec, - (mode, count, type, indices, primcount)); -} - /* GL_IBM_multimode_draw_arrays */ static void GLAPIENTRY exec_MultiModeDrawArraysIBM(const GLenum * mode, const GLint * first, @@ -8108,7 +8096,6 @@ _mesa_init_dlist_table(struct _glapi_table *table) /* 148. GL_EXT_multi_draw_arrays */ SET_MultiDrawArraysEXT(table, exec_MultiDrawArraysEXT); - SET_MultiDrawElementsEXT(table, exec_MultiDrawElementsEXT); /* 149. GL_EXT_fog_coord */ SET_FogCoordPointerEXT(table, exec_FogCoordPointerEXT); @@ -8723,6 +8710,7 @@ _mesa_save_vtxfmt_init(GLvertexformat * vfmt) vfmt->DrawArrays = 0; vfmt->DrawElements = 0; vfmt->DrawRangeElements = 0; + vfmt->MultiDrawElemementsEXT = 0; #endif } diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c index be1c03cec2a..6cd2a2f4f64 100644 --- a/src/mesa/main/varray.c +++ b/src/mesa/main/varray.c @@ -1038,24 +1038,6 @@ _mesa_MultiDrawArraysEXT( GLenum mode, GLint *first, } -/* GL_EXT_multi_draw_arrays */ -void GLAPIENTRY -_mesa_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type, - const GLvoid **indices, GLsizei primcount ) -{ - GET_CURRENT_CONTEXT(ctx); - GLint i; - - ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); - - for (i = 0; i < primcount; i++) { - if (count[i] > 0) { - CALL_DrawElements(ctx->Exec, (mode, count[i], type, indices[i])); - } - } -} - - /* GL_IBM_multimode_draw_arrays */ void GLAPIENTRY _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first, diff --git a/src/mesa/main/vtxfmt.c b/src/mesa/main/vtxfmt.c index 1f807dc3dc3..8d6f560a80a 100644 --- a/src/mesa/main/vtxfmt.c +++ b/src/mesa/main/vtxfmt.c @@ -133,6 +133,7 @@ install_vtxfmt( struct _glapi_table *tab, const GLvertexformat *vfmt ) SET_DrawArrays(tab, vfmt->DrawArrays); SET_DrawElements(tab, vfmt->DrawElements); SET_DrawRangeElements(tab, vfmt->DrawRangeElements); + SET_MultiDrawElementsEXT(tab, vfmt->MultiDrawElementsEXT); SET_EvalMesh1(tab, vfmt->EvalMesh1); SET_EvalMesh2(tab, vfmt->EvalMesh2); ASSERT(tab->EvalMesh2); diff --git a/src/mesa/main/vtxfmt_tmp.h b/src/mesa/main/vtxfmt_tmp.h index 6f5d01e40f2..1308d0aa466 100644 --- a/src/mesa/main/vtxfmt_tmp.h +++ b/src/mesa/main/vtxfmt_tmp.h @@ -335,6 +335,17 @@ static void GLAPIENTRY TAG(DrawElements)( GLenum mode, GLsizei count, GLenum typ CALL_DrawElements(GET_DISPATCH(), ( mode, count, type, indices )); } +static void GLAPIENTRY TAG(MultiDrawElementsEXT)( GLenum mode, + const GLsizei *count, + GLenum type, + const GLvoid **indices, + GLsizei primcount) +{ + PRE_LOOPBACK( MultiDrawElementsEXT ); + CALL_MultiDrawElementsEXT(GET_DISPATCH(), ( mode, count, type, indices, + primcount )); +} + static void GLAPIENTRY TAG(DrawRangeElements)( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices ) @@ -522,6 +533,7 @@ static GLvertexformat TAG(vtxfmt) = { TAG(DrawArrays), TAG(DrawElements), TAG(DrawRangeElements), + TAG(MultiDrawElementsEXT), TAG(EvalMesh1), TAG(EvalMesh2) }; diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c index 4148469ef45..12911f5750c 100644 --- a/src/mesa/vbo/vbo_exec_array.c +++ b/src/mesa/vbo/vbo_exec_array.c @@ -33,6 +33,7 @@ #include "main/api_noop.h" #include "main/varray.h" #include "main/bufferobj.h" +#include "main/macros.h" #include "glapi/dispatch.h" #include "vbo_context.h" @@ -721,6 +722,152 @@ vbo_exec_DrawElements(GLenum mode, GLsizei count, GLenum type, count, type, indices); } +/* Inner support for both _mesa_DrawElements and _mesa_DrawRangeElements */ +static void +vbo_validated_multidrawelements(GLcontext *ctx, GLenum mode, + const GLsizei *count, GLenum type, + const GLvoid **indices, GLsizei primcount) +{ + struct vbo_context *vbo = vbo_context(ctx); + struct vbo_exec_context *exec = &vbo->exec; + struct _mesa_index_buffer ib; + struct _mesa_prim *prim; + unsigned int index_type_size = 0; + uintptr_t min_index_ptr, max_index_ptr; + GLboolean fallback = GL_FALSE; + int i; + + if (primcount == 0) + return; + + FLUSH_CURRENT( ctx, 0 ); + + if (ctx->NewState) + _mesa_update_state( ctx ); + + if (!_mesa_valid_to_render(ctx, "glMultiDrawElements")) { + return; + } + + if (ctx->NewState) + _mesa_update_state( ctx ); + + prim = _mesa_calloc(primcount * sizeof(*prim)); + if (prim == NULL) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glMultiDrawElements"); + return; + } + + /* Decide if we can do this all as one set of primitives sharing the + * same index buffer, or if we have to reset the index pointer per primitive. + */ + bind_arrays( ctx ); + + switch (type) { + case GL_UNSIGNED_INT: + index_type_size = 4; + break; + case GL_UNSIGNED_SHORT: + index_type_size = 2; + break; + case GL_UNSIGNED_BYTE: + index_type_size = 1; + break; + default: + assert(0); + } + + min_index_ptr = (uintptr_t)indices[0]; + max_index_ptr = 0; + for (i = 0; i < primcount; i++) { + min_index_ptr = MIN2(min_index_ptr, (uintptr_t)indices[i]); + max_index_ptr = MAX2(max_index_ptr, (uintptr_t)indices[i] + + index_type_size * count[i]); + } + + /* Check if we can handle this thing as a bunch of index offsets from the + * same index pointer. If we can't, then we have to fall back to doing + * a draw_prims per primitive. + */ + if (index_type_size != 1) { + for (i = 0; i < primcount; i++) { + if ((((uintptr_t)indices[i] - min_index_ptr) % index_type_size) != 0) { + fallback = GL_TRUE; + break; + } + } + } + + /* If the index buffer isn't in a VBO, then treating the application's + * subranges of the index buffer as one large index buffer may lead to + * us reading unmapped memory. + */ + if (!_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) + fallback = GL_TRUE; + + if (!fallback) { + ib.count = (max_index_ptr - min_index_ptr) / index_type_size; + ib.type = type; + ib.obj = ctx->Array.ElementArrayBufferObj; + ib.ptr = (void *)min_index_ptr; + + for (i = 0; i < primcount; i++) { + prim[i].begin = (i == 0); + prim[i].end = (i == primcount - 1); + prim[i].weak = 0; + prim[i].pad = 0; + prim[i].mode = mode; + prim[i].start = ((uintptr_t)indices[i] - min_index_ptr) / index_type_size; + prim[i].count = count[i]; + prim[i].indexed = 1; + } + + vbo->draw_prims(ctx, exec->array.inputs, prim, primcount, &ib, + GL_FALSE, ~0, ~0); + } else { + for (i = 0; i < primcount; i++) { + ib.count = count[i]; + ib.type = type; + ib.obj = ctx->Array.ElementArrayBufferObj; + ib.ptr = indices[i]; + + + prim[0].begin = 1; + prim[0].end = 1; + prim[0].weak = 0; + prim[0].pad = 0; + prim[0].mode = mode; + prim[0].start = 0; + prim[0].count = count[i]; + prim[0].indexed = 1; + } + + vbo->draw_prims(ctx, exec->array.inputs, prim, 1, &ib, + GL_FALSE, ~0, ~0); + } + _mesa_free(prim); +} + +static void GLAPIENTRY +vbo_exec_MultiDrawElements(GLenum mode, + const GLsizei *count, GLenum type, + const GLvoid **indices, + GLsizei primcount) +{ + GET_CURRENT_CONTEXT(ctx); + GLint i; + + ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); + + for (i = 0; i < primcount; i++) { + if (!_mesa_validate_DrawElements( ctx, mode, count[i], type, indices[i] )) + return; + } + + vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount); +} + + /*********************************************************************** * Initialization @@ -733,10 +880,12 @@ vbo_exec_array_init( struct vbo_exec_context *exec ) exec->vtxfmt.DrawArrays = vbo_exec_DrawArrays; exec->vtxfmt.DrawElements = vbo_exec_DrawElements; exec->vtxfmt.DrawRangeElements = vbo_exec_DrawRangeElements; + exec->vtxfmt.MultiDrawElementsEXT = vbo_exec_MultiDrawElements; #else exec->vtxfmt.DrawArrays = _mesa_noop_DrawArrays; exec->vtxfmt.DrawElements = _mesa_noop_DrawElements; exec->vtxfmt.DrawRangeElements = _mesa_noop_DrawRangeElements; + exec->vtxfmt.MultiDrawElementsEXT = _mesa_noop_MultiDrawElements; #endif } @@ -772,3 +921,11 @@ _mesa_DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, { vbo_exec_DrawRangeElements(mode, start, end, count, type, indices); } + +/* GL_EXT_multi_draw_arrays */ +void GLAPIENTRY +_mesa_MultiDrawElementsEXT(GLenum mode, const GLsizei *count, GLenum type, + const GLvoid **indices, GLsizei primcount) +{ + vbo_exec_MultiDrawElements(mode, count, type, indices, primcount); +} diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c index cdbbc9c1876..1771510d848 100644 --- a/src/mesa/vbo/vbo_save_api.c +++ b/src/mesa/vbo/vbo_save_api.c @@ -73,6 +73,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #include "main/dlist.h" #include "main/enums.h" #include "main/macros.h" +#include "main/api_noop.h" #include "main/api_validate.h" #include "main/api_arrayelt.h" #include "main/vtxfmt.h" @@ -1038,6 +1039,8 @@ static void _save_vtxfmt_init( GLcontext *ctx ) vfmt->DrawArrays = _save_DrawArrays; vfmt->DrawElements = _save_DrawElements; vfmt->DrawRangeElements = _save_DrawRangeElements; + /* Loops back into vfmt->DrawElements */ + vfmt->MultiDrawElementsEXT = _mesa_noop_MultiDrawElements; } @@ -1228,6 +1231,8 @@ void vbo_save_api_init( struct vbo_save_context *save ) ctx->ListState.ListVtxfmt.DrawArrays = _save_OBE_DrawArrays; ctx->ListState.ListVtxfmt.DrawElements = _save_OBE_DrawElements; ctx->ListState.ListVtxfmt.DrawRangeElements = _save_OBE_DrawRangeElements; + /* loops back into _save_OBE_DrawElements */ + ctx->ListState.ListVtxfmt.MultiDrawElementsEXT = _mesa_noop_MultiDrawElements; _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt ); } |