Mesa (instanced-arrays): sp: Implement draw_elements_instanced().

Michał Król michal at kemper.freedesktop.org
Wed Dec 30 09:54:20 PST 2009


Module: Mesa
Branch: instanced-arrays
Commit: bccdb239c700e0c7c90d27a281d5246b958581b5
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=bccdb239c700e0c7c90d27a281d5246b958581b5

Author: Michal Krol <michal at vmware.com>
Date:   Wed Dec 30 18:27:58 2009 +0100

sp: Implement draw_elements_instanced().

---

 src/gallium/drivers/softpipe/sp_context.c     |    1 +
 src/gallium/drivers/softpipe/sp_draw_arrays.c |   46 +++++++++++++++++++++++-
 src/gallium/drivers/softpipe/sp_state.h       |   10 +++++
 3 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c
index 406414a..969d69d 100644
--- a/src/gallium/drivers/softpipe/sp_context.c
+++ b/src/gallium/drivers/softpipe/sp_context.c
@@ -239,6 +239,7 @@ softpipe_create( struct pipe_screen *screen )
    softpipe->pipe.draw_elements = softpipe_draw_elements;
    softpipe->pipe.draw_range_elements = softpipe_draw_range_elements;
    softpipe->pipe.draw_arrays_instanced = softpipe_draw_arrays_instanced;
+   softpipe->pipe.draw_elements_instanced = softpipe_draw_elements_instanced;
 
    softpipe->pipe.clear = softpipe_clear;
    softpipe->pipe.flush = softpipe_flush;
diff --git a/src/gallium/drivers/softpipe/sp_draw_arrays.c b/src/gallium/drivers/softpipe/sp_draw_arrays.c
index 6a593fb..debf5bf 100644
--- a/src/gallium/drivers/softpipe/sp_draw_arrays.c
+++ b/src/gallium/drivers/softpipe/sp_draw_arrays.c
@@ -193,6 +193,26 @@ softpipe_draw_arrays_instanced(struct pipe_context *pipe,
                                unsigned startInstance,
                                unsigned instanceCount)
 {
+   return softpipe_draw_elements_instanced(pipe,
+                                           NULL,
+                                           0,
+                                           mode,
+                                           start,
+                                           count,
+                                           startInstance,
+                                           instanceCount);
+}
+
+boolean
+softpipe_draw_elements_instanced(struct pipe_context *pipe,
+                                 struct pipe_buffer *indexBuffer,
+                                 unsigned indexSize,
+                                 unsigned mode,
+                                 unsigned start,
+                                 unsigned count,
+                                 unsigned startInstance,
+                                 unsigned instanceCount)
+{
    struct softpipe_context *sp = softpipe_context(pipe);
    struct draw_context *draw = sp->draw;
    unsigned i;
@@ -216,8 +236,26 @@ softpipe_draw_arrays_instanced(struct pipe_context *pipe,
       draw_set_mapped_vertex_buffer(draw, i, buf);
    }
 
-   draw_set_mapped_element_buffer_range(draw, 0, start,
-                                        start + count - 1, NULL);
+   /* Map index buffer, if present */
+   if (indexBuffer) {
+      void *mapped_indexes;
+
+      mapped_indexes = pipe_buffer_map(pipe->screen,
+                                       indexBuffer,
+                                       PIPE_BUFFER_USAGE_CPU_READ);
+      draw_set_mapped_element_buffer_range(draw,
+                                           indexSize,
+                                           0,
+                                           0xffffffff,
+                                           mapped_indexes);
+   } else {
+      /* no index/element buffer */
+      draw_set_mapped_element_buffer_range(draw,
+                                           0,
+                                           start,
+                                           start + count - 1,
+                                           NULL);
+   }
 
    /* draw! */
    draw_arrays_instanced(draw, mode, start, count, startInstance, instanceCount);
@@ -227,6 +265,10 @@ softpipe_draw_arrays_instanced(struct pipe_context *pipe,
       draw_set_mapped_vertex_buffer(draw, i, NULL);
       pipe_buffer_unmap(pipe->screen, sp->vertex_buffer[i].buffer);
    }
+   if (indexBuffer) {
+      draw_set_mapped_element_buffer(draw, 0, NULL);
+      pipe_buffer_unmap(pipe->screen, indexBuffer);
+   }
 
    /* Note: leave drawing surfaces mapped */
    softpipe_unmap_constant_buffers(sp);
diff --git a/src/gallium/drivers/softpipe/sp_state.h b/src/gallium/drivers/softpipe/sp_state.h
index 13935fd..00da41b 100644
--- a/src/gallium/drivers/softpipe/sp_state.h
+++ b/src/gallium/drivers/softpipe/sp_state.h
@@ -197,6 +197,16 @@ softpipe_draw_arrays_instanced(struct pipe_context *pipe,
                                unsigned startInstance,
                                unsigned instanceCount);
 
+boolean
+softpipe_draw_elements_instanced(struct pipe_context *pipe,
+                                 struct pipe_buffer *indexBuffer,
+                                 unsigned indexSize,
+                                 unsigned mode,
+                                 unsigned start,
+                                 unsigned count,
+                                 unsigned startInstance,
+                                 unsigned instanceCount);
+
 void
 softpipe_map_transfers(struct softpipe_context *sp);
 



More information about the mesa-commit mailing list