[Mesa-dev] [PATCH] cso: handle sampler view changes the same way for all shader types

Brian Paul brianp at vmware.com
Thu Dec 10 13:14:09 PST 2015


Previously, we were tracking sampler views for fragment shaders and
suppressing redundant state changes, but not for other types of shaders.
Now sampler views for all shader types are handled the same way.

v2: s/PIPE_MAX_SAMPLERS/PIPE_MAX_SHADER_SAMPLER_VIEWS/, per Ilia.
---
 src/gallium/auxiliary/cso_cache/cso_context.c | 88 ++++++++++++++++-----------
 1 file changed, 51 insertions(+), 37 deletions(-)

diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index 6b29b20..79a9455 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -61,6 +61,16 @@ struct sampler_info
 };
 
 
+/**
+ * Per-shader sampler view information.
+ */
+struct sampler_view_info
+{
+   struct pipe_sampler_view *views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
+   unsigned nr_views;
+};
+
+
 
 struct cso_context {
    struct pipe_context *pipe;
@@ -71,8 +81,7 @@ struct cso_context {
    boolean has_tessellation;
    boolean has_streamout;
 
-   struct pipe_sampler_view *fragment_views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
-   unsigned nr_fragment_views;
+   struct sampler_view_info sampler_views[PIPE_SHADER_TYPES];
 
    struct pipe_sampler_view *fragment_views_saved[PIPE_MAX_SHADER_SAMPLER_VIEWS];
    unsigned nr_fragment_views_saved;
@@ -289,7 +298,7 @@ out:
  */
 void cso_destroy_context( struct cso_context *ctx )
 {
-   unsigned i;
+   unsigned i, sh;
 
    if (ctx->pipe) {
       ctx->pipe->set_index_buffer(ctx->pipe, NULL);
@@ -301,7 +310,6 @@ void cso_destroy_context( struct cso_context *ctx )
          static struct pipe_sampler_view *views[PIPE_MAX_SHADER_SAMPLER_VIEWS] = { NULL };
          static void *zeros[PIPE_MAX_SAMPLERS] = { NULL };
          struct pipe_screen *scr = ctx->pipe->screen;
-         unsigned sh;
          for (sh = 0; sh < PIPE_SHADER_TYPES; sh++) {
             int maxsam = scr->get_shader_param(scr, sh,
                                                PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS);
@@ -339,8 +347,14 @@ void cso_destroy_context( struct cso_context *ctx )
          ctx->pipe->set_stream_output_targets(ctx->pipe, 0, NULL, NULL);
    }
 
+
+   for (sh = 0; sh < PIPE_SHADER_TYPES; sh++) {
+      for (i = 0; i < ctx->sampler_views[sh].nr_views; i++) {
+         pipe_sampler_view_reference(&ctx->sampler_views[sh].views[i], NULL);
+      }
+   }
+
    for (i = 0; i < PIPE_MAX_SHADER_SAMPLER_VIEWS; i++) {
-      pipe_sampler_view_reference(&ctx->fragment_views[i], NULL);
       pipe_sampler_view_reference(&ctx->fragment_views_saved[i], NULL);
    }
 
@@ -1194,46 +1208,45 @@ cso_set_sampler_views(struct cso_context *ctx,
                       unsigned count,
                       struct pipe_sampler_view **views)
 {
-   if (shader_stage == PIPE_SHADER_FRAGMENT) {
-      unsigned i;
-      boolean any_change = FALSE;
+   struct sampler_view_info *info = &ctx->sampler_views[shader_stage];
+   unsigned i;
+   boolean any_change = FALSE;
 
-      /* reference new views */
-      for (i = 0; i < count; i++) {
-         any_change |= ctx->fragment_views[i] != views[i];
-         pipe_sampler_view_reference(&ctx->fragment_views[i], views[i]);
-      }
-      /* unref extra old views, if any */
-      for (; i < ctx->nr_fragment_views; i++) {
-         any_change |= ctx->fragment_views[i] != NULL;
-         pipe_sampler_view_reference(&ctx->fragment_views[i], NULL);
-      }
+   /* reference new views */
+   for (i = 0; i < count; i++) {
+      any_change |= info->views[i] != views[i];
+      pipe_sampler_view_reference(&info->views[i], views[i]);
+   }
 
-      /* bind the new sampler views */
-      if (any_change) {
-         ctx->pipe->set_sampler_views(ctx->pipe, shader_stage, 0,
-                                      MAX2(ctx->nr_fragment_views, count),
-                                      ctx->fragment_views);
-      }
+   /* unref extra old views, if any */
+   for (; i < info->nr_views; i++) {
+      any_change |= info->views[i] != NULL;
+      pipe_sampler_view_reference(&info->views[i], NULL);
+   }
 
-      ctx->nr_fragment_views = count;
+   /* bind the new sampler views */
+   if (any_change) {
+      ctx->pipe->set_sampler_views(ctx->pipe, shader_stage, 0,
+                                   MAX2(info->nr_views, count),
+                                   info->views);
    }
-   else
-      ctx->pipe->set_sampler_views(ctx->pipe, shader_stage, 0, count, views);
+
+   info->nr_views = count;
 }
 
 
 void
 cso_save_fragment_sampler_views(struct cso_context *ctx)
 {
+   struct sampler_view_info *info = &ctx->sampler_views[PIPE_SHADER_FRAGMENT];
    unsigned i;
 
-   ctx->nr_fragment_views_saved = ctx->nr_fragment_views;
+   ctx->nr_fragment_views_saved = info->nr_views;
 
-   for (i = 0; i < ctx->nr_fragment_views; i++) {
+   for (i = 0; i < info->nr_views; i++) {
       assert(!ctx->fragment_views_saved[i]);
       pipe_sampler_view_reference(&ctx->fragment_views_saved[i],
-                                  ctx->fragment_views[i]);
+                                  info->views[i]);
    }
 }
 
@@ -1241,26 +1254,27 @@ cso_save_fragment_sampler_views(struct cso_context *ctx)
 void
 cso_restore_fragment_sampler_views(struct cso_context *ctx)
 {
+   struct sampler_view_info *info = &ctx->sampler_views[PIPE_SHADER_FRAGMENT];
    unsigned i, nr_saved = ctx->nr_fragment_views_saved;
    unsigned num;
 
    for (i = 0; i < nr_saved; i++) {
-      pipe_sampler_view_reference(&ctx->fragment_views[i], NULL);
+      pipe_sampler_view_reference(&info->views[i], NULL);
       /* move the reference from one pointer to another */
-      ctx->fragment_views[i] = ctx->fragment_views_saved[i];
+      info->views[i] = ctx->fragment_views_saved[i];
       ctx->fragment_views_saved[i] = NULL;
    }
-   for (; i < ctx->nr_fragment_views; i++) {
-      pipe_sampler_view_reference(&ctx->fragment_views[i], NULL);
+   for (; i < info->nr_views; i++) {
+      pipe_sampler_view_reference(&info->views[i], NULL);
    }
 
-   num = MAX2(ctx->nr_fragment_views, nr_saved);
+   num = MAX2(info->nr_views, nr_saved);
 
    /* bind the old/saved sampler views */
    ctx->pipe->set_sampler_views(ctx->pipe, PIPE_SHADER_FRAGMENT, 0, num,
-                                ctx->fragment_views);
+                                info->views);
 
-   ctx->nr_fragment_views = nr_saved;
+   info->nr_views = nr_saved;
    ctx->nr_fragment_views_saved = 0;
 }
 
-- 
1.9.1



More information about the mesa-dev mailing list