Squashed commit of the following:
[mesa.git] / src / gallium / drivers / llvmpipe / lp_state_sampler.c
index 8333805a3fde21e59307b33dea4e7ce10ef9c518..3552ff50ce1b73420eb2996d76d89847ead00e47 100644 (file)
@@ -29,6 +29,7 @@
  *  Brian Paul
  */
 
+#include "util/u_inlines.h"
 #include "util/u_memory.h"
 
 #include "draw/draw_context.h"
@@ -36,8 +37,6 @@
 #include "lp_context.h"
 #include "lp_context.h"
 #include "lp_state.h"
-#include "lp_texture.h"
-#include "lp_tex_cache.h"
 #include "draw/draw_context.h"
 
 
@@ -78,8 +77,37 @@ llvmpipe_bind_sampler_states(struct pipe_context *pipe,
 
 
 void
-llvmpipe_set_sampler_textures(struct pipe_context *pipe,
-                              unsigned num, struct pipe_texture **texture)
+llvmpipe_bind_vertex_sampler_states(struct pipe_context *pipe,
+                                    unsigned num_samplers,
+                                    void **samplers)
+{
+   struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
+   unsigned i;
+
+   assert(num_samplers <= PIPE_MAX_VERTEX_SAMPLERS);
+
+   /* Check for no-op */
+   if (num_samplers == llvmpipe->num_vertex_samplers &&
+       !memcmp(llvmpipe->vertex_samplers, samplers, num_samplers * sizeof(void *)))
+      return;
+
+   draw_flush(llvmpipe->draw);
+
+   for (i = 0; i < num_samplers; ++i)
+      llvmpipe->vertex_samplers[i] = samplers[i];
+   for (i = num_samplers; i < PIPE_MAX_VERTEX_SAMPLERS; ++i)
+      llvmpipe->vertex_samplers[i] = NULL;
+
+   llvmpipe->num_vertex_samplers = num_samplers;
+
+   llvmpipe->dirty |= LP_NEW_SAMPLER;
+}
+
+
+void
+llvmpipe_set_fragment_sampler_views(struct pipe_context *pipe,
+                                    unsigned num,
+                                    struct pipe_sampler_view **views)
 {
    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
    uint i;
@@ -87,32 +115,79 @@ llvmpipe_set_sampler_textures(struct pipe_context *pipe,
    assert(num <= PIPE_MAX_SAMPLERS);
 
    /* Check for no-op */
-   if (num == llvmpipe->num_textures &&
-       !memcmp(llvmpipe->texture, texture, num * sizeof(struct pipe_texture *)))
+   if (num == llvmpipe->num_fragment_sampler_views &&
+       !memcmp(llvmpipe->fragment_sampler_views, views, num * sizeof(struct pipe_sampler_view *)))
       return;
 
    draw_flush(llvmpipe->draw);
 
    for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
-      struct pipe_texture *tex = i < num ? texture[i] : NULL;
-
-      pipe_texture_reference(&llvmpipe->texture[i], tex);
-      lp_tex_tile_cache_set_texture(llvmpipe->tex_cache[i], tex);
-
-      if(tex) {
-         struct llvmpipe_texture *lp_tex = llvmpipe_texture(tex);
-         struct lp_jit_texture *jit_tex = &llvmpipe->jit_context.textures[i];
-         jit_tex->width = tex->width0;
-         jit_tex->height = tex->height0;
-         jit_tex->stride = lp_tex->stride[0];
-         if(!lp_tex->dt)
-            jit_tex->data = lp_tex->data;
-      }
+      struct pipe_sampler_view *view = i < num ? views[i] : NULL;
+
+      pipe_sampler_view_reference(&llvmpipe->fragment_sampler_views[i], view);
+   }
+
+   llvmpipe->num_fragment_sampler_views = num;
+
+   llvmpipe->dirty |= LP_NEW_SAMPLER_VIEW;
+}
+
+
+void
+llvmpipe_set_vertex_sampler_views(struct pipe_context *pipe,
+                                  unsigned num,
+                                  struct pipe_sampler_view **views)
+{
+   struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
+   uint i;
+
+   assert(num <= PIPE_MAX_VERTEX_SAMPLERS);
+
+   /* Check for no-op */
+   if (num == llvmpipe->num_vertex_sampler_views &&
+       !memcmp(llvmpipe->vertex_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) {
+      return;
+   }
+
+   draw_flush(llvmpipe->draw);
+
+   for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
+      struct pipe_sampler_view *view = i < num ? views[i] : NULL;
+
+      pipe_sampler_view_reference(&llvmpipe->vertex_sampler_views[i], view);
+   }
+
+   llvmpipe->num_vertex_sampler_views = num;
+
+   llvmpipe->dirty |= LP_NEW_SAMPLER_VIEW;
+}
+
+
+struct pipe_sampler_view *
+llvmpipe_create_sampler_view(struct pipe_context *pipe,
+                            struct pipe_resource *texture,
+                            const struct pipe_sampler_view *templ)
+{
+   struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view);
+
+   if (view) {
+      *view = *templ;
+      view->reference.count = 1;
+      view->texture = NULL;
+      pipe_resource_reference(&view->texture, texture);
+      view->context = pipe;
    }
 
-   llvmpipe->num_textures = num;
+   return view;
+}
+
 
-   llvmpipe->dirty |= LP_NEW_TEXTURE;
+void
+llvmpipe_sampler_view_destroy(struct pipe_context *pipe,
+                              struct pipe_sampler_view *view)
+{
+   pipe_resource_reference(&view->texture, NULL);
+   FREE(view);
 }