llvmpipe: disconnect vertex texture sampling from the setup
authorZack Rusin <zackr@vmware.com>
Tue, 6 Jul 2010 17:27:31 +0000 (13:27 -0400)
committerZack Rusin <zackr@vmware.com>
Tue, 6 Jul 2010 17:29:04 +0000 (13:29 -0400)
it was wrong to put this in the fs paths, but it was easier to just
stuff it along the fragment texture sampling paths. the patch
disconnects vertex texture sampling and just maps the textures
before the draw itself and unmaps them after.

src/gallium/drivers/llvmpipe/lp_context.h
src/gallium/drivers/llvmpipe/lp_draw_arrays.c
src/gallium/drivers/llvmpipe/lp_setup.c
src/gallium/drivers/llvmpipe/lp_setup.h
src/gallium/drivers/llvmpipe/lp_setup_context.h
src/gallium/drivers/llvmpipe/lp_state.h
src/gallium/drivers/llvmpipe/lp_state_derived.c
src/gallium/drivers/llvmpipe/lp_state_sampler.c

index 986e604ce7c167a9a5da10ecb89c3113f06af1cf..b2643ab33cd27f934221c79b370ff3ec858b2ba9 100644 (file)
@@ -83,6 +83,7 @@ struct llvmpipe_context {
       int so_count[PIPE_MAX_SO_BUFFERS];
       int num_buffers;
    } so_target;
+   struct pipe_resource *mapped_vs_tex[PIPE_MAX_VERTEX_SAMPLERS];
 
    unsigned num_samplers;
    unsigned num_fragment_sampler_views;
index 98780d7631b466e9d250219dcb1aadd7ea4e84d5..91d99db01717f58c1eff40fa52b43760538299a9 100644 (file)
@@ -84,6 +84,9 @@ llvmpipe_draw_range_elements(struct pipe_context *pipe,
       draw_set_mapped_element_buffer_range(draw, 0, 0, start,
                                            start + count - 1, NULL);
    }
+   llvmpipe_prepare_vertex_sampling(lp,
+                                    lp->num_vertex_sampler_views,
+                                    lp->vertex_sampler_views);
 
    /* draw! */
    draw_arrays(draw, mode, start, count);
