Mesa (master): llvmpipe: implement instanced drawing functions

Brian Paul brianp at kemper.freedesktop.org
Thu Jul 15 21:57:24 UTC 2010


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

Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jul 15 15:47:03 2010 -0600

llvmpipe: implement instanced drawing functions

And express all the other drawing functions in terms of
llvmpipe_draw_range_elements_instanced().

---

 src/gallium/drivers/llvmpipe/lp_draw_arrays.c |  128 +++++++++++++++++++++----
 1 files changed, 108 insertions(+), 20 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_draw_arrays.c b/src/gallium/drivers/llvmpipe/lp_draw_arrays.c
index 91d99db..625d0c8 100644
--- a/src/gallium/drivers/llvmpipe/lp_draw_arrays.c
+++ b/src/gallium/drivers/llvmpipe/lp_draw_arrays.c
@@ -43,18 +43,23 @@
 
 
 /**
- * Draw vertex arrays, with optional indexing.
+ * Draw vertex arrays, with optional indexing, optional instancing.
+ * All the other drawing functions are implemented in terms of this function.
  * Basically, map the vertex buffers (and drawing surfaces), then hand off
  * the drawing to the 'draw' module.
  */
 static void
-llvmpipe_draw_range_elements(struct pipe_context *pipe,
-                             struct pipe_resource *indexBuffer,
-                             unsigned indexSize,
-                             int indexBias,
-                             unsigned min_index,
-                             unsigned max_index,
-                             unsigned mode, unsigned start, unsigned count)
+llvmpipe_draw_range_elements_instanced(struct pipe_context *pipe,
+                                       struct pipe_resource *indexBuffer,
+                                       unsigned indexSize,
+                                       int indexBias,
+                                       unsigned minIndex,
+                                       unsigned maxIndex,
+                                       unsigned mode,
+                                       unsigned start,
+                                       unsigned count,
+                                       unsigned startInstance,
+                                       unsigned instanceCount)
 {
    struct llvmpipe_context *lp = llvmpipe_context(pipe);
    struct draw_context *draw = lp->draw;
@@ -74,9 +79,11 @@ llvmpipe_draw_range_elements(struct pipe_context *pipe,
    /* Map index buffer, if present */
    if (indexBuffer) {
       void *mapped_indexes = llvmpipe_resource_data(indexBuffer);
-      draw_set_mapped_element_buffer_range(draw, indexSize, indexBias,
-                                           min_index,
-                                           max_index,
+      draw_set_mapped_element_buffer_range(draw,
+                                           indexSize,
+                                           indexBias,
+                                           minIndex,
+                                           maxIndex,
                                            mapped_indexes);
    }
    else {
@@ -89,7 +96,8 @@ llvmpipe_draw_range_elements(struct pipe_context *pipe,
                                     lp->vertex_sampler_views);
 
    /* draw! */
-   draw_arrays(draw, mode, start, count);
+   draw_arrays_instanced(draw, mode, start, count,
+                         startInstance, instanceCount);
 
    /*
     * unmap vertex/index buffers
@@ -112,24 +120,102 @@ llvmpipe_draw_range_elements(struct pipe_context *pipe,
 
 
 static void
+llvmpipe_draw_arrays_instanced(struct pipe_context *pipe,
+                               unsigned mode,
+                               unsigned start,
+                               unsigned count,
+                               unsigned startInstance,
+                               unsigned instanceCount)
+{
+   llvmpipe_draw_range_elements_instanced(pipe,
+                                          NULL, /* no indexBuffer */
+                                          0, 0, /* indexSize, indexBias */
+                                          0, ~0, /* minIndex, maxIndex */
+                                          mode,
+                                          start,
+                                          count,
+                                          startInstance,
+                                          instanceCount);
+}
+
+
+static void
+llvmpipe_draw_elements_instanced(struct pipe_context *pipe,
+                                 struct pipe_resource *indexBuffer,
+                                 unsigned indexSize,
+                                 int indexBias,
+                                 unsigned mode,
+                                 unsigned start,
+                                 unsigned count,
+                                 unsigned startInstance,
+                                 unsigned instanceCount)
+{
+   llvmpipe_draw_range_elements_instanced(pipe,
+                                          indexBuffer,
+                                          indexSize, indexBias,
+                                          0, ~0, /* minIndex, maxIndex */
+                                          mode,
+                                          start,
+                                          count,
+                                          startInstance,
+                                          instanceCount);
+}
+
+
+static void
 llvmpipe_draw_elements(struct pipe_context *pipe,
                        struct pipe_resource *indexBuffer,
                        unsigned indexSize,
                        int indexBias,
-                       unsigned mode, unsigned start, unsigned count)
+                       unsigned mode,
+                       unsigned start,
+                       unsigned count)
+{
+   llvmpipe_draw_range_elements_instanced(pipe,
+                                          indexBuffer,
+                                          indexSize, indexBias,
+                                          0, 0xffffffff,  /* min, maxIndex */
+                                          mode, start, count,
+                                          0,  /* startInstance */
+                                          1);  /* instanceCount */
+}
+
+
+static void
+llvmpipe_draw_range_elements(struct pipe_context *pipe,
+                             struct pipe_resource *indexBuffer,
+                             unsigned indexSize,
+                             int indexBias,
+                             unsigned min_index,
+                             unsigned max_index,
+                             unsigned mode,
+                             unsigned start,
+                             unsigned count)
 {
-   llvmpipe_draw_range_elements( pipe, indexBuffer,
-                                 indexSize, indexBias,
-                                 0, 0xffffffff,
-                                 mode, start, count );
+   llvmpipe_draw_range_elements_instanced(pipe,
+                                          indexBuffer,
+                                          indexSize, indexBias,
+                                          min_index, max_index,
+                                          mode, start, count,
+                                          0,  /* startInstance */
+                                          1);  /* instanceCount */
 }
 
 
 static void
-llvmpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
-                     unsigned start, unsigned count)
+llvmpipe_draw_arrays(struct pipe_context *pipe,
+                     unsigned mode,
+                     unsigned start,
+                     unsigned count)
 {
-   llvmpipe_draw_elements(pipe, NULL, 0, 0, mode, start, count);
+   llvmpipe_draw_range_elements_instanced(pipe,
+                                          NULL,  /* indexBuffer */
+                                          0,  /* indexSize */
+                                          0,  /* indexBias */
+                                          0, ~0,  /* min, maxIndex */
+                                          mode, start, count,
+                                          0,  /* startInstance */
+                                          1);  /* instanceCount */
 }
 
 
@@ -139,4 +225,6 @@ llvmpipe_init_draw_funcs(struct llvmpipe_context *llvmpipe)
    llvmpipe->pipe.draw_arrays = llvmpipe_draw_arrays;
    llvmpipe->pipe.draw_elements = llvmpipe_draw_elements;
    llvmpipe->pipe.draw_range_elements = llvmpipe_draw_range_elements;
+   llvmpipe->pipe.draw_arrays_instanced = llvmpipe_draw_arrays_instanced;
+   llvmpipe->pipe.draw_elements_instanced = llvmpipe_draw_elements_instanced;
 }




More information about the mesa-commit mailing list