Squashed commit of the following:
[mesa.git] / src / gallium / drivers / llvmpipe / lp_state_sampler.c
index d382f9ca87e1cea4563785e21c423cda04bad305..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"
 
 
@@ -106,8 +105,9 @@ llvmpipe_bind_vertex_sampler_states(struct pipe_context *pipe,
 
 
 void
-llvmpipe_set_sampler_textures(struct pipe_context *pipe,
-                              unsigned num, struct pipe_texture **texture)
+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;
@@ -115,63 +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_textures = num;
+   llvmpipe->num_fragment_sampler_views = num;
 
-   llvmpipe->dirty |= LP_NEW_TEXTURE;
+   llvmpipe->dirty |= LP_NEW_SAMPLER_VIEW;
 }
 
 
 void
-llvmpipe_set_vertex_sampler_textures(struct pipe_context *pipe,
-                                     unsigned num_textures,
-                                     struct pipe_texture **textures)
+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_textures <= PIPE_MAX_VERTEX_SAMPLERS);
+   assert(num <= PIPE_MAX_VERTEX_SAMPLERS);
 
    /* Check for no-op */
-   if (num_textures == llvmpipe->num_vertex_textures &&
-       !memcmp(llvmpipe->vertex_textures, textures, num_textures * sizeof(struct pipe_texture *))) {
+   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_texture *tex = i < num_textures ? textures[i] : NULL;
+      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;
+}
 
-      pipe_texture_reference(&llvmpipe->vertex_textures[i], tex);
-      lp_tex_tile_cache_set_texture(llvmpipe->vertex_tex_cache[i], tex);
+
+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_vertex_textures = num_textures;
+   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);
 }