@@ -97,6 +100,7 @@ llvmpipe_draw_range_elements(struct pipe_context *pipe,
    if (indexBuffer) {
       draw_set_mapped_element_buffer(draw, 0, 0, NULL);
    }
+   llvmpipe_cleanup_vertex_sampling(lp);
 
    /*
     * TODO: Flush only when a user vertex/index buffer is present
index fcb6e06123d716f430a384a9dded828f30ad5062..2bd6fcebe7f9b0a21b583dd467ea79819033ecaf 100644 (file)
@@ -656,75 +656,6 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup,
 }
 
 
-/**
- * Called during state validation when LP_NEW_SAMPLER_VIEW is set.
- */
-void
-lp_setup_set_vertex_sampler_views(struct lp_setup_context *setup,
-                                  unsigned num,
-                                  struct pipe_sampler_view **views)
-{
-   unsigned i;
-   uint32_t row_stride[DRAW_MAX_TEXTURE_LEVELS];
-   uint32_t img_stride[DRAW_MAX_TEXTURE_LEVELS];
-   const void *data[DRAW_MAX_TEXTURE_LEVELS];
-   struct lp_scene *scene;
-   struct llvmpipe_context *lp;
-
-   LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__);
-
-   assert(num <= PIPE_MAX_VERTEX_SAMPLERS);
-
-   scene = lp_setup_get_current_scene(setup);
-   lp = llvmpipe_context(scene->pipe);
-
-   for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
-      struct pipe_sampler_view *view = i < num ? views[i] : NULL;
-
-      if (view) {
-         struct pipe_resource *tex = view->texture;
-         struct llvmpipe_resource *lp_tex = llvmpipe_resource(tex);
-
-         /* We're referencing the texture's internal data, so save a
-          * reference to it.
-          */
-         pipe_resource_reference(&setup->vs.current_tex[i], tex);
-
-         if (!lp_tex->dt) {
-            /* regular texture - setup array of mipmap level pointers */
-            int j;
-            for (j = 0; j <= tex->last_level; j++) {
-               data[j] =
-                  llvmpipe_get_texture_image_all(lp_tex, j, LP_TEX_USAGE_READ,
-                                                 LP_TEX_LAYOUT_LINEAR);
-               row_stride[j] = lp_tex->row_stride[j];
-               img_stride[j] = lp_tex->img_stride[j];
-            }
-         }
-         else {
-            /* display target texture/surface */
-            /*
-             * XXX: Where should this be unmapped?
-             */
-            struct llvmpipe_screen *screen = llvmpipe_screen(tex->screen);
-            struct sw_winsys *winsys = screen->winsys;
-            data[0] = winsys->displaytarget_map(winsys, lp_tex->dt,
-                                                PIPE_TRANSFER_READ);
-            row_stride[0] = lp_tex->row_stride[0];
-            img_stride[0] = lp_tex->img_stride[0];
-            assert(data[0]);
-         }
-         draw_set_mapped_texture(lp->draw,
-                                 i,
-                                 tex->width0, tex->height0, tex->depth0,
-                                 tex->last_level,
-                                 row_stride, img_stride, data);
-      }
-   }
-}
-
-
-
 /**
  * Is the given texture referenced by any scene?
  * Note: we have to check all scenes including any scenes currently
@@ -918,9 +849,6 @@ lp_setup_destroy( struct lp_setup_context *setup )
 
    util_unreference_framebuffer_state(&setup->fb);
 
-   for (i = 0; i < Elements(setup->vs.current_tex); i++) {
-      pipe_resource_reference(&setup->vs.current_tex[i], NULL);
-   }
    for (i = 0; i < Elements(setup->fs.current_tex); i++) {
       pipe_resource_reference(&setup->fs.current_tex[i], NULL);
    }
index fd2c927c2ea9c865672860cdeb177f4cfed3a701..6a0dc551290ffb4800da7a17850fcc3790a62b55 100644 (file)
@@ -133,11 +133,6 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup,
                                     unsigned num,
                                     struct pipe_sampler_view **views);
 
-void
-lp_setup_set_vertex_sampler_views(struct lp_setup_context *setup,
-                                  unsigned num,
-                                  struct pipe_sampler_view **views);
-
 unsigned
 lp_setup_is_resource_referenced( const struct lp_setup_context *setup,
                                 const struct pipe_resource *texture );
index 947d5efe2b0d6241205b869b43e13fe69d1c50de..8f4e00f0732a8295be1c4e98c63aa5456e944e24 100644 (file)
@@ -116,10 +116,6 @@ struct lp_setup_context
       struct pipe_resource *current_tex[PIPE_MAX_SAMPLERS];
    } fs;
 
-   struct {
-      struct pipe_resource *current_tex[PIPE_MAX_VERTEX_SAMPLERS];
-   } vs;
-
    /** fragment shader constants */
    struct {
       struct pipe_resource *current;
index 05d1b9379449cae2211425e079283835d9db9b7e..86313e1c48469e5efbf7aed40ca238afe5553970 100644 (file)
@@ -130,6 +130,12 @@ llvmpipe_init_rasterizer_funcs(struct llvmpipe_context *llvmpipe);
 void
 llvmpipe_init_so_funcs(struct llvmpipe_context *llvmpipe);
 
+void
+llvmpipe_prepare_vertex_sampling(struct llvmpipe_context *ctx,
+                                 unsigned num,
+                                 struct pipe_sampler_view **views);
+void
+llvmpipe_cleanup_vertex_sampling(struct llvmpipe_context *ctx);
 
 
 #endif
index 263b11749405ccdb35c47f9726c92fc0bf0a4381..77bec4640bb5517b4e83465df84119e0daf633b3 100644 (file)
@@ -188,14 +188,10 @@ void llvmpipe_update_derived( struct llvmpipe_context *llvmpipe )
       lp_setup_set_fs_constants(llvmpipe->setup, 
                                 llvmpipe->constants[PIPE_SHADER_FRAGMENT][0]);
 
-   if (llvmpipe->dirty & LP_NEW_SAMPLER_VIEW) {
+   if (llvmpipe->dirty & LP_NEW_SAMPLER_VIEW)
       lp_setup_set_fragment_sampler_views(llvmpipe->setup,
                                           llvmpipe->num_fragment_sampler_views,
                                           llvmpipe->fragment_sampler_views);
-      lp_setup_set_vertex_sampler_views(llvmpipe->setup,
-                                        llvmpipe->num_vertex_sampler_views,
-                                        llvmpipe->vertex_sampler_views);
-   }
 
    llvmpipe->dirty = 0;
 }
