Keith Whitwell wrote:
> Ralf, I haven't been able to test your patch, but it sounds like it works
> well for those who've tried it. If you clean it up to include just the agp
> texture stuff, I can commit it...
>
> Keith
>
lets hope it works for everyone then :)
--
ralf willenbacher ([EMAIL PROTECTED])
diff -ur 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 -ur 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 Thu Oct 25 15:05:35 2001
@@ -377,7 +378,8 @@
/* Fill in the secondary buffer with properly converted texels
* from the mesa buffer. */
- if(t->heap == MGA_CARD_HEAP) {
+ /* no idea how to sync the one below */
+ if(t->heap == MGA_CARD_HEAP || t->heap == MGA_AGP_HEAP) {
mgaGetILoadBufferLocked( mmesa );
mgaConvertTexture( (GLuint *)mmesa->iload_buffer->address,
texelBytes, image, x, y, width, height );
@@ -434,7 +436,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 -ur 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 -ur 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 -ur 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",
diff -ur xc2/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_dma.c
xc/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_dma.c
--- xc2/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_dma.c Tue
Aug 7 18:15:09 2001
+++ xc/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_dma.c Thu
+Oct 25 19:03:56 2001
@@ -481,8 +481,6 @@
dev_priv->depth_offset = init->depth_offset;
dev_priv->depth_pitch = init->depth_pitch;
- /* FIXME: Need to support AGP textures...
- */
dev_priv->texture_offset = init->texture_offset[0];
dev_priv->texture_size = init->texture_size[0];
@@ -551,6 +549,12 @@
dev->dev_private = (void *)dev_priv;
mga_do_cleanup_dma( dev );
return -EINVAL;
+ }
+
+
+ DRM_FIND_MAP(dev_priv->agp_textures, init->texture_offset[1]);
+ if(!dev_priv->agp_textures) {
+ /* either its an old X server or its broken; iload will figure it out... */
}
dev_priv->sarea_priv =
diff -ur xc2/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_state.c
xc/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_state.c
--- xc2/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_state.c Mon
Jun 18 19:25:15 2001
+++ xc/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_state.c Thu
+Oct 25 18:50:17 2001
@@ -470,9 +470,14 @@
static int mga_verify_iload( drm_mga_private_t *dev_priv,
unsigned int dstorg, unsigned int length )
{
- if ( dstorg < dev_priv->texture_offset ||
+ if ( (dstorg < dev_priv->texture_offset ||
dstorg + length > (dev_priv->texture_offset +
- dev_priv->texture_size) ) {
+ dev_priv->texture_size) ) &&
+ (
+ !dev_priv->agp_textures || ( /* check if agp textures are there at
+all.. */
+ dstorg < dev_priv->agp_textures->offset ||
+ dstorg + length > (dev_priv->agp_textures->offset +
+ dev_priv->agp_textures->size)))) {
DRM_ERROR( "*** bad iload DSTORG: 0x%x\n", dstorg );
return -EINVAL;
}