Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_maos_arrays.c
index 31eea13f4eff6fdd1a95be574eda79a58eef778d..d810e6080eb786d38f4bb440c705ce1e25f6d117 100644 (file)
@@ -48,331 +48,48 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "radeon_maos.h"
 #include "radeon_tcl.h"
 
-#if 0
-/* Usage:
- *   - from radeon_tcl_render
- *   - call radeonEmitArrays to ensure uptodate arrays in dma
- *   - emit primitives (new type?) which reference the data
- *       -- need to use elts for lineloop, quads, quadstrip/flat
- *       -- other primitives are all well-formed (need tristrip-1,fake-poly)
- *
- */
-static void emit_ubyte_rgba3( GLcontext *ctx,
-                      struct radeon_dma_region *rvb,
-                      char *data,
-                      int stride,
-                      int count )
-{
-   int i;
-   radeon_color_t *out = (radeon_color_t *)(rvb->start + rvb->address);
-
-   if (RADEON_DEBUG & DEBUG_VERTS)
-      fprintf(stderr, "%s count %d stride %d out %p\n",
-             __FUNCTION__, count, stride, (void *)out);
-
-   for (i = 0; i < count; i++) {
-      out->red   = *data;
-      out->green = *(data+1);
-      out->blue  = *(data+2);
-      out->alpha = 0xFF;
-      out++;
-      data += stride;
-   }
-}
-
-static void emit_ubyte_rgba4( GLcontext *ctx,
-                             struct radeon_dma_region *rvb,
-                             char *data,
-                             int stride,
-                             int count )
+static void emit_vecfog(GLcontext *ctx, struct radeon_aos *aos,
+                       GLvoid *data, int stride, int count)
 {
    int i;
-   int *out = (int *)(rvb->address + rvb->start);
+   uint32_t *out;
+   int size = 1;
+   radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
 
-   if (RADEON_DEBUG & DEBUG_VERTS)
+   if (RADEON_DEBUG & RADEON_VERTS)
       fprintf(stderr, "%s count %d stride %d\n",
              __FUNCTION__, count, stride);
 
-   if (stride == 4)
-       COPY_DWORDS( out, data, count );
-   else
-      for (i = 0; i < count; i++) {
-        *out++ = LE32_TO_CPU(*(int *)data);
-        data += stride;
-      }
-}
-
-
-static void emit_ubyte_rgba( GLcontext *ctx,
-                            struct radeon_dma_region *rvb,
-                            char *data,
-                            int size,
-                            int stride,
-                            int count )
-{
-   radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
-
-   if (RADEON_DEBUG & DEBUG_VERTS)
-      fprintf(stderr, "%s %d/%d\n", __FUNCTION__, count, size);
-
-   assert (!rvb->buf);
-
    if (stride == 0) {
-      radeonAllocDmaRegion( rmesa, rvb, 4, 4 );
+      radeonAllocDmaRegion( rmesa, &aos->bo, &aos->offset, size * 4, 32 );
       count = 1;
-      rvb->aos_start = GET_START(rvb);
-      rvb->aos_stride = 0;
-      rvb->aos_size = 1;
+      aos->stride = 0;
    }
    else {
-      radeonAllocDmaRegion( rmesa, rvb, 4 * count, 4 );        /* alignment? */
-      rvb->aos_start = GET_START(rvb);
-      rvb->aos_stride = 1;
-      rvb->aos_size = 1;
+      radeonAllocDmaRegion(rmesa, &aos->bo, &aos->offset, size * 4, 32);
+      aos->stride = size;
    }
 
-   /* Emit the data
-    */
-   switch (size) {
-   case 3:
-      emit_ubyte_rgba3( ctx, rvb, data, stride, count );
-      break;
-   case 4:
-      emit_ubyte_rgba4( ctx, rvb, data, stride, count );
-      break;
-   default:
-      assert(0);
-      exit(1);
-      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 radeon_dma_region *rvb,
-                        char *data,
-                        int stride,
-                        int count )
-{
-   int i;
-   GLfloat *out;
-
-   radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
-
-   if (RADEON_DEBUG & DEBUG_VERTS)
-      fprintf(stderr, "%s count %d stride %d\n",
-             __FUNCTION__, count, stride);
+   aos->components = size;
+   aos->count = count;
 
-   assert (!rvb->buf);
-
-   if (stride == 0) {
-      radeonAllocDmaRegion( rmesa, rvb, 4, 4 );
-      count = 1;
-      rvb->aos_start = GET_START(rvb);
-      rvb->aos_stride = 0;
-      rvb->aos_size = 1;
-   }
-   else {
-      radeonAllocDmaRegion( 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);
+   radeon_bo_map(aos->bo, 1);
+   out = (uint32_t*)((char*)aos->bo->ptr + aos->offset);
    for (i = 0; i < count; i++) {
       out[0] = radeonComputeFogBlendFactor( ctx, *(GLfloat *)data );
       out++;
       data += stride;
    }
+   radeon_bo_unmap(aos->bo);
 }
 
-static void emit_vec4( GLcontext *ctx,
-                      struct radeon_dma_region *rvb,
-                      char *data,
-                      int stride,
-                      int count )
+static void emit_s0_vec(uint32_t *out, GLvoid *data, int stride, int count)
 {
    int i;
-   int *out = (int *)(rvb->address + rvb->start);
-
-   if (RADEON_DEBUG & DEBUG_VERTS)
-      fprintf(stderr, "%s count %d stride %d\n",
-             __FUNCTION__, count, stride);
-
-   if (stride == 4)
-      COPY_DWORDS( out, data, count );
-   else
-      for (i = 0; i < count; i++) {
-        out[0] = *(int *)data;
-        out++;
-        data += stride;
-      }
-}
-
-
-static void emit_vec8( GLcontext *ctx,
-                      struct radeon_dma_region *rvb,
-                      char *data,
-                      int stride,
-                      int count )
-{
-   int i;
-   int *out = (int *)(rvb->address + rvb->start);
-
-   if (RADEON_DEBUG & DEBUG_VERTS)
-      fprintf(stderr, "%s count %d stride %d\n",
-             __FUNCTION__, count, stride);
-
-   if (stride == 8)
-      COPY_DWORDS( out, data, count*2 );
-   else
-      for (i = 0; i < count; i++) {
-        out[0] = *(int *)data;
-        out[1] = *(int *)(data+4);
-        out += 2;
-        data += stride;
-      }
-}
-
-static void emit_vec12( GLcontext *ctx,
-                      struct radeon_dma_region *rvb,
-                      char *data,
-                      int stride,
-                      int count )
-{
-   int i;
-   int *out = (int *)(rvb->address + rvb->start);
-
-   if (RADEON_DEBUG & DEBUG_VERTS)
-      fprintf(stderr, "%s count %d stride %d out %p data %p\n",
-             __FUNCTION__, count, stride, (void *)out, (void *)data);
-
-   if (stride == 12)
-      COPY_DWORDS( out, data, count*3 );
-   else
-      for (i = 0; i < count; i++) {
-        out[0] = *(int *)data;
-        out[1] = *(int *)(data+4);
-        out[2] = *(int *)(data+8);
-        out += 3;
-        data += stride;
-      }
-}
-
-static void emit_vec16( GLcontext *ctx,
-                       struct radeon_dma_region *rvb,
-                       char *data,
-                       int stride,
-                       int count )
-{
-   int i;
-   int *out = (int *)(rvb->address + rvb->start);
-
-   if (RADEON_DEBUG & DEBUG_VERTS)
-      fprintf(stderr, "%s count %d stride %d\n",
-             __FUNCTION__, count, stride);
-
-   if (stride == 16)
-      COPY_DWORDS( out, data, count*4 );
-   else
-      for (i = 0; i < count; i++) {
-        out[0] = *(int *)data;
-        out[1] = *(int *)(data+4);
-        out[2] = *(int *)(data+8);
-        out[3] = *(int *)(data+12);
-        out += 4;
-        data += stride;
-      }
-}
-
-
-static void emit_vector( GLcontext *ctx,
-                        struct radeon_dma_region *rvb,
-                        char *data,
-                        int size,
-                        int stride,
-                        int count )
-{
-   radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
-
-   if (RADEON_DEBUG & DEBUG_VERTS)
-      fprintf(stderr, "%s count %d size %d stride %d\n",
-             __FUNCTION__, count, size, stride);
-
-   assert (!rvb->buf);
-
-   if (stride == 0) {
-      radeonAllocDmaRegion( rmesa, rvb, size * 4, 4 );
-      count = 1;
-      rvb->aos_start = GET_START(rvb);
-      rvb->aos_stride = 0;
-      rvb->aos_size = size;
-   }
-   else {
-      radeonAllocDmaRegion( rmesa, rvb, size * count * 4, 4 ); /* alignment? */
-      rvb->aos_start = GET_START(rvb);
-      rvb->aos_stride = size;
-      rvb->aos_size = size;
-   }
-
-   /* Emit the data
-    */
-   switch (size) {
-   case 1:
-      emit_vec4( ctx, rvb, data, stride, count );
-      break;
-   case 2:
-      emit_vec8( ctx, rvb, data, stride, count );
-      break;
-   case 3:
-      emit_vec12( ctx, rvb, data, stride, count );
-      break;
-   case 4:
-      emit_vec16( ctx, rvb, data, stride, count );
-      break;
-   default:
-      assert(0);
-      exit(1);
-      break;
-   }
-
-}
-
-
-
-static void emit_s0_vec( GLcontext *ctx,
-                        struct radeon_dma_region *rvb,
-                        char *data,
-                        int stride,
-                        int count )
-{
-   int i;
-   int *out = (int *)(rvb->address + rvb->start);
-
-   if (RADEON_DEBUG & DEBUG_VERTS)
+   if (RADEON_DEBUG & RADEON_VERTS)
       fprintf(stderr, "%s count %d stride %d\n",
              __FUNCTION__, count, stride);
 
@@ -384,16 +101,11 @@ static void emit_s0_vec( GLcontext *ctx,
    }
 }
 
-static void emit_stq_vec( GLcontext *ctx,
-                        struct radeon_dma_region *rvb,
-                        char *data,
-                        int stride,
-                        int count )
+static void emit_stq_vec(uint32_t *out, GLvoid *data, int stride, int count)
 {
    int i;
-   int *out = (int *)(rvb->address + rvb->start);
 
-   if (RADEON_DEBUG & DEBUG_VERTS)
+   if (RADEON_DEBUG & RADEON_VERTS)
       fprintf(stderr, "%s count %d stride %d\n",
              __FUNCTION__, count, stride);
 
@@ -409,21 +121,16 @@ static void emit_stq_vec( GLcontext *ctx,
 
 
 
-static void emit_tex_vector( GLcontext *ctx,
-                            struct radeon_dma_region *rvb,
-                            char *data,
-                            int size,
-                            int stride,
-                            int count )
+static void emit_tex_vector(GLcontext *ctx, struct radeon_aos *aos,
+                           GLvoid *data, int size, int stride, int count)
 {
    radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
    int emitsize;
+   uint32_t *out;
 
-   if (RADEON_DEBUG & DEBUG_VERTS)
+   if (RADEON_DEBUG & RADEON_VERTS)
       fprintf(stderr, "%s %d/%d\n", __FUNCTION__, count, size);
 
-   assert (!rvb->buf);
-
    switch (size) {
    case 4: emitsize = 3; break;
    case 3: emitsize = 3; break;
@@ -432,40 +139,41 @@ static void emit_tex_vector( GLcontext *ctx,
 
 
    if (stride == 0) {
-      radeonAllocDmaRegion( rmesa, rvb, 4 * emitsize, 4 );
+      radeonAllocDmaRegion(rmesa, &aos->bo, &aos->offset, emitsize * 4, 32);
       count = 1;
-      rvb->aos_start = GET_START(rvb);
-      rvb->aos_stride = 0;
-      rvb->aos_size = emitsize;
+      aos->stride = 0;
    }
    else {
-      radeonAllocDmaRegion( rmesa, rvb, 4 * emitsize * count, 4 );
-      rvb->aos_start = GET_START(rvb);
-      rvb->aos_stride = emitsize;
-      rvb->aos_size = emitsize;
+      radeonAllocDmaRegion(rmesa, &aos->bo, &aos->offset, emitsize * count * 4, 32);
+      aos->stride = emitsize;
    }
 
+   aos->components = emitsize;
+   aos->count = count;
 
    /* Emit the data
     */
+   radeon_bo_map(aos->bo, 1);
+   out = (uint32_t*)((char*)aos->bo->ptr + aos->offset);
    switch (size) {
    case 1:
-      emit_s0_vec( ctx, rvb, data, stride, count ); 
+      emit_s0_vec( out, data, stride, count );
       break;
    case 2:
-      emit_vec8( ctx, rvb, data, stride, count );
+      radeonEmitVec8( out, data, stride, count );
       break;
    case 3:
-      emit_vec12( ctx, rvb, data, stride, count );
+      radeonEmitVec12( out, data, stride, count );
       break;
    case 4:
-      emit_stq_vec( ctx, rvb, data, stride, count );
+      emit_stq_vec( out, data, stride, count );
       break;
    default:
       assert(0);
       exit(1);
       break;
    }
+   radeon_bo_unmap(aos->bo);
 }
 
 
@@ -476,57 +184,56 @@ static void emit_tex_vector( GLcontext *ctx,
  */
 void radeonEmitArrays( GLcontext *ctx, GLuint inputs )
 {
-   radeonContextPtr rmesa = RADEON_CONTEXT( ctx );
+   r100ContextPtr rmesa = R100_CONTEXT( ctx );
    struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
-   struct radeon_dma_region **component = rmesa->tcl.aos_components;
    GLuint nr = 0;
    GLuint vfmt = 0;
    GLuint count = VB->Count;
    GLuint vtx, unit;
    
 #if 0
-   if (RADEON_DEBUG & DEBUG_VERTS) 
+   if (RADEON_DEBUG & RADEON_VERTS)
       _tnl_print_vert_flags( __FUNCTION__, inputs );
 #endif
 
    if (1) {
       if (!rmesa->tcl.obj.buf) 
-        emit_vector( ctx, 
-                     &rmesa->tcl.obj, 
-                     (char *)VB->ObjPtr->data,
-                     VB->ObjPtr->size,
-                     VB->ObjPtr->stride,
-                     count);
-
-      switch( VB->ObjPtr->size ) {
+       rcommon_emit_vector( ctx, 
+                            &(rmesa->tcl.aos[nr]),
+                            (char *)VB->AttribPtr[_TNL_ATTRIB_POS]->data,
+                            VB->AttribPtr[_TNL_ATTRIB_POS]->size,
+                            VB->AttribPtr[_TNL_ATTRIB_POS]->stride,
+                            count);
+
+      switch( VB->AttribPtr[_TNL_ATTRIB_POS]->size ) {
       case 4: vfmt |= RADEON_CP_VC_FRMT_W0;
       case 3: vfmt |= RADEON_CP_VC_FRMT_Z;
       case 2: vfmt |= RADEON_CP_VC_FRMT_XY;
       default:
          break;
       }
-      component[nr++] = &rmesa->tcl.obj;
+      nr++;
    }
    
 
    if (inputs & VERT_BIT_NORMAL) {
       if (!rmesa->tcl.norm.buf)
-        emit_vector( ctx, 
-                     &(rmesa->tcl.norm), 
-                     (char *)VB->NormalPtr->data,
-                     3,
-                     VB->NormalPtr->stride,
-                     count);
+        rcommon_emit_vector( ctx, 
+                             &(rmesa->tcl.aos[nr]),
+                             (char *)VB->AttribPtr[_TNL_ATTRIB_NORMAL]->data,
+                             3,
+                             VB->AttribPtr[_TNL_ATTRIB_NORMAL]->stride,
+                             count);
 
       vfmt |= RADEON_CP_VC_FRMT_N0;
-      component[nr++] = &rmesa->tcl.norm;
+      nr++;
    }
 
    if (inputs & VERT_BIT_COLOR0) {
       int emitsize;
-      if (VB->ColorPtr[0]->size == 4 &&
-         (VB->ColorPtr[0]->stride != 0 ||
-          VB->ColorPtr[0]->data[0][3] != 1.0)) {
+      if (VB->AttribPtr[_TNL_ATTRIB_COLOR0]->size == 4 &&
+         (VB->AttribPtr[_TNL_ATTRIB_COLOR0]->stride != 0 ||
+          VB->AttribPtr[_TNL_ATTRIB_COLOR0]->data[0][3] != 1.0)) {
         vfmt |= RADEON_CP_VC_FRMT_FPCOLOR | RADEON_CP_VC_FRMT_FPALPHA;
         emitsize = 4;
       }
@@ -537,31 +244,30 @@ void radeonEmitArrays( GLcontext *ctx, GLuint inputs )
       }
 
       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;
+       rcommon_emit_vector( ctx,
+                            &(rmesa->tcl.aos[nr]),
+                            (char *)VB->AttribPtr[_TNL_ATTRIB_COLOR0]->data,
+                            emitsize,
+                            VB->AttribPtr[_TNL_ATTRIB_COLOR0]->stride,
+                            count);
+
+      nr++;
    }
 
 
    if (inputs & VERT_BIT_COLOR1) {
       if (!rmesa->tcl.spec.buf) {
 
-        emit_vector( ctx,
-                     &rmesa->tcl.spec,
-                     (char *)VB->SecondaryColorPtr[0]->data,
-                     3,
-                     VB->SecondaryColorPtr[0]->stride,
-                     count);
+       rcommon_emit_vector( ctx,
+                            &(rmesa->tcl.aos[nr]),
+                            (char *)VB->AttribPtr[_TNL_ATTRIB_COLOR1]->data,
+                            3,
+                            VB->AttribPtr[_TNL_ATTRIB_COLOR1]->stride,
+                            count);
       }
 
       vfmt |= RADEON_CP_VC_FRMT_FPSPEC;
-      component[nr++] = &rmesa->tcl.spec;
+      nr++;
    }
 
 /* FIXME: not sure if this is correct. May need to stitch this together with
@@ -570,13 +276,13 @@ void radeonEmitArrays( GLcontext *ctx, GLuint inputs )
    if (inputs & VERT_BIT_FOG) {
       if (!rmesa->tcl.fog.buf)
         emit_vecfog( ctx,
-                     &(rmesa->tcl.fog),
-                     (char *)VB->FogCoordPtr->data,
-                     VB->FogCoordPtr->stride,
+                     &(rmesa->tcl.aos[nr]),
+                     (char *)VB->AttribPtr[_TNL_ATTRIB_FOG]->data,
+                     VB->AttribPtr[_TNL_ATTRIB_FOG]->stride,
                      count);
 
       vfmt |= RADEON_CP_VC_FRMT_FPFOG;
-      component[nr++] = &rmesa->tcl.fog;
+      nr++;
    }
 
 
@@ -587,29 +293,29 @@ void radeonEmitArrays( GLcontext *ctx, GLuint inputs )
       if (inputs & VERT_BIT_TEX(unit)) {
         if (!rmesa->tcl.tex[unit].buf)
            emit_tex_vector( ctx,
-                            &(rmesa->tcl.tex[unit]),
-                            (char *)VB->TexCoordPtr[unit]->data,
-                            VB->TexCoordPtr[unit]->size,
-                            VB->TexCoordPtr[unit]->stride,
+                            &(rmesa->tcl.aos[nr]),
+                            (char *)VB->AttribPtr[_TNL_ATTRIB_TEX0 + unit]->data,
+                            VB->AttribPtr[_TNL_ATTRIB_TEX0 + unit]->size,
+                            VB->AttribPtr[_TNL_ATTRIB_TEX0 + unit]->stride,
                             count );
+        nr++;
 
         vfmt |= RADEON_ST_BIT(unit);
          /* assume we need the 3rd coord if texgen is active for r/q OR at least
            3 coords are submitted. This may not be 100% correct */
-         if (VB->TexCoordPtr[unit]->size >= 3) {
+         if (VB->AttribPtr[_TNL_ATTRIB_TEX0 + unit]->size >= 3) {
            vtx |= RADEON_Q_BIT(unit);
            vfmt |= RADEON_Q_BIT(unit);
         }
         if ( (ctx->Texture.Unit[unit].TexGenEnabled & (R_BIT | Q_BIT)) )
            vtx |= RADEON_Q_BIT(unit);
-        else if ((VB->TexCoordPtr[unit]->size >= 3) &&
+        else if ((VB->AttribPtr[_TNL_ATTRIB_TEX0 + unit]->size >= 3) &&
                  ((ctx->Texture.Unit[unit]._ReallyEnabled & (TEXTURE_CUBE_BIT)) == 0)) {
-           GLuint swaptexmatcol = (VB->TexCoordPtr[unit]->size - 3);
+           GLuint swaptexmatcol = (VB->AttribPtr[_TNL_ATTRIB_TEX0 + unit]->size - 3);
            if (((rmesa->NeedTexMatrix >> unit) & 1) &&
                 (swaptexmatcol != ((rmesa->TexMatColSwap >> unit) & 1)))
               radeonUploadTexMatrix( rmesa, unit, swaptexmatcol ) ;
         }
-        component[nr++] = &rmesa->tcl.tex[unit];
       }
    }
 
@@ -622,34 +328,3 @@ void radeonEmitArrays( GLcontext *ctx, GLuint inputs )
    rmesa->tcl.vertex_format = vfmt;
 }
 
-
-void radeonReleaseArrays( GLcontext *ctx, GLuint newinputs )
-{
-   radeonContextPtr rmesa = RADEON_CONTEXT( ctx );
-   GLuint unit;
-
-#if 0
-   if (RADEON_DEBUG & DEBUG_VERTS) 
-      _tnl_print_vert_flags( __FUNCTION__, newinputs );
-#endif
-
-   if (newinputs & VERT_BIT_POS) 
-     radeonReleaseDmaRegion( rmesa, &rmesa->tcl.obj, __FUNCTION__ );
-
-   if (newinputs & VERT_BIT_NORMAL) 
-      radeonReleaseDmaRegion( rmesa, &rmesa->tcl.norm, __FUNCTION__ );
-
-   if (newinputs & VERT_BIT_COLOR0) 
-      radeonReleaseDmaRegion( rmesa, &rmesa->tcl.rgba, __FUNCTION__ );
-
-   if (newinputs & VERT_BIT_COLOR1) 
-      radeonReleaseDmaRegion( rmesa, &rmesa->tcl.spec, __FUNCTION__ );
-      
-   if (newinputs & VERT_BIT_FOG)
-      radeonReleaseDmaRegion( rmesa, &rmesa->tcl.fog, __FUNCTION__ );
-
-   for (unit = 0 ; unit < ctx->Const.MaxTextureUnits; unit++) {
-      if (newinputs & VERT_BIT_TEX(unit))
-         radeonReleaseDmaRegion( rmesa, &rmesa->tcl.tex[unit], __FUNCTION__ );
-   }
-}