fix up radeon span functions using latest r200 code from Brian,
[mesa.git] / src / mesa / drivers / dri / r200 / r200_maos_arrays.c
index 7842c0c594f89e02b762a1a83bd2c012f13711f8..12ea462a400abea13205df635bf151ff7dcf5c04 100644 (file)
@@ -43,14 +43,16 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "math/m_translate.h"
 #include "tnl/tnl.h"
 #include "tnl/t_context.h"
-#include "tnl/t_imm_debug.h"
 
 #include "r200_context.h"
 #include "r200_ioctl.h"
 #include "r200_state.h"
 #include "r200_swtcl.h"
 #include "r200_maos.h"
+#include "r200_tcl.h"
 
+
+#if 0
 /* Usage:
  *   - from r200_tcl_render
  *   - call r200EmitArrays to ensure uptodate arrays in dma
@@ -70,7 +72,7 @@ static void emit_ubyte_rgba3( GLcontext *ctx,
 
    if (R200_DEBUG & DEBUG_VERTS)
       fprintf(stderr, "%s count %d stride %d out %p\n",
-             __FUNCTION__, count, stride, out);
+             __FUNCTION__, count, stride, (void *)out);
 
    for (i = 0; i < count; i++) {
       out->red   = *data;
@@ -82,29 +84,6 @@ static void emit_ubyte_rgba3( GLcontext *ctx,
    }
 }
 
-
-#if defined(USE_X86_ASM)
-#define COPY_DWORDS( dst, src, nr )                                    \
-do {                                                                   \
-       int __tmp;                                                      \
-       __asm__ __volatile__( "rep ; movsl"                             \
-                             : "=%c" (__tmp), "=D" (dst), "=S" (__tmp) \
-                             : "0" (nr),                               \
-                               "D" ((long)dst),                        \
-                               "S" ((long)src) );                      \
-} while (0)
-#else
-#define COPY_DWORDS( dst, src, nr )            \
-do {                                           \
-   int j;                                      \
-   for ( j = 0 ; j < nr ; j++ )                        \
-      dst[j] = ((int *)src)[j];                        \
-   dst += nr;                                  \
-} while (0)
-#endif
-
-
-
 static void emit_ubyte_rgba4( GLcontext *ctx,
                              struct r200_dma_region *rvb,
                              char *data,
@@ -173,6 +152,71 @@ static void emit_ubyte_rgba( GLcontext *ctx,
       break;
    }
 }
+#endif
+
+
+#if defined(USE_X86_ASM)
+#define COPY_DWORDS( dst, src, nr )                                    \
+do {                                                                   \
+       int __tmp;                                                      \
+       __asm__ __volatile__( "rep ; movsl"                             \
+                             : "=%c" (__tmp), "=D" (dst), "=S" (__tmp) \
+                             : "0" (nr),                               \
+                               "D" ((long)dst),                        \
+                               "S" ((long)src) );                      \
+} while (0)
+#else
+#define COPY_DWORDS( dst, src, nr )            \
+do {                                           \
+   int j;                                      \
+   for ( j = 0 ; j < nr ; j++ )                        \
+      dst[j] = ((int *)src)[j];                        \
+   dst += nr;                                  \
+} while (0)
+#endif
+
+
+static void emit_vecfog( GLcontext *ctx,
+                        struct r200_dma_region *rvb,
+                        char *data,
+                        int stride,
+                        int count )
+{
+   int i;
+   GLfloat *out;
+
+   r200ContextPtr rmesa = R200_CONTEXT(ctx);
+   
+   if (R200_DEBUG & DEBUG_VERTS)
+      fprintf(stderr, "%s count %d stride %d\n",
+             __FUNCTION__, count, stride);
+
+   assert (!rvb->buf);
+
+   if (stride == 0) {
+      r200AllocDmaRegion( rmesa, rvb, 4, 4 );
+      count = 1;
+      rvb->aos_start = GET_START(rvb);
+      rvb->aos_stride = 0;
+      rvb->aos_size = 1;
+   }
+   else {
+      r200AllocDmaRegion( rmesa, rvb, count * 4, 4 );  /* alignment? */
+      rvb->aos_start = GET_START(rvb);
+      rvb->aos_stride = 1;
+      rvb->aos_size = 1;
+   }
+
+   /* Emit the data
+    */
+   out = (GLfloat *)(rvb->address + rvb->start);
+   for (i = 0; i < count; i++) {
+      out[0] = r200ComputeFogBlendFactor( ctx, *(GLfloat *)data );
+      out++;
+      data += stride;
+   }
+
+}
 
 
 static void emit_vec4( GLcontext *ctx,
@@ -234,7 +278,7 @@ static void emit_vec12( GLcontext *ctx,
 
    if (R200_DEBUG & DEBUG_VERTS)
       fprintf(stderr, "%s count %d stride %d out %p data %p\n",
-             __FUNCTION__, count, stride, out, data);
+             __FUNCTION__, count, stride, (void *)out, (void *)data);
 
    if (stride == 12)
       COPY_DWORDS( out, data, count*3 );
@@ -340,10 +384,8 @@ void r200EmitArrays( GLcontext *ctx, GLuint inputs )
    GLuint nr = 0;
    GLuint vfmt0 = 0, vfmt1 = 0;
    GLuint count = VB->Count;
+   GLuint i;
    
-   if (R200_DEBUG & DEBUG_VERTS) 
-      _tnl_print_vert_flags( __FUNCTION__, inputs );
-
    if (1) {
       if (!rmesa->tcl.obj.buf) 
         emit_vector( ctx, 
@@ -358,7 +400,7 @@ void r200EmitArrays( GLcontext *ctx, GLuint inputs )
       case 3: vfmt0 |= R200_VTX_Z0;
       case 2: 
       default:
-       break;
+        break;
       }
       component[nr++] = &rmesa->tcl.obj;
    }
@@ -377,91 +419,73 @@ void r200EmitArrays( GLcontext *ctx, GLuint inputs )
       component[nr++] = &rmesa->tcl.norm;
    }
 
