Keith Whitwell wrote:
> Ralf,
> 
> I've had time now to look at the patch and the problem I see with it is the
> kernel changes.  Kernel changes are problematic because of the compatibility
> issues they introduce - people upgrading X but not the kernel and vice versa.
> 
> >>From the look of it, the changes are just to support dma texture uploads to
> agp memory.  Using dma to upload to agp memory has one advantage:
> synchronization.  Theoretically the rendering engine doesn't need to be
> flushed prior to updating texture memory in this way.  However, I don't know
> if the mga hardware is reliable enough for this to work; I seem to remember we
> flush the render engine before any texture uploads anyway...
> 
> Using dma to upload to agp memory doesn't have any speed advantages; the dma
> buffer is in agp memory anyway, so you might as well go straight to the
> destination.  Have you considered doing this (and hopefully avoiding changes
> to the kernel module)?
> 
> Keith
> 

i used the existing iload based upload because it keeps everything in
sync.

anyway, i came up with the following that doesnt require any kernel
changes.
the texture upload function needs to wait until the card has rendered
all
remaining primitives so that no currently used agp texture is
overwritten.
so its rather slow.


-- 
ralf willenbacher ([EMAIL PROTECTED])
diff -ru xc2/xc/lib/GL/mesa/src/drv/mga/mga_xmesa.c 
xc/xc/lib/GL/mesa/src/drv/mga/mga_xmesa.c
--- xc2/xc/lib/GL/mesa/src/drv/mga/mga_xmesa.c  Tue May  1 21:39:09 2001
+++ xc/xc/lib/GL/mesa/src/drv/mga/mga_xmesa.c   Thu Oct 25 15:05:35 2001
@@ -221,6 +221,17 @@
 
    mgaScreen->texVirtual[MGA_CARD_HEAP] = (char *)(mgaScreen->sPriv->pFB +
                                           serverInfo->textureOffset);
+   if (drmMap(sPriv->fd,
+              serverInfo->agpTextureOffset,
+              serverInfo->agpTextureSize,
+              (drmAddress *)&mgaScreen->texVirtual[MGA_AGP_HEAP]) != 0)
+   {
+      Xfree(mgaScreen);
+      sPriv->private = NULL;
+      __driMesaMessage("Couldn't map agptexture region");
+      return GL_FALSE;
+   }
+
 #if 0
    mgaScreen->texVirtual[MGA_AGP_HEAP] = (mgaScreen->agp.map +
                                          serverInfo->agpTextureOffset);
diff -ru xc2/xc/lib/GL/mesa/src/drv/mga/mgatexmem.c 
xc/xc/lib/GL/mesa/src/drv/mga/mgatexmem.c
--- xc2/xc/lib/GL/mesa/src/drv/mga/mgatexmem.c  Tue May  1 21:39:10 2001
+++ xc/xc/lib/GL/mesa/src/drv/mga/mgatexmem.c   Tue Oct 30 14:01:25 2001
@@ -377,7 +378,8 @@
 
    /* Fill in the secondary buffer with properly converted texels
     * from the mesa buffer. */
