Mesa (master): svga: fix index buffer reference in the hw state

Brian Paul brianp at kemper.freedesktop.org
Thu Jun 23 13:41:57 UTC 2016


Module: Mesa
Branch: master
Commit: a1d74f5528f4bab6679fc08b1a25055336c85089
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a1d74f5528f4bab6679fc08b1a25055336c85089

Author: Charmaine Lee <charmainel at vmware.com>
Date:   Mon May  2 18:12:24 2016 -0700

svga: fix index buffer reference in the hw state

Instead of copy the index buffer resource handle to the hw state in
the context structure, use pipe_resource_reference to properly reference
the index buffer resource in the context.

Reviewed-by: Brian Paul <brianp at vmware.com>

---

 src/gallium/drivers/svga/svga_context.h     |  2 +-
 src/gallium/drivers/svga/svga_draw.c        | 18 +++++++++++++-----
 src/gallium/drivers/svga/svga_pipe_vertex.c |  2 ++
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h
index 007d5bc..01f290e 100644
--- a/src/gallium/drivers/svga/svga_context.h
+++ b/src/gallium/drivers/svga/svga_context.h
@@ -361,7 +361,7 @@ struct svga_hw_draw_state
    struct svga_winsys_surface *vbuffer_handles[PIPE_MAX_ATTRIBS];
    unsigned num_vbuffers;
 
-   struct svga_winsys_surface *ib;  /**< index buffer for drawing */
+   struct pipe_resource *ib;  /**< index buffer for drawing */
    SVGA3dSurfaceFormat ib_format;
    unsigned ib_offset;
 
diff --git a/src/gallium/drivers/svga/svga_draw.c b/src/gallium/drivers/svga/svga_draw.c
index f314d55..b6de7af 100644
--- a/src/gallium/drivers/svga/svga_draw.c
+++ b/src/gallium/drivers/svga/svga_draw.c
@@ -441,6 +441,7 @@ draw_vgpu10(struct svga_hwtnl *hwtnl,
    const unsigned vbuf_count = hwtnl->cmd.vbuf_count;
    enum pipe_error ret;
    unsigned i;
+   boolean rebind_ib = FALSE;
 
    assert(svga_have_vgpu10(svga));
    assert(hwtnl->cmd.prim_count == 0);
@@ -465,7 +466,7 @@ draw_vgpu10(struct svga_hwtnl *hwtnl,
          return ret;
 
       /* Force rebinding the index buffer when needed */
-      svga->state.hw_draw.ib = NULL;
+      rebind_ib = TRUE;
    }
 
    ret = validate_sampler_resources(svga);
@@ -563,15 +564,19 @@ draw_vgpu10(struct svga_hwtnl *hwtnl,
       SVGA3dSurfaceFormat indexFormat = xlate_index_format(range->indexWidth);
 
       /* setup index buffer */
-      if (ib_handle != svga->state.hw_draw.ib ||
+      if (rebind_ib ||
+          ib != svga->state.hw_draw.ib ||
           indexFormat != svga->state.hw_draw.ib_format ||
           range->indexArray.offset != svga->state.hw_draw.ib_offset) {
+
+         assert(indexFormat != SVGA3D_FORMAT_INVALID);
          ret = SVGA3D_vgpu10_SetIndexBuffer(svga->swc, ib_handle,
                                             indexFormat,
                                             range->indexArray.offset);
          if (ret != PIPE_OK)
             return ret;
-         svga->state.hw_draw.ib = ib_handle;
+
+         pipe_resource_reference(&svga->state.hw_draw.ib, ib);
          svga->state.hw_draw.ib_format = indexFormat;
          svga->state.hw_draw.ib_offset = range->indexArray.offset;
       }
@@ -598,16 +603,19 @@ draw_vgpu10(struct svga_hwtnl *hwtnl,
    }
    else {
       /* non-indexed drawing */
-      if (svga->state.hw_draw.ib_format != SVGA3D_FORMAT_INVALID) {
+      if (svga->state.hw_draw.ib_format != SVGA3D_FORMAT_INVALID ||
+          svga->state.hw_draw.ib != NULL) {
          /* Unbind previously bound index buffer */
          ret = SVGA3D_vgpu10_SetIndexBuffer(svga->swc, NULL,
                                             SVGA3D_FORMAT_INVALID, 0);
          if (ret != PIPE_OK)
             return ret;
          svga->state.hw_draw.ib_format = SVGA3D_FORMAT_INVALID;
-         svga->state.hw_draw.ib = NULL;
+         pipe_resource_reference(&svga->state.hw_draw.ib, NULL);
       }
 
+      assert(svga->state.hw_draw.ib == NULL);
+
       if (instance_count > 1) {
          ret = SVGA3D_vgpu10_DrawInstanced(svga->swc,
                                            vcount,
diff --git a/src/gallium/drivers/svga/svga_pipe_vertex.c b/src/gallium/drivers/svga/svga_pipe_vertex.c
index 99757e4..4692f76 100644
--- a/src/gallium/drivers/svga/svga_pipe_vertex.c
+++ b/src/gallium/drivers/svga/svga_pipe_vertex.c
@@ -327,6 +327,8 @@ void svga_cleanup_vertex_state( struct svga_context *svga )
    
    for (i = 0 ; i < svga->curr.num_vertex_buffers; i++)
       pipe_resource_reference(&svga->curr.vb[i].buffer, NULL);
+
+   pipe_resource_reference(&svga->state.hw_draw.ib, NULL);
 }
 
 




More information about the mesa-commit mailing list