i915g: Don't (un)map vbuf on each (un)map call
authorJakob Bornecrantz <wallbraker@gmail.com>
Wed, 1 Dec 2010 04:49:42 +0000 (05:49 +0100)
committerJakob Bornecrantz <wallbraker@gmail.com>
Fri, 21 Jan 2011 19:53:29 +0000 (20:53 +0100)
src/gallium/drivers/i915/i915_prim_vbuf.c

index baebbc7bae3a471594507761fdbf1d2af4ff975a..3473c863970b949598dc5901bcfcbef53bbdb2e9 100644 (file)
@@ -181,6 +181,7 @@ i915_vbuf_render_new_buf(struct i915_vbuf_render *i915_render, size_t size)
    struct i915_winsys *iws = i915->iws;
 
    if (i915_render->vbo) {
+      iws->buffer_unmap(iws, i915_render->vbo);
       iws->buffer_destroy(iws, i915_render->vbo);
       /*
        * XXX If buffers where referenced then this should be done in
@@ -208,6 +209,7 @@ i915_vbuf_render_new_buf(struct i915_vbuf_render *i915_render, size_t size)
 
    i915_render->vbo = iws->buffer_create(iws, i915_render->vbo_size,
                                          I915_NEW_VERTEX);
+   i915_render->vbo_ptr = iws->buffer_map(iws, i915_render->vbo, TRUE);
 }
 
 /**
@@ -262,16 +264,13 @@ i915_vbuf_render_map_vertices(struct vbuf_render *render)
 {
    struct i915_vbuf_render *i915_render = i915_vbuf_render(render);
    struct i915_context *i915 = i915_render->i915;
-   struct i915_winsys *iws = i915->iws;
 
    if (i915->vbo_flushed)
       debug_printf("%s bad vbo flush occured stalling on hw\n", __FUNCTION__);
 
 #ifdef VBUF_MAP_BUFFER
-   i915_render->vbo_ptr = iws->buffer_map(iws, i915_render->vbo, TRUE);
    return (unsigned char *)i915_render->vbo_ptr + i915_render->vbo_sw_offset;
 #else
-   (void)iws;
    return (unsigned char *)i915_render->vbo_ptr;
 #endif
 }
@@ -288,7 +287,7 @@ i915_vbuf_render_unmap_vertices(struct vbuf_render *render,
    i915_render->vbo_max_index = max_index;
    i915_render->vbo_max_used = MAX2(i915_render->vbo_max_used, i915_render->vertex_size * (max_index + 1));
 #ifdef VBUF_MAP_BUFFER
-   iws->buffer_unmap(iws, i915_render->vbo);
+   (void)iws;
 #else
    i915_render->map_used_start = i915_render->vertex_size * min_index;
    i915_render->map_used_end = i915_render->vertex_size * (max_index + 1);
@@ -684,6 +683,15 @@ static void
 i915_vbuf_render_destroy(struct vbuf_render *render)
 {
    struct i915_vbuf_render *i915_render = i915_vbuf_render(render);
+   struct i915_context *i915 = i915_render->i915;
+   struct i915_winsys *iws = i915->iws;
+
+   if (i915_render->vbo) {
+      i915->vbo = NULL;
+      iws->buffer_unmap(iws, i915_render->vbo);
+      iws->buffer_destroy(iws, i915_render->vbo);
+   }
+
    FREE(i915_render);
 }