softpipe: Bind samplers to views instead of the underlying resource.

Signed-off-by: Brian Paul <brianp@vmware.com>
diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c
index db02d0e..2ee2181 100644
--- a/src/gallium/drivers/softpipe/sp_context.c
+++ b/src/gallium/drivers/softpipe/sp_context.c
@@ -106,7 +106,7 @@
 
    for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
       sp_destroy_tex_tile_cache(softpipe->fragment_tex_cache[i]);
-      pipe_sampler_view_reference(&softpipe->sampler_views[i], NULL);
+      pipe_sampler_view_reference(&softpipe->fragment_sampler_views[i], NULL);
    }
 
    for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
diff --git a/src/gallium/drivers/softpipe/sp_context.h b/src/gallium/drivers/softpipe/sp_context.h
index 6e20b43..035d712 100644
--- a/src/gallium/drivers/softpipe/sp_context.h
+++ b/src/gallium/drivers/softpipe/sp_context.h
@@ -77,7 +77,7 @@
    struct pipe_framebuffer_state framebuffer;
    struct pipe_poly_stipple poly_stipple;
    struct pipe_scissor_state scissor;
-   struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
+   struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
    struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS];
    struct pipe_sampler_view *geometry_sampler_views[PIPE_MAX_GEOMETRY_SAMPLERS];
    struct pipe_viewport_state viewport;
diff --git a/src/gallium/drivers/softpipe/sp_state_sampler.c b/src/gallium/drivers/softpipe/sp_state_sampler.c
index 7becd6e..3894356 100644
--- a/src/gallium/drivers/softpipe/sp_state_sampler.c
+++ b/src/gallium/drivers/softpipe/sp_state_sampler.c
@@ -192,7 +192,8 @@
 
    /* Check for no-op */
    if (num == softpipe->num_sampler_views &&
-       !memcmp(softpipe->sampler_views, views, num * sizeof(struct pipe_sampler_view *)))
+       !memcmp(softpipe->fragment_sampler_views, views,
+               num * sizeof(struct pipe_sampler_view *)))
       return;
 
    draw_flush(softpipe->draw);
@@ -200,7 +201,7 @@
    for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
       struct pipe_sampler_view *view = i < num ? views[i] : NULL;
 
-      pipe_sampler_view_reference(&softpipe->sampler_views[i], view);
+      pipe_sampler_view_reference(&softpipe->fragment_sampler_views[i], view);
       sp_tex_tile_cache_set_sampler_view(softpipe->fragment_tex_cache[i], view);
    }
 