index 0fea7f20a738785ea34acdefb5bc4227570a4f34..715ce2f02e4e8dd4909ccb2f63a99a0657f6ba35 100644 (file)
 #include "draw/draw_context.h"
 
 #include "lp_context.h"
-#include "lp_context.h"
+#include "lp_screen.h"
 #include "lp_state.h"
-#include "draw/draw_context.h"
-
+#include "state_tracker/sw_winsys.h"
 
 
 static void *
@@ -222,6 +221,77 @@ llvmpipe_delete_sampler_state(struct pipe_context *pipe,
 }
 
 
+/**
+ * Called during state validation when LP_NEW_SAMPLER_VIEW is set.
+ */
+void
+llvmpipe_prepare_vertex_sampling(struct llvmpipe_context *lp,
+                                 unsigned num,
+                                 struct pipe_sampler_view **views)
+{
+   unsigned i;
+   uint32_t row_stride[DRAW_MAX_TEXTURE_LEVELS];
+   uint32_t img_stride[DRAW_MAX_TEXTURE_LEVELS];
+   const void *data[DRAW_MAX_TEXTURE_LEVELS];
+
+   assert(num <= PIPE_MAX_VERTEX_SAMPLERS);
+   if (!num)
+      return;
+
+   for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
+      struct pipe_sampler_view *view = i < num ? views[i] : NULL;
+
+      if (view) {
+         struct pipe_resource *tex = view->texture;
+         struct llvmpipe_resource *lp_tex = llvmpipe_resource(tex);
+
+         /* We're referencing the texture's internal data, so save a
+          * reference to it.
+          */
+         pipe_resource_reference(&lp->mapped_vs_tex[i], tex);
+
+         if (!lp_tex->dt) {
+            /* regular texture - setup array of mipmap level pointers */
+            int j;
+            for (j = 0; j <= tex->last_level; j++) {
+               data[j] =
+                  llvmpipe_get_texture_image_all(lp_tex, j, LP_TEX_USAGE_READ,
+                                                 LP_TEX_LAYOUT_LINEAR);
+               row_stride[j] = lp_tex->row_stride[j];
+               img_stride[j] = lp_tex->img_stride[j];
+            }
+         }
+         else {
+            /* display target texture/surface */
+            /*
+             * XXX: Where should this be unmapped?
+             */
+            struct llvmpipe_screen *screen = llvmpipe_screen(tex->screen);
+            struct sw_winsys *winsys = screen->winsys;
+            data[0] = winsys->displaytarget_map(winsys, lp_tex->dt,
+                                                PIPE_TRANSFER_READ);
+            row_stride[0] = lp_tex->row_stride[0];
+            img_stride[0] = lp_tex->img_stride[0];
+            assert(data[0]);
+         }
+         draw_set_mapped_texture(lp->draw,
+                                 i,
+                                 tex->width0, tex->height0, tex->depth0,
+                                 tex->last_level,
+                                 row_stride, img_stride, data);
+      }
+   }
+}
+
+void
+llvmpipe_cleanup_vertex_sampling(struct llvmpipe_context *ctx)
+{
+   unsigned i;
+   for (i = 0; i < Elements(ctx->mapped_vs_tex); i++) {
+      pipe_resource_reference(&ctx->mapped_vs_tex[i], NULL);
+   }
+}
+
 void
 llvmpipe_init_sampler_funcs(struct llvmpipe_context *llvmpipe)
 {