diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/main/mtypes.h | 2 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_bufferobjects.c | 32 | ||||
-rw-r--r-- | src/mesa/vbo/vbo_exec_draw.c | 15 |
3 files changed, 37 insertions, 12 deletions
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index f906de8357e..baf5850b83b 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1499,6 +1499,8 @@ struct gl_buffer_object GLenum Usage; GLenum Access; GLvoid *Pointer; /**< Only valid while buffer is mapped */ + GLintptr Offset; /**< mapped offset */ + GLsizeiptr Length; /**< mapped length */ GLsizeiptrARB Size; /**< Size of storage in bytes */ GLubyte *Data; /**< Location of storage either in RAM or VRAM. */ GLboolean OnCard; /**< Is buffer in VRAM? (hardware drivers) */ diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index 45fbe8c76e0..3651e4ae7dc 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -201,6 +201,10 @@ st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access, } obj->Pointer = pipe_buffer_map(pipe->screen, st_obj->buffer, flags); + if(obj->Pointer) { + obj->Offset = 0; + obj->Length = obj->Size; + } return obj->Pointer; } @@ -231,11 +235,18 @@ st_bufferobj_map_range(GLcontext *ctx, GLenum target, if (access & MESA_MAP_NOWAIT_BIT) flags |= PIPE_BUFFER_USAGE_DONTBLOCK; - map = pipe_buffer_map_range(pipe->screen, st_obj->buffer, offset, length, flags); - /* this is expected to point to the buffer start, in order to calculate the - * vertices offsets - */ - obj->Pointer = map ? map - offset : NULL; + assert(offset >= 0); + assert(length >= 0); + 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) { + obj->Offset = 0; + obj->Length = obj->Size; + map += offset; + } + return map; } @@ -248,7 +259,14 @@ st_bufferobj_flush_mapped_range(GLcontext *ctx, GLenum target, struct pipe_context *pipe = st_context(ctx)->pipe; struct st_buffer_object *st_obj = st_buffer_object(obj); - pipe_buffer_flush_mapped_range(pipe->screen, st_obj->buffer, offset, length); + /* Subrange is relative to mapped range */ + assert(offset >= 0); + assert(length >= 0); + assert(offset < obj->Length); + assert(offset + length <= obj->Length); + + pipe_buffer_flush_mapped_range(pipe->screen, st_obj->buffer, + obj->Offset + offset, length); } @@ -263,6 +281,8 @@ st_bufferobj_unmap(GLcontext *ctx, GLenum target, struct gl_buffer_object *obj) pipe_buffer_unmap(pipe->screen, st_obj->buffer); obj->Pointer = NULL; + obj->Offset = 0; + obj->Length = 0; return GL_TRUE; } diff --git a/src/mesa/vbo/vbo_exec_draw.c b/src/mesa/vbo/vbo_exec_draw.c index 6f8d1f8eb07..b3787459169 100644 --- a/src/mesa/vbo/vbo_exec_draw.c +++ b/src/mesa/vbo/vbo_exec_draw.c @@ -240,13 +240,16 @@ static void vbo_exec_vtx_unmap( struct vbo_exec_context *exec ) if (exec->vtx.bufferobj->Name) { GLcontext *ctx = exec->ctx; - GLintptr offset = exec->vtx.buffer_used; - GLsizeiptr length = (exec->vtx.buffer_ptr - exec->vtx.buffer_map) * sizeof(float); - if(ctx->Driver.FlushMappedBufferRange) - ctx->Driver.FlushMappedBufferRange(ctx, target, - offset, length, - exec->vtx.bufferobj); + if(ctx->Driver.FlushMappedBufferRange) { + GLintptr offset = exec->vtx.buffer_used - exec->vtx.bufferobj->Offset; + GLsizeiptr length = (exec->vtx.buffer_ptr - exec->vtx.buffer_map) * sizeof(float); + + if(length) + ctx->Driver.FlushMappedBufferRange(ctx, target, + offset, length, + exec->vtx.bufferobj); + } exec->vtx.buffer_used += (exec->vtx.buffer_ptr - exec->vtx.buffer_map) * sizeof(float); |