@@ -342,33 +343,21 @@
     */
    for (i = 0; i <= softpipe->vs->max_sampler; i++) {
       if (softpipe->vertex_samplers[i]) {
-         struct pipe_resource *texture = NULL;
-
-         if (softpipe->vertex_sampler_views[i]) {
-            texture = softpipe->vertex_sampler_views[i]->texture;
-         }
-
          softpipe->tgsi.vert_samplers_list[i] = 
             get_sampler_variant( i,
                                  sp_sampler(softpipe->vertex_samplers[i]),
                                  softpipe->vertex_sampler_views[i],
                                  TGSI_PROCESSOR_VERTEX );
 
-         sp_sampler_variant_bind_texture( softpipe->tgsi.vert_samplers_list[i], 
-                                          softpipe->vertex_tex_cache[i],
-                                          texture );
+         sp_sampler_variant_bind_view( softpipe->tgsi.vert_samplers_list[i],
+                                       softpipe->vertex_tex_cache[i],
+                                       softpipe->vertex_sampler_views[i] );
       }
    }
 
    if (softpipe->gs) {
       for (i = 0; i <= softpipe->gs->max_sampler; i++) {
          if (softpipe->geometry_samplers[i]) {
-            struct pipe_resource *texture = NULL;
-
-            if (softpipe->geometry_sampler_views[i]) {
-               texture = softpipe->geometry_sampler_views[i]->texture;
-            }
-
             softpipe->tgsi.geom_samplers_list[i] =
                get_sampler_variant(
                   i,
@@ -376,31 +365,25 @@
                   softpipe->geometry_sampler_views[i],
                   TGSI_PROCESSOR_GEOMETRY );
 
-            sp_sampler_variant_bind_texture(
+            sp_sampler_variant_bind_view(
                softpipe->tgsi.geom_samplers_list[i],
                softpipe->geometry_tex_cache[i],
-               texture );
+               softpipe->geometry_sampler_views[i] );
          }
       }
    }
 
    for (i = 0; i <= softpipe->fs->info.file_max[TGSI_FILE_SAMPLER]; i++) {
       if (softpipe->sampler[i]) {
-         struct pipe_resource *texture = NULL;
-
-         if (softpipe->sampler_views[i]) {
-            texture = softpipe->sampler_views[i]->texture;
-         }
-
          softpipe->tgsi.frag_samplers_list[i] =
             get_sampler_variant( i,
                                  sp_sampler(softpipe->sampler[i]),
-                                 softpipe->sampler_views[i],
+                                 softpipe->fragment_sampler_views[i],
                                  TGSI_PROCESSOR_FRAGMENT );
 
-         sp_sampler_variant_bind_texture( softpipe->tgsi.frag_samplers_list[i], 
-                                          softpipe->fragment_tex_cache[i],
-                                          texture );
+         sp_sampler_variant_bind_view( softpipe->tgsi.frag_samplers_list[i],
+                                       softpipe->fragment_tex_cache[i],
+                                       softpipe->fragment_sampler_views[i] );
       }
    }
 }
diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.c b/src/gallium/drivers/softpipe/sp_tex_sample.c
index cbc40d4..242c27c 100644
--- a/src/gallium/drivers/softpipe/sp_tex_sample.c
+++ b/src/gallium/drivers/softpipe/sp_tex_sample.c
@@ -550,7 +550,7 @@
                   const float t[QUAD_SIZE],
                   const float p[QUAD_SIZE])
 {
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]);
    float dsdy = fabsf(s[QUAD_TOP_LEFT]     - s[QUAD_BOTTOM_LEFT]);
    float rho = MAX2(dsdx, dsdy) * texture->width0;
@@ -565,7 +565,7 @@
                   const float t[QUAD_SIZE],
                   const float p[QUAD_SIZE])
 {
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]);
    float dsdy = fabsf(s[QUAD_TOP_LEFT]     - s[QUAD_BOTTOM_LEFT]);
    float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]);
@@ -584,7 +584,7 @@
                   const float t[QUAD_SIZE],
                   const float p[QUAD_SIZE])
 {
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]);
    float dsdy = fabsf(s[QUAD_TOP_LEFT]     - s[QUAD_BOTTOM_LEFT]);
    float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]);
@@ -654,7 +654,7 @@
 get_texel_2d(const struct sp_sampler_variant *samp,
 	     union tex_tile_address addr, int x, int y)
 {
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    unsigned level = addr.bits.level;
 
    if (x < 0 || x >= (int) u_minify(texture->width0, level) ||
@@ -747,7 +747,7 @@
 get_texel_3d(const struct sp_sampler_variant *samp,
 	     union tex_tile_address addr, int x, int y, int z)
 {
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    unsigned level = addr.bits.level;
 
    if (x < 0 || x >= (int) u_minify(texture->width0, level) ||
@@ -959,7 +959,7 @@
                         float rgba[NUM_CHANNELS][QUAD_SIZE])
 {
    const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler);
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    unsigned level0, j;
    int width;
    int x[4];
@@ -999,7 +999,7 @@
                       float rgba[NUM_CHANNELS][QUAD_SIZE])
 {
    const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler);
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    unsigned level0, j;
    int width, height;
    int x[4], y[4];
@@ -1051,7 +1051,7 @@
                         float rgba[NUM_CHANNELS][QUAD_SIZE])
 {
    const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler);
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    const unsigned *faces = samp->faces; /* zero when not cube-mapping */
    unsigned level0, j;
    int width, height;
@@ -1095,7 +1095,7 @@
                       float rgba[NUM_CHANNELS][QUAD_SIZE])
 {
    const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler);
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    unsigned level0, j;
    int width, height, depth;
    int x[4], y[4], z[4];
