Merge remote branch 'origin/master' into pipe-video
[mesa.git] / src / gallium / auxiliary / util / u_simple_shaders.c
index b751e29ab62dd5c25b88461a9fa95d40ad7f1dcf..b0f2dd8aa29e8173c9620140c180fa2f6c5a4238 100644 (file)
@@ -37,7 +37,9 @@
 
 #include "pipe/p_context.h"
 #include "pipe/p_shader_tokens.h"
+#include "pipe/p_state.h"
 #include "util/u_simple_shaders.h"
+#include "util/u_debug.h"
 #include "tgsi/tgsi_ureg.h"
 
 
@@ -86,10 +88,15 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
  *  MOV OUT[0], IMM[0]                    // (if writemask != 0xf)
  *  TEX OUT[0].writemask, IN[0], SAMP[0], 2D;
  *  END;
+ *
+ * \param tex_target  one of PIPE_TEXTURE_x
+ * \parma interp_mode  either TGSI_INTERPOLATE_LINEAR or PERSPECTIVE
+ * \param writemask  mask of TGSI_WRITEMASK_x
  */
 void *
 util_make_fragment_tex_shader_writemask(struct pipe_context *pipe,
                                         unsigned tex_target,
+                                        unsigned interp_mode,
                                         unsigned writemask )
 {
    struct ureg_program *ureg;
@@ -97,6 +104,9 @@ util_make_fragment_tex_shader_writemask(struct pipe_context *pipe,
    struct ureg_src tex;
    struct ureg_dst out;
 
+   assert(interp_mode == TGSI_INTERPOLATE_LINEAR ||
+          interp_mode == TGSI_INTERPOLATE_PERSPECTIVE);
+
    ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT );
    if (ureg == NULL)
       return NULL;
@@ -105,7 +115,7 @@ util_make_fragment_tex_shader_writemask(struct pipe_context *pipe,
 
    tex = ureg_DECL_fs_input( ureg, 
                              TGSI_SEMANTIC_GENERIC, 0, 
-                             TGSI_INTERPOLATE_PERSPECTIVE );
+                             interp_mode );
 
    out = ureg_DECL_output( ureg, 
                            TGSI_SEMANTIC_COLOR,
@@ -132,10 +142,12 @@ util_make_fragment_tex_shader_writemask(struct pipe_context *pipe,
  * \param tex_target  one of PIPE_TEXTURE_x
  */
 void *
-util_make_fragment_tex_shader(struct pipe_context *pipe, unsigned tex_target )
+util_make_fragment_tex_shader(struct pipe_context *pipe, unsigned tex_target,
+                              unsigned interp_mode)
 {
    return util_make_fragment_tex_shader_writemask( pipe,
                                                    tex_target,
+                                                   interp_mode,
                                                    TGSI_WRITEMASK_XYZW );
 }
 
@@ -146,7 +158,8 @@ util_make_fragment_tex_shader(struct pipe_context *pipe, unsigned tex_target )
  */
 void *
 util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe,
-                                         unsigned tex_target)
+                                         unsigned tex_target,
+                                         unsigned interp_mode)
 {
    struct ureg_program *ureg;
    struct ureg_src sampler;
@@ -162,7 +175,7 @@ util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe,
 
    tex = ureg_DECL_fs_input( ureg,
                              TGSI_SEMANTIC_GENERIC, 0,
-                             TGSI_INTERPOLATE_PERSPECTIVE );
+                             interp_mode );
 
    out = ureg_DECL_output( ureg,
                            TGSI_SEMANTIC_COLOR,
@@ -191,7 +204,8 @@ util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe,
 void *
 util_make_fragment_passthrough_shader(struct pipe_context *pipe)
 {
-   return util_make_fragment_clonecolor_shader(pipe, 1);
+   return util_make_fragment_cloneinput_shader(pipe, 1, TGSI_SEMANTIC_COLOR,
+                                               TGSI_INTERPOLATE_PERSPECTIVE);
 }
 
 
@@ -199,7 +213,9 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe)
  * Make a fragment shader that copies the input color to N output colors.
  */
 void *
-util_make_fragment_clonecolor_shader(struct pipe_context *pipe, int num_cbufs)
+util_make_fragment_cloneinput_shader(struct pipe_context *pipe, int num_cbufs,
+                                     int input_semantic,
+                                     int input_interpolate)
 {
    struct ureg_program *ureg;
    struct ureg_src src;
@@ -212,8 +228,8 @@ util_make_fragment_clonecolor_shader(struct pipe_context *pipe, int num_cbufs)
    if (ureg == NULL)
       return NULL;
 
-   src = ureg_DECL_fs_input( ureg, TGSI_SEMANTIC_COLOR, 0, 
-                             TGSI_INTERPOLATE_PERSPECTIVE );
+   src = ureg_DECL_fs_input( ureg, input_semantic, 0,
+                             input_interpolate );
 
    for (i = 0; i < num_cbufs; i++)
       dst[i] = ureg_DECL_output( ureg, TGSI_SEMANTIC_COLOR, i );