gallium: add a shader stage/type param to some draw functions
authorBrian Paul <brianp@vmware.com>
Fri, 10 Aug 2012 02:59:43 +0000 (20:59 -0600)
committerBrian Paul <brianp@vmware.com>
Thu, 16 Aug 2012 15:01:31 +0000 (09:01 -0600)
To prepare for geometry shader texture support in the draw module.
Note: we still only handle the vertex shader case.

src/gallium/auxiliary/draw/draw_context.c
src/gallium/auxiliary/draw/draw_context.h
src/gallium/drivers/i915/i915_state.c
src/gallium/drivers/llvmpipe/lp_state_sampler.c
src/gallium/drivers/softpipe/sp_state_sampler.c

index be30b7db245234d4aeeb50eefe7fa4b671ec8423..dd4698be9528fac62709e44800b938272cedd5b8 100644 (file)
@@ -754,45 +754,52 @@ draw_set_so_state(struct draw_context *draw,
 
 void
 draw_set_sampler_views(struct draw_context *draw,
+                       unsigned shader_stage,
                        struct pipe_sampler_view **views,
                        unsigned num)
 {
    unsigned i;
 
-   debug_assert(num <= PIPE_MAX_VERTEX_SAMPLERS);
+   if (shader_stage == PIPE_SHADER_VERTEX) {
+      debug_assert(num <= PIPE_MAX_VERTEX_SAMPLERS);
 
-   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[i] = views[i];
+      for (i = num; i < PIPE_MAX_VERTEX_SAMPLERS; ++i)
+         draw->sampler_views[i] = NULL;
 
-   draw->num_sampler_views = num;
+      draw->num_sampler_views = num;
+   }
 }
 
 void
 draw_set_samplers(struct draw_context *draw,
+                  unsigned shader_stage,
                   struct pipe_sampler_state **samplers,
                   unsigned num)
 {
    unsigned i;
 
-   debug_assert(num <= PIPE_MAX_VERTEX_SAMPLERS);
+   if (shader_stage == PIPE_SHADER_VERTEX) {
+      debug_assert(num <= PIPE_MAX_VERTEX_SAMPLERS);
 
-   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[i] = samplers[i];
+      for (i = num; i < PIPE_MAX_VERTEX_SAMPLERS; ++i)
+         draw->samplers[i] = NULL;
 
-   draw->num_samplers = num;
+      draw->num_samplers = num;
 
 #ifdef HAVE_LLVM
-   if (draw->llvm)
-      draw_llvm_set_sampler_state(draw);
+      if (draw->llvm)
+         draw_llvm_set_sampler_state(draw);
 #endif
+   }
 }
 
 void
 draw_set_mapped_texture(struct draw_context *draw,
+                        unsigned shader_stage,
                         unsigned sampler_idx,
                         uint32_t width, uint32_t height, uint32_t depth,
                         uint32_t first_level, uint32_t last_level,
@@ -800,12 +807,14 @@ draw_set_mapped_texture(struct draw_context *draw,
                         uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
                         const void *data[PIPE_MAX_TEXTURE_LEVELS])
 {
+   if (shader_stage == PIPE_SHADER_VERTEX) {
 #ifdef HAVE_LLVM
-   if(draw->llvm)
-      draw_llvm_set_mapped_texture(draw,
-                                sampler_idx,
-                                width, height, depth, first_level, last_level,
-                                row_stride, img_stride, data);
+      if (draw->llvm)
+         draw_llvm_set_mapped_texture(draw,
+                                      sampler_idx,
+                                      width, height, depth, first_level, last_level,
+                                      row_stride, img_stride, data);
+   }
 #endif
 }
 
index cc95600c5309093ee9e74641d25fe6ade77ae9bd..4a73ec8c37d6dd5007300cdb3431653aa4e692e5 100644 (file)
@@ -139,15 +139,18 @@ draw_texture_samplers(struct draw_context *draw,
 
 void
 draw_set_sampler_views(struct draw_context *draw,
+                       unsigned shader_stage,
                        struct pipe_sampler_view **views,
                        unsigned num);
 void
 draw_set_samplers(struct draw_context *draw,
+                  unsigned shader_stage,
                   struct pipe_sampler_state **samplers,
                   unsigned num);
 
 void
 draw_set_mapped_texture(struct draw_context *draw,
+                        unsigned shader_stage,
                         unsigned sampler_idx,
                         uint32_t width, uint32_t height, uint32_t depth,
                         uint32_t first_level, uint32_t last_level,
index c5ec0c6c076325676b2f4305fabaa6bd72acb0fe..8af26fa9dc54caf00327cffbe7a43357ea5dad1d 100644 (file)
@@ -325,6 +325,7 @@ i915_bind_vertex_sampler_states(struct pipe_context *pipe,
    i915->num_vertex_samplers = num_samplers;
 
    draw_set_samplers(i915->draw,
+                     PIPE_SHADER_VERTEX,
                      i915->vertex_samplers,
                      i915->num_vertex_samplers);
 }
@@ -405,6 +406,7 @@ i915_prepare_vertex_sampling(struct i915_context *i915)
          }
 
          draw_set_mapped_texture(i915->draw,
+                                 PIPE_SHADER_VERTEX,
                                  i,
                                  tex->width0, tex->height0, tex->depth0,
                                  view->u.tex.first_level, tex->last_level,
@@ -792,6 +794,7 @@ i915_set_vertex_sampler_views(struct pipe_context *pipe,
    i915->num_vertex_sampler_views = num;
 
    draw_set_sampler_views(i915->draw,
+                          PIPE_SHADER_VERTEX,
                           i915->vertex_sampler_views,
                           i915->num_vertex_sampler_views);
 }
index 604a42e6cd0bf8af0eab4ca58004a904f8f5cdbd..121569ede73354321ffd19145c3a18f504ba56cf 100644 (file)
@@ -88,13 +88,11 @@ llvmpipe_bind_sampler_states(struct pipe_context *pipe,
 
    llvmpipe->num_samplers[shader] = num;
 
-   /* XXX call draw_set_samplers() here for geometry shaders once
-    * draw_set_samplers() is extended to accept a shader argument.
-    */
-   if (shader == PIPE_SHADER_VERTEX) {
+   if (shader == PIPE_SHADER_VERTEX || shader == PIPE_SHADER_GEOMETRY) {
       draw_set_samplers(llvmpipe->draw,
-                        llvmpipe->samplers[PIPE_SHADER_VERTEX],
-                        llvmpipe->num_samplers[PIPE_SHADER_VERTEX]);
+                        shader,
+                        llvmpipe->samplers[shader],
+                        llvmpipe->num_samplers[shader]);
    }
 
    llvmpipe->dirty |= LP_NEW_SAMPLER;
@@ -150,13 +148,11 @@ llvmpipe_set_sampler_views(struct pipe_context *pipe,
 
    llvmpipe->num_sampler_views[shader] = num;
 
-   /* XXX call draw_set_sampler_views() here for geometry shaders once
-    * draw_set_sampler_views() is extended to accept a shader argument.
-    */
-   if (shader == PIPE_SHADER_VERTEX) {
+   if (shader == PIPE_SHADER_VERTEX || shader == PIPE_SHADER_GEOMETRY) {
       draw_set_sampler_views(llvmpipe->draw,
-                             llvmpipe->sampler_views[PIPE_SHADER_VERTEX],
-                             llvmpipe->num_sampler_views[PIPE_SHADER_VERTEX]);
+                             shader,
+                             llvmpipe->sampler_views[shader],
+                             llvmpipe->num_sampler_views[shader]);
    }
 
    llvmpipe->dirty |= LP_NEW_SAMPLER_VIEW;
@@ -279,6 +275,7 @@ llvmpipe_prepare_vertex_sampling(struct llvmpipe_context *lp,
             assert(data[0]);
          }
          draw_set_mapped_texture(lp->draw,
+                                 PIPE_SHADER_VERTEX,
                                  i,
                                  tex->width0, tex->height0, tex->depth0,
                                  view->u.tex.first_level, tex->last_level,
index 93ae9178928f811a36e953a3caa3ee7576d41cd5..fe33508a3322f7fd36d6a8e8f3a4090e63277ccf 100644 (file)
@@ -90,10 +90,11 @@ softpipe_bind_sampler_states(struct pipe_context *pipe,
 
    softpipe->num_samplers[shader] = num;
 
-   if (shader == PIPE_SHADER_VERTEX) {
+   if (shader == PIPE_SHADER_VERTEX || shader == PIPE_SHADER_GEOMETRY) {
       draw_set_samplers(softpipe->draw,
-                        softpipe->samplers[PIPE_SHADER_VERTEX],
-                        softpipe->num_samplers[PIPE_SHADER_VERTEX]);
+                        shader,
+                        softpipe->samplers[shader],
+                        softpipe->num_samplers[shader]);
    }
 
    softpipe->dirty |= SP_NEW_SAMPLER;
@@ -183,10 +184,11 @@ softpipe_set_sampler_views(struct pipe_context *pipe,
 
    softpipe->num_sampler_views[shader] = num;
 
-   if (shader == PIPE_SHADER_VERTEX) {
+   if (shader == PIPE_SHADER_VERTEX || shader == PIPE_SHADER_GEOMETRY) {
       draw_set_sampler_views(softpipe->draw,
-                             softpipe->sampler_views[PIPE_SHADER_VERTEX],
-                             softpipe->num_sampler_views[PIPE_SHADER_VERTEX]);
+                             shader,
+                             softpipe->sampler_views[shader],
+                             softpipe->num_sampler_views[shader]);
    }
 
    softpipe->dirty |= SP_NEW_TEXTURE;