@@ -1137,7 +1137,7 @@
                      float rgba[NUM_CHANNELS][QUAD_SIZE])
 {
    const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler);
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    unsigned level0, j;
    int width;
    int x0[4], x1[4];
@@ -1177,7 +1177,7 @@
                      float rgba[NUM_CHANNELS][QUAD_SIZE])
 {
    const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler);
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    unsigned level0, j;
    int width, height;
    int x0[4], y0[4], x1[4], y1[4];
@@ -1224,7 +1224,7 @@
                        float rgba[NUM_CHANNELS][QUAD_SIZE])
 {
    const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler);
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    const unsigned *faces = samp->faces; /* zero when not cube-mapping */
    unsigned level0, j;
    int width, height;
@@ -1273,7 +1273,7 @@
                      float rgba[NUM_CHANNELS][QUAD_SIZE])
 {
    const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler);
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    unsigned level0, j;
    int width, height, depth;
    int x0[4], x1[4], y0[4], y1[4], z0[4], z1[4];
@@ -1349,7 +1349,7 @@
                   float rgba[NUM_CHANNELS][QUAD_SIZE])
 {
    struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler);
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    int level0;
    float lambda;
    float lod[QUAD_SIZE];
@@ -1416,7 +1416,7 @@
                    float rgba[NUM_CHANNELS][QUAD_SIZE])
 {
    struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler);
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    float lambda;
    float lod[QUAD_SIZE];
 
@@ -1500,7 +1500,7 @@
    float rgba[NUM_CHANNELS][QUAD_SIZE])
 {
    struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler);
-   const struct pipe_resource *texture = samp->texture;
+   const struct pipe_resource *texture = samp->view->texture;
    int level0;
    float lambda;
    float lod[QUAD_SIZE];
@@ -1990,13 +1990,14 @@
  * Bind the given texture object and texture cache to the sampler variant.
  */
 void
-sp_sampler_variant_bind_texture( struct sp_sampler_variant *samp,
-                                 struct softpipe_tex_tile_cache *tex_cache,
-                                 const struct pipe_resource *texture )
+sp_sampler_variant_bind_view( struct sp_sampler_variant *samp,
+                              struct softpipe_tex_tile_cache *tex_cache,
+                              const struct pipe_sampler_view *view )
 {
    const struct pipe_sampler_state *sampler = samp->sampler;
+   const struct pipe_resource *texture = view->texture;
 
-   samp->texture = texture;
+   samp->view = view;
    samp->cache = tex_cache;
    samp->xpot = util_unsigned_logbase2( texture->width0 );
    samp->ypot = util_unsigned_logbase2( texture->height0 );
diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.h b/src/gallium/drivers/softpipe/sp_tex_sample.h
index ed99006..f0b867e 100644
--- a/src/gallium/drivers/softpipe/sp_tex_sample.h
+++ b/src/gallium/drivers/softpipe/sp_tex_sample.h
@@ -89,7 +89,7 @@
 
    /* Currently bound texture:
     */
-   const struct pipe_resource *texture;
+   const struct pipe_sampler_view *view;
    struct softpipe_tex_tile_cache *cache;
 
    unsigned processor;
@@ -132,9 +132,9 @@
 sp_create_sampler_variant( const struct pipe_sampler_state *sampler,
                            const union sp_sampler_key key );
 
-void sp_sampler_variant_bind_texture( struct sp_sampler_variant *variant,
-                                      struct softpipe_tex_tile_cache *tex_cache,
-                                      const struct pipe_resource *tex );
+void sp_sampler_variant_bind_view( struct sp_sampler_variant *variant,
+                                   struct softpipe_tex_tile_cache *tex_cache,
+                                   const struct pipe_sampler_view *view );
 
 void sp_sampler_variant_destroy( struct sp_sampler_variant * );