draw: index samplers and sampler_view state by shader type
authorBrian Paul <brianp@vmware.com>
Fri, 10 Aug 2012 02:59:44 +0000 (20:59 -0600)
committerBrian Paul <brianp@vmware.com>
Thu, 16 Aug 2012 15:01:31 +0000 (09:01 -0600)
So that we can handle GS state and other types of shaders in the future.

src/gallium/auxiliary/draw/draw_context.c
src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/draw/draw_private.h

index 3c9c7f1690eba6a1511d02a8fd2666f930ff344a..9ca4191aee2b1f82e5eced9241c91cef991b890e 100644 (file)
@@ -760,16 +760,15 @@ draw_set_sampler_views(struct draw_context *draw,
 {
    unsigned i;
 
-   if (shader_stage == PIPE_SHADER_VERTEX) {
-      debug_assert(num <= PIPE_MAX_VERTEX_SAMPLERS);
+   debug_assert(num <= Elements(draw->sampler_views));
+   debug_assert(shader_stage <= PIPE_SHADER_TYPES);
 
-      for (i = 0; i < num; ++i)
-         draw->sampler_views[i] = views[i];
-      for (i = num; i < PIPE_MAX_VERTEX_SAMPLERS; ++i)
-         draw->sampler_views[i] = NULL;
+   for (i = 0; i < num; ++i)
+      draw->sampler_views[shader_stage][i] = views[i];
+   for (i = num; i < Elements(draw->sampler_views); ++i)
+      draw->sampler_views[shader_stage][i] = NULL;
 
-      draw->num_sampler_views = num;
-   }
+   draw->num_sampler_views[shader_stage] = num;
 }
 
 void
@@ -780,21 +779,20 @@ draw_set_samplers(struct draw_context *draw,
 {
    unsigned i;
 
-   if (shader_stage == PIPE_SHADER_VERTEX) {
-      debug_assert(num <= PIPE_MAX_VERTEX_SAMPLERS);
+   debug_assert(num <= Elements(draw->samplers));
+   debug_assert(shader_stage <= PIPE_SHADER_TYPES);
 
-      for (i = 0; i < num; ++i)
-         draw->samplers[i] = samplers[i];
-      for (i = num; i < PIPE_MAX_VERTEX_SAMPLERS; ++i)
-         draw->samplers[i] = NULL;
+   for (i = 0; i < num; ++i)
+      draw->samplers[shader_stage][i] = samplers[i];
+   for (i = num; i < Elements(draw->samplers); ++i)
+      draw->samplers[shader_stage][i] = NULL;
 
-      draw->num_samplers = num;
+   draw->num_samplers[shader_stage] = num;
 
 #ifdef HAVE_LLVM
-      if (draw->llvm)
-         draw_llvm_set_sampler_state(draw);
+   if (draw->llvm && shader_stage == PIPE_SHADER_VERTEX)
+      draw_llvm_set_sampler_state(draw);
 #endif
-   }
 }
 
 void
index 3400661fb29e0e6e3b5011d8a0d3634ba33d53ac..133aa5f698378af780323e331437a955c2d807d5 100644 (file)
@@ -1351,8 +1351,8 @@ draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store)
 
    for (i = 0 ; i < key->nr_samplers; i++) {
       lp_sampler_static_state(&sampler[i],
-                             llvm->draw->sampler_views[i],
-                             llvm->draw->samplers[i]);
+                             llvm->draw->sampler_views[PIPE_SHADER_VERTEX][i],
+                             llvm->draw->samplers[PIPE_SHADER_VERTEX][i]);
    }
 
    return key;
@@ -1394,14 +1394,16 @@ draw_llvm_set_sampler_state(struct draw_context *draw)
 {
    unsigned i;
 
-   for (i = 0; i < draw->num_samplers; i++) {
+   for (i = 0; i < draw->num_samplers[PIPE_SHADER_VERTEX]; i++) {
       struct draw_jit_texture *jit_tex = &draw->llvm->jit_context.textures[i];
 
       if (draw->samplers[i]) {
-         jit_tex->min_lod = draw->samplers[i]->min_lod;
-         jit_tex->max_lod = draw->samplers[i]->max_lod;
-         jit_tex->lod_bias = draw->samplers[i]->lod_bias;
-         COPY_4V(jit_tex->border_color, draw->samplers[i]->border_color.f);
+         const struct pipe_sampler_state *s
+            = draw->samplers[PIPE_SHADER_VERTEX][i];
+         jit_tex->min_lod = s->min_lod;
+         jit_tex->max_lod = s->max_lod;
+         jit_tex->lod_bias = s->lod_bias;
+         COPY_4V(jit_tex->border_color, s->border_color.f);
       }
    }
 }
index 6a085be27fc9507778714819b043db818a7a48e3..c2af0f36bcadd6e4432358ef0fab0750243c4b23 100644 (file)
@@ -308,10 +308,15 @@ struct draw_context
    struct draw_llvm *llvm;
 #endif
 
-   struct pipe_sampler_view *sampler_views[PIPE_MAX_VERTEX_SAMPLERS];
-   unsigned num_sampler_views;
-   const struct pipe_sampler_state *samplers[PIPE_MAX_VERTEX_SAMPLERS];
-   unsigned num_samplers;
+   /** Texture sampler and sampler view state.
+    * Note that we have arrays indexed by shader type.  At this time
+    * we only handle vertex and geometry shaders in the draw module, but
+    * there may be more in the future (ex: hull and tessellation).
+    */
+   struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
+   unsigned num_sampler_views[PIPE_SHADER_TYPES];
+   const struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
+   unsigned num_samplers[PIPE_SHADER_TYPES];
 
    void *driver_private;
 };