OSDN Git Service

Fix some issues with perspective-corrected interpolation.
authorBrian <brian.paul@tungstengraphics.com>
Tue, 18 Sep 2007 18:55:20 +0000 (12:55 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Tue, 18 Sep 2007 18:56:23 +0000 (12:56 -0600)
In mesa_to_tgsi.c, use TGSI_INTERPOLATE_PERSPECTIVE by default (to match
post-transform vertex info convention).  More to be done there...
In sp_quad_fs.c, interpolate W in addition to Z.  This fixes the divide
by zero happening in perspective_interpolation() tgsi_exec.c
As it was, we were only getting perspective correction of texture coords
used by the TGSI_TEX instruction since it does a homogeneous divide.
Other coords/varyings were incorrect.

src/mesa/pipe/softpipe/sp_quad_fs.c
src/mesa/pipe/tgsi/exec/tgsi_exec.c
src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c

index 25bc170..7d2712a 100755 (executable)
@@ -68,10 +68,9 @@ quad_shade_stage(struct quad_stage *qs)
  *   INPUT[attr] = MAD INPUT[attr],   COEF_DADY[attr], INPUT_WPOS.yyyy
  */
 static INLINE void
-linterp_z(const struct tgsi_interp_coef *coef,
-          struct tgsi_exec_vector *pos)
+linterp(const struct tgsi_interp_coef *coef,
+          struct tgsi_exec_vector *pos, uint ch)
 {
-   uint ch = 2;
    uint j;
    for (j = 0; j < QUAD_SIZE; j++) {
       const float x = pos->xyzw[0].f[j];
@@ -83,7 +82,6 @@ linterp_z(const struct tgsi_interp_coef *coef,
 }
 
 
-
 /* This should be done by the fragment shader execution unit (code
  * generated from the decl instructions).  Do it here for now.
  */
@@ -131,7 +129,8 @@ shade_quad(
    machine.Inputs[0].xyzw[1].f[3] = fy + 1.0f;
 
    /* interp Z */
-   linterp_z(&quad->coef[0], &machine.Inputs[0]);
+   linterp(&quad->coef[0], &machine.Inputs[0], 2); /* Z */
+   linterp(&quad->coef[0], &machine.Inputs[0], 3); /* 1/W */
 
    /* run shader */
    tgsi_exec_machine_run( &machine );
index 793f8bc..28dc049 100644 (file)
@@ -1104,6 +1104,7 @@ perspective_interpolation(
       const float y = mach->Inputs[0].xyzw[1].f[i];
       // WPOS.w here is really 1/w
       const float w = 1.0f / mach->Inputs[0].xyzw[3].f[i];
+      assert(mach->Inputs[0].xyzw[3].f[i] != 0.0);
 
       mach->Inputs[attrib].xyzw[chan].f[i] =
          (mach->InterpCoefs[attrib].a0[chan] +
index 182a7ef..2820706 100644 (file)
@@ -859,7 +859,7 @@ tgsi_mesa_compile_fp_program(
       fulldecl = make_frag_input_decl(\r
          1,\r
          1 + count - 1,\r
-         TGSI_INTERPOLATE_LINEAR,\r
+         TGSI_INTERPOLATE_PERSPECTIVE,\r
          TGSI_WRITEMASK_XYZW );\r
       ti += tgsi_build_full_declaration(\r
          &fulldecl,\r