From 92033a9516942d7272ce4bf36ecd422009bbaf60 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 31 Aug 2009 08:50:15 -0600 Subject: mesa: new assertions, comments about buffer mapping Since ctx->Driver.MapBuffer() and ctx->Driver.MapBufferRange() may be called from other places in Mesa (such as VBO) it's important that the driver callbacks set all the buffer object fields properly (Pointer, Offset, Length, etc). Add assertions to make sure that the driver does that. --- src/mesa/main/bufferobj.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'src/mesa/main/bufferobj.c') diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index f96185a4b5..715a6e650b 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -1165,6 +1165,8 @@ _mesa_MapBufferARB(GLenum target, GLenum access) GET_CURRENT_CONTEXT(ctx); struct gl_buffer_object * bufObj; GLbitfield accessFlags; + void *map; + ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL); switch (access) { @@ -1197,14 +1199,21 @@ _mesa_MapBufferARB(GLenum target, GLenum access) } ASSERT(ctx->Driver.MapBuffer); - bufObj->Pointer = ctx->Driver.MapBuffer( ctx, target, access, bufObj ); - if (!_mesa_bufferobj_mapped(bufObj)) { + map = ctx->Driver.MapBuffer( ctx, target, access, bufObj ); + if (!map) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glMapBufferARB(access)"); } - bufObj->AccessFlags = accessFlags; - bufObj->Offset = 0; - bufObj->Length = bufObj->Size; + if (map) { + /* The driver callback should have set these fields. + * This is important because other modules (like VBO) might call + * the driver function directly. + */ + ASSERT(bufObj->Pointer == map); + ASSERT(bufObj->Length == bufObj->Size); + ASSERT(bufObj->Offset == 0); + bufObj->AccessFlags = accessFlags; + } if (access == GL_WRITE_ONLY_ARB || access == GL_READ_WRITE_ARB) bufObj->Written = GL_TRUE; @@ -1455,6 +1464,8 @@ _mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, { GET_CURRENT_CONTEXT(ctx); struct gl_buffer_object *bufObj; + void *map; + ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL); if (!ctx->Extensions.ARB_map_buffer_range) { @@ -1518,14 +1529,20 @@ _mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, } ASSERT(ctx->Driver.MapBufferRange); - bufObj->Pointer = ctx->Driver.MapBufferRange(ctx, target, offset, length, - access, bufObj); - - bufObj->Offset = offset; - bufObj->Length = length; - bufObj->AccessFlags = access; + map = ctx->Driver.MapBufferRange(ctx, target, offset, length, + access, bufObj); + if (map) { + /* The driver callback should have set all these fields. + * This is important because other modules (like VBO) might call + * the driver function directly. + */ + ASSERT(bufObj->Pointer == map); + ASSERT(bufObj->Length == length); + ASSERT(bufObj->Offset == offset); + ASSERT(bufObj->AccessFlags == access); + } - return bufObj->Pointer; + return map; } -- cgit v1.2.3 From 822c7964819ca1fcc270880d4ca8b3de8a4276d0 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 31 Aug 2009 08:59:38 -0600 Subject: mesa: additional assertions for ctx->Driver.UnmapBuffer() The Pointer, Offset and Lenght fields should be cleared by the driver function since ctx->Driver.Unmap() may be called from VBO code, etc. --- src/mesa/main/bufferobj.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/mesa/main/bufferobj.c') diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 715a6e650b..3fd1d17ff9 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -484,6 +484,9 @@ _mesa_buffer_unmap( GLcontext *ctx, GLenum target, (void) target; /* XXX we might assert here that bufObj->Pointer is non-null */ bufObj->Pointer = NULL; + bufObj->Length = 0; + bufObj->Offset = 0; + bufObj->AccessFlags = 0x0; return GL_TRUE; } @@ -1095,7 +1098,7 @@ _mesa_BufferDataARB(GLenum target, GLsizeiptrARB size, /* Unmap the existing buffer. We'll replace it now. Not an error. */ ctx->Driver.UnmapBuffer(ctx, target, bufObj); bufObj->AccessFlags = DEFAULT_ACCESS; - bufObj->Pointer = NULL; + ASSERT(bufObj->Pointer == NULL); } FLUSH_VERTICES(ctx, _NEW_BUFFER_OBJECT); @@ -1304,9 +1307,9 @@ _mesa_UnmapBufferARB(GLenum target) status = ctx->Driver.UnmapBuffer( ctx, target, bufObj ); bufObj->AccessFlags = DEFAULT_ACCESS; - bufObj->Pointer = NULL; - bufObj->Offset = 0; - bufObj->Length = 0; + ASSERT(bufObj->Pointer == NULL); + ASSERT(bufObj->Offset == 0); + ASSERT(bufObj->Length == 0); return status; } -- cgit v1.2.3 From d1da8acd82190542cef7ffea41517974c0c9cc25 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 31 Aug 2009 09:05:28 -0600 Subject: mesa: set Length/Offset fields in _mesa_buffer_map() --- src/mesa/main/bufferobj.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/mesa/main/bufferobj.c') diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 3fd1d17ff9..165eec019a 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -428,6 +428,8 @@ _mesa_buffer_map( GLcontext *ctx, GLenum target, GLenum access, return NULL; } bufObj->Pointer = bufObj->Data; + bufObj->Length = bufObj->Size; + bufObj->Offset = 0; return bufObj->Pointer; } -- cgit v1.2.3 From 2b6ab615a42bd162b4a870218a5951ca32416c20 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 31 Aug 2009 09:12:04 -0600 Subject: mesa: set additional fields in _mesa_buffer_map_range() --- src/mesa/main/bufferobj.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/mesa/main/bufferobj.c') diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 165eec019a..ebca798635 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -445,11 +445,13 @@ _mesa_buffer_map_range( GLcontext *ctx, GLenum target, GLintptr offset, { (void) ctx; (void) target; - (void) access; - (void) length; assert(!_mesa_bufferobj_mapped(bufObj)); /* Just return a direct pointer to the data */ - return bufObj->Data + offset; + bufObj->Pointer = bufObj->Data + offset; + bufObj->Length = length; + bufObj->Offset = offset; + bufObj->AccessFlags = access; + return bufObj->Pointer; } -- cgit v1.2.3 From 2f6d2a9e27f8582591dc60655f7d7b14d7552bbc Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 3 Sep 2009 09:41:41 -0600 Subject: mesa: change ctx->Driver.BufferData() to return GLboolean for success/failure Return GL_FALSE if we failed to allocate the buffer. Then raise GL_OUT_OF_MEMORY in core Mesa. --- src/mesa/drivers/dri/intel/intel_buffer_objects.c | 11 ++++++--- .../drivers/dri/radeon/radeon_buffer_objects.c | 9 ++++++-- src/mesa/main/bufferobj.c | 26 +++++++++++++++------- src/mesa/main/dd.h | 6 ++--- src/mesa/state_tracker/st_cb_bufferobjects.c | 9 ++++---- 5 files changed, 41 insertions(+), 20 deletions(-) (limited to 'src/mesa/main/bufferobj.c') diff --git a/src/mesa/drivers/dri/intel/intel_buffer_objects.c b/src/mesa/drivers/dri/intel/intel_buffer_objects.c index ae6f3064a8..c55c5c426e 100644 --- a/src/mesa/drivers/dri/intel/intel_buffer_objects.c +++ b/src/mesa/drivers/dri/intel/intel_buffer_objects.c @@ -130,9 +130,10 @@ intel_bufferobj_free(GLcontext * ctx, struct gl_buffer_object *obj) * Allocate space for and store data in a buffer object. Any data that was * previously stored in the buffer object is lost. If data is NULL, * memory will be allocated, but no copy will occur. - * Called via glBufferDataARB(). + * Called via ctx->Driver.BufferData(). + * \return GL_TRUE for success, GL_FALSE if out of memory */ -static void +static GLboolean intel_bufferobj_data(GLcontext * ctx, GLenum target, GLsizeiptrARB size, @@ -167,15 +168,19 @@ intel_bufferobj_data(GLcontext * ctx, if (intel_obj->sys_buffer != NULL) { if (data != NULL) memcpy(intel_obj->sys_buffer, data, size); - return; + return GL_TRUE; } } #endif intel_bufferobj_alloc_buffer(intel, intel_obj); + if (!intel_obj->buffer) + return GL_FALSE; if (data != NULL) dri_bo_subdata(intel_obj->buffer, 0, size, data); } + + return GL_TRUE; } diff --git a/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c b/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c index e8ae51e6ea..a24b6dac26 100644 --- a/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c +++ b/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c @@ -78,9 +78,10 @@ radeonDeleteBufferObject(GLcontext * ctx, * Allocate space for and store data in a buffer object. Any data that was * previously stored in the buffer object is lost. If data is NULL, * memory will be allocated, but no copy will occur. - * Called via glBufferDataARB(). + * Called via ctx->Driver.BufferData(). + * \return GL_TRUE for success, GL_FALSE if out of memory */ -static void +static GLboolean radeonBufferData(GLcontext * ctx, GLenum target, GLsizeiptrARB size, @@ -107,6 +108,9 @@ radeonBufferData(GLcontext * ctx, RADEON_GEM_DOMAIN_GTT, 0); + if (!radeon_obj->bo) + return GL_FALSE; + if (data != NULL) { radeon_bo_map(radeon_obj->bo, GL_TRUE); @@ -115,6 +119,7 @@ radeonBufferData(GLcontext * ctx, radeon_bo_unmap(radeon_obj->bo); } } + return GL_TRUE; } /** diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index ebca798635..81b77b6ff2 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -314,9 +314,10 @@ _mesa_initialize_buffer_object( struct gl_buffer_object *obj, * \param usage Hints about how the data will be used. * \param bufObj Object to be used. * + * \return GL_TRUE for success, GL_FALSE for failure * \sa glBufferDataARB, dd_function_table::BufferData. */ -static void +static GLboolean _mesa_buffer_data( GLcontext *ctx, GLenum target, GLsizeiptrARB size, const GLvoid * data, GLenum usage, struct gl_buffer_object * bufObj ) @@ -334,6 +335,11 @@ _mesa_buffer_data( GLcontext *ctx, GLenum target, GLsizeiptrARB size, if (data) { _mesa_memcpy( bufObj->Data, data, size ); } + + return GL_TRUE; + } + else { + return GL_FALSE; } } @@ -1107,8 +1113,6 @@ _mesa_BufferDataARB(GLenum target, GLsizeiptrARB size, FLUSH_VERTICES(ctx, _NEW_BUFFER_OBJECT); - ASSERT(ctx->Driver.BufferData); - bufObj->Written = GL_TRUE; #ifdef VBO_DEBUG @@ -1119,8 +1123,11 @@ _mesa_BufferDataARB(GLenum target, GLsizeiptrARB size, #ifdef BOUNDS_CHECK size += 100; #endif - /* Give the buffer object to the driver! may be null! */ - ctx->Driver.BufferData( ctx, target, size, data, usage, bufObj ); + + ASSERT(ctx->Driver.BufferData); + if (!ctx->Driver.BufferData( ctx, target, size, data, usage, bufObj )) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBufferDataARB(access)"); + } } @@ -1209,9 +1216,9 @@ _mesa_MapBufferARB(GLenum target, GLenum access) map = ctx->Driver.MapBuffer( ctx, target, access, bufObj ); if (!map) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glMapBufferARB(access)"); + return NULL; } - - if (map) { + else { /* The driver callback should have set these fields. * This is important because other modules (like VBO) might call * the driver function directly. @@ -1538,7 +1545,10 @@ _mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, ASSERT(ctx->Driver.MapBufferRange); map = ctx->Driver.MapBufferRange(ctx, target, offset, length, access, bufObj); - if (map) { + if (!map) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glMapBufferARB(access)"); + } + else { /* The driver callback should have set all these fields. * This is important because other modules (like VBO) might call * the driver function directly. diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h index f02e868d4a..4400e166c6 100644 --- a/src/mesa/main/dd.h +++ b/src/mesa/main/dd.h @@ -783,9 +783,9 @@ struct dd_function_table { void (*DeleteBuffer)( GLcontext *ctx, struct gl_buffer_object *obj ); - void (*BufferData)( GLcontext *ctx, GLenum target, GLsizeiptrARB size, - const GLvoid *data, GLenum usage, - struct gl_buffer_object *obj ); + GLboolean (*BufferData)( GLcontext *ctx, GLenum target, GLsizeiptrARB size, + const GLvoid *data, GLenum usage, + struct gl_buffer_object *obj ); void (*BufferSubData)( GLcontext *ctx, GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data, diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index 69dd76d083..8e09d0b932 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -134,9 +134,10 @@ st_bufferobj_get_subdata(GLcontext *ctx, * Allocate space for and store data in a buffer object. Any data that was * previously stored in the buffer object is lost. If data is NULL, * memory will be allocated, but no copy will occur. - * Called via glBufferDataARB(). + * Called via ctx->Driver.BufferData(). + * \return GL_TRUE for success, GL_FALSE if out of memory */ -static void +static GLboolean st_bufferobj_data(GLcontext *ctx, GLenum target, GLsizeiptrARB size, @@ -172,13 +173,13 @@ st_bufferobj_data(GLcontext *ctx, st_obj->buffer = pipe_buffer_create( pipe->screen, 32, buffer_usage, size ); if (!st_obj->buffer) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBufferDataARB"); - return; + return GL_FALSE; } if (data) st_no_flush_pipe_buffer_write(st_context(ctx), st_obj->buffer, 0, size, data); + return GL_TRUE; } -- cgit v1.2.3 From 1b448c7a5cafa68eeead2a4c45f4362a9883383b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 3 Sep 2009 11:29:18 -0600 Subject: mesa: consolidate PBO map/unmap helpers Instead of _mesa_map_readpix_pbo() use _mesa_map_pbo_source(). Instead of _mesa_map_drawpix_pbo() and _mesa_map_bitmap_pbo() use _mesa_map_pbo_dest(). --- src/mesa/main/bufferobj.c | 99 ++++++++++--------------------- src/mesa/main/bufferobj.h | 27 +++------ src/mesa/state_tracker/st_cb_bitmap.c | 6 +- src/mesa/state_tracker/st_cb_drawpixels.c | 10 ++-- src/mesa/state_tracker/st_cb_readpixels.c | 6 +- src/mesa/state_tracker/st_cb_texture.c | 4 +- src/mesa/swrast/s_bitmap.c | 4 +- src/mesa/swrast/s_drawpix.c | 4 +- src/mesa/swrast/s_readpix.c | 4 +- 9 files changed, 60 insertions(+), 104 deletions(-) (limited to 'src/mesa/main/bufferobj.c') diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 81b77b6ff2..1ae63a0ef6 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -658,6 +658,8 @@ _mesa_update_default_objects_buffer_objects(GLcontext *ctx) * currently mapped. Whoever calls this function should check for that. * Remember, we can't use a PBO when it's mapped! * + * If we're not using a PBO, this is a no-op. + * * \param width width of image to read/write * \param height height of image to read/write * \param depth depth of image to read/write @@ -676,7 +678,8 @@ _mesa_validate_pbo_access(GLuint dimensions, GLvoid *start, *end; const GLubyte *sizeAddr; /* buffer size, cast to a pointer */ - ASSERT(_mesa_is_bufferobj(pack->BufferObj)); + if (!_mesa_is_bufferobj(pack->BufferObj)) + return GL_TRUE; /* no PBO, OK */ if (pack->BufferObj->Size == 0) /* no buffer! */ @@ -708,17 +711,18 @@ _mesa_validate_pbo_access(GLuint dimensions, /** - * If the source of glBitmap data is a PBO, check that we won't read out - * of buffer bounds, then map the buffer. - * If not sourcing from a PBO, just return the bitmap pointer. - * This is a helper function for (some) drivers. - * Return NULL if error. - * If non-null return, must call _mesa_unmap_bitmap_pbo() when done. + * For commands that read from a PBO (glDrawPixels, glTexImage, + * glPolygonStipple, etc), if we're reading from a PBO, map it read-only + * and return the pointer into the PBO. If we're not reading from a + * PBO, return \p src as-is. + * If non-null return, must call _mesa_unmap_pbo_source() when done. + * + * \return NULL if error, else pointer to start of data */ -const GLubyte * -_mesa_map_bitmap_pbo(GLcontext *ctx, +const GLvoid * +_mesa_map_pbo_source(GLcontext *ctx, const struct gl_pixelstore_attrib *unpack, - const GLubyte *bitmap) + const GLvoid *src) { const GLubyte *buf; @@ -730,11 +734,11 @@ _mesa_map_bitmap_pbo(GLcontext *ctx, if (!buf) return NULL; - buf = ADD_POINTERS(buf, bitmap); + buf = ADD_POINTERS(buf, src); } else { /* unpack from normal memory */ - buf = bitmap; + buf = src; } return buf; @@ -742,13 +746,13 @@ _mesa_map_bitmap_pbo(GLcontext *ctx, /** - * Counterpart to _mesa_map_bitmap_pbo() - * This is a helper function for (some) drivers. + * Counterpart to _mesa_map_pbo_source() */ void -_mesa_unmap_bitmap_pbo(GLcontext *ctx, +_mesa_unmap_pbo_source(GLcontext *ctx, const struct gl_pixelstore_attrib *unpack) { + ASSERT(unpack != &ctx->Pack); /* catch pack/unpack mismatch */ if (_mesa_is_bufferobj(unpack->BufferObj)) { ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, unpack->BufferObj); @@ -757,57 +761,17 @@ _mesa_unmap_bitmap_pbo(GLcontext *ctx, /** - * \sa _mesa_map_bitmap_pbo - */ -const GLvoid * -_mesa_map_drawpix_pbo(GLcontext *ctx, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels) -{ - const GLvoid *buf; - - if (_mesa_is_bufferobj(unpack->BufferObj)) { - /* unpack from PBO */ - buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, - GL_READ_ONLY_ARB, - unpack->BufferObj); - if (!buf) - return NULL; - - buf = ADD_POINTERS(buf, pixels); - } - else { - /* unpack from normal memory */ - buf = pixels; - } - - return buf; -} - - -/** - * \sa _mesa_unmap_bitmap_pbo - */ -void -_mesa_unmap_drawpix_pbo(GLcontext *ctx, - const struct gl_pixelstore_attrib *unpack) -{ - if (_mesa_is_bufferobj(unpack->BufferObj)) { - ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, - unpack->BufferObj); - } -} - - -/** - * If PBO is bound, map the buffer, return dest pointer in mapped buffer. - * Call _mesa_unmap_readpix_pbo() when finished - * \return NULL if error + * For commands that write to a PBO (glReadPixels, glGetColorTable, etc), + * if we're writing to a PBO, map it write-only and return the pointer + * into the PBO. If we're not writing to a PBO, return \p dst as-is. + * If non-null return, must call _mesa_unmap_pbo_dest() when done. + * + * \return NULL if error, else pointer to start of data */ void * -_mesa_map_readpix_pbo(GLcontext *ctx, - const struct gl_pixelstore_attrib *pack, - GLvoid *dest) +_mesa_map_pbo_dest(GLcontext *ctx, + const struct gl_pixelstore_attrib *pack, + GLvoid *dest) { void *buf; @@ -831,12 +795,13 @@ _mesa_map_readpix_pbo(GLcontext *ctx, /** - * Counterpart to _mesa_map_readpix_pbo() + * Counterpart to _mesa_map_pbo_dest() */ void -_mesa_unmap_readpix_pbo(GLcontext *ctx, - const struct gl_pixelstore_attrib *pack) +_mesa_unmap_pbo_dest(GLcontext *ctx, + const struct gl_pixelstore_attrib *pack) { + ASSERT(pack != &ctx->Unpack); /* catch pack/unpack mismatch */ if (_mesa_is_bufferobj(pack->BufferObj)) { ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, pack->BufferObj); } diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h index decb44a65e..2e7afc2d76 100644 --- a/src/mesa/main/bufferobj.h +++ b/src/mesa/main/bufferobj.h @@ -81,32 +81,23 @@ _mesa_validate_pbo_access(GLuint dimensions, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *ptr); -extern const GLubyte * -_mesa_map_bitmap_pbo(GLcontext *ctx, +extern const GLvoid * +_mesa_map_pbo_source(GLcontext *ctx, const struct gl_pixelstore_attrib *unpack, - const GLubyte *bitmap); + const GLvoid *src); extern void -_mesa_unmap_bitmap_pbo(GLcontext *ctx, +_mesa_unmap_pbo_source(GLcontext *ctx, const struct gl_pixelstore_attrib *unpack); -extern const GLvoid * -_mesa_map_drawpix_pbo(GLcontext *ctx, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels); - -extern void -_mesa_unmap_drawpix_pbo(GLcontext *ctx, - const struct gl_pixelstore_attrib *unpack); - extern void * -_mesa_map_readpix_pbo(GLcontext *ctx, - const struct gl_pixelstore_attrib *pack, - GLvoid *dest); +_mesa_map_pbo_dest(GLcontext *ctx, + const struct gl_pixelstore_attrib *pack, + GLvoid *dest); extern void -_mesa_unmap_readpix_pbo(GLcontext *ctx, - const struct gl_pixelstore_attrib *pack); +_mesa_unmap_pbo_dest(GLcontext *ctx, + const struct gl_pixelstore_attrib *pack); extern void diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 3171b67376..902fb38d1a 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -275,7 +275,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, struct pipe_texture *pt; /* PBO source... */ - bitmap = _mesa_map_bitmap_pbo(ctx, unpack, bitmap); + bitmap = _mesa_map_pbo_source(ctx, unpack, bitmap); if (!bitmap) { return NULL; } @@ -287,7 +287,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, 0, width, height, 1, PIPE_TEXTURE_USAGE_SAMPLER); if (!pt) { - _mesa_unmap_bitmap_pbo(ctx, unpack); + _mesa_unmap_pbo_source(ctx, unpack); return NULL; } @@ -302,7 +302,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, unpack_bitmap(ctx->st, 0, 0, width, height, unpack, bitmap, dest, transfer->stride); - _mesa_unmap_bitmap_pbo(ctx, unpack); + _mesa_unmap_pbo_source(ctx, unpack); /* Release transfer */ screen->transfer_unmap(screen, transfer); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index d19a88fa7c..e00754a036 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -353,7 +353,7 @@ make_texture(struct st_context *st, assert(pipeFormat); cpp = st_sizeof_format(pipeFormat); - pixels = _mesa_map_drawpix_pbo(ctx, unpack, pixels); + pixels = _mesa_map_pbo_source(ctx, unpack, pixels); if (!pixels) return NULL; @@ -381,7 +381,7 @@ make_texture(struct st_context *st, pt = st_texture_create(st, PIPE_TEXTURE_2D, pipeFormat, 0, ptw, pth, 1, PIPE_TEXTURE_USAGE_SAMPLER); if (!pt) { - _mesa_unmap_drawpix_pbo(ctx, unpack); + _mesa_unmap_pbo_source(ctx, unpack); return NULL; } @@ -428,7 +428,7 @@ make_texture(struct st_context *st, ctx->_ImageTransferState = imageTransferStateSave; } - _mesa_unmap_drawpix_pbo(ctx, unpack); + _mesa_unmap_pbo_source(ctx, unpack); return pt; } @@ -681,7 +681,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, stmap = screen->transfer_map(screen, pt); - pixels = _mesa_map_drawpix_pbo(ctx, unpack, pixels); + pixels = _mesa_map_pbo_source(ctx, unpack, pixels); assert(pixels); /* if width > MAX_WIDTH, have to process image in chunks */ @@ -775,7 +775,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, skipPixels += spanWidth; } - _mesa_unmap_drawpix_pbo(ctx, unpack); + _mesa_unmap_pbo_source(ctx, unpack); /* unmap the stencil buffer */ screen->transfer_unmap(screen, pt); diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index ccf1a0b563..75424aa2e7 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -353,7 +353,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, return; } - dest = _mesa_map_readpix_pbo(ctx, &clippedPacking, dest); + dest = _mesa_map_pbo_dest(ctx, &clippedPacking, dest); if (!dest) return; @@ -380,7 +380,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, if (st_fast_readpixels(ctx, strb, x, y, width, height, format, type, pack, dest)) { /* success! */ - _mesa_unmap_readpix_pbo(ctx, &clippedPacking); + _mesa_unmap_pbo_dest(ctx, &clippedPacking); return; } @@ -534,7 +534,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, screen->tex_transfer_destroy(trans); - _mesa_unmap_readpix_pbo(ctx, &clippedPacking); + _mesa_unmap_pbo_dest(ctx, &clippedPacking); } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 90a059ca69..dc39a70121 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -870,7 +870,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level, PIPE_TRANSFER_READ, 0, 0, width, height); - pixels = _mesa_map_readpix_pbo(ctx, &ctx->Pack, pixels); + pixels = _mesa_map_pbo_dest(ctx, &ctx->Pack, pixels); /* copy/pack data into user buffer */ if (st_equal_formats(stImage->pt->format, format, type)) { @@ -903,7 +903,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level, } } - _mesa_unmap_readpix_pbo(ctx, &ctx->Pack); + _mesa_unmap_pbo_dest(ctx, &ctx->Pack); /* destroy the temp / dest surface */ util_destroy_rgba_surface(dst_texture, dst_surface); diff --git a/src/mesa/swrast/s_bitmap.c b/src/mesa/swrast/s_bitmap.c index 5e7822cf32..3dbdf2a61a 100644 --- a/src/mesa/swrast/s_bitmap.c +++ b/src/mesa/swrast/s_bitmap.c @@ -56,7 +56,7 @@ _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py, ASSERT(ctx->RenderMode == GL_RENDER); - bitmap = _mesa_map_bitmap_pbo(ctx, unpack, bitmap); + bitmap = (const GLubyte *) _mesa_map_pbo_source(ctx, unpack, bitmap); if (!bitmap) return; @@ -133,7 +133,7 @@ _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py, swrast_render_finish(ctx); - _mesa_unmap_bitmap_pbo(ctx, unpack); + _mesa_unmap_pbo_source(ctx, unpack); } diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c index a9ef8e685f..d31c402eea 100644 --- a/src/mesa/swrast/s_drawpix.c +++ b/src/mesa/swrast/s_drawpix.c @@ -847,7 +847,7 @@ _swrast_DrawPixels( GLcontext *ctx, if (swrast->NewState) _swrast_validate_derived( ctx ); - pixels = _mesa_map_drawpix_pbo(ctx, unpack, pixels); + pixels = _mesa_map_pbo_source(ctx, unpack, pixels); if (!pixels) { swrast_render_finish(ctx); _mesa_set_vp_override(ctx, save_vp_override); @@ -892,7 +892,7 @@ _swrast_DrawPixels( GLcontext *ctx, swrast_render_finish(ctx); _mesa_set_vp_override(ctx, save_vp_override); - _mesa_unmap_drawpix_pbo(ctx, unpack); + _mesa_unmap_pbo_source(ctx, unpack); } diff --git a/src/mesa/swrast/s_readpix.c b/src/mesa/swrast/s_readpix.c index e901fc6b5d..48b9408d24 100644 --- a/src/mesa/swrast/s_readpix.c +++ b/src/mesa/swrast/s_readpix.c @@ -574,7 +574,7 @@ _swrast_ReadPixels( GLcontext *ctx, return; } - pixels = _mesa_map_readpix_pbo(ctx, &clippedPacking, pixels); + pixels = _mesa_map_pbo_dest(ctx, &clippedPacking, pixels); if (!pixels) return; @@ -616,5 +616,5 @@ _swrast_ReadPixels( GLcontext *ctx, swrast_render_finish(ctx); - _mesa_unmap_readpix_pbo(ctx, &clippedPacking); + _mesa_unmap_pbo_dest(ctx, &clippedPacking); } -- cgit v1.2.3 From dc947c8f92732fab75f89015e2d506e964a41ace Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 3 Sep 2009 11:22:27 -0600 Subject: mesa: combined PBO validate/map helpers --- src/mesa/main/bufferobj.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++ src/mesa/main/bufferobj.h | 16 +++++++++ 2 files changed, 98 insertions(+) (limited to 'src/mesa/main/bufferobj.c') diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 1ae63a0ef6..b95e00af5b 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -745,6 +745,47 @@ _mesa_map_pbo_source(GLcontext *ctx, } +/** + * Combine PBO-read validation and mapping. + * If any GL errors are detected, they'll be recorded and NULL returned. + * \sa _mesa_validate_pbo_access + * \sa _mesa_map_pbo_source + * A call to this function should have a matching call to + * _mesa_unmap_pbo_source(). + */ +const GLvoid * +_mesa_map_validate_pbo_source(GLcontext *ctx, + GLuint dimensions, + const struct gl_pixelstore_attrib *unpack, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, const GLvoid *ptr, + const char *where) +{ + ASSERT(dimensions == 1 || dimensions == 2 || dimensions == 3); + + if (!_mesa_is_bufferobj(unpack->BufferObj)) { + /* non-PBO access: no validation to be done */ + return ptr; + } + + if (!_mesa_validate_pbo_access(dimensions, unpack, + width, height, depth, format, type, ptr)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(out of bounds PBO access)", where); + return NULL; + } + + if (_mesa_bufferobj_mapped(unpack->BufferObj)) { + /* buffer is already mapped - that's an error */ + _mesa_error(ctx, GL_INVALID_OPERATION, "%s(PBO is mapped)", where); + return NULL; + } + + ptr = _mesa_map_pbo_source(ctx, unpack, ptr); + return ptr; +} + + /** * Counterpart to _mesa_map_pbo_source() */ @@ -794,6 +835,47 @@ _mesa_map_pbo_dest(GLcontext *ctx, } +/** + * Combine PBO-write validation and mapping. + * If any GL errors are detected, they'll be recorded and NULL returned. + * \sa _mesa_validate_pbo_access + * \sa _mesa_map_pbo_dest + * A call to this function should have a matching call to + * _mesa_unmap_pbo_dest(). + */ +GLvoid * +_mesa_map_validate_pbo_dest(GLcontext *ctx, + GLuint dimensions, + const struct gl_pixelstore_attrib *unpack, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, GLvoid *ptr, + const char *where) +{ + ASSERT(dimensions == 1 || dimensions == 2 || dimensions == 3); + + if (!_mesa_is_bufferobj(unpack->BufferObj)) { + /* non-PBO access: no validation to be done */ + return ptr; + } + + if (!_mesa_validate_pbo_access(dimensions, unpack, + width, height, depth, format, type, ptr)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(out of bounds PBO access)", where); + return NULL; + } + + if (_mesa_bufferobj_mapped(unpack->BufferObj)) { + /* buffer is already mapped - that's an error */ + _mesa_error(ctx, GL_INVALID_OPERATION, "%s(PBO is mapped)", where); + return NULL; + } + + ptr = _mesa_map_pbo_dest(ctx, unpack, ptr); + return ptr; +} + + /** * Counterpart to _mesa_map_pbo_dest() */ diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h index 2e7afc2d76..9f732ec0c0 100644 --- a/src/mesa/main/bufferobj.h +++ b/src/mesa/main/bufferobj.h @@ -86,6 +86,14 @@ _mesa_map_pbo_source(GLcontext *ctx, const struct gl_pixelstore_attrib *unpack, const GLvoid *src); +extern const GLvoid * +_mesa_map_validate_pbo_source(GLcontext *ctx, + GLuint dimensions, + const struct gl_pixelstore_attrib *unpack, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, const GLvoid *ptr, + const char *where); + extern void _mesa_unmap_pbo_source(GLcontext *ctx, const struct gl_pixelstore_attrib *unpack); @@ -95,6 +103,14 @@ _mesa_map_pbo_dest(GLcontext *ctx, const struct gl_pixelstore_attrib *pack, GLvoid *dest); +extern GLvoid * +_mesa_map_validate_pbo_dest(GLcontext *ctx, + GLuint dimensions, + const struct gl_pixelstore_attrib *unpack, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, GLvoid *ptr, + const char *where); + extern void _mesa_unmap_pbo_dest(GLcontext *ctx, const struct gl_pixelstore_attrib *pack); -- cgit v1.2.3