llvmpipe: make geometry shaders and stream output work
authorZack Rusin <zackr@vmware.com>
Tue, 22 Jun 2010 16:56:54 +0000 (12:56 -0400)
committerZack Rusin <zackr@vmware.com>
Tue, 22 Jun 2010 16:58:04 +0000 (12:58 -0400)
src/gallium/drivers/llvmpipe/Makefile
src/gallium/drivers/llvmpipe/SConscript
src/gallium/drivers/llvmpipe/lp_context.c
src/gallium/drivers/llvmpipe/lp_context.h
src/gallium/drivers/llvmpipe/lp_state.h
src/gallium/drivers/llvmpipe/lp_state_fs.c
src/gallium/drivers/llvmpipe/lp_state_sampler.c
src/gallium/drivers/llvmpipe/lp_state_so.c [new file with mode: 0644]

index c79c8bd9d1e9193a2547c7c0073c1a5b9eabd2c4..ee28179c303272e18e9269352d8fbb3e0ffaba03 100644 (file)
@@ -37,6 +37,7 @@ C_SOURCES = \
        lp_state_gs.c \
        lp_state_rasterizer.c \
        lp_state_sampler.c \
+        lp_state_so.c \
        lp_state_surface.c \
        lp_state_vertex.c \
        lp_state_vs.c \
index a0646692e7b67256ab9125afbaaceecb999f296e..a1ef71da89d754e0594898d93f605f06bc17fe94 100644 (file)
@@ -57,6 +57,7 @@ llvmpipe = env.ConvenienceLibrary(
                'lp_state_gs.c',
                'lp_state_rasterizer.c',
                'lp_state_sampler.c',
+                'lp_state_so.c',
                'lp_state_surface.c',
                'lp_state_vertex.c',
                'lp_state_vs.c',
index 06689c20eb8e427c05b944dbc6eb6e3bf68a0ebe..3db4f12ebb61821586ff89b0758e529470dc3f25 100644 (file)
@@ -113,6 +113,7 @@ llvmpipe_create_context( struct pipe_screen *screen, void *priv )
    llvmpipe_init_sampler_funcs(llvmpipe);
    llvmpipe_init_query_funcs( llvmpipe );
    llvmpipe_init_vertex_funcs(llvmpipe);
+   llvmpipe_init_so_funcs(llvmpipe);
    llvmpipe_init_fs_funcs(llvmpipe);
    llvmpipe_init_vs_funcs(llvmpipe);
    llvmpipe_init_gs_funcs(llvmpipe);
index 1bdd0f79e195e381be6b0f2d34172777e699d447..986e604ce7c167a9a5da10ecb89c3113f06af1cf 100644 (file)
@@ -63,6 +63,7 @@ struct llvmpipe_context {
    const struct lp_vertex_shader *vs;
    const struct lp_geometry_shader *gs;
    const struct lp_velems_state *velems;
+   const struct lp_so_state *so;
 
    /** Other rendering state */
    struct pipe_blend_color blend_color;
@@ -76,6 +77,12 @@ struct llvmpipe_context {
    struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS];
    struct pipe_viewport_state viewport;
    struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
+   struct {
+      struct llvmpipe_resource *buffer[PIPE_MAX_SO_BUFFERS];
+      int offset[PIPE_MAX_SO_BUFFERS];
+      int so_count[PIPE_MAX_SO_BUFFERS];
+      int num_buffers;
+   } so_target;
 
    unsigned num_samplers;
    unsigned num_fragment_sampler_views;
index 3f7a85b6827318b77b67d9eeee322cd73a4f252a..05d1b9379449cae2211425e079283835d9db9b7e 100644 (file)
@@ -54,6 +54,9 @@
 #define LP_NEW_QUERY         0x4000
 #define LP_NEW_BLEND_COLOR   0x8000
 #define LP_NEW_GS            0x10000
+#define LP_NEW_SO            0x20000
+#define LP_NEW_SO_BUFFERS    0x40000
+
 
 
 struct vertex_info;
@@ -82,6 +85,10 @@ struct lp_velems_state
    struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS];
 };
 
