summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gallium/include/pipe/p_inlines.h48
-rw-r--r--src/gallium/include/pipe/p_screen.h28
-rw-r--r--src/mesa/main/mtypes.h2
-rw-r--r--src/mesa/state_tracker/st_cb_bufferobjects.c40
-rw-r--r--src/mesa/vbo/vbo_exec_draw.c17
5 files changed, 122 insertions, 13 deletions
diff --git a/src/gallium/include/pipe/p_inlines.h b/src/gallium/include/pipe/p_inlines.h
index a68b521429..1232c87968 100644
--- a/src/gallium/include/pipe/p_inlines.h
+++ b/src/gallium/include/pipe/p_inlines.h
@@ -60,7 +60,13 @@ pipe_buffer_map(struct pipe_screen *screen,
struct pipe_buffer *buf,
unsigned usage)
{
- return screen->buffer_map(screen, buf, usage);
+ if(screen->buffer_map_range) {
+ unsigned offset = 0;
+ unsigned length = buf->size;
+ return screen->buffer_map_range(screen, buf, offset, length, usage);
+ }
+ else
+ return screen->buffer_map(screen, buf, usage);
}
static INLINE void
@@ -70,6 +76,35 @@ pipe_buffer_unmap(struct pipe_screen *screen,
screen->buffer_unmap(screen, buf);
}
+static INLINE void *
+pipe_buffer_map_range(struct pipe_screen *screen,
+ struct pipe_buffer *buf,
+ unsigned offset,
+ unsigned length,
+ unsigned usage)
+{
+ assert(offset < buf->size);
+ assert(offset + length <= buf->size);
+ assert(length);
+ if(screen->buffer_map_range)
+ return screen->buffer_map_range(screen, buf, offset, length, usage);
+ else
+ return screen->buffer_map(screen, buf, usage);
+}
+
+static INLINE void
+pipe_buffer_flush_mapped_range(struct pipe_screen *screen,
+ struct pipe_buffer *buf,
+ unsigned offset,
+ unsigned length)
+{
+ assert(offset < buf->size);
+ assert(offset + length <= buf->size);
+ assert(length);
+ if(screen->buffer_flush_mapped_range)
+ screen->buffer_flush_mapped_range(screen, buf, offset, length);
+}
+
static INLINE void
pipe_buffer_write(struct pipe_screen *screen,
struct pipe_buffer *buf,
@@ -80,11 +115,13 @@ pipe_buffer_write(struct pipe_screen *screen,
assert(offset < buf->size);
assert(offset + size <= buf->size);
-
- map = pipe_buffer_map(screen, buf, PIPE_BUFFER_USAGE_CPU_WRITE);
+ assert(size);
+
+ map = pipe_buffer_map_range(screen, buf, offset, size, PIPE_BUFFER_USAGE_CPU_WRITE);
assert(map);
if(map) {
memcpy(map + offset, data, size);
+ pipe_buffer_flush_mapped_range(screen, buf, offset, size);
pipe_buffer_unmap(screen, buf);
}
}
@@ -99,8 +136,9 @@ pipe_buffer_read(struct pipe_screen *screen,
assert(offset < buf->size);
assert(offset + size <= buf->size);
-
- map = pipe_buffer_map(screen, buf, PIPE_BUFFER_USAGE_CPU_READ);
+ assert(size);
+
+ map = pipe_buffer_map_range(screen, buf, offset, size, PIPE_BUFFER_USAGE_CPU_READ);
assert(map);
if(map) {
memcpy(data, map + offset, size);
diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h
index 3688d58118..ed3a026023 100644
--- a/src/gallium/include/pipe/p_screen.h
+++ b/src/gallium/include/pipe/p_screen.h
@@ -202,9 +202,35 @@ struct pipe_screen {
void *(*buffer_map)( struct pipe_screen *screen,
struct pipe_buffer *buf,
unsigned usage );
+ /**
+ * Map a subrange of the buffer data store into the client's address space.
+ *
+ * The returned pointer is always relative to buffer start, regardless of
+ * the specified range. This is different from the ARB_map_buffer_range
+ * semantics because we don't forbid multiple mappings of the same buffer
+ * (yet).
+ */
+ void *(*buffer_map_range)( struct pipe_screen *screen,
+ struct pipe_buffer *buf,
+ unsigned offset,
+ unsigned length,
+ unsigned usage);
+
+ /**
+ * Notify a range that was actually written into.
+ *
+ * The range is relative to the buffer start, regardless of the range
+ * specified to buffer_map_range. This is different from the
+ * ARB_map_buffer_range semantics because we don't forbid multiple mappings
+ * of the same buffer (yet).
+ */
+ void (*buffer_flush_mapped_range)( struct pipe_screen *screen,
+ struct pipe_buffer *buf,
+ unsigned offset,
+ unsigned length);
void (*buffer_unmap)( struct pipe_screen *screen,
- struct pipe_buffer *buf );
+ struct pipe_buffer *buf );
void (*buffer_destroy)( struct pipe_buffer *buf );
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index f906de8357..baf5850b83 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 52099232ad..3651e4ae7d 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;
}
@@ -217,6 +221,7 @@ 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);
GLuint flags = 0;
+ char *map;
if (access & GL_MAP_WRITE_BIT)
flags |= PIPE_BUFFER_USAGE_CPU_WRITE;
@@ -230,11 +235,39 @@ st_bufferobj_map_range(GLcontext *ctx, GLenum target,
if (access & MESA_MAP_NOWAIT_BIT)
flags |= PIPE_BUFFER_USAGE_DONTBLOCK;
- obj->Pointer = pipe_buffer_map(pipe->screen, st_obj->buffer, flags);
- return obj->Pointer;
+ 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;
}
+static void
+st_bufferobj_flush_mapped_range(GLcontext *ctx, GLenum target,
+ GLintptr offset, GLsizeiptr length,
+ struct gl_buffer_object *obj)
+{
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_buffer_object *st_obj = st_buffer_object(obj);
+
+ /* 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);
+}
/**
@@ -248,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;
}
@@ -262,5 +297,6 @@ st_init_bufferobject_functions(struct dd_function_table *functions)
functions->GetBufferSubData = st_bufferobj_get_subdata;
functions->MapBuffer = st_bufferobj_map;
functions->MapBufferRange = st_bufferobj_map_range;
+ functions->FlushMappedBufferRange = st_bufferobj_flush_mapped_range;
functions->UnmapBuffer = st_bufferobj_unmap;
}
diff --git a/src/mesa/vbo/vbo_exec_draw.c b/src/mesa/vbo/vbo_exec_draw.c
index 59e176b837..b378745916 100644
--- a/src/mesa/vbo/vbo_exec_draw.c
+++ b/src/mesa/vbo/vbo_exec_draw.c
@@ -240,6 +240,16 @@ static void vbo_exec_vtx_unmap( struct vbo_exec_context *exec )
if (exec->vtx.bufferobj->Name) {
GLcontext *ctx = exec->ctx;
+
+ 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);
@@ -286,11 +296,8 @@ void vbo_exec_vtx_map( struct vbo_exec_context *exec )
exec->vtx.bufferobj);
exec->vtx.buffer_ptr = exec->vtx.buffer_map;
}
-
- if (exec->vtx.buffer_map) {
- exec->vtx.buffer_map += exec->vtx.buffer_used / sizeof(float);
- }
- else {
+
+ if (!exec->vtx.buffer_map) {
exec->vtx.buffer_used = 0;
ctx->Driver.BufferData(ctx, target,