softpipe: combine vert/frag/geom texture caches in an array
authorBrian Paul <brianp@vmware.com>
Sat, 4 Aug 2012 14:46:41 +0000 (08:46 -0600)
committerBrian Paul <brianp@vmware.com>
Mon, 6 Aug 2012 14:33:17 +0000 (08:33 -0600)
This lets us consolidate some code now, and more in subsequent patches.

Reviewed-by: José Fonseca <jfonseca@vmware.com>
src/gallium/drivers/softpipe/sp_context.c
src/gallium/drivers/softpipe/sp_context.h
src/gallium/drivers/softpipe/sp_flush.c
src/gallium/drivers/softpipe/sp_state_derived.c
src/gallium/drivers/softpipe/sp_state_sampler.c

index a79a7a04fdea8eb389544c001ca7f052e954545f..3d8a69a60adbd584dc197920aeb8fd1e4ee8a3a5 100644 (file)
@@ -89,7 +89,7 @@ static void
 softpipe_destroy( struct pipe_context *pipe )
 {
    struct softpipe_context *softpipe = softpipe_context( pipe );
-   uint i;
+   uint i, sh;
 
 #if DO_PSTIPPLE_IN_HELPER_MODULE
    if (softpipe->pstipple.sampler)
@@ -123,26 +123,31 @@ softpipe_destroy( struct pipe_context *pipe )
    pipe_surface_reference(&softpipe->framebuffer.zsbuf, NULL);
 
    for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
-      sp_destroy_tex_tile_cache(softpipe->fragment_tex_cache[i]);
+      sp_destroy_tex_tile_cache(softpipe->tex_cache[PIPE_SHADER_FRAGMENT][i]);
       pipe_sampler_view_reference(&softpipe->fragment_sampler_views[i], NULL);
    }
 
    for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
-      sp_destroy_tex_tile_cache(softpipe->vertex_tex_cache[i]);
+      sp_destroy_tex_tile_cache(softpipe->tex_cache[PIPE_SHADER_VERTEX][i]);
       pipe_sampler_view_reference(&softpipe->vertex_sampler_views[i], NULL);
    }
 
    for (i = 0; i < PIPE_MAX_GEOMETRY_SAMPLERS; i++) {
-      sp_destroy_tex_tile_cache(softpipe->geometry_tex_cache[i]);
+      sp_destroy_tex_tile_cache(softpipe->tex_cache[PIPE_SHADER_GEOMETRY][i]);
       pipe_sampler_view_reference(&softpipe->geometry_sampler_views[i], NULL);
    }
 