+struct lp_so_state {
+   struct pipe_stream_output_state base;
+};
+
 
 void
 llvmpipe_set_framebuffer_state(struct pipe_context *,
@@ -120,5 +127,9 @@ llvmpipe_init_gs_funcs(struct llvmpipe_context *llvmpipe);
 void
 llvmpipe_init_rasterizer_funcs(struct llvmpipe_context *llvmpipe);
 
+void
+llvmpipe_init_so_funcs(struct llvmpipe_context *llvmpipe);
+
+
 
 #endif
index bb9b82b2accc6519a55b6ef92cb236a9b1d5d572..65115052cdd50a2adc1489ae6433cd09880ef287 100644 (file)
@@ -1111,9 +1111,10 @@ llvmpipe_set_constant_buffer(struct pipe_context *pipe,
    /* note: reference counting */
    pipe_resource_reference(&llvmpipe->constants[shader][index], constants);
 
-   if(shader == PIPE_SHADER_VERTEX) {
-      draw_set_mapped_constant_buffer(llvmpipe->draw, PIPE_SHADER_VERTEX, index,
-                                      data, size);
+   if(shader == PIPE_SHADER_VERTEX ||
+      shader == PIPE_SHADER_GEOMETRY) {
+      draw_set_mapped_constant_buffer(llvmpipe->draw, shader,
+                                      index, data, size);
    }
 
    llvmpipe->dirty |= LP_NEW_CONSTANTS;
index 55d43368a3e6b4ba06674dbd0063c12b528d8b38..e94065fb6ab571b465e0b3e4fb8276e40449173b 100644 (file)
@@ -104,6 +104,13 @@ llvmpipe_bind_vertex_sampler_states(struct pipe_context *pipe,
 }
 
 
+static void
+llvmpipe_bind_geometry_sampler_states(struct pipe_context *pipe,
+                                      unsigned num, void **sampler)
+{
+   /* XXX: implementation missing */
+}
+
 static void
 llvmpipe_set_fragment_sampler_views(struct pipe_context *pipe,
                                     unsigned num,
@@ -163,6 +170,14 @@ llvmpipe_set_vertex_sampler_views(struct pipe_context *pipe,
 }
 
 
+static void
+llvmpipe_set_geometry_sampler_views(struct pipe_context *pipe,
+                                    unsigned num,
+                                    struct pipe_sampler_view **views)
+{
+   /*XXX: implementation missing */
+}
+
 static struct pipe_sampler_view *
 llvmpipe_create_sampler_view(struct pipe_context *pipe,
                             struct pipe_resource *texture,
@@ -206,8 +221,10 @@ llvmpipe_init_sampler_funcs(struct llvmpipe_context *llvmpipe)
 
    llvmpipe->pipe.bind_fragment_sampler_states  = llvmpipe_bind_sampler_states;
    llvmpipe->pipe.bind_vertex_sampler_states  = llvmpipe_bind_vertex_sampler_states;
+   llvmpipe->pipe.bind_geometry_sampler_states  = llvmpipe_bind_geometry_sampler_states;
    llvmpipe->pipe.set_fragment_sampler_views = llvmpipe_set_fragment_sampler_views;
    llvmpipe->pipe.set_vertex_sampler_views = llvmpipe_set_vertex_sampler_views;
+   llvmpipe->pipe.set_geometry_sampler_views = llvmpipe_set_geometry_sampler_views;
    llvmpipe->pipe.create_sampler_view = llvmpipe_create_sampler_view;
    llvmpipe->pipe.sampler_view_destroy = llvmpipe_sampler_view_destroy;
    llvmpipe->pipe.delete_sampler_state = llvmpipe_delete_sampler_state;
diff --git a/src/gallium/drivers/llvmpipe/lp_state_so.c b/src/gallium/drivers/llvmpipe/lp_state_so.c
new file mode 100644 (file)
index 0000000..4c64a5b
--- /dev/null
@@ -0,0 +1,138 @@
+/**************************************************************************
+ *
+ * Copyright 2010 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "lp_context.h"
+#include "lp_state.h"
+#include "lp_texture.h"
+
+#include "util/u_format.h"
+#include "util/u_memory.h"
+#include "draw/draw_context.h"
+
+
+static void *
+llvmpipe_create_stream_output_state(struct pipe_context *pipe,
+                                    const struct pipe_stream_output_state *templ)
+{
+   struct lp_so_state *so;
+   so = (struct lp_so_state *) CALLOC_STRUCT(lp_so_state);
+
+   if (so) {
+      so->base.num_outputs = templ->num_outputs;
+      so->base.stride = templ->stride;
+      memcpy(so->base.output_buffer,
+             templ->output_buffer,
+             sizeof(int) * templ->num_outputs);
+      memcpy(so->base.register_index,
+             templ->register_index,
+             sizeof(int) * templ->num_outputs);
+      memcpy(so->base.register_mask,
+             templ->register_mask,
+             sizeof(ubyte) * templ->num_outputs);
+   }
+   return so;
+}
+
+static void
+llvmpipe_bind_stream_output_state(struct pipe_context *pipe,
+                                  void *so)
+{
+   struct llvmpipe_context *lp = llvmpipe_context(pipe);
+   struct lp_so_state *lp_so = (struct lp_so_state *) so;
+
+   lp->so = lp_so;
+
+   lp->dirty |= LP_NEW_SO;
+
+   if (lp_so)
+      draw_set_so_state(lp->draw, &lp_so->base);
+}
+
+static void
+llvmpipe_delete_stream_output_state(struct pipe_context *pipe, void *so)
+{
+   FREE( so );
+}
+
+static void
+llvmpipe_set_stream_output_buffers(struct pipe_context *pipe,
+                                   struct pipe_resource **buffers,
+                                   int *offsets,
+                                   int num_buffers)
+{
+   struct llvmpipe_context *lp = llvmpipe_context(pipe);
+   int i;
+   void *map_buffers[PIPE_MAX_SO_BUFFERS];
+
+   assert(num_buffers <= PIPE_MAX_SO_BUFFERS);
+   if (num_buffers > PIPE_MAX_SO_BUFFERS)
+      num_buffers = PIPE_MAX_SO_BUFFERS;
+
+   lp->dirty |= LP_NEW_SO_BUFFERS;
+
+   for (i = 0; i < num_buffers; ++i) {
+      void *mapped;
+      struct llvmpipe_resource *res = llvmpipe_resource(buffers[i]);
+
+      if (!res) {
+         /* the whole call is invalid, bail out */
+         lp->so_target.num_buffers = 0;
+         draw_set_mapped_so_buffers(lp->draw, 0, 0);
+         return;
+      }
+
+      lp->so_target.buffer[i] = res;
+      lp->so_target.offset[i] = offsets[i];
+      lp->so_target.so_count[i] = 0;
+
+      mapped = res->data;
+      if (offsets[i] >= 0)
+         map_buffers[i] = ((char*)mapped) + offsets[i];
+      else {
+         /* this is a buffer append */
+         assert(!"appending not implemented");
+         map_buffers[i] = mapped;
+      }
+   }
+   lp->so_target.num_buffers = num_buffers;
+
+   draw_set_mapped_so_buffers(lp->draw, map_buffers, num_buffers);
+}
+
+void
+llvmpipe_init_so_funcs(struct llvmpipe_context *llvmpipe)
+{
+   llvmpipe->pipe.create_stream_output_state =
+      llvmpipe_create_stream_output_state;
+   llvmpipe->pipe.bind_stream_output_state =
+      llvmpipe_bind_stream_output_state;
+   llvmpipe->pipe.delete_stream_output_state =
+      llvmpipe_delete_stream_output_state;
+
+   llvmpipe->pipe.set_stream_output_buffers =
+      llvmpipe_set_stream_output_buffers;
+}