sp: Implement draw_elements_instanced().
authorMichal Krol <michal@vmware.com>
Wed, 30 Dec 2009 17:27:58 +0000 (18:27 +0100)
committerMichal Krol <michal@vmware.com>
Wed, 30 Dec 2009 17:27:58 +0000 (18:27 +0100)
src/gallium/drivers/softpipe/sp_context.c
src/gallium/drivers/softpipe/sp_draw_arrays.c
src/gallium/drivers/softpipe/sp_state.h

index 406414ae3d2fbf59595e88576a7a43584a6be0c9..969d69d6b42863c155d75cddd87d6007cb41db91 100644 (file)
@@ -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;
index 6a593fb06a0a9eb0f3b255b82e4a7960b4b198de..debf5bfe068a66316094b600a353d9b950e10802 100644 (file)
@@ -192,6 +192,26 @@ softpipe_draw_arrays_instanced(struct pipe_context *pipe,
                                unsigned count,
                                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;
@@ -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);
index 13935fd799f918e7f0f902dd19d5323475d57af5..00da41b98577c23781b70fe439df50cf1c5d76ca 100644 (file)
@@ -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);