X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fstate_tracker%2Fst_cb_bufferobjects.c;h=b55a085cc7c7cb936facea486ee55e9584dd8c88;hb=275c4bd3643d773210780cb8d578ca84f2604684;hp=1ecf7bf7844fa8356e72764ed4f67d50cd4e51fa;hpb=9d029e0e200eb97993c1b9fb8ab9046172e703e8;p=mesa.git diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index 1ecf7bf7844..b55a085cc7c 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -42,7 +42,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" -#include "pipe/p_inlines.h" +#include "util/u_inlines.h" /** @@ -75,10 +75,12 @@ st_bufferobj_free(GLcontext *ctx, struct gl_buffer_object *obj) { struct st_buffer_object *st_obj = st_buffer_object(obj); + assert(obj->RefCount == 0); + if (st_obj->buffer) pipe_buffer_reference(&st_obj->buffer, NULL); - _mesa_free(st_obj); + free(st_obj); } @@ -98,6 +100,22 @@ st_bufferobj_subdata(GLcontext *ctx, { struct st_buffer_object *st_obj = st_buffer_object(obj); + /* we may be called from VBO code, so double-check params here */ + ASSERT(offset >= 0); + ASSERT(size >= 0); + ASSERT(offset + size <= obj->Size); + + if (!size) + return; + + /* + * According to ARB_vertex_buffer_object specification, if data is null, + * then the contents of the buffer object's data store is undefined. We just + * ignore, and leave it unchanged. + */ + if (!data) + return; + st_cond_flush_pipe_buffer_write(st_context(ctx), st_obj->buffer, offset, size, data); } @@ -115,6 +133,14 @@ st_bufferobj_get_subdata(GLcontext *ctx, { struct st_buffer_object *st_obj = st_buffer_object(obj); + /* we may be called from VBO code, so double-check params here */ + ASSERT(offset >= 0); + ASSERT(size >= 0); + ASSERT(offset + size <= obj->Size); + + if (!size) + return; + st_cond_flush_pipe_buffer_read(st_context(ctx), st_obj->buffer, offset, size, data); } @@ -124,9 +150,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, @@ -159,16 +186,20 @@ st_bufferobj_data(GLcontext *ctx, pipe_buffer_reference( &st_obj->buffer, NULL ); - st_obj->buffer = pipe_buffer_create( pipe->screen, 32, buffer_usage, size ); + if (size != 0) { + 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; + if (!st_obj->buffer) { + return GL_FALSE; + } + + if (data) + st_no_flush_pipe_buffer_write(st_context(ctx), st_obj->buffer, 0, + size, data); + return GL_TRUE; } - if (data) - st_no_flush_pipe_buffer_write(st_context(ctx), st_obj->buffer, 0, - size, data); + return GL_TRUE; } @@ -207,6 +238,13 @@ st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access, } +/** + * Dummy data whose's pointer is used for zero length ranges. + */ +static long +st_bufferobj_zero_length_range = 0; + + /** * Called via glMapBufferRange(). */ @@ -218,7 +256,6 @@ st_bufferobj_map_range(GLcontext *ctx, GLenum target, struct pipe_context *pipe = st_context(ctx)->pipe; struct st_buffer_object *st_obj = st_buffer_object(obj); uint flags = 0x0; - char *map; if (access & GL_MAP_WRITE_BIT) flags |= PIPE_BUFFER_USAGE_CPU_WRITE; @@ -226,6 +263,12 @@ st_bufferobj_map_range(GLcontext *ctx, GLenum target, if (access & GL_MAP_READ_BIT) flags |= PIPE_BUFFER_USAGE_CPU_READ; + if (access & GL_MAP_FLUSH_EXPLICIT_BIT) + flags |= PIPE_BUFFER_USAGE_FLUSH_EXPLICIT; + + if (access & GL_MAP_UNSYNCHRONIZED_BIT) + flags |= PIPE_BUFFER_USAGE_UNSYNCHRONIZED; + /* ... other flags ... */ @@ -237,14 +280,27 @@ st_bufferobj_map_range(GLcontext *ctx, GLenum target, assert(offset < obj->Size); assert(offset + length <= obj->Size); - map = obj->Pointer = pipe_buffer_map_range(pipe->screen, st_obj->buffer, offset, length, flags); - if(obj->Pointer) { + /* + * We go out of way here to hide the degenerate yet valid case of zero + * length range from the pipe driver. + */ + if (!length) { + obj->Pointer = &st_bufferobj_zero_length_range; + } + else { + obj->Pointer = pipe_buffer_map_range(pipe->screen, st_obj->buffer, offset, length, flags); + if (obj->Pointer) { + obj->Pointer = (ubyte *) obj->Pointer + offset; + } + } + + if (obj->Pointer) { obj->Offset = offset; obj->Length = length; - map += offset; + obj->AccessFlags = access; } - - return map; + + return obj->Pointer; } @@ -261,6 +317,9 @@ st_bufferobj_flush_mapped_range(GLcontext *ctx, GLenum target, assert(length >= 0); assert(offset + length <= obj->Length); + if (!length) + return; + pipe_buffer_flush_mapped_range(pipe->screen, st_obj->buffer, obj->Offset + offset, length); } @@ -275,7 +334,9 @@ st_bufferobj_unmap(GLcontext *ctx, GLenum target, struct gl_buffer_object *obj) struct pipe_context *pipe = st_context(ctx)->pipe; struct st_buffer_object *st_obj = st_buffer_object(obj); - pipe_buffer_unmap(pipe->screen, st_obj->buffer); + if(obj->Length) + pipe_buffer_unmap(pipe->screen, st_obj->buffer); + obj->Pointer = NULL; obj->Offset = 0; obj->Length = 0; @@ -298,6 +359,9 @@ st_copy_buffer_subdata(GLcontext *ctx, struct st_buffer_object *dstObj = st_buffer_object(dst); ubyte *srcPtr, *dstPtr; + if(!size) + return; + /* buffer should not already be mapped */ assert(!src->Pointer); assert(!dst->Pointer); @@ -313,7 +377,7 @@ st_copy_buffer_subdata(GLcontext *ctx, PIPE_BUFFER_USAGE_CPU_WRITE); if (srcPtr && dstPtr) - _mesa_memcpy(dstPtr + writeOffset, srcPtr + readOffset, size); + memcpy(dstPtr + writeOffset, srcPtr + readOffset, size); pipe_buffer_unmap(pipe->screen, srcObj->buffer); pipe_buffer_unmap(pipe->screen, dstObj->buffer);