-   if(t->heap == MGA_CARD_HEAP) {
+   /* FIXME: the sync for direct copy reduces speed.. */
+   if(t->heap == MGA_CARD_HEAP  ) {
       mgaGetILoadBufferLocked( mmesa );
       mgaConvertTexture( (GLuint *)mmesa->iload_buffer->address,
                         texelBytes, image, x, y, width, height );
@@ -400,6 +402,8 @@
       /* This works, is slower for uploads to card space and needs
        * additional synchronization with the dma stream.
        */
+       
+      UPDATE_LOCK(mmesa, DRM_LOCK_FLUSH | DRM_LOCK_QUIESCENT);
       mgaConvertTexture( (GLuint *)
                         (mmesa->mgaScreen->texVirtual[t->heap] +
                          offset +
@@ -434,7 +438,43 @@
 
 static int mgaChooseTexHeap( mgaContextPtr mmesa, mgaTextureObjectPtr t )
 {
-       return 0;
+   int freeagp, freecard;
+   int fitincard, fitinagp;
+   int totalcard, totalagp;
+   TMemBlock *b;
+
+   totalcard = totalagp = fitincard = fitinagp = freeagp = freecard = 0;
+
+   b = mmesa->texHeap[0];
+   while(b)
+   {
+     totalcard += b->size;
+     if(b->free) if(t->totalSize <= b->size)fitincard = 1;
+     b = b->next;
+   }
+
+   b = mmesa->texHeap[1];
+   while(b)
+   {
+     totalagp += b->size;
+     if(b->free)  if(t->totalSize <= b->size)fitinagp = 1;
+     b = b->next;
+   }
+
+   if(fitincard)return 0;
+   if(fitinagp)return 1;
+
+   if(totalcard && totalagp)
+   {
+     int ages;
+     int ratio = (totalcard > totalagp) ? totalcard / totalagp : totalagp / totalcard;
+     ages = mmesa->sarea->texAge[0] + mmesa->sarea->texAge[1];
+     if( (ages % ratio) == 0)return totalcard > totalagp ? 1 : 0;
+     else return totalcard > totalagp ? 0 : 1;
+   }
+
+   if(totalagp) return 1;
+   return 0;
 }
 
 
diff -ru xc2/xc/programs/Xserver/hw/xfree86/drivers/mga/mga.h 
xc/xc/programs/Xserver/hw/xfree86/drivers/mga/mga.h
--- xc2/xc/programs/Xserver/hw/xfree86/drivers/mga/mga.h        Thu Jun 14 22:23:42 
2001
+++ xc/xc/programs/Xserver/hw/xfree86/drivers/mga/mga.h Thu Oct 25 15:05:35 2001
@@ -348,6 +348,7 @@
     void               (*GetQuiescence)(ScrnInfoPtr pScrn);
 
     int                agpMode;
+    int                 agpSize;
 
 #endif
     XF86VideoAdaptorPtr adaptor;
diff -ru xc2/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dri.c 
xc/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dri.c
--- xc2/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dri.c    Thu Jun 14 22:23:42 
2001
+++ xc/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dri.c     Thu Oct 25 15:05:35 
+2001
@@ -571,11 +571,14 @@
    MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo;
    unsigned long mode;
    unsigned int vendor, device;
-   int ret, count;
+   int ret, count, i;
+
+   if(pMga->agpSize < 12)pMga->agpSize = 12;
+   if(pMga->agpSize > 64)pMga->agpSize = 64; /* cap */
 
    /* FIXME: Make these configurable...
     */
-   pMGADRIServer->agp.size = 12 * 1024 * 1024;
+   pMGADRIServer->agp.size = pMga->agpSize * 1024 * 1024;
 
    pMGADRIServer->warp.offset = 0;
    pMGADRIServer->warp.size = MGA_WARP_UCODE_SIZE;
@@ -588,6 +591,13 @@
                                    pMGADRIServer->primary.size);
    pMGADRIServer->buffers.size = MGA_NUM_BUFFERS * MGA_BUFFER_SIZE;
 
+
+   pMGADRIServer->agpTextures.offset = (pMGADRIServer->buffers.offset +
+                                    pMGADRIServer->buffers.size);
+
+   pMGADRIServer->agpTextures.size = pMGADRIServer->agp.size -
+                                     pMGADRIServer->agpTextures.offset;
+
    if ( drmAgpAcquire( pMga->drmFD ) < 0 ) {
       xf86DrvMsg( pScreen->myNum, X_ERROR, "[agp] AGP not available\n" );
       return FALSE;
@@ -750,6 +760,28 @@
               "[drm] Added %d %d byte DMA buffers\n",
               count, MGA_BUFFER_SIZE );
 
+   i = mylog2(pMGADRIServer->agpTextures.size / MGA_NR_TEX_REGIONS);
+   if(i < MGA_LOG_MIN_TEX_REGION_SIZE)
+      i = MGA_LOG_MIN_TEX_REGION_SIZE;
+   pMGADRIServer->agpTextures.size = (pMGADRIServer->agpTextures.size >> i) << i;
+
+   if ( drmAddMap( pMga->drmFD,
+                   pMGADRIServer->agpTextures.offset,
+                   pMGADRIServer->agpTextures.size,
+                   DRM_AGP, 0,
+                   &pMGADRIServer->agpTextures.handle ) < 0 ) {
+      xf86DrvMsg( pScreen->myNum, X_ERROR,
+                  "[agp] Could not add agpTexture mapping\n" );
+      return FALSE;
+   }
+/* should i map it ? */
+   xf86DrvMsg( pScreen->myNum, X_INFO,
+               "[agp] agpTexture handle = 0x%08lx\n",
+               pMGADRIServer->agpTextures.handle );
+   xf86DrvMsg( pScreen->myNum, X_INFO,
+               "[agp] agpTexture size: %d kb\n", pMGADRIServer->agpTextures.size/1024 
+);
+
+
    xf86EnablePciBusMaster( pMga->PciInfo, TRUE );
 
    return TRUE;
@@ -852,6 +884,9 @@
    init.primary_offset = pMGADRIServer->primary.handle;
    init.buffers_offset = pMGADRIServer->buffers.handle;
 
+   init.texture_offset[1] = pMGADRIServer->agpTextures.handle;
+   init.texture_size[1] = pMGADRIServer->agpTextures.size;
+
    ret = drmMGAInitDMA( pMga->drmFD, &init );
    if ( ret < 0 ) {
       xf86DrvMsg( pScrn->scrnIndex, X_ERROR,
@@ -1190,6 +1225,14 @@
    pMGADRI->logTextureGranularity = i;
    pMGADRI->textureSize = (pMGADRI->textureSize >> i) << i; /* truncate */
 
+   i = mylog2( pMGADRIServer->agpTextures.size / MGA_NR_TEX_REGIONS );
+   if ( i < MGA_LOG_MIN_TEX_REGION_SIZE )
+      i = MGA_LOG_MIN_TEX_REGION_SIZE;
+
+   pMGADRI->logAgpTextureGranularity = i;
+   pMGADRI->agpTextureOffset = (unsigned int)pMGADRIServer->agpTextures.handle;
+   pMGADRI->agpTextureSize = (unsigned int)pMGADRIServer->agpTextures.size;
+
    pMGADRI->registers.handle   = pMGADRIServer->registers.handle;
    pMGADRI->registers.size     = pMGADRIServer->registers.size;
    pMGADRI->status.handle      = pMGADRIServer->status.handle;
@@ -1231,6 +1274,11 @@
    if ( pMGADRIServer->warp.map ) {
       drmUnmap( pMGADRIServer->warp.map, pMGADRIServer->warp.size );
       pMGADRIServer->warp.map = NULL;
+   }
+
+   if ( pMGADRIServer->agpTextures.map ) {
+      drmUnmap( pMGADRIServer->agpTextures.map, pMGADRIServer->agpTextures.size );
+      pMGADRIServer->agpTextures.map = NULL;
    }
 
    if ( pMGADRIServer->agp.handle ) {
diff -ru xc2/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_driver.c 
xc/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_driver.c
--- xc2/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_driver.c Wed Aug 22 18:24:50 
2001
+++ xc/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_driver.c  Thu Oct 25 15:05:35 
+2001
@@ -211,6 +211,7 @@
     OPTION_CRTC2RAM,
     OPTION_INT10,
     OPTION_AGP_MODE,
+    OPTION_AGP_SIZE,
     OPTION_DIGITAL,
     OPTION_TV,
     OPTION_TVSTANDARD,
@@ -242,6 +243,7 @@
     { OPTION_CRTC2RAM,         "Crtc2Ram",     OPTV_INTEGER,   {0}, FALSE },
     { OPTION_INT10,            "Int10",        OPTV_BOOLEAN,   {0}, FALSE },
     { OPTION_AGP_MODE,         "AGPMode",      OPTV_INTEGER,   {0}, FALSE },
+    { OPTION_AGP_SIZE,          "AGPSize",      OPTV_INTEGER,   {0}, FALSE },
     { OPTION_DIGITAL,          "DigitalScreen",OPTV_BOOLEAN,   {0}, FALSE },
     { OPTION_TV,               "TV",           OPTV_BOOLEAN,   {0}, FALSE },
     { OPTION_TVSTANDARD,       "TVStandard",   OPTV_ANYSTR,    {0}, FALSE },
@@ -1499,6 +1501,12 @@
          pMga->agpMode = MGA_MAX_AGP_MODE;
        }
        from = X_CONFIG;
+    }
+    if (xf86GetOptValInteger(pMga->Options,
+                             OPTION_AGP_SIZE, &(pMga->agpSize))) {
+                             /* check later */
+       xf86DrvMsg(pScrn->scrnIndex, from, "Using %d MB of AGP memory\n",
+                 pMga->agpSize);
     }
 
     xf86DrvMsg(pScrn->scrnIndex, from, "Using AGP %dx mode\n",

Reply via email to