gallium/cso: fix sampler / sampler_view counts
authorRoland Scheidegger <sroland@vmware.com>
Tue, 26 Nov 2013 02:42:44 +0000 (03:42 +0100)
committerRoland Scheidegger <sroland@vmware.com>
Thu, 28 Nov 2013 03:02:41 +0000 (04:02 +0100)
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@vmware.com>
src/gallium/auxiliary/cso_cache/cso_context.c

index 23d3245e881b53e8fc1d7affd8ca40b13a09c435..33adee8d77ae328aff1e88e88ac82a568ef7dd2f 100644 (file)
@@ -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);
       }