-   for (i = 0; i < PIPE_SHADER_TYPES; i++) {
-      uint j;
+   for (sh = 0; sh < Elements(softpipe->tex_cache); sh++) {
+      for (i = 0; i < Elements(softpipe->tex_cache[0]); i++) {
+         sp_destroy_tex_tile_cache(softpipe->tex_cache[sh][i]);
+         pipe_sampler_view_reference(&softpipe->sampler_views[sh][i], NULL);
+      }
+   }
 
-      for (j = 0; j < PIPE_MAX_CONSTANT_BUFFERS; j++) {
-         if (softpipe->constants[i][j]) {
-            pipe_resource_reference(&softpipe->constants[i][j], NULL);
+   for (sh = 0; sh < Elements(softpipe->constants); sh++) {
+      for (i = 0; i < Elements(softpipe->constants[0]); i++) {
+         if (softpipe->constants[sh][i]) {
+            pipe_resource_reference(&softpipe->constants[sh][i], NULL);
          }
       }
    }
@@ -171,7 +176,7 @@ softpipe_is_resource_referenced( struct pipe_context *pipe,
                                  unsigned level, int layer)
 {
    struct softpipe_context *softpipe = softpipe_context( pipe );
-   unsigned i;
+   unsigned i, sh;
 
    if (texture->target == PIPE_BUFFER)
       return SP_UNREFERENCED;
@@ -191,20 +196,12 @@ softpipe_is_resource_referenced( struct pipe_context *pipe,
    }
    
    /* check if any of the tex_cache textures are this texture */
-   for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
-      if (softpipe->fragment_tex_cache[i] &&
-          softpipe->fragment_tex_cache[i]->texture == texture)
-         return SP_REFERENCED_FOR_READ;
-   }
-   for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
-      if (softpipe->vertex_tex_cache[i] &&
-          softpipe->vertex_tex_cache[i]->texture == texture)
-         return SP_REFERENCED_FOR_READ;
-   }
-   for (i = 0; i < PIPE_MAX_GEOMETRY_SAMPLERS; i++) {
-      if (softpipe->geometry_tex_cache[i] &&
-          softpipe->geometry_tex_cache[i]->texture == texture)
-         return SP_REFERENCED_FOR_READ;
+   for (sh = 0; sh < Elements(softpipe->tex_cache); sh++) {
+      for (i = 0; i < Elements(softpipe->tex_cache[0]); i++) {
+         if (softpipe->tex_cache[sh][i] &&
+             softpipe->tex_cache[sh][i]->texture == texture)
+            return SP_REFERENCED_FOR_READ;
+      }
    }
 
    return SP_UNREFERENCED;
@@ -232,7 +229,7 @@ softpipe_create_context( struct pipe_screen *screen,
 {
    struct softpipe_screen *sp_screen = softpipe_screen(screen);
    struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context);
-   uint i;
+   uint i, sh;
 
    util_init_math();
 
@@ -274,22 +271,13 @@ softpipe_create_context( struct pipe_screen *screen,
       softpipe->cbuf_cache[i] = sp_create_tile_cache( &softpipe->pipe );
    softpipe->zsbuf_cache = sp_create_tile_cache( &softpipe->pipe );
 
-   for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
-      softpipe->fragment_tex_cache[i] = sp_create_tex_tile_cache( &softpipe->pipe );
-      if (!softpipe->fragment_tex_cache[i])
-         goto fail;
-   }
-
-   for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
-      softpipe->vertex_tex_cache[i] = sp_create_tex_tile_cache( &softpipe->pipe );
-      if (!softpipe->vertex_tex_cache[i])
-         goto fail;
-   }
-
-   for (i = 0; i < PIPE_MAX_GEOMETRY_SAMPLERS; i++) {
-      softpipe->geometry_tex_cache[i] = sp_create_tex_tile_cache( &softpipe->pipe );
-      if (!softpipe->geometry_tex_cache[i])
-         goto fail;
+   /* Allocate texture caches */
+   for (sh = 0; sh < Elements(softpipe->tex_cache); sh++) {
+      for (i = 0; i < Elements(softpipe->tex_cache[0]); i++) {
+         softpipe->tex_cache[sh][i] = sp_create_tex_tile_cache(&softpipe->pipe);
+         if (!softpipe->tex_cache[sh][i])
+            goto fail;
+      }
    }
 
    softpipe->fs_machine = tgsi_exec_machine_create();
index 7634254104b9bc18d5f00ea4bd7b304239de1da3..95f5b769a5a9c2648489b2330363ccc964e096fe 100644 (file)
@@ -184,9 +184,13 @@ struct softpipe_context {
    struct softpipe_tile_cache *zsbuf_cache;
 
    unsigned tex_timestamp;
-   struct softpipe_tex_tile_cache *fragment_tex_cache[PIPE_MAX_SAMPLERS];
-   struct softpipe_tex_tile_cache *vertex_tex_cache[PIPE_MAX_VERTEX_SAMPLERS];
-   struct softpipe_tex_tile_cache *geometry_tex_cache[PIPE_MAX_GEOMETRY_SAMPLERS];
+
+   /*
+    * Texture caches for vertex, fragment, geometry stages.
+    * Don't use PIPE_SHADER_TYPES here to avoid allocating unused memory
+    * for compute shaders.
+    */
+   struct softpipe_tex_tile_cache *tex_cache[PIPE_SHADER_GEOMETRY+1][PIPE_MAX_SAMPLERS];
 
    unsigned dump_fs : 1;
    unsigned dump_gs : 1;
index a2733e95878f52f386f82653696b75076c79822b..4651e8bb56bc928a17e088048bc6912d98dbe4ba 100644 (file)
@@ -38,6 +38,7 @@
 #include "sp_state.h"
 #include "sp_tile_cache.h"
 #include "sp_tex_tile_cache.h"
+#include "util/u_memory.h"
 
 
 void
@@ -52,13 +53,13 @@ softpipe_flush( struct pipe_context *pipe,
 
    if (flags & SP_FLUSH_TEXTURE_CACHE) {
       for (i = 0; i < softpipe->num_fragment_sampler_views; i++) {
-         sp_flush_tex_tile_cache(softpipe->fragment_tex_cache[i]);
+         sp_flush_tex_tile_cache(softpipe->tex_cache[PIPE_SHADER_FRAGMENT][i]);
       }
       for (i = 0; i < softpipe->num_vertex_sampler_views; i++) {
-         sp_flush_tex_tile_cache(softpipe->vertex_tex_cache[i]);
+         sp_flush_tex_tile_cache(softpipe->tex_cache[PIPE_SHADER_VERTEX][i]);
       }
       for (i = 0; i < softpipe->num_geometry_sampler_views; i++) {
-         sp_flush_tex_tile_cache(softpipe->geometry_tex_cache[i]);
+         sp_flush_tex_tile_cache(softpipe->tex_cache[PIPE_SHADER_GEOMETRY][i]);
       }
    }
 
index b9b0f94289fdfef1684a16706e11890517cf9bc3..7fbff73f27d22ba4772da4dca260cd8d332736b8 100644 (file)
@@ -207,46 +207,22 @@ compute_cliprect(struct softpipe_context *sp)
 static void
 update_tgsi_samplers( struct softpipe_context *softpipe )
 {
-   unsigned i;
+   unsigned i, sh;
 
    softpipe_reset_sampler_variants( softpipe );
 
-   for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
-      struct softpipe_tex_tile_cache *tc = softpipe->fragment_tex_cache[i];
-      if (tc && tc->texture) {
-         struct softpipe_resource *spt = softpipe_resource(tc->texture);
-         if (spt->timestamp != tc->timestamp) {
-           sp_tex_tile_cache_validate_texture( tc );
-            /*
-            _debug_printf("INV %d %d\n", tc->timestamp, spt->timestamp);
-            */
-            tc->timestamp = spt->timestamp;
-         }
-      }
-   }
-
-   for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
-      struct softpipe_tex_tile_cache *tc = softpipe->vertex_tex_cache[i];
-
-      if (tc && tc->texture) {
-         struct softpipe_resource *spt = softpipe_resource(tc->texture);
-
-         if (spt->timestamp != tc->timestamp) {
-           sp_tex_tile_cache_validate_texture(tc);
-            tc->timestamp = spt->timestamp;
-         }
-      }
-   }
-
-   for (i = 0; i < PIPE_MAX_GEOMETRY_SAMPLERS; i++) {
-      struct softpipe_tex_tile_cache *tc = softpipe->geometry_tex_cache[i];
-
-      if (tc && tc->texture) {
-         struct softpipe_resource *spt = softpipe_resource(tc->texture);
-
-         if (spt->timestamp != tc->timestamp) {
-           sp_tex_tile_cache_validate_texture(tc);
-            tc->timestamp = spt->timestamp;
+   for (sh = 0; sh < Elements(softpipe->tex_cache); sh++) {
+      for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
+         struct softpipe_tex_tile_cache *tc = softpipe->tex_cache[sh][i];
+         if (tc && tc->texture) {
+            struct softpipe_resource *spt = softpipe_resource(tc->texture);
+            if (spt->timestamp != tc->timestamp) {
+               sp_tex_tile_cache_validate_texture( tc );
+               /*
+                 _debug_printf("INV %d %d\n", tc->timestamp, spt->timestamp);
+               */
+               tc->timestamp = spt->timestamp;
+            }
          }
       }
    }
@@ -338,7 +314,7 @@ update_polygon_stipple_enable(struct softpipe_context *softpipe, unsigned prim)
       pipe_sampler_view_reference(&softpipe->fragment_sampler_views[unit],
                                   softpipe->pstipple.sampler_view);
 
-      sp_tex_tile_cache_set_sampler_view(softpipe->fragment_tex_cache[unit],
+      sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[PIPE_SHADER_FRAGMENT][unit],
                                          softpipe->pstipple.sampler_view);
 
       softpipe->dirty |= SP_NEW_SAMPLER;
index 16023c990a708a5bbb646468c1780881e1b00705..260295d1ae50480b4bed7da538c074df1128875f 100644 (file)
@@ -202,7 +202,7 @@ softpipe_set_fragment_sampler_views(struct pipe_context *pipe,
       struct pipe_sampler_view *view = i < num ? views[i] : NULL;
 
       pipe_sampler_view_reference(&softpipe->fragment_sampler_views[i], view);
-      sp_tex_tile_cache_set_sampler_view(softpipe->fragment_tex_cache[i], view);
+      sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[PIPE_SHADER_FRAGMENT][i], view);
    }
 
    softpipe->num_fragment_sampler_views = num;
@@ -233,7 +233,7 @@ softpipe_set_vertex_sampler_views(struct pipe_context *pipe,
       struct pipe_sampler_view *view = i < num ? views[i] : NULL;
 
       pipe_sampler_view_reference(&softpipe->vertex_sampler_views[i], view);
-      sp_tex_tile_cache_set_sampler_view(softpipe->vertex_tex_cache[i], view);
+      sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[PIPE_SHADER_VERTEX][i], view);
    }
 
    softpipe->num_vertex_sampler_views = num;
@@ -268,7 +268,7 @@ softpipe_set_geometry_sampler_views(struct pipe_context *pipe,
       struct pipe_sampler_view *view = i < num ? views[i] : NULL;
 
       pipe_sampler_view_reference(&softpipe->geometry_sampler_views[i], view);
-      sp_tex_tile_cache_set_sampler_view(softpipe->geometry_tex_cache[i], view);
+      sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[PIPE_SHADER_GEOMETRY][i], view);
    }
 
    softpipe->num_geometry_sampler_views = num;
@@ -350,7 +350,7 @@ softpipe_reset_sampler_variants(struct softpipe_context *softpipe)
                                  TGSI_PROCESSOR_VERTEX );
 
          sp_sampler_variant_bind_view( softpipe->tgsi.vert_samplers_list[i],
-                                       softpipe->vertex_tex_cache[i],
+                                       softpipe->tex_cache[PIPE_SHADER_VERTEX][i],
                                        softpipe->vertex_sampler_views[i] );
       }
    }
@@ -367,7 +367,7 @@ softpipe_reset_sampler_variants(struct softpipe_context *softpipe)
 
             sp_sampler_variant_bind_view(
                softpipe->tgsi.geom_samplers_list[i],
-               softpipe->geometry_tex_cache[i],
+               softpipe->tex_cache[PIPE_SHADER_GEOMETRY][i],
                softpipe->geometry_sampler_views[i] );
          }
       }
@@ -383,7 +383,7 @@ softpipe_reset_sampler_variants(struct softpipe_context *softpipe)
                                  TGSI_PROCESSOR_FRAGMENT );
 
          sp_sampler_variant_bind_view( softpipe->tgsi.frag_samplers_list[i],
-                                       softpipe->fragment_tex_cache[i],
+                                       softpipe->tex_cache[PIPE_SHADER_FRAGMENT][i],
                                        softpipe->fragment_sampler_views[i] );
       }
    }