From: Brian Paul Date: Fri, 12 Aug 2016 16:44:22 +0000 (-0600) Subject: svga: optimize memcpy() in svga_buffer_update_hw() X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ce3b34b72702195694ee8fc64c8259d4a16711ab;p=mesa.git svga: optimize memcpy() in svga_buffer_update_hw() When we migrate a buffer from sw/malloc storage to a hardware buffer, don't memcpy the whole buffer, just copy the part we've written to. Reviewed-by: Charmaine Lee --- diff --git a/src/gallium/drivers/svga/svga_resource_buffer_upload.c b/src/gallium/drivers/svga/svga_resource_buffer_upload.c index e1e65c1ccb3..7ecf95c1af7 100644 --- a/src/gallium/drivers/svga/svga_resource_buffer_upload.c +++ b/src/gallium/drivers/svga/svga_resource_buffer_upload.c @@ -620,6 +620,7 @@ svga_buffer_update_hw(struct svga_context *svga, struct svga_buffer *sbuf) enum pipe_error ret; boolean retry; void *map; + unsigned i; assert(sbuf->swbuf); if (!sbuf->swbuf) @@ -639,7 +640,13 @@ svga_buffer_update_hw(struct svga_context *svga, struct svga_buffer *sbuf) return PIPE_ERROR; } - memcpy(map, sbuf->swbuf, sbuf->b.b.width0); + /* Copy data from malloc'd swbuf to the new hardware buffer */ + for (i = 0; i < sbuf->map.num_ranges; i++) { + unsigned start = sbuf->map.ranges[i].start; + unsigned len = sbuf->map.ranges[i].end - start; + memcpy((uint8_t *) map + start, (uint8_t *) sbuf->swbuf + start, len); + } + svga_buffer_hw_storage_unmap(svga, sbuf); /* This user/malloc buffer is now indistinguishable from a gpu buffer */