+   if (inputs & VERT_BIT_FOG) {
+      if (!rmesa->tcl.fog.buf)
+        emit_vecfog( ctx, 
+                     &(rmesa->tcl.fog), 
+                     (char *)VB->FogCoordPtr->data,
+                     VB->FogCoordPtr->stride,
+                     count);
+
+      vfmt0 |= R200_VTX_DISCRETE_FOG;
+      component[nr++] = &rmesa->tcl.fog;
+   }
    if (inputs & VERT_BIT_COLOR0) {
-      if (VB->ColorPtr[0]->Type == GL_UNSIGNED_BYTE) {
-        if (!rmesa->tcl.rgba.buf)
-           emit_ubyte_rgba( ctx, 
-                            &rmesa->tcl.rgba, 
-                            (char *)VB->ColorPtr[0]->Ptr,
-                            VB->ColorPtr[0]->Size,
-                            VB->ColorPtr[0]->StrideB,
-                            count);
-
-        vfmt0 |= R200_VTX_PK_RGBA << R200_VTX_COLOR_0_SHIFT; 
+      int emitsize;
+
+      if (VB->ColorPtr[0]->size == 4 &&
+         (VB->ColorPtr[0]->stride != 0 ||
+          VB->ColorPtr[0]->data[0][3] != 1.0)) { 
+        vfmt0 |= R200_VTX_FP_RGBA << R200_VTX_COLOR_0_SHIFT; 
+        emitsize = 4;
       }
-      else {
-        int emitsize;
-
-        if (VB->ColorPtr[0]->Size == 4 &&
-            (VB->ColorPtr[0]->StrideB != 0 ||
-             ((GLfloat *)VB->ColorPtr[0]->Ptr)[3] != 1.0)) { 
-           vfmt0 |= R200_VTX_FP_RGBA << R200_VTX_COLOR_0_SHIFT; 
-           emitsize = 4;
-        }
-        else { 
-           vfmt0 |= R200_VTX_FP_RGB << R200_VTX_COLOR_0_SHIFT; 
-           emitsize = 3;
-        }
-
-        if (!rmesa->tcl.rgba.buf)
-           emit_vector( ctx, 
-                        &(rmesa->tcl.rgba), 
-                        (char *)VB->ColorPtr[0]->Ptr,
-                        emitsize,
-                        VB->ColorPtr[0]->StrideB,
-                        count);
+      else { 
+        vfmt0 |= R200_VTX_FP_RGB << R200_VTX_COLOR_0_SHIFT; 
+        emitsize = 3;
       }
 
+      if (!rmesa->tcl.rgba.buf)
+        emit_vector( ctx, 
+                     &(rmesa->tcl.rgba), 
+                     (char *)VB->ColorPtr[0]->data,
+                     emitsize,
+                     VB->ColorPtr[0]->stride,
+                     count);
+
       component[nr++] = &rmesa->tcl.rgba;
    }
 
 
    if (inputs & VERT_BIT_COLOR1) {
       if (!rmesa->tcl.spec.buf) {
-        if (VB->SecondaryColorPtr[0]->Type != GL_UNSIGNED_BYTE)
-           r200_import_float_spec_colors( ctx );
-
-        emit_ubyte_rgba( ctx, 
-                         &rmesa->tcl.spec, 
-                         (char *)VB->SecondaryColorPtr[0]->Ptr,
-                         3,
-                         VB->SecondaryColorPtr[0]->StrideB,
-                         count);
+        emit_vector( ctx, 
+                     &rmesa->tcl.spec, 
+                     (char *)VB->SecondaryColorPtr[0]->data,
+                     3,
+                     VB->SecondaryColorPtr[0]->stride,
+                     count);
       }
 
       /* How does this work?
        */
-      vfmt0 |= R200_VTX_PK_RGBA << R200_VTX_COLOR_1_SHIFT; 
+      vfmt0 |= R200_VTX_FP_RGB << R200_VTX_COLOR_1_SHIFT; 
       component[nr++] = &rmesa->tcl.spec;
    }
-
-/*    vtx = (rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] & */
-/*       ~(R200_TCL_VTX_Q0|R200_TCL_VTX_Q1)); */
       
-   if (inputs & VERT_BIT_TEX0) {
-      if (!rmesa->tcl.tex[0].buf)
-        emit_vector( ctx, 
-                     &(rmesa->tcl.tex[0]), 
-                     (char *)VB->TexCoordPtr[0]->data,
-                     VB->TexCoordPtr[0]->size,
-                     VB->TexCoordPtr[0]->stride,
-                     count );
-
-      vfmt1 |= VB->TexCoordPtr[0]->size << R200_VTX_TEX0_COMP_CNT_SHIFT;
-      component[nr++] = &rmesa->tcl.tex[0];
-   }
-
-   if (inputs & VERT_BIT_TEX1) {
-      if (!rmesa->tcl.tex[1].buf)
-        emit_vector( ctx, 
-                     &(rmesa->tcl.tex[1]), 
-                     (char *)VB->TexCoordPtr[1]->data,
-                     VB->TexCoordPtr[1]->size,
-                     VB->TexCoordPtr[1]->stride,
-                     count );
-        
-      vfmt1 |= VB->TexCoordPtr[1]->size << R200_VTX_TEX1_COMP_CNT_SHIFT;
-      component[nr++] = &rmesa->tcl.tex[1];
+   for ( i = 0 ; i < ctx->Const.MaxTextureUnits ; i++ ) {
+      if (inputs & (VERT_BIT_TEX0 << i)) {
+        if (!rmesa->tcl.tex[i].buf)
+            emit_vector( ctx, 
+                         &(rmesa->tcl.tex[i]),
+                         (char *)VB->TexCoordPtr[i]->data,
+                         VB->TexCoordPtr[i]->size,
+                         VB->TexCoordPtr[i]->stride,
+                         count );
+
+        vfmt1 |= VB->TexCoordPtr[i]->size << (i * 3);
+        component[nr++] = &rmesa->tcl.tex[i];
+      }
    }
 
    if (vfmt0 != rmesa->hw.vtx.cmd[VTX_VTXFMT_0] ||
@@ -478,16 +502,20 @@ void r200EmitArrays( GLcontext *ctx, GLuint inputs )
 
 void r200ReleaseArrays( GLcontext *ctx, GLuint newinputs )
 {
+   GLuint unit;
    r200ContextPtr rmesa = R200_CONTEXT( ctx );
 
-   if (R200_DEBUG & DEBUG_VERTS) 
-      _tnl_print_vert_flags( __FUNCTION__, newinputs );
+/*    if (R200_DEBUG & DEBUG_VERTS)  */
+/*       _tnl_print_vert_flags( __FUNCTION__, newinputs ); */
 
    if (newinputs & VERT_BIT_POS) 
      r200ReleaseDmaRegion( rmesa, &rmesa->tcl.obj, __FUNCTION__ );
 
    if (newinputs & VERT_BIT_NORMAL) 
       r200ReleaseDmaRegion( rmesa, &rmesa->tcl.norm, __FUNCTION__ );
+      
+   if (newinputs & VERT_BIT_FOG) 
+      r200ReleaseDmaRegion( rmesa, &rmesa->tcl.fog, __FUNCTION__ );
 
    if (newinputs & VERT_BIT_COLOR0) 
       r200ReleaseDmaRegion( rmesa, &rmesa->tcl.rgba, __FUNCTION__ );
@@ -495,9 +523,8 @@ void r200ReleaseArrays( GLcontext *ctx, GLuint newinputs )
    if (newinputs & VERT_BIT_COLOR1) 
       r200ReleaseDmaRegion( rmesa, &rmesa->tcl.spec, __FUNCTION__ );
 
-   if (newinputs & VERT_BIT_TEX0)
-      r200ReleaseDmaRegion( rmesa, &rmesa->tcl.tex[0], __FUNCTION__ );
-
-   if (newinputs & VERT_BIT_TEX1)
-      r200ReleaseDmaRegion( rmesa, &rmesa->tcl.tex[1], __FUNCTION__ );
+   for (unit = 0 ; unit < ctx->Const.MaxTextureUnits; unit++) {
+      if (newinputs & VERT_BIT_TEX(unit))
+        r200ReleaseDmaRegion( rmesa, &rmesa->tcl.tex[unit], __FUNCTION__ );
+   }
 }