From f37070bab6af350caec905ea7658e9241042b6cc Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 28 Aug 2009 20:10:05 -0700 Subject: ARB sync: Add support for GL_ARB_sync to swrast This isn't quite right yet. The delete behavior and the context clean-up needs some work. --- src/mesa/main/mtypes.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/mesa/main/mtypes.h') diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 53dc6360ea..58da5d15eb 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1986,6 +1986,20 @@ struct gl_query_state }; +/** Sync object state */ +struct gl_sync_object { + GLenum Type; /**< GL_SYNC_FENCE */ + GLuint Name; /**< Fence name */ + GLint RefCount; /**< Reference count */ + GLboolean DeletePending; /**< Object was deleted while there were still + * live references (e.g., sync not yet finished) + */ + GLenum SyncCondition; + GLbitfield Flags; /**< Flags passed to glFenceSync */ + GLuint Status:1; /**< Has the sync object been signaled? */ +}; + + /** Set by #pragma directives */ struct gl_sl_pragmas { @@ -2435,6 +2449,12 @@ struct gl_constants GLbitfield SupportedBumpUnits; /**> units supporting GL_ATI_envmap_bumpmap as targets */ + /** + * Maximum amount of time, measured in nanseconds, that the server can wait. + */ + GLuint64 MaxServerWaitTimeout; + + /**< GL_EXT_provoking_vertex */ GLboolean QuadsFollowProvokingVertexConvention; }; @@ -2467,6 +2487,7 @@ struct gl_extensions GLboolean ARB_shading_language_120; GLboolean ARB_shadow; GLboolean ARB_shadow_ambient; /* or GL_ARB_shadow_ambient */ + GLboolean ARB_sync; GLboolean ARB_texture_border_clamp; GLboolean ARB_texture_compression; GLboolean ARB_texture_cube_map; -- cgit v1.2.3 From 16b393d05990b6e917e144f9de87d0103b4c3e6d Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 31 Aug 2009 14:57:50 -0700 Subject: ARB sync: Fix delete behavior and context destruction behavior I believe this resolves the outstanding issues WRT sync object deletetion. I have also added a large comment at the top of syncobj.c describing the expected memory management behavior. I'm still a little uncertain about the locking on ctx->Shared. --- src/mesa/main/mtypes.h | 6 ++++ src/mesa/main/shared.c | 19 +++++++++- src/mesa/main/syncobj.c | 96 +++++++++++++++++++++++++++++++++++++------------ src/mesa/main/syncobj.h | 6 ++++ 4 files changed, 103 insertions(+), 24 deletions(-) (limited to 'src/mesa/main/mtypes.h') diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 58da5d15eb..bd3bf28328 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -40,6 +40,7 @@ #include "main/mfeatures.h" #include "glapi/glapi.h" #include "math/m_matrix.h" /* GLmatrix */ +#include "main/simple_list.h" /* struct simple_node */ /** @@ -1988,6 +1989,7 @@ struct gl_query_state /** Sync object state */ struct gl_sync_object { + struct simple_node link; GLenum Type; /**< GL_SYNC_FENCE */ GLuint Name; /**< Fence name */ GLint RefCount; /**< Reference count */ @@ -2145,6 +2147,10 @@ struct gl_shared_state struct _mesa_HashTable *FrameBuffers; #endif +#if FEATURE_ARB_sync + struct simple_node SyncObjects; +#endif + void *DriverData; /**< Device driver shared state */ }; diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c index 93bbccd3c7..643ad3354e 100644 --- a/src/mesa/main/shared.c +++ b/src/mesa/main/shared.c @@ -43,7 +43,9 @@ #if FEATURE_ATI_fragment_shader #include "shader/atifragshader.h" #endif - +#if FEATURE_ARB_sync +#include "syncobj.h" +#endif /** * Allocate and initialize a shared context state structure. @@ -127,6 +129,10 @@ _mesa_alloc_shared_state(GLcontext *ctx) shared->RenderBuffers = _mesa_NewHashTable(); #endif +#if FEATURE_ARB_sync + make_empty_list(& shared->SyncObjects); +#endif + return shared; } @@ -336,6 +342,17 @@ _mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared) ctx->Driver.DeleteBuffer(ctx, shared->NullBufferObj); #endif +#if FEATURE_ARB_sync + { + struct simple_node *node; + struct simple_node *temp; + + foreach_s(node, temp, & shared->SyncObjects) { + _mesa_unref_sync_object(ctx, (struct gl_sync_object *) node); + } + } +#endif + /* * Free texture objects (after FBOs since some textures might have * been bound to FBOs). diff --git a/src/mesa/main/syncobj.c b/src/mesa/main/syncobj.c index eeeeb49175..0471a0ad7f 100644 --- a/src/mesa/main/syncobj.c +++ b/src/mesa/main/syncobj.c @@ -25,6 +25,33 @@ * \file syncobj.c * Sync object management. * + * Unlike textures and other objects that are shared between contexts, sync + * objects are not bound to the context. As a result, the reference counting + * and delete behavior of sync objects is slightly different. References to + * sync objects are added: + * + * - By \c glFencSynce. This sets the initial reference count to 1. + * - At the start of \c glClientWaitSync. The reference is held for the + * duration of the wait call. + * + * References are removed: + * + * - By \c glDeleteSync. + * - At the end of \c glClientWaitSync. + * + * Additionally, drivers may call \c _mesa_ref_sync_object and + * \c _mesa_unref_sync_object as needed to implement \c ServerWaitSync. + * + * As with shader objects, sync object names become invalid as soon as + * \c glDeleteSync is called. For this reason \c glDeleteSync sets the + * \c DeletePending flag. All functions validate object handles by testing + * this flag. + * + * \note + * Only \c GL_ARB_sync objects are shared between contexts. If support is ever + * added for either \c GL_NV_fence or \c GL_APPLE_fence different semantics + * will need to be implemented. + * * \author Ian Romanick */ @@ -130,31 +157,52 @@ _mesa_free_sync_data(GLcontext *ctx) } -GLboolean -_mesa_IsSync(GLsync sync) +static int +_mesa_validate_sync(struct gl_sync_object *syncObj) { - GET_CURRENT_CONTEXT(ctx); - struct gl_sync_object *const syncObj = (struct gl_sync_object *) sync; - ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); + return (syncObj != NULL) + && (syncObj->Type == GL_SYNC_FENCE) + && !syncObj->DeletePending; +} - return ((syncObj != NULL) && (syncObj->Type == GL_SYNC_FENCE)) - ? GL_TRUE : GL_FALSE; +void +_mesa_ref_sync_object(GLcontext *ctx, struct gl_sync_object *syncObj) +{ + _glthread_LOCK_MUTEX(ctx->Shared->Mutex); + syncObj->RefCount++; + _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); } -static void +void _mesa_unref_sync_object(GLcontext *ctx, struct gl_sync_object *syncObj) { + _glthread_LOCK_MUTEX(ctx->Shared->Mutex); syncObj->RefCount--; if (syncObj->RefCount == 0) { + remove_from_list(& syncObj->link); + _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); + (*ctx->Driver.DeleteSyncObject)(ctx, syncObj); } else { - syncObj->DeletePending = 1; + _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); } } +GLboolean +_mesa_IsSync(GLsync sync) +{ + GET_CURRENT_CONTEXT(ctx); + struct gl_sync_object *const syncObj = (struct gl_sync_object *) sync; + ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); + + + return _mesa_validate_sync(syncObj) ? GL_TRUE : GL_FALSE; +} + + void _mesa_DeleteSync(GLsync sync) { @@ -173,7 +221,7 @@ _mesa_DeleteSync(GLsync sync) return; } - if (syncObj->Type != GL_SYNC_FENCE) { + if (!_mesa_validate_sync(syncObj)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glDeleteSync"); return; } @@ -182,6 +230,7 @@ _mesa_DeleteSync(GLsync sync) /* If there are no client-waits or server-waits pending on this sync, delete * the underlying object. */ + syncObj->DeletePending = GL_TRUE; _mesa_unref_sync_object(ctx, syncObj); } @@ -224,6 +273,10 @@ _mesa_FenceSync(GLenum condition, GLbitfield flags) (*ctx->Driver.FenceSync)(ctx, syncObj, condition, flags); + _glthread_LOCK_MUTEX(ctx->Shared->Mutex); + insert_at_tail(& ctx->Shared->SyncObjects, & syncObj->link); + _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); + return (GLsync) syncObj; } @@ -240,7 +293,7 @@ _mesa_ClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_WAIT_FAILED); - if ((syncObj == NULL) || (syncObj->Type != GL_SYNC_FENCE)) { + if (!_mesa_validate_sync(syncObj)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glClientWaitSync"); return GL_WAIT_FAILED; } @@ -251,6 +304,8 @@ _mesa_ClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) } + _mesa_ref_sync_object(ctx, syncObj); + /* From the GL_ARB_sync spec: * * ClientWaitSync returns one of four status values. A return value of @@ -259,20 +314,15 @@ _mesa_ClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) * if was signaled, even if the value of is zero. */ (*ctx->Driver.CheckSync)(ctx, syncObj); - if (syncObj->Status) { - return GL_ALREADY_SIGNALED; - } - - - (*ctx->Driver.ClientWaitSync)(ctx, syncObj, flags, timeout); - - ret = syncObj->Status ? GL_CONDITION_SATISFIED : GL_TIMEOUT_EXPIRED; + ret = GL_ALREADY_SIGNALED; + } else { + (*ctx->Driver.ClientWaitSync)(ctx, syncObj, flags, timeout); - if (syncObj->DeletePending && syncObj->Status) { - _mesa_unref_sync_object(ctx, syncObj); + ret = syncObj->Status ? GL_CONDITION_SATISFIED : GL_TIMEOUT_EXPIRED; } + _mesa_unref_sync_object(ctx, syncObj); return ret; } @@ -285,7 +335,7 @@ _mesa_WaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) ASSERT_OUTSIDE_BEGIN_END(ctx); - if ((syncObj == NULL) || (syncObj->Type != GL_SYNC_FENCE)) { + if (!_mesa_validate_sync(syncObj)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glWaitSync"); return; } @@ -318,7 +368,7 @@ _mesa_GetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, ASSERT_OUTSIDE_BEGIN_END(ctx); - if ((syncObj == NULL) || (syncObj->Type != GL_SYNC_FENCE)) { + if (!_mesa_validate_sync(syncObj)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glGetSynciv"); return; } diff --git a/src/mesa/main/syncobj.h b/src/mesa/main/syncobj.h index d2b4d051c9..fc160af289 100644 --- a/src/mesa/main/syncobj.h +++ b/src/mesa/main/syncobj.h @@ -42,6 +42,12 @@ _mesa_init_sync(GLcontext *); extern void _mesa_free_sync_data(GLcontext *); +extern void +_mesa_ref_sync_object(GLcontext *ctx, struct gl_sync_object *syncObj); + +extern void +_mesa_unref_sync_object(GLcontext *ctx, struct gl_sync_object *syncObj); + extern GLboolean _mesa_IsSync(GLsync sync); -- cgit v1.2.3 From e059885ce357dee8b847f10e8e8c515a4a20042e Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 3 Sep 2009 12:47:25 -0600 Subject: mesa: rename gl_sync_object::Status to StatusFlag There's a symbol collision with X11/Xlib.h #define Status int in the Mesa xlib code. This seems the simpliest way to work around this. --- src/mesa/drivers/dri/intel/intel_syncobj.c | 4 ++-- src/mesa/main/mtypes.h | 2 +- src/mesa/main/syncobj.c | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/mesa/main/mtypes.h') diff --git a/src/mesa/drivers/dri/intel/intel_syncobj.c b/src/mesa/drivers/dri/intel/intel_syncobj.c index d447b6a0fa..1286fe929b 100644 --- a/src/mesa/drivers/dri/intel/intel_syncobj.c +++ b/src/mesa/drivers/dri/intel/intel_syncobj.c @@ -94,7 +94,7 @@ static void intel_client_wait_sync(GLcontext *ctx, struct gl_sync_object *s, if (sync->bo) { drm_intel_bo_wait_rendering(sync->bo); - s->Status = 1; + s->StatusFlag = 1; drm_intel_bo_unreference(sync->bo); sync->bo = NULL; } @@ -117,7 +117,7 @@ static void intel_check_sync(GLcontext *ctx, struct gl_sync_object *s) if (sync->bo && drm_intel_bo_busy(sync->bo)) { drm_intel_bo_unreference(sync->bo); sync->bo = NULL; - s->Status = 1; + s->StatusFlag = 1; } } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index bd3bf28328..6b64bf8139 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1998,7 +1998,7 @@ struct gl_sync_object { */ GLenum SyncCondition; GLbitfield Flags; /**< Flags passed to glFenceSync */ - GLuint Status:1; /**< Has the sync object been signaled? */ + GLuint StatusFlag:1; /**< Has the sync object been signaled? */ }; diff --git a/src/mesa/main/syncobj.c b/src/mesa/main/syncobj.c index 075931c7ce..64f923ff91 100644 --- a/src/mesa/main/syncobj.c +++ b/src/mesa/main/syncobj.c @@ -90,7 +90,7 @@ _mesa_fence_sync(GLcontext *ctx, struct gl_sync_object *syncObj, (void) condition; (void) flags; - syncObj->Status = 1; + syncObj->StatusFlag = 1; } @@ -263,7 +263,7 @@ _mesa_FenceSync(GLenum condition, GLbitfield flags) syncObj->DeletePending = GL_FALSE; syncObj->SyncCondition = condition; syncObj->Flags = flags; - syncObj->Status = 0; + syncObj->StatusFlag = 0; ctx->Driver.FenceSync(ctx, syncObj, condition, flags); @@ -306,12 +306,12 @@ _mesa_ClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) * if was signaled, even if the value of is zero. */ ctx->Driver.CheckSync(ctx, syncObj); - if (syncObj->Status) { + if (syncObj->StatusFlag) { ret = GL_ALREADY_SIGNALED; } else { ctx->Driver.ClientWaitSync(ctx, syncObj, flags, timeout); - ret = syncObj->Status ? GL_CONDITION_SATISFIED : GL_TIMEOUT_EXPIRED; + ret = syncObj->StatusFlag ? GL_CONDITION_SATISFIED : GL_TIMEOUT_EXPIRED; } _mesa_unref_sync_object(ctx, syncObj); @@ -381,7 +381,7 @@ _mesa_GetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, */ ctx->Driver.CheckSync(ctx, syncObj); - v[0] = (syncObj->Status) ? GL_SIGNALED : GL_UNSIGNALED; + v[0] = (syncObj->StatusFlag) ? GL_SIGNALED : GL_UNSIGNALED; size = 1; break; -- cgit v1.2.3 From b4922b533155cc139ebafb111502bb55d2ad2ccf Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 26 Aug 2009 09:51:15 -0700 Subject: mesa: Add support for ARB_depth_clamp. This currently doesn't include fixing up the cliptests in the assembly paths to support ARB_depth_clamp, so enabling depth_clamp forces the C path. --- src/mesa/drivers/dri/swrast/swrast.c | 1 + src/mesa/drivers/x11/xm_api.c | 1 + src/mesa/glapi/ARB_depth_clamp.xml | 12 ++++++++++ src/mesa/glapi/Makefile | 1 + src/mesa/glapi/gl_API.xml | 2 ++ src/mesa/main/attrib.c | 7 ++++++ src/mesa/main/enable.c | 20 ++++++++++++++++ src/mesa/main/extensions.c | 2 ++ src/mesa/main/get_gen.py | 4 ++++ src/mesa/main/mtypes.h | 2 ++ src/mesa/math/m_clip_tmp.h | 44 ++++++++++++++++++++++++------------ src/mesa/math/m_debug_clip.c | 9 +++++--- src/mesa/math/m_xform.h | 6 +++-- src/mesa/sparc/clip.S | 3 ++- src/mesa/sparc/sparc.c | 6 +++-- src/mesa/swrast/s_depth.c | 27 ++++++++++++++++++++++ src/mesa/swrast/s_depth.h | 2 ++ src/mesa/swrast/s_span.c | 3 +++ src/mesa/tnl/t_rasterpos.c | 25 ++++++++++++-------- src/mesa/tnl/t_vb_program.c | 6 +++-- src/mesa/tnl/t_vb_vertex.c | 6 +++-- src/mesa/x86/x86_xform.c | 9 +++++--- 22 files changed, 158 insertions(+), 40 deletions(-) create mode 100644 src/mesa/glapi/ARB_depth_clamp.xml (limited to 'src/mesa/main/mtypes.h') diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c index a858af30c1..9a130d61cf 100644 --- a/src/mesa/drivers/dri/swrast/swrast.c +++ b/src/mesa/drivers/dri/swrast/swrast.c @@ -95,6 +95,7 @@ const struct dri_extension card_extensions[] = { "GL_EXT_histogram", GL_EXT_histogram_functions }, { "GL_SGI_color_table", GL_SGI_color_table_functions }, + { "GL_ARB_depth_clamp", NULL }, { "GL_ARB_shader_objects", GL_ARB_shader_objects_functions }, { "GL_ARB_vertex_array_object", GL_ARB_vertex_array_object_functions }, { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions }, diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index 2c7be9f182..78545d0e17 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -1347,6 +1347,7 @@ const struct dri_extension card_extensions[] = { "GL_EXT_histogram", GL_EXT_histogram_functions }, { "GL_SGI_color_table", GL_SGI_color_table_functions }, + { "GL_ARB_depth_clamp", NULL }, { "GL_ARB_shader_objects", GL_ARB_shader_objects_functions }, { "GL_ARB_sync", GL_ARB_sync_functions }, { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions }, diff --git a/src/mesa/glapi/ARB_depth_clamp.xml b/src/mesa/glapi/ARB_depth_clamp.xml new file mode 100644 index 0000000000..157c9a86b1 --- /dev/null +++ b/src/mesa/glapi/ARB_depth_clamp.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/mesa/glapi/Makefile b/src/mesa/glapi/Makefile index 65edab7cec..22f65b74c2 100644 --- a/src/mesa/glapi/Makefile +++ b/src/mesa/glapi/Makefile @@ -48,6 +48,7 @@ SERVER_OUTPUTS = \ API_XML = gl_API.xml \ EXT_framebuffer_object.xml \ ARB_copy_buffer.xml \ + ARB_depth_clamp.xml \ ARB_framebuffer_object.xml \ ARB_map_buffer_range.xml \ ARB_seamless_cube_map.xml \ diff --git a/src/mesa/glapi/gl_API.xml b/src/mesa/glapi/gl_API.xml index 1dfd92be08..920ce80c45 100644 --- a/src/mesa/glapi/gl_API.xml +++ b/src/mesa/glapi/gl_API.xml @@ -7950,6 +7950,8 @@ + + diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c index ab99ca1c64..0fb8fa3bba 100644 --- a/src/mesa/main/attrib.c +++ b/src/mesa/main/attrib.c @@ -74,6 +74,7 @@ struct gl_enable_attrib GLboolean Convolution2D; GLboolean Separable2D; GLboolean CullFace; + GLboolean DepthClamp; GLboolean DepthTest; GLboolean Dither; GLboolean Fog; @@ -265,6 +266,7 @@ _mesa_PushAttrib(GLbitfield mask) attr->Convolution2D = ctx->Pixel.Convolution2DEnabled; attr->Separable2D = ctx->Pixel.Separable2DEnabled; attr->CullFace = ctx->Polygon.CullFlag; + attr->DepthClamp = ctx->Transform.DepthClamp; attr->DepthTest = ctx->Depth.Test; attr->Dither = ctx->Color.DitherFlag; attr->Fog = ctx->Fog.Enabled; @@ -514,6 +516,8 @@ pop_enable_group(GLcontext *ctx, const struct gl_enable_attrib *enable) enable->ColorTable[COLORTABLE_POSTCOLORMATRIX], GL_POST_COLOR_MATRIX_COLOR_TABLE); TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE); + TEST_AND_UPDATE(ctx->Transform.DepthClamp, enable->DepthClamp, + GL_DEPTH_CLAMP); TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST); TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER); TEST_AND_UPDATE(ctx->Pixel.Convolution1DEnabled, enable->Convolution1D, @@ -1221,6 +1225,9 @@ _mesa_PopAttrib(void) if (xform->RescaleNormals != ctx->Transform.RescaleNormals) _mesa_set_enable(ctx, GL_RESCALE_NORMAL_EXT, ctx->Transform.RescaleNormals); + if (xform->DepthClamp != ctx->Transform.DepthClamp) + _mesa_set_enable(ctx, GL_DEPTH_CLAMP, + ctx->Transform.DepthClamp); } break; case GL_TEXTURE_BIT: diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c index 4bc54771e9..d066153fc2 100644 --- a/src/mesa/main/enable.c +++ b/src/mesa/main/enable.c @@ -37,6 +37,7 @@ #include "mtypes.h" #include "enums.h" #include "math/m_matrix.h" +#include "math/m_xform.h" #include "api_arrayelt.h" @@ -947,6 +948,20 @@ _mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state) ctx->Depth.BoundsTest = state; break; + case GL_DEPTH_CLAMP: + if (ctx->Transform.DepthClamp == state) + return; + /* Neither the x86 nor sparc asm cliptest functions have been updated + * for ARB_depth_clamp, so force the C paths. + */ + if (state) + init_c_cliptest(); + + CHECK_EXTENSION(ARB_depth_clamp, cap); + FLUSH_VERTICES(ctx, _NEW_TRANSFORM); + ctx->Transform.DepthClamp = state; + break; + #if FEATURE_ATI_fragment_shader case GL_FRAGMENT_SHADER_ATI: CHECK_EXTENSION(ATI_fragment_shader, cap); @@ -1395,6 +1410,11 @@ _mesa_IsEnabled( GLenum cap ) CHECK_EXTENSION(EXT_depth_bounds_test); return ctx->Depth.BoundsTest; + /* GL_ARB_depth_clamp */ + case GL_DEPTH_CLAMP: + CHECK_EXTENSION(ARB_depth_clamp); + return ctx->Transform.DepthClamp; + #if FEATURE_ATI_fragment_shader case GL_FRAGMENT_SHADER_ATI: CHECK_EXTENSION(ATI_fragment_shader); diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index e3070b1547..ea67f820af 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -47,6 +47,7 @@ static const struct { } default_extensions[] = { { OFF, "GL_ARB_copy_buffer", F(ARB_copy_buffer) }, { OFF, "GL_ARB_depth_texture", F(ARB_depth_texture) }, + { OFF, "GL_ARB_depth_clamp", F(ARB_depth_clamp) }, { ON, "GL_ARB_draw_buffers", F(ARB_draw_buffers) }, { OFF, "GL_ARB_fragment_program", F(ARB_fragment_program) }, { OFF, "GL_ARB_fragment_program_shadow", F(ARB_fragment_program_shadow) }, @@ -192,6 +193,7 @@ void _mesa_enable_sw_extensions(GLcontext *ctx) { ctx->Extensions.ARB_copy_buffer = GL_TRUE; + ctx->Extensions.ARB_depth_clamp = GL_TRUE; ctx->Extensions.ARB_depth_texture = GL_TRUE; /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/ #if FEATURE_ARB_fragment_program diff --git a/src/mesa/main/get_gen.py b/src/mesa/main/get_gen.py index 2878c1b552..364d8c55c4 100644 --- a/src/mesa/main/get_gen.py +++ b/src/mesa/main/get_gen.py @@ -905,6 +905,10 @@ StateVars = [ ["ctx->Depth.BoundsMin", "ctx->Depth.BoundsMax"], "", ["EXT_depth_bounds_test"] ), + # GL_ARB_depth_clamp + ( "GL_DEPTH_CLAMP", GLboolean, ["ctx->Transform.DepthClamp"], "", + ["ARB_depth_clamp"] ), + # GL_ARB_draw_buffers ( "GL_MAX_DRAW_BUFFERS_ARB", GLint, ["ctx->Const.MaxDrawBuffers"], "", None ), diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 6b64bf8139..20cd3aa5c0 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1482,6 +1482,7 @@ struct gl_transform_attrib GLboolean Normalize; /**< Normalize all normals? */ GLboolean RescaleNormals; /**< GL_EXT_rescale_normal */ GLboolean RasterPositionUnclipped; /**< GL_IBM_rasterpos_clip */ + GLboolean DepthClamp; /**< GL_ARB_depth_clamp */ GLboolean CullVertexFlag; /**< True if GL_CULL_VERTEX_EXT is enabled */ GLfloat CullEyePos[4]; @@ -2475,6 +2476,7 @@ struct gl_extensions GLboolean dummy; /* don't remove this! */ GLboolean ARB_copy_buffer; GLboolean ARB_depth_texture; + GLboolean ARB_depth_clamp; GLboolean ARB_draw_buffers; GLboolean ARB_fragment_program; GLboolean ARB_fragment_program_shadow; diff --git a/src/mesa/math/m_clip_tmp.h b/src/mesa/math/m_clip_tmp.h index f3a589be05..2e30964057 100644 --- a/src/mesa/math/m_clip_tmp.h +++ b/src/mesa/math/m_clip_tmp.h @@ -44,7 +44,8 @@ static GLvector4f * _XFORMAPI TAG(cliptest_points4)( GLvector4f *clip_vec, GLvector4f *proj_vec, GLubyte clipMask[], GLubyte *orMask, - GLubyte *andMask ) + GLubyte *andMask, + GLboolean viewport_z_clip ) { const GLuint stride = clip_vec->stride; const GLfloat *from = (GLfloat *)clip_vec->start; @@ -66,16 +67,20 @@ static GLvector4f * _XFORMAPI TAG(cliptest_points4)( GLvector4f *clip_vec, mask |= (((cw < -cx) << CLIP_LEFT_SHIFT)); mask |= (((cw < cy) << CLIP_TOP_SHIFT)); mask |= (((cw < -cy) << CLIP_BOTTOM_SHIFT)); - mask |= (((cw < cz) << CLIP_FAR_SHIFT)); - mask |= (((cw < -cz) << CLIP_NEAR_SHIFT)); + if (viewport_z_clip) { + mask |= (((cw < cz) << CLIP_FAR_SHIFT)); + mask |= (((cw < -cz) << CLIP_NEAR_SHIFT)); + } #else /* !defined(macintosh)) */ GLubyte mask = 0; if (-cx + cw < 0) mask |= CLIP_RIGHT_BIT; if ( cx + cw < 0) mask |= CLIP_LEFT_BIT; if (-cy + cw < 0) mask |= CLIP_TOP_BIT; if ( cy + cw < 0) mask |= CLIP_BOTTOM_BIT; - if (-cz + cw < 0) mask |= CLIP_FAR_BIT; - if ( cz + cw < 0) mask |= CLIP_NEAR_BIT; + if (viewport_z_clip) { + if (-cz + cw < 0) mask |= CLIP_FAR_BIT; + if ( cz + cw < 0) mask |= CLIP_NEAR_BIT; + } #endif /* defined(macintosh) */ clipMask[i] = mask; @@ -119,7 +124,8 @@ static GLvector4f * _XFORMAPI TAG(cliptest_np_points4)( GLvector4f *clip_vec, GLvector4f *proj_vec, GLubyte clipMask[], GLubyte *orMask, - GLubyte *andMask ) + GLubyte *andMask, + GLboolean viewport_z_clip ) { const GLuint stride = clip_vec->stride; const GLuint count = clip_vec->count; @@ -141,16 +147,20 @@ static GLvector4f * _XFORMAPI TAG(cliptest_np_points4)( GLvector4f *clip_vec, mask |= (((cw < -cx) << CLIP_LEFT_SHIFT)); mask |= (((cw < cy) << CLIP_TOP_SHIFT)); mask |= (((cw < -cy) << CLIP_BOTTOM_SHIFT)); - mask |= (((cw < cz) << CLIP_FAR_SHIFT)); - mask |= (((cw < -cz) << CLIP_NEAR_SHIFT)); + if (viewport_z_clip) { + mask |= (((cw < cz) << CLIP_FAR_SHIFT)); + mask |= (((cw < -cz) << CLIP_NEAR_SHIFT)); + } #else /* !defined(macintosh)) */ GLubyte mask = 0; if (-cx + cw < 0) mask |= CLIP_RIGHT_BIT; if ( cx + cw < 0) mask |= CLIP_LEFT_BIT; if (-cy + cw < 0) mask |= CLIP_TOP_BIT; if ( cy + cw < 0) mask |= CLIP_BOTTOM_BIT; - if (-cz + cw < 0) mask |= CLIP_FAR_BIT; - if ( cz + cw < 0) mask |= CLIP_NEAR_BIT; + if (viewport_z_clip) { + if (-cz + cw < 0) mask |= CLIP_FAR_BIT; + if ( cz + cw < 0) mask |= CLIP_NEAR_BIT; + } #endif /* defined(macintosh) */ clipMask[i] = mask; @@ -171,7 +181,8 @@ static GLvector4f * _XFORMAPI TAG(cliptest_points3)( GLvector4f *clip_vec, GLvector4f *proj_vec, GLubyte clipMask[], GLubyte *orMask, - GLubyte *andMask ) + GLubyte *andMask, + GLboolean viewport_z_clip ) { const GLuint stride = clip_vec->stride; const GLuint count = clip_vec->count; @@ -187,8 +198,10 @@ static GLvector4f * _XFORMAPI TAG(cliptest_points3)( GLvector4f *clip_vec, else if (cx < -1.0) mask |= CLIP_LEFT_BIT; if (cy > 1.0) mask |= CLIP_TOP_BIT; else if (cy < -1.0) mask |= CLIP_BOTTOM_BIT; - if (cz > 1.0) mask |= CLIP_FAR_BIT; - else if (cz < -1.0) mask |= CLIP_NEAR_BIT; + if (viewport_z_clip) { + if (cz > 1.0) mask |= CLIP_FAR_BIT; + else if (cz < -1.0) mask |= CLIP_NEAR_BIT; + } clipMask[i] = mask; tmpOrMask |= mask; tmpAndMask &= mask; @@ -204,7 +217,8 @@ static GLvector4f * _XFORMAPI TAG(cliptest_points2)( GLvector4f *clip_vec, GLvector4f *proj_vec, GLubyte clipMask[], GLubyte *orMask, - GLubyte *andMask ) + GLubyte *andMask, + GLboolean viewport_z_clip ) { const GLuint stride = clip_vec->stride; const GLuint count = clip_vec->count; @@ -231,7 +245,7 @@ static GLvector4f * _XFORMAPI TAG(cliptest_points2)( GLvector4f *clip_vec, } -static void TAG(init_c_cliptest)( void ) +void TAG(init_c_cliptest)( void ) { _mesa_clip_tab[4] = TAG(cliptest_points4); _mesa_clip_tab[3] = TAG(cliptest_points3); diff --git a/src/mesa/math/m_debug_clip.c b/src/mesa/math/m_debug_clip.c index 460fed4a75..f2b757a91b 100644 --- a/src/mesa/math/m_debug_clip.c +++ b/src/mesa/math/m_debug_clip.c @@ -67,7 +67,8 @@ static GLvector4f *ref_cliptest_points4( GLvector4f *clip_vec, GLvector4f *proj_vec, GLubyte clipMask[], GLubyte *orMask, - GLubyte *andMask ) + GLubyte *andMask, + GLboolean viewport_z_clip ) { const GLuint stride = clip_vec->stride; const GLuint count = clip_vec->count; @@ -87,8 +88,10 @@ static GLvector4f *ref_cliptest_points4( GLvector4f *clip_vec, if ( cx + cw < 0 ) mask |= CLIP_LEFT_BIT; if ( -cy + cw < 0 ) mask |= CLIP_TOP_BIT; if ( cy + cw < 0 ) mask |= CLIP_BOTTOM_BIT; - if ( -cz + cw < 0 ) mask |= CLIP_FAR_BIT; - if ( cz + cw < 0 ) mask |= CLIP_NEAR_BIT; + if (viewport_z_clip) { + if ( -cz + cw < 0 ) mask |= CLIP_FAR_BIT; + if ( cz + cw < 0 ) mask |= CLIP_NEAR_BIT; + } clipMask[i] = mask; if ( mask ) { c++; diff --git a/src/mesa/math/m_xform.h b/src/mesa/math/m_xform.h index 7ef76e0b92..33421ad1c0 100644 --- a/src/mesa/math/m_xform.h +++ b/src/mesa/math/m_xform.h @@ -43,7 +43,8 @@ extern void _math_init_transformation(void); - +extern void +init_c_cliptest(void); /* KW: Clip functions now do projective divide as well. The projected * coordinates are very useful to us because they let us cull @@ -102,7 +103,8 @@ typedef GLvector4f * (_XFORMAPIP clip_func)( GLvector4f *vClip, GLvector4f *vProj, GLubyte clipMask[], GLubyte *orMask, - GLubyte *andMask ); + GLubyte *andMask, + GLboolean viewport_z_clip ); typedef void (*dotprod_func)( GLfloat *out, GLuint out_stride, diff --git a/src/mesa/sparc/clip.S b/src/mesa/sparc/clip.S index 208843c606..dc239171ff 100644 --- a/src/mesa/sparc/clip.S +++ b/src/mesa/sparc/clip.S @@ -58,7 +58,8 @@ clip_table: .byte 31, 29, 31, 30, 27, 25, 27, 26 /* GLvector4f *clip_vec, GLvector4f *proj_vec, - GLubyte clipMask[], GLubyte *orMask, GLubyte *andMask */ + GLubyte clipMask[], GLubyte *orMask, GLubyte *andMask, + GLboolean viewport_z_enable */ .align 64 __pc_tramp: diff --git a/src/mesa/sparc/sparc.c b/src/mesa/sparc/sparc.c index d2286a2c83..cea0c7cecf 100644 --- a/src/mesa/sparc/sparc.c +++ b/src/mesa/sparc/sparc.c @@ -78,13 +78,15 @@ extern GLvector4f *_mesa_sparc_cliptest_points4(GLvector4f *clip_vec, GLvector4f *proj_vec, GLubyte clipMask[], GLubyte *orMask, - GLubyte *andMask); + GLubyte *andMask, + GLboolean viewport_z_clip); extern GLvector4f *_mesa_sparc_cliptest_points4_np(GLvector4f *clip_vec, GLvector4f *proj_vec, GLubyte clipMask[], GLubyte *orMask, - GLubyte *andMask); + GLubyte *andMask, + GLboolean viewport_z_clip); #define NORM_ARGS const GLmatrix *mat, \ GLfloat scale, \ diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c index 26e23f02d5..1a428fb1a2 100644 --- a/src/mesa/swrast/s_depth.c +++ b/src/mesa/swrast/s_depth.c @@ -497,6 +497,33 @@ depth_test_span32( GLcontext *ctx, GLuint n, return passed; } +/* Apply ARB_depth_clamp to span of fragments. */ +void +_swrast_depth_clamp_span( GLcontext *ctx, SWspan *span ) +{ + struct gl_framebuffer *fb = ctx->DrawBuffer; + struct gl_renderbuffer *rb = fb->_DepthBuffer; + const GLuint count = span->end; + GLuint *zValues = span->array->z; + GLuint near, far; + int i; + + if (rb->DataType == GL_UNSIGNED_SHORT) { + near = FLOAT_TO_UINT(ctx->Viewport.Near); + far = FLOAT_TO_UINT(ctx->Viewport.Far); + } else { + assert(rb->DataType == GL_UNSIGNED_INT); + CLAMPED_FLOAT_TO_USHORT(near, ctx->Viewport.Near); + CLAMPED_FLOAT_TO_USHORT(far, ctx->Viewport.Far); + } + for (i = 0; i < count; i++) { + if (zValues[i] < near) + zValues[i] = near; + if (zValues[i] > far) + zValues[i] = far; + } +} + /* diff --git a/src/mesa/swrast/s_depth.h b/src/mesa/swrast/s_depth.h index 3688625683..7eae366742 100644 --- a/src/mesa/swrast/s_depth.h +++ b/src/mesa/swrast/s_depth.h @@ -33,6 +33,8 @@ extern GLuint _swrast_depth_test_span( GLcontext *ctx, SWspan *span); +extern void +_swrast_depth_clamp_span( GLcontext *ctx, SWspan *span ); extern GLboolean _swrast_depth_bounds_test( GLcontext *ctx, SWspan *span ); diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c index 0e2793b474..a45eac438e 100644 --- a/src/mesa/swrast/s_span.c +++ b/src/mesa/swrast/s_span.c @@ -880,6 +880,9 @@ _swrast_write_index_span( GLcontext *ctx, SWspan *span) stipple_polygon_span(ctx, span); } + if (ctx->Transform.DepthClamp) + _swrast_depth_clamp_span(ctx, span); + /* Stencil and Z testing */ if (ctx->Stencil._Enabled || ctx->Depth.Test) { if (!(span->arrayMask & SPAN_Z)) diff --git a/src/mesa/tnl/t_rasterpos.c b/src/mesa/tnl/t_rasterpos.c index f1fdddf0f5..99b6787455 100644 --- a/src/mesa/tnl/t_rasterpos.c +++ b/src/mesa/tnl/t_rasterpos.c @@ -46,11 +46,10 @@ * \return zero if outside view volume, or one if inside. */ static GLuint -viewclip_point( const GLfloat v[] ) +viewclip_point_xy( const GLfloat v[] ) { if ( v[0] > v[3] || v[0] < -v[3] - || v[1] > v[3] || v[1] < -v[3] - || v[2] > v[3] || v[2] < -v[3] ) { + || v[1] > v[3] || v[1] < -v[3] ) { return 0; } else { @@ -408,18 +407,18 @@ _tnl_RasterPos(GLcontext *ctx, const GLfloat vObj[4]) /* apply projection matrix: clip = Proj * eye */ TRANSFORM_POINT( clip, ctx->ProjectionMatrixStack.Top->m, eye ); - /* clip to view volume */ - if (ctx->Transform.RasterPositionUnclipped) { - /* GL_IBM_rasterpos_clip: only clip against Z */ + /* clip to view volume. */ + if (!ctx->Transform.DepthClamp) { if (viewclip_point_z(clip) == 0) { ctx->Current.RasterPosValid = GL_FALSE; return; } } - else if (viewclip_point(clip) == 0) { - /* Normal OpenGL behaviour */ - ctx->Current.RasterPosValid = GL_FALSE; - return; + if (!ctx->Transform.RasterPositionUnclipped) { + if (viewclip_point_xy(clip) == 0) { + ctx->Current.RasterPosValid = GL_FALSE; + return; + } } /* clip to user clipping planes */ @@ -443,6 +442,12 @@ _tnl_RasterPos(GLcontext *ctx, const GLfloat vObj[4]) / ctx->DrawBuffer->_DepthMaxF; ctx->Current.RasterPos[3] = clip[3]; + if (ctx->Transform.DepthClamp) { + ctx->Current.RasterPos[3] = CLAMP(ctx->Current.RasterPos[3], + ctx->Viewport.Near, + ctx->Viewport.Far); + } + /* compute raster distance */ if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) ctx->Current.RasterDistance = ctx->Current.Attrib[VERT_ATTRIB_FOG][0]; diff --git a/src/mesa/tnl/t_vb_program.c b/src/mesa/tnl/t_vb_program.c index dc954bcba1..5d89f8bc31 100644 --- a/src/mesa/tnl/t_vb_program.c +++ b/src/mesa/tnl/t_vb_program.c @@ -137,7 +137,8 @@ do_ndc_cliptest(GLcontext *ctx, struct vp_stage_data *store) &store->ndcCoords, store->clipmask, &store->ormask, - &store->andmask ); + &store->andmask, + !ctx->Transform.DepthClamp ); } else { VB->NdcPtr = NULL; @@ -145,7 +146,8 @@ do_ndc_cliptest(GLcontext *ctx, struct vp_stage_data *store) NULL, store->clipmask, &store->ormask, - &store->andmask ); + &store->andmask, + !ctx->Transform.DepthClamp ); } if (store->andmask) { diff --git a/src/mesa/tnl/t_vb_vertex.c b/src/mesa/tnl/t_vb_vertex.c index 30aa7c4086..6a746417c8 100644 --- a/src/mesa/tnl/t_vb_vertex.c +++ b/src/mesa/tnl/t_vb_vertex.c @@ -173,7 +173,8 @@ static GLboolean run_vertex_stage( GLcontext *ctx, &store->proj, store->clipmask, &store->ormask, - &store->andmask ); + &store->andmask, + !ctx->Transform.DepthClamp ); } else { VB->NdcPtr = NULL; @@ -181,7 +182,8 @@ static GLboolean run_vertex_stage( GLcontext *ctx, NULL, store->clipmask, &store->ormask, - &store->andmask ); + &store->andmask, + !ctx->Transform.DepthClamp ); } if (store->andmask) diff --git a/src/mesa/x86/x86_xform.c b/src/mesa/x86/x86_xform.c index 16b2b26bcc..52f6b25d81 100644 --- a/src/mesa/x86/x86_xform.c +++ b/src/mesa/x86/x86_xform.c @@ -60,21 +60,24 @@ _mesa_x86_cliptest_points4( GLvector4f *clip_vec, GLvector4f *proj_vec, GLubyte clipMask[], GLubyte *orMask, - GLubyte *andMask ); + GLubyte *andMask, + GLboolean viewport_z_clip ); extern GLvector4f * _ASMAPI _mesa_x86_cliptest_points4_np( GLvector4f *clip_vec, GLvector4f *proj_vec, GLubyte clipMask[], GLubyte *orMask, - GLubyte *andMask ); + GLubyte *andMask, + GLboolean viewport_z_clip ); extern void _ASMAPI _mesa_v16_x86_cliptest_points4( GLfloat *first_vert, GLfloat *last_vert, GLubyte *or_mask, GLubyte *and_mask, - GLubyte *clip_mask ); + GLubyte *clip_mask, + GLboolean viewport_z_clip ); extern void _ASMAPI _mesa_v16_x86_general_xform( GLfloat *dest, -- cgit v1.2.3 From 92d7ed8a20d4a018ce5324e6537ae7b478b9e5bf Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 27 Aug 2009 10:09:24 -0700 Subject: mesa: Add support for ARB_draw_elements_base_vertex. --- src/mesa/drivers/dri/swrast/swrast.c | 2 + src/mesa/drivers/x11/xm_api.c | 2 + src/mesa/main/api_noop.c | 78 ++++++++++++++++++++- src/mesa/main/api_noop.h | 7 ++ src/mesa/main/api_validate.c | 108 +++++++++++------------------ src/mesa/main/api_validate.h | 4 +- src/mesa/main/dd.h | 17 ++++- src/mesa/main/dlist.c | 3 + src/mesa/main/extensions.c | 2 + src/mesa/main/mtypes.h | 1 + src/mesa/main/varray.h | 15 ++++ src/mesa/main/vtxfmt.c | 3 + src/mesa/main/vtxfmt_tmp.h | 41 +++++++++++ src/mesa/tnl/t_draw.c | 58 +++++++++++----- src/mesa/vbo/vbo.h | 1 + src/mesa/vbo/vbo_exec_array.c | 131 ++++++++++++++++++++++++++++++----- src/mesa/vbo/vbo_rebase.c | 15 +++- src/mesa/vbo/vbo_save_api.c | 36 +++++++++- src/mesa/vbo/vbo_split.c | 8 ++- src/mesa/vbo/vbo_split_copy.c | 52 ++++++++------ 20 files changed, 453 insertions(+), 131 deletions(-) (limited to 'src/mesa/main/mtypes.h') diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c index 2d2aa5e0f1..3016987d56 100644 --- a/src/mesa/drivers/dri/swrast/swrast.c +++ b/src/mesa/drivers/dri/swrast/swrast.c @@ -62,6 +62,7 @@ #define need_GL_SGI_color_table /* sw extensions not associated with some GL version */ +#define need_GL_ARB_draw_elements_base_vertex #define need_GL_ARB_shader_objects #define need_GL_ARB_vertex_array_object #define need_GL_ARB_vertex_program @@ -96,6 +97,7 @@ const struct dri_extension card_extensions[] = { "GL_SGI_color_table", GL_SGI_color_table_functions }, { "GL_ARB_depth_clamp", NULL }, + { "GL_ARB_draw_elements_base_vertex", GL_ARB_draw_elements_base_vertex_functions }, { "GL_ARB_shader_objects", GL_ARB_shader_objects_functions }, { "GL_ARB_vertex_array_object", GL_ARB_vertex_array_object_functions }, { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions }, diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index 777635b783..662c61ae7e 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -1317,6 +1317,7 @@ xmesa_convert_from_x_visual_type( int visualType ) #define need_GL_SGI_color_table /* sw extensions not associated with some GL version */ +#define need_GL_ARB_draw_elements_base_vertex #define need_GL_ARB_shader_objects #define need_GL_ARB_sync #define need_GL_ARB_vertex_program @@ -1348,6 +1349,7 @@ const struct dri_extension card_extensions[] = { "GL_SGI_color_table", GL_SGI_color_table_functions }, { "GL_ARB_depth_clamp", NULL }, + { "GL_ARB_draw_elements_base_vertex", GL_ARB_draw_elements_base_vertex_functions }, { "GL_ARB_shader_objects", GL_ARB_shader_objects_functions }, { "GL_ARB_sync", GL_ARB_sync_functions }, { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions }, diff --git a/src/mesa/main/api_noop.c b/src/mesa/main/api_noop.c index 09ba7e5062..0b669e7e7f 100644 --- a/src/mesa/main/api_noop.c +++ b/src/mesa/main/api_noop.c @@ -731,7 +731,7 @@ _mesa_noop_DrawElements(GLenum mode, GLsizei count, GLenum type, GET_CURRENT_CONTEXT(ctx); GLint i; - if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices )) + if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices, 0 )) return; CALL_Begin(GET_DISPATCH(), (mode)); @@ -757,6 +757,43 @@ _mesa_noop_DrawElements(GLenum mode, GLsizei count, GLenum type, CALL_End(GET_DISPATCH(), ()); } +static void GLAPIENTRY +_mesa_noop_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type, + const GLvoid *indices, GLint basevertex) +{ + GET_CURRENT_CONTEXT(ctx); + GLint i; + + if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices, + basevertex )) + return; + + CALL_Begin(GET_DISPATCH(), (mode)); + + switch (type) { + case GL_UNSIGNED_BYTE: + for (i = 0 ; i < count ; i++) + CALL_ArrayElement(GET_DISPATCH(), ( ((GLubyte *)indices)[i] + + basevertex)); + break; + case GL_UNSIGNED_SHORT: + for (i = 0 ; i < count ; i++) + CALL_ArrayElement(GET_DISPATCH(), ( ((GLushort *)indices)[i] + + basevertex )); + break; + case GL_UNSIGNED_INT: + for (i = 0 ; i < count ; i++) + CALL_ArrayElement(GET_DISPATCH(), ( ((GLuint *)indices)[i] + + basevertex )); + break; + default: + _mesa_error( ctx, GL_INVALID_ENUM, "glDrawElementsBaseVertex(type)" ); + break; + } + + CALL_End(GET_DISPATCH(), ()); +} + static void GLAPIENTRY _mesa_noop_DrawRangeElements(GLenum mode, @@ -768,7 +805,7 @@ _mesa_noop_DrawRangeElements(GLenum mode, if (_mesa_validate_DrawRangeElements( ctx, mode, start, end, - count, type, indices )) + count, type, indices, 0 )) CALL_DrawElements(GET_DISPATCH(), (mode, count, type, indices)); } @@ -786,6 +823,40 @@ _mesa_noop_MultiDrawElements(GLenum mode, const GLsizei *count, GLenum type, } } +static void GLAPIENTRY +_mesa_noop_DrawRangeElementsBaseVertex(GLenum mode, + GLuint start, GLuint end, + GLsizei count, GLenum type, + const GLvoid *indices, GLint basevertex) +{ + GET_CURRENT_CONTEXT(ctx); + + if (_mesa_validate_DrawRangeElements( ctx, mode, + start, end, + count, type, indices, basevertex )) + CALL_DrawElementsBaseVertex(GET_DISPATCH(), (mode, count, type, indices, + basevertex)); +} + +/* GL_EXT_multi_draw_arrays */ +void GLAPIENTRY +_mesa_noop_MultiDrawElementsBaseVertex(GLenum mode, const GLsizei *count, + GLenum type, + const GLvoid **indices, + GLsizei primcount, + const GLint *basevertex) +{ + GLsizei i; + + for (i = 0; i < primcount; i++) { + if (count[i] > 0) { + CALL_DrawElementsBaseVertex(GET_DISPATCH(), (mode, count[i], type, + indices[i], + basevertex[i])); + } + } +} + /* * Eval Mesh */ @@ -995,6 +1066,9 @@ _mesa_noop_vtxfmt_init( GLvertexformat *vfmt ) vfmt->DrawElements = _mesa_noop_DrawElements; vfmt->DrawRangeElements = _mesa_noop_DrawRangeElements; vfmt->MultiDrawElementsEXT = _mesa_noop_MultiDrawElements; + vfmt->DrawElementsBaseVertex = _mesa_noop_DrawElementsBaseVertex; + vfmt->DrawRangeElementsBaseVertex = _mesa_noop_DrawRangeElementsBaseVertex; + vfmt->MultiDrawElementsBaseVertex = _mesa_noop_MultiDrawElementsBaseVertex; 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 a7956d00b3..1150984d64 100644 --- a/src/mesa/main/api_noop.h +++ b/src/mesa/main/api_noop.h @@ -44,6 +44,13 @@ extern void GLAPIENTRY _mesa_noop_MultiDrawElements(GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount); +extern void GLAPIENTRY +_mesa_noop_MultiDrawElementsBaseVertex(GLenum mode, const GLsizei *count, + GLenum type, + const GLvoid **indices, + GLsizei primcount, + const GLint *basevertex); + extern void _mesa_noop_vtxfmt_init(GLvertexformat *vfmt); diff --git a/src/mesa/main/api_validate.c b/src/mesa/main/api_validate.c index 2df4f17389..4a1448deee 100644 --- a/src/mesa/main/api_validate.c +++ b/src/mesa/main/api_validate.c @@ -29,7 +29,7 @@ #include "imports.h" #include "mtypes.h" #include "state.h" - +#include "vbo/vbo.h" /** @@ -51,51 +51,6 @@ index_bytes(GLenum type, GLsizei count) } -/** - * Find the max index in the given element/index buffer - */ -static GLuint -max_buffer_index(GLcontext *ctx, GLuint count, GLenum type, - const void *indices, - struct gl_buffer_object *elementBuf) -{ - const GLubyte *map = NULL; - GLuint max = 0; - GLuint i; - - if (_mesa_is_bufferobj(elementBuf)) { - /* elements are in a user-defined buffer object. need to map it */ - map = ctx->Driver.MapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER, - GL_READ_ONLY, elementBuf); - /* Actual address is the sum of pointers */ - indices = (const GLvoid *) ADD_POINTERS(map, (const GLubyte *) indices); - } - - if (type == GL_UNSIGNED_INT) { - for (i = 0; i < count; i++) - if (((GLuint *) indices)[i] > max) - max = ((GLuint *) indices)[i]; - } - else if (type == GL_UNSIGNED_SHORT) { - for (i = 0; i < count; i++) - if (((GLushort *) indices)[i] > max) - max = ((GLushort *) indices)[i]; - } - else { - ASSERT(type == GL_UNSIGNED_BYTE); - for (i = 0; i < count; i++) - if (((GLubyte *) indices)[i] > max) - max = ((GLubyte *) indices)[i]; - } - - if (map) { - ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, elementBuf); - } - - return max; -} - - /** * Check if OK to draw arrays/elements. */ @@ -124,6 +79,40 @@ check_valid_to_render(GLcontext *ctx, const char *function) return GL_TRUE; } +static GLboolean +check_index_bounds(GLcontext *ctx, GLsizei count, GLenum type, + const GLvoid *indices, GLint basevertex) +{ + struct _mesa_prim prim; + struct _mesa_index_buffer ib; + GLuint min, max; + + /* Only the X Server needs to do this -- otherwise, accessing outside + * array/BO bounds allows application termination. + */ + if (!ctx->Const.CheckArrayBounds) + return GL_TRUE; + + memset(&prim, 0, sizeof(prim)); + prim.count = count; + + memset(&ib, 0, sizeof(ib)); + ib.type = type; + ib.ptr = indices; + ib.obj = ctx->Array.ElementArrayBufferObj; + + vbo_get_minmax_index(ctx, &prim, &ib, &min, &max); + + if (min + basevertex < 0 || + max + basevertex > ctx->Array.ArrayObj->_MaxElement) { + /* the max element is out of bounds of one or more enabled arrays */ + _mesa_warning(ctx, "glDrawElements() index=%u is " + "out of bounds (max=%u)", max, ctx->Array.ArrayObj->_MaxElement); + return GL_FALSE; + } + + return GL_TRUE; +} /** * Error checking for glDrawElements(). Includes parameter checking @@ -133,7 +122,7 @@ check_valid_to_render(GLcontext *ctx, const char *function) GLboolean _mesa_validate_DrawElements(GLcontext *ctx, GLenum mode, GLsizei count, GLenum type, - const GLvoid *indices) + const GLvoid *indices, GLint basevertex) { ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); @@ -177,17 +166,8 @@ _mesa_validate_DrawElements(GLcontext *ctx, return GL_FALSE; } - if (ctx->Const.CheckArrayBounds) { - /* find max array index */ - GLuint max = max_buffer_index(ctx, count, type, indices, - ctx->Array.ElementArrayBufferObj); - if (max >= ctx->Array.ArrayObj->_MaxElement) { - /* the max element is out of bounds of one or more enabled arrays */ - _mesa_warning(ctx, "glDrawElements() index=%u is " - "out of bounds (max=%u)", max, ctx->Array.ArrayObj->_MaxElement); - return GL_FALSE; - } - } + if (!check_index_bounds(ctx, count, type, indices, basevertex)) + return GL_FALSE; return GL_TRUE; } @@ -202,7 +182,7 @@ GLboolean _mesa_validate_DrawRangeElements(GLcontext *ctx, GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, - const GLvoid *indices) + const GLvoid *indices, GLint basevertex) { ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); @@ -250,14 +230,8 @@ _mesa_validate_DrawRangeElements(GLcontext *ctx, GLenum mode, return GL_FALSE; } - if (ctx->Const.CheckArrayBounds) { - GLuint max = max_buffer_index(ctx, count, type, indices, - ctx->Array.ElementArrayBufferObj); - if (max >= ctx->Array.ArrayObj->_MaxElement) { - /* the max element is out of bounds of one or more enabled arrays */ - return GL_FALSE; - } - } + if (!check_index_bounds(ctx, count, type, indices, basevertex)) + return GL_FALSE; return GL_TRUE; } diff --git a/src/mesa/main/api_validate.h b/src/mesa/main/api_validate.h index 10f0c34e66..1d3ae157d7 100644 --- a/src/mesa/main/api_validate.h +++ b/src/mesa/main/api_validate.h @@ -37,13 +37,13 @@ _mesa_validate_DrawArrays(GLcontext *ctx, extern GLboolean _mesa_validate_DrawElements(GLcontext *ctx, GLenum mode, GLsizei count, GLenum type, - const GLvoid *indices); + const GLvoid *indices, GLint basevertex); extern GLboolean _mesa_validate_DrawRangeElements(GLcontext *ctx, GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, - const GLvoid *indices); + const GLvoid *indices, GLint basevertex); #endif diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h index 4a700b5cb4..ce5e158626 100644 --- a/src/mesa/main/dd.h +++ b/src/mesa/main/dd.h @@ -1172,7 +1172,22 @@ typedef struct { GLenum type, const GLvoid **indices, GLsizei primcount); - /*@}*/ + void (GLAPIENTRYP DrawElementsBaseVertex)( GLenum mode, GLsizei count, + GLenum type, + const GLvoid *indices, + GLint basevertex ); + void (GLAPIENTRYP DrawRangeElementsBaseVertex)( GLenum mode, GLuint start, + GLuint end, GLsizei count, + GLenum type, + const GLvoid *indices, + GLint basevertex); + void (GLAPIENTRYP MultiDrawElementsBaseVertex)( GLenum mode, + const GLsizei *count, + GLenum type, + const GLvoid **indices, + GLsizei primcount, + const GLint *basevertex); + /*@}*/ /** * \name Eval diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c index 8cff9ea64a..d721f699fd 100644 --- a/src/mesa/main/dlist.c +++ b/src/mesa/main/dlist.c @@ -8711,6 +8711,9 @@ _mesa_save_vtxfmt_init(GLvertexformat * vfmt) vfmt->DrawElements = 0; vfmt->DrawRangeElements = 0; vfmt->MultiDrawElemementsEXT = 0; + vfmt->DrawElementsBaseVertex = 0; + vfmt->DrawRangeElementsBaseVertex = 0; + vfmt->MultiDrawElemementsBaseVertex = 0; #endif } diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index d0e77bafdd..2ad66de7dd 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -49,6 +49,7 @@ static const struct { { OFF, "GL_ARB_depth_texture", F(ARB_depth_texture) }, { OFF, "GL_ARB_depth_clamp", F(ARB_depth_clamp) }, { ON, "GL_ARB_draw_buffers", F(ARB_draw_buffers) }, + { OFF, "GL_ARB_draw_elements_base_vertex", F(ARB_draw_elements_base_vertex) }, { OFF, "GL_ARB_fragment_program", F(ARB_fragment_program) }, { OFF, "GL_ARB_fragment_program_shadow", F(ARB_fragment_program_shadow) }, { OFF, "GL_ARB_fragment_shader", F(ARB_fragment_shader) }, @@ -197,6 +198,7 @@ _mesa_enable_sw_extensions(GLcontext *ctx) ctx->Extensions.ARB_depth_clamp = GL_TRUE; ctx->Extensions.ARB_depth_texture = GL_TRUE; /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/ + ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE; #if FEATURE_ARB_fragment_program ctx->Extensions.ARB_fragment_program = GL_TRUE; ctx->Extensions.ARB_fragment_program_shadow = GL_TRUE; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 20cd3aa5c0..ae169fb9db 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2478,6 +2478,7 @@ struct gl_extensions GLboolean ARB_depth_texture; GLboolean ARB_depth_clamp; GLboolean ARB_draw_buffers; + GLboolean ARB_draw_elements_base_vertex; GLboolean ARB_fragment_program; GLboolean ARB_fragment_program_shadow; GLboolean ARB_fragment_shader; diff --git a/src/mesa/main/varray.h b/src/mesa/main/varray.h index becc67c29d..ef790c504e 100644 --- a/src/mesa/main/varray.h +++ b/src/mesa/main/varray.h @@ -129,6 +129,11 @@ extern void GLAPIENTRY _mesa_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount ); +extern void GLAPIENTRY +_mesa_MultiDrawElementsBaseVertex( GLenum mode, + const GLsizei *count, GLenum type, + const GLvoid **indices, GLsizei primcount, + const GLint *basevertex); extern void GLAPIENTRY _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first, @@ -159,6 +164,16 @@ extern void GLAPIENTRY _mesa_DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +extern void GLAPIENTRY +_mesa_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type, + const GLvoid *indices, GLint basevertex); + +extern void GLAPIENTRY +_mesa_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end, + GLsizei count, GLenum type, + const GLvoid *indices, + GLint basevertex); + extern void _mesa_copy_client_array(GLcontext *ctx, diff --git a/src/mesa/main/vtxfmt.c b/src/mesa/main/vtxfmt.c index 8d6f560a80..91412f138a 100644 --- a/src/mesa/main/vtxfmt.c +++ b/src/mesa/main/vtxfmt.c @@ -134,6 +134,9 @@ install_vtxfmt( struct _glapi_table *tab, const GLvertexformat *vfmt ) SET_DrawElements(tab, vfmt->DrawElements); SET_DrawRangeElements(tab, vfmt->DrawRangeElements); SET_MultiDrawElementsEXT(tab, vfmt->MultiDrawElementsEXT); + SET_DrawElementsBaseVertex(tab, vfmt->DrawElementsBaseVertex); + SET_DrawRangeElementsBaseVertex(tab, vfmt->DrawRangeElementsBaseVertex); + SET_MultiDrawElementsBaseVertex(tab, vfmt->MultiDrawElementsBaseVertex); 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 1308d0aa46..d56a2bb95e 100644 --- a/src/mesa/main/vtxfmt_tmp.h +++ b/src/mesa/main/vtxfmt_tmp.h @@ -354,6 +354,44 @@ static void GLAPIENTRY TAG(DrawRangeElements)( GLenum mode, GLuint start, CALL_DrawRangeElements(GET_DISPATCH(), ( mode, start, end, count, type, indices )); } +static void GLAPIENTRY TAG(DrawElementsBaseVertex)( GLenum mode, + GLsizei count, + GLenum type, + const GLvoid *indices, + GLint basevertex) +{ + PRE_LOOPBACK( DrawElementsBaseVertex ); + CALL_DrawElementsBaseVertex(GET_DISPATCH(), ( mode, count, type, + indices, basevertex )); +} + +static void GLAPIENTRY TAG(DrawRangeElementsBaseVertex)( GLenum mode, + GLuint start, + GLuint end, + GLsizei count, + GLenum type, + const GLvoid *indices, + GLint basevertex) +{ + PRE_LOOPBACK( DrawRangeElementsBaseVertex ); + CALL_DrawRangeElementsBaseVertex(GET_DISPATCH(), ( mode, start, end, + count, type, indices, + basevertex )); +} + +static void GLAPIENTRY TAG(MultiDrawElementsBaseVertex)( GLenum mode, + const GLsizei *count, + GLenum type, + const GLvoid **indices, + GLsizei primcount, + const GLint *basevertex) +{ + PRE_LOOPBACK( MultiDrawElementsBaseVertex ); + CALL_MultiDrawElementsBaseVertex(GET_DISPATCH(), ( mode, count, type, + indices, + primcount, basevertex )); +} + static void GLAPIENTRY TAG(EvalMesh1)( GLenum mode, GLint i1, GLint i2 ) { PRE_LOOPBACK( EvalMesh1 ); @@ -534,6 +572,9 @@ static GLvertexformat TAG(vtxfmt) = { TAG(DrawElements), TAG(DrawRangeElements), TAG(MultiDrawElementsEXT), + TAG(DrawElementsBaseVertex), + TAG(DrawRangeElementsBaseVertex), + TAG(MultiDrawElementsBaseVertex), TAG(EvalMesh1), TAG(EvalMesh2) }; diff --git a/src/mesa/tnl/t_draw.c b/src/mesa/tnl/t_draw.c index c64c2c2077..04fa106300 100644 --- a/src/mesa/tnl/t_draw.c +++ b/src/mesa/tnl/t_draw.c @@ -316,22 +316,27 @@ static void bind_indices( GLcontext *ctx, ptr = ADD_POINTERS(ib->obj->Pointer, ib->ptr); - if (ib->type == GL_UNSIGNED_INT) { + if (ib->type == GL_UNSIGNED_INT && VB->Primitive[0].basevertex == 0) { VB->Elts = (GLuint *) ptr; } else { GLuint *elts = (GLuint *)get_space(ctx, ib->count * sizeof(GLuint)); VB->Elts = elts; - if (ib->type == GL_UNSIGNED_SHORT) { + if (ib->type == GL_UNSIGNED_INT) { + const GLuint *in = (GLuint *)ptr; + for (i = 0; i < ib->count; i++) + *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; + } + else if (ib->type == GL_UNSIGNED_SHORT) { const GLushort *in = (GLushort *)ptr; for (i = 0; i < ib->count; i++) - *elts++ = (GLuint)(*in++); + *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; } else { const GLubyte *in = (GLubyte *)ptr; for (i = 0; i < ib->count; i++) - *elts++ = (GLuint)(*in++); + *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; } } } @@ -390,10 +395,14 @@ void _tnl_draw_prims( GLcontext *ctx, TNLcontext *tnl = TNL_CONTEXT(ctx); const GLuint TEST_SPLIT = 0; const GLint max = TEST_SPLIT ? 8 : tnl->vb.Size - MAX_CLIPPED_VERTICES; + GLuint max_basevertex = prim->basevertex; + GLuint i; + + for (i = 1; i < nr_prims; i++) + max_basevertex = MAX2(max_basevertex, prim[i].basevertex); if (0) { - GLuint i; _mesa_printf("%s %d..%d\n", __FUNCTION__, min_index, max_index); for (i = 0; i < nr_prims; i++) _mesa_printf("prim %d: %s start %d count %d\n", i, @@ -410,7 +419,7 @@ void _tnl_draw_prims( GLcontext *ctx, _tnl_vbo_draw_prims ); return; } - else if (max_index > max) { + else if (max_index + max_basevertex > max) { /* The software TNL pipeline has a fixed amount of storage for * vertices and it is necessary to split incoming drawing commands * if they exceed that limit. @@ -424,7 +433,7 @@ void _tnl_draw_prims( GLcontext *ctx, * recursively call back into this function. */ vbo_split_prims( ctx, arrays, prim, nr_prims, ib, - 0, max_index, + 0, max_index + prim->basevertex, _tnl_vbo_draw_prims, &limits ); } @@ -435,17 +444,34 @@ void _tnl_draw_prims( GLcontext *ctx, struct gl_buffer_object *bo[VERT_ATTRIB_MAX + 1]; GLuint nr_bo = 0; - /* Binding inputs may imply mapping some vertex buffer objects. - * They will need to be unmapped below. - */ - bind_inputs(ctx, arrays, max_index+1, bo, &nr_bo); - bind_indices(ctx, ib, bo, &nr_bo); - bind_prims(ctx, prim, nr_prims ); + for (i = 0; i < nr_prims;) { + GLuint this_nr_prims; + + /* Our SW TNL pipeline doesn't handle basevertex yet, so bind_indices + * will rebase the elements to the basevertex, and we'll only + * emit strings of prims with the same basevertex in one draw call. + */ + for (this_nr_prims = 1; i + this_nr_prims < nr_prims; + this_nr_prims++) { + if (prim[i].basevertex != prim[i + this_nr_prims].basevertex) + break; + } + + /* Binding inputs may imply mapping some vertex buffer objects. + * They will need to be unmapped below. + */ + bind_prims(ctx, &prim[i], this_nr_prims); + bind_inputs(ctx, arrays, max_index + prim[i].basevertex + 1, + bo, &nr_bo); + bind_indices(ctx, ib, bo, &nr_bo); - TNL_CONTEXT(ctx)->Driver.RunPipeline(ctx); + TNL_CONTEXT(ctx)->Driver.RunPipeline(ctx); - unmap_vbos(ctx, bo, nr_bo); - free_space(ctx); + unmap_vbos(ctx, bo, nr_bo); + free_space(ctx); + + i += this_nr_prims; + } } } diff --git a/src/mesa/vbo/vbo.h b/src/mesa/vbo/vbo.h index 5986e93576..b24ecfd7cd 100644 --- a/src/mesa/vbo/vbo.h +++ b/src/mesa/vbo/vbo.h @@ -44,6 +44,7 @@ struct _mesa_prim { GLuint start; GLuint count; + GLint basevertex; }; /* Would like to call this a "vbo_index_buffer", but this would be diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c index 12911f5750..b9550d6106 100644 --- a/src/mesa/vbo/vbo_exec_array.c +++ b/src/mesa/vbo/vbo_exec_array.c @@ -181,7 +181,7 @@ unmap_array_buffer(GLcontext *ctx, struct gl_client_array *array) */ static void check_draw_elements_data(GLcontext *ctx, GLsizei count, GLenum elemType, - const void *elements) + const void *elements, GLint basevertex) { struct gl_array_object *arrayObj = ctx->Array.ArrayObj; const void *elemMap; @@ -518,6 +518,7 @@ vbo_exec_DrawArrays(GLenum mode, GLint start, GLsizei count) prim[0].start = start; prim[0].count = count; prim[0].indexed = 0; + prim[0].basevertex = 0; vbo->draw_prims( ctx, exec->array.inputs, prim, 1, NULL, GL_TRUE, start, start + count - 1 ); @@ -592,7 +593,8 @@ vbo_validated_drawrangeelements(GLcontext *ctx, GLenum mode, GLboolean index_bounds_valid, GLuint start, GLuint end, GLsizei count, GLenum type, - const GLvoid *indices) + const GLvoid *indices, + GLint basevertex) { struct vbo_context *vbo = vbo_context(ctx); struct vbo_exec_context *exec = &vbo->exec; @@ -626,6 +628,7 @@ vbo_validated_drawrangeelements(GLcontext *ctx, GLenum mode, prim[0].start = 0; prim[0].count = count; prim[0].indexed = 1; + prim[0].basevertex = basevertex; /* Need to give special consideration to rendering a range of * indices starting somewhere above zero. Typically the @@ -663,23 +666,25 @@ vbo_validated_drawrangeelements(GLcontext *ctx, GLenum mode, } static void GLAPIENTRY -vbo_exec_DrawRangeElements(GLenum mode, - GLuint start, GLuint end, - GLsizei count, GLenum type, const GLvoid *indices) +vbo_exec_DrawRangeElementsBaseVertex(GLenum mode, + GLuint start, GLuint end, + GLsizei count, GLenum type, + const GLvoid *indices, + GLint basevertex) { GET_CURRENT_CONTEXT(ctx); if (!_mesa_validate_DrawRangeElements( ctx, mode, start, end, count, - type, indices )) + type, indices, basevertex )) return; if (end >= ctx->Array.ArrayObj->_MaxElement) { /* the max element is out of bounds of one or more enabled arrays */ - _mesa_warning(ctx, "glDraw[Range]Elements(start %u, end %u, count %d, " - "type 0x%x, indices=%p)\n" + _mesa_warning(ctx, "glDraw[Range]Elements{,BaseVertex}(start %u, end %u, " + "count %d, type 0x%x, indices=%p, base=%d)\n" "\tindex=%u is out of bounds (max=%u) " "Element Buffer %u (size %d)", - start, end, count, type, indices, end, + start, end, count, type, indices, end, basevertex, ctx->Array.ArrayObj->_MaxElement - 1, ctx->Array.ElementArrayBufferObj->Name, ctx->Array.ElementArrayBufferObj->Size); @@ -692,10 +697,12 @@ vbo_exec_DrawRangeElements(GLenum mode, return; } else if (0) { - _mesa_printf("glDraw[Range]Elements" - "(start %u, end %u, type 0x%x, count %d) ElemBuf %u\n", + _mesa_printf("glDraw[Range]Elements{,BaseVertex}" + "(start %u, end %u, type 0x%x, count %d) ElemBuf %u, " + "base %d\n", start, end, type, count, - ctx->Array.ElementArrayBufferObj->Name); + ctx->Array.ElementArrayBufferObj->Name, + basevertex); } #if 0 @@ -705,7 +712,17 @@ vbo_exec_DrawRangeElements(GLenum mode, #endif vbo_validated_drawrangeelements(ctx, mode, GL_TRUE, start, end, - count, type, indices); + count, type, indices, basevertex); +} + +static void GLAPIENTRY +vbo_exec_DrawRangeElements(GLenum mode, + GLuint start, GLuint end, + GLsizei count, GLenum type, + const GLvoid *indices) +{ + vbo_exec_DrawRangeElementsBaseVertex(mode, start, end, count, type, + indices, 0); } @@ -715,18 +732,33 @@ vbo_exec_DrawElements(GLenum mode, GLsizei count, GLenum type, { GET_CURRENT_CONTEXT(ctx); - if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices )) + if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices, 0 )) + return; + + vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0, + count, type, indices, 0); +} + +static void GLAPIENTRY +vbo_exec_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type, + const GLvoid *indices, GLint basevertex) +{ + GET_CURRENT_CONTEXT(ctx); + + if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices, + basevertex )) return; vbo_validated_drawrangeelements(ctx, mode, GL_FALSE, ~0, ~0, - count, type, indices); + count, type, indices, basevertex); } /* 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) + const GLvoid **indices, GLsizei primcount, + const GLint *basevertex) { struct vbo_context *vbo = vbo_context(ctx); struct vbo_exec_context *exec = &vbo->exec; @@ -820,6 +852,10 @@ vbo_validated_multidrawelements(GLcontext *ctx, GLenum mode, prim[i].start = ((uintptr_t)indices[i] - min_index_ptr) / index_type_size; prim[i].count = count[i]; prim[i].indexed = 1; + if (basevertex != NULL) + prim[i].basevertex = basevertex[i]; + else + prim[i].basevertex = 0; } vbo->draw_prims(ctx, exec->array.inputs, prim, primcount, &ib, @@ -840,6 +876,10 @@ vbo_validated_multidrawelements(GLcontext *ctx, GLenum mode, prim[0].start = 0; prim[0].count = count[i]; prim[0].indexed = 1; + if (basevertex != NULL) + prim[0].basevertex = basevertex[i]; + else + prim[0].basevertex = 0; } vbo->draw_prims(ctx, exec->array.inputs, prim, 1, &ib, @@ -860,13 +900,36 @@ vbo_exec_MultiDrawElements(GLenum mode, ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); for (i = 0; i < primcount; i++) { - if (!_mesa_validate_DrawElements( ctx, mode, count[i], type, indices[i] )) + if (!_mesa_validate_DrawElements(ctx, mode, count[i], type, indices[i], + 0)) return; } - vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount); + vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount, + NULL); } +static void GLAPIENTRY +vbo_exec_MultiDrawElementsBaseVertex(GLenum mode, + const GLsizei *count, GLenum type, + const GLvoid **indices, + GLsizei primcount, + const GLsizei *basevertex) +{ + 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], + basevertex[i])) + return; + } + + vbo_validated_multidrawelements(ctx, mode, count, type, indices, primcount, + basevertex); +} /*********************************************************************** @@ -881,11 +944,17 @@ vbo_exec_array_init( struct vbo_exec_context *exec ) exec->vtxfmt.DrawElements = vbo_exec_DrawElements; exec->vtxfmt.DrawRangeElements = vbo_exec_DrawRangeElements; exec->vtxfmt.MultiDrawElementsEXT = vbo_exec_MultiDrawElements; + exec->vtxfmt.DrawElementsBaseVertex = vbo_exec_DrawElementsBaseVertex; + exec->vtxfmt.DrawRangeElementsBaseVertex = vbo_exec_DrawRangeElementsBaseVertex; + exec->vtxfmt.MultiDrawElementsBaseVertex = vbo_exec_MultiDrawElementsBaseVertex; #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; + exec->vtxfmt.DrawElementsBaseVertex = _mesa_noop_DrawElementsBaseVertex; + exec->vtxfmt.DrawRangeElementsBaseVertex = _mesa_noop_DrawRangeElementsBaseVertex; + exec->vtxfmt.MultiDrawElementsBaseVertex = _mesa_noop_MultiDrawElementsBaseVertex; #endif } @@ -913,6 +982,13 @@ _mesa_DrawElements(GLenum mode, GLsizei count, GLenum type, vbo_exec_DrawElements(mode, count, type, indices); } +void GLAPIENTRY +_mesa_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type, + const GLvoid *indices, GLint basevertex) +{ + vbo_exec_DrawElementsBaseVertex(mode, count, type, indices, basevertex); +} + /* This API entrypoint is not ordinarily used */ void GLAPIENTRY @@ -922,6 +998,15 @@ _mesa_DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, vbo_exec_DrawRangeElements(mode, start, end, count, type, indices); } +void GLAPIENTRY +_mesa_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end, + GLsizei count, GLenum type, + const GLvoid *indices, GLint basevertex) +{ + vbo_exec_DrawRangeElementsBaseVertex(mode, start, end, count, type, + indices, basevertex); +} + /* GL_EXT_multi_draw_arrays */ void GLAPIENTRY _mesa_MultiDrawElementsEXT(GLenum mode, const GLsizei *count, GLenum type, @@ -929,3 +1014,13 @@ _mesa_MultiDrawElementsEXT(GLenum mode, const GLsizei *count, GLenum type, { vbo_exec_MultiDrawElements(mode, count, type, indices, primcount); } + +void GLAPIENTRY +_mesa_MultiDrawElementsBaseVertex(GLenum mode, + const GLsizei *count, GLenum type, + const GLvoid **indices, GLsizei primcount, + const GLint *basevertex) +{ + vbo_exec_MultiDrawElementsBaseVertex(mode, count, type, indices, + primcount, basevertex); +} diff --git a/src/mesa/vbo/vbo_rebase.c b/src/mesa/vbo/vbo_rebase.c index 3bf7ef580f..799a25fc1c 100644 --- a/src/mesa/vbo/vbo_rebase.c +++ b/src/mesa/vbo/vbo_rebase.c @@ -126,7 +126,20 @@ void vbo_rebase_prims( GLcontext *ctx, if (0) _mesa_printf("%s %d..%d\n", __FUNCTION__, min_index, max_index); - if (ib) { + + if (ib && ctx->Extensions.ARB_draw_elements_base_vertex) { + /* If we can just tell the hardware or the TNL to interpret our + * indices with a different base, do so. + */ + tmp_prims = (struct _mesa_prim *)_mesa_malloc(sizeof(*prim) * nr_prims); + + for (i = 0; i < nr_prims; i++) { + tmp_prims[i] = prim[i]; + tmp_prims[i].basevertex -= min_index; + } + + prim = tmp_prims; + } else if (ib) { /* Unfortunately need to adjust each index individually. */ GLboolean map_ib = ib->obj->Name && !ib->obj->Pointer; diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c index 1771510d84..41cd21d04b 100644 --- a/src/mesa/vbo/vbo_save_api.c +++ b/src/mesa/vbo/vbo_save_api.c @@ -826,6 +826,33 @@ static void GLAPIENTRY _save_DrawRangeElements(GLenum mode, _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawRangeElements" ); } +static void GLAPIENTRY _save_DrawElementsBaseVertex(GLenum mode, + GLsizei count, + GLenum type, + const GLvoid *indices, + GLint basevertex) +{ + GET_CURRENT_CONTEXT(ctx); + (void) mode; (void) count; (void) type; (void) indices; (void)basevertex; + + _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawElements" ); +} + +static void GLAPIENTRY _save_DrawRangeElementsBaseVertex(GLenum mode, + GLuint start, + GLuint end, + GLsizei count, + GLenum type, + const GLvoid *indices, + GLint basevertex) +{ + GET_CURRENT_CONTEXT(ctx); + (void) mode; (void) start; (void) end; (void) count; (void) type; + (void) indices; (void)basevertex; + + _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawRangeElements" ); +} + static void GLAPIENTRY _save_DrawArrays(GLenum mode, GLint start, GLsizei count) { GET_CURRENT_CONTEXT(ctx); @@ -907,7 +934,7 @@ static void GLAPIENTRY _save_OBE_DrawElements(GLenum mode, GLsizei count, GLenum GET_CURRENT_CONTEXT(ctx); GLint i; - if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices )) + if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices, 0 )) return; _ae_map_vbos( ctx ); @@ -948,7 +975,7 @@ static void GLAPIENTRY _save_OBE_DrawRangeElements(GLenum mode, GET_CURRENT_CONTEXT(ctx); if (_mesa_validate_DrawRangeElements( ctx, mode, start, end, - count, type, indices )) + count, type, indices, 0 )) _save_OBE_DrawElements( mode, count, type, indices ); } @@ -1039,9 +1066,11 @@ static void _save_vtxfmt_init( GLcontext *ctx ) vfmt->DrawArrays = _save_DrawArrays; vfmt->DrawElements = _save_DrawElements; vfmt->DrawRangeElements = _save_DrawRangeElements; + vfmt->DrawElementsBaseVertex = _save_DrawElementsBaseVertex; + vfmt->DrawRangeElementsBaseVertex = _save_DrawRangeElementsBaseVertex; /* Loops back into vfmt->DrawElements */ vfmt->MultiDrawElementsEXT = _mesa_noop_MultiDrawElements; - + vfmt->MultiDrawElementsBaseVertex = _mesa_noop_MultiDrawElementsBaseVertex; } @@ -1233,6 +1262,7 @@ void vbo_save_api_init( struct vbo_save_context *save ) ctx->ListState.ListVtxfmt.DrawRangeElements = _save_OBE_DrawRangeElements; /* loops back into _save_OBE_DrawElements */ ctx->ListState.ListVtxfmt.MultiDrawElementsEXT = _mesa_noop_MultiDrawElements; + ctx->ListState.ListVtxfmt.MultiDrawElementsBaseVertex = _mesa_noop_MultiDrawElementsBaseVertex; _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt ); } diff --git a/src/mesa/vbo/vbo_split.c b/src/mesa/vbo/vbo_split.c index 58e879628d..c445acca7d 100644 --- a/src/mesa/vbo/vbo_split.c +++ b/src/mesa/vbo/vbo_split.c @@ -50,6 +50,7 @@ #include "main/glheader.h" #include "main/imports.h" #include "main/mtypes.h" +#include "main/macros.h" #include "vbo_split.h" #include "vbo.h" @@ -107,7 +108,12 @@ void vbo_split_prims( GLcontext *ctx, vbo_draw_func draw, const struct split_limits *limits ) { - + GLuint max_basevertex = prim->basevertex; + GLuint i; + + for (i = 1; i < nr_prims; i++) + max_basevertex = MAX2(max_basevertex, prim[i].basevertex); + if (ib) { if (limits->max_indices == 0) { /* Could traverse the indices, re-emitting vertices in turn. diff --git a/src/mesa/vbo/vbo_split_copy.c b/src/mesa/vbo/vbo_split_copy.c index 8ec180d550..c45190b9dd 100644 --- a/src/mesa/vbo/vbo_split_copy.c +++ b/src/mesa/vbo/vbo_split_copy.c @@ -589,28 +589,40 @@ void vbo_split_copy( GLcontext *ctx, const struct split_limits *limits ) { struct copy_context copy; - GLuint i; + GLuint i, this_nr_prims; + + for (i = 0; i < nr_prims;) { + /* Our SW TNL pipeline doesn't handle basevertex yet, so bind_indices + * will rebase the elements to the basevertex, and we'll only + * emit strings of prims with the same basevertex in one draw call. + */ + for (this_nr_prims = 1; i + this_nr_prims < nr_prims; + this_nr_prims++) { + if (prim[i].basevertex != prim[i + this_nr_prims].basevertex) + break; + } - memset(©, 0, sizeof(copy)); + memset(©, 0, sizeof(copy)); - /* Require indexed primitives: - */ - assert(ib); - - copy.ctx = ctx; - copy.array = arrays; - copy.prim = prim; - copy.nr_prims = nr_prims; - copy.ib = ib; - copy.draw = draw; - copy.limits = limits; + /* Require indexed primitives: + */ + assert(ib); - /* Clear the vertex cache: - */ - for (i = 0; i < ELT_TABLE_SIZE; i++) - copy.vert_cache[i].in = ~0; + copy.ctx = ctx; + copy.array = arrays; + copy.prim = &prim[i]; + copy.nr_prims = this_nr_prims; + copy.ib = ib; + copy.draw = draw; + copy.limits = limits; - replay_init(©); - replay_elts(©); - replay_finish(©); + /* Clear the vertex cache: + */ + for (i = 0; i < ELT_TABLE_SIZE; i++) + copy.vert_cache[i].in = ~0; + + replay_init(©); + replay_elts(©); + replay_finish(©); + } } -- cgit v1.2.3