Mesa (master): gallium/cso: fix sampler / sampler_view counts

Roland Scheidegger sroland at kemper.freedesktop.org
Thu Nov 28 03:03:53 UTC 2013


Module: Mesa
Branch: master
Commit: ca39f4eee272bd111eccae79f770493d55cf91bb
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ca39f4eee272bd111eccae79f770493d55cf91bb

Author: Roland Scheidegger <sroland at vmware.com>
Date:   Tue Nov 26 03:42:44 2013 +0100

gallium/cso: fix sampler / sampler_view counts

Now that it is possible to query drivers for the max sampler view it should
be safe to increase this without crashing.
Not entirely convinced this really works correctly though if state trackers
using non-linked sampler / sampler_views use this.

Reviewed-by: Jose Fonseca <jfonseca at vmware.com>

---

 src/gallium/auxiliary/cso_cache/cso_context.c |   27 ++++++++++++++----------
 1 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index 23d3245..33adee8 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -67,10 +67,10 @@ struct sampler_info
    void *samplers_saved[PIPE_MAX_SAMPLERS];
    unsigned nr_samplers_saved;
 
-   struct pipe_sampler_view *views[PIPE_MAX_SAMPLERS];
+   struct pipe_sampler_view *views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
    unsigned nr_views;
 
-   struct pipe_sampler_view *views_saved[PIPE_MAX_SAMPLERS];
+   struct pipe_sampler_view *views_saved[PIPE_MAX_SHADER_SAMPLER_VIEWS];
    unsigned nr_views_saved;
 };
 
@@ -306,17 +306,22 @@ void cso_release_all( struct cso_context *ctx )
       ctx->pipe->bind_rasterizer_state( ctx->pipe, NULL );
 
       {
-         static struct pipe_sampler_view *views[PIPE_MAX_SAMPLERS] = { NULL };
+         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 max = scr->get_shader_param(scr, sh,
-                                      PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS);
-            assert(max <= PIPE_MAX_SAMPLERS);
-            if (max > 0) {
-               ctx->pipe->bind_sampler_states(ctx->pipe, sh, 0, max, zeros);
-               ctx->pipe->set_sampler_views(ctx->pipe, sh, 0, max, views);
+            int maxsam = scr->get_shader_param(scr, sh,
+                                               PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS);
+            int maxview = scr->get_shader_param(scr, sh,
+                                                PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS);
+            assert(maxsam <= PIPE_MAX_SAMPLERS);
+            assert(maxview <= PIPE_MAX_SHADER_SAMPLER_VIEWS);
+            if (maxsam > 0) {
+               ctx->pipe->bind_sampler_states(ctx->pipe, sh, 0, maxsam, zeros);
+            }
+            if (maxview > 0) {
+               ctx->pipe->set_sampler_views(ctx->pipe, sh, 0, maxview, views);
             }
          }
       }
@@ -330,10 +335,10 @@ void cso_release_all( struct cso_context *ctx )
          ctx->pipe->set_stream_output_targets(ctx->pipe, 0, NULL, 0);
    }
 
-   /* free fragment samplers, views */
+   /* free fragment sampler views */
    for (shader = 0; shader < Elements(ctx->samplers); shader++) {
       struct sampler_info *info = &ctx->samplers[shader];
-      for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
+      for (i = 0; i < PIPE_MAX_SHADER_SAMPLER_VIEWS; i++) {
          pipe_sampler_view_reference(&info->views[i], NULL);
          pipe_sampler_view_reference(&info->views_saved[i], NULL);
       }




More information about the mesa-commit mailing list