diff options
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/include/pipe/p_inlines.h | 43 | ||||
-rw-r--r-- | src/gallium/include/pipe/p_screen.h | 21 |
2 files changed, 58 insertions, 6 deletions
diff --git a/src/gallium/include/pipe/p_inlines.h b/src/gallium/include/pipe/p_inlines.h index a68b5214292..1f46461043e 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,32 @@ 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) +{ + if(screen->buffer_map_range) + return screen->buffer_map_range(screen, buf, offset, length, usage); + else { + uint8_t *map; + map = screen->buffer_map(screen, buf, usage); + return map ? map + offset : NULL; + } +} + +static INLINE void +pipe_buffer_flush_mapped_range(struct pipe_screen *screen, + struct pipe_buffer *buf, + unsigned offset, + unsigned 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, @@ -81,10 +113,11 @@ 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); + map = pipe_buffer_map_range(screen, buf, offset, size, PIPE_BUFFER_USAGE_CPU_WRITE); assert(map); if(map) { - memcpy(map + offset, data, size); + memcpy(map, data, size); + pipe_buffer_flush_mapped_range(screen, buf, offset, size); pipe_buffer_unmap(screen, buf); } } @@ -100,10 +133,10 @@ 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); + map = pipe_buffer_map_range(screen, buf, offset, size, PIPE_BUFFER_USAGE_CPU_READ); assert(map); if(map) { - memcpy(data, map + offset, size); + memcpy(data, map, size); pipe_buffer_unmap(screen, buf); } } diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h index 3688d581186..d7e79ec655e 100644 --- a/src/gallium/include/pipe/p_screen.h +++ b/src/gallium/include/pipe/p_screen.h @@ -202,9 +202,28 @@ 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. + * + * Return pointer is always relative to offset 0, regardless of the + * read/write ranges. + */ + void *(*buffer_map_range)( struct pipe_screen *screen, + struct pipe_buffer *buf, + unsigned offset, + unsigned length, + unsigned usage); + + /** + * written is the range that the client actually wrote. + */ + 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 ); |