[ I originally sent this to [EMAIL PROTECTED], but it's really
  more of a driver topic than a RENDER topic, probably this is
  a better place; I apologize for the duplication. ]

====

Testing out my rendering code, I noticed that I wasn't getting the
speedups I expected with HW compositing on the MGA. Looking into this,
I discoved that MGASetupForCPUToScreenTexture() copied the entire
source drawable into video memory every time. Since the way that GTK+
works is to use a different bit of one large source drawable for every
operation, this causing just a bit of a slowdown.

Here's a patch that fixes this problem by simply allocating the
scratch area in MGASetupForCPUToScreenTexture() and then doing the
copies in MGASubsequentCPUToScreenTexture().

Since this is not an area that I'm very familiar with, I'd appreciate
if someone would look this over - in particular, the way I'm passing
a bunch of parameters from MGASetupForCPUToScreen*Texture() to
MGASubsequentCPUToScreenTexture() using a bunch of static variables
seems ugly, but that was how it was done for tex_padh/padw so I
copied that.

The other reason I have some trepidation about this patch is that
things are not really working for me correctly now - the general
symptom is that the alpha channel is correct but everything appears as
black. (But the right data seems to be fed to the card.) I had this
symptom with XFree86-4.1, upgraded to 4.2, seemed to go away, made my
patch, seemed to work fine, then at some point it stopped working
so it possibly is some sort of unitialized register problem. 

Regards,
                                        Owen

? Makefile
? mga.4.html
? mga._man
Index: mga_storm.c
===================================================================
RCS file: /cvs/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_storm.c,v
retrieving revision 1.96
diff -u -p -r1.96 mga_storm.c
--- mga_storm.c	2001/12/06 15:54:52	1.96
+++ mga_storm.c	2002/01/08 03:05:40
@@ -282,6 +282,10 @@ GetPowerOfTwo(int w)
 
 
 static int tex_padw, tex_padh;
+static CARD8 *tex_mem;
+static int tex_mem_pitch;
+static int tex_scratch_pitch;
+static int tex_bytes_per_pixel;
 
 Bool
 MGASetupForCPUToScreenAlphaTextureFaked (
@@ -379,7 +383,6 @@ MGASetupForCPUToScreenAlphaTexture (
    int		flags
 ){
     int log2w, log2h, i, pitch, sizeNeeded, offset;
-    CARD8 *dst;
     MGAPtr pMga = MGAPTR(pScrn);
 
     if(op != PictOpOver)  /* only one tested */
@@ -415,13 +418,12 @@ MGASetupForCPUToScreenAlphaTexture (
 	MGAStormSync(pScrn);
 
     i = height;
-    dst = pMga->FbStart + offset;
-    while(i--) {
-	memcpy(dst, alphaPtr, width);
-	dst += pitch;
-	alphaPtr += alphaPitch;
-    }
-
+    
+    tex_mem = alphaPtr;
+    tex_mem_pitch = alphaPitch;
+    tex_scratch_pitch = pitch;
+    tex_bytes_per_pixel = 1;
+    
     tex_padw = 1 << log2w;
     tex_padh = 1 << log2h;
 
@@ -502,6 +504,11 @@ MGASetupForCPUToScreenTexture (
     if(!AllocateLinear(pScrn, sizeNeeded))
 	return FALSE;
 
+    tex_mem = texPtr;
+    tex_mem_pitch = texPitch;
+    tex_scratch_pitch = pitch << 2;
+    tex_bytes_per_pixel = 4;
+    
     offset = pMga->LinearScratch->offset << 1;
     if(pScrn->bitsPerPixel == 32)
         offset <<= 1;
@@ -509,16 +516,6 @@ MGASetupForCPUToScreenTexture (
     if(pMga->AccelInfoRec->NeedToSync)
 	MGAStormSync(pScrn);
 
-    {
-	CARD8 *dst = (CARD8*)(pMga->FbStart + offset);
-	i = height;
-	while(i--) {
-            memcpy(dst, texPtr, width << 2);
-	    texPtr += texPitch;
-	    dst += pitch << 2;
-	}
-    }
-
     tex_padw = 1 << log2w;
     tex_padh = 1 << log2h;
 
@@ -553,7 +550,22 @@ MGASubsequentCPUToScreenTexture (
     int		width,
     int		height
 ){
+    int i, offset;
     MGAPtr pMga = MGAPTR(pScrn);
+    CARD8 *texPtr = tex_mem + srcy * tex_mem_pitch + (srcx << 2);
+    CARD8 *dst;
+
+    offset = pMga->LinearScratch->offset << 1;
+    if(pScrn->bitsPerPixel == 32)
+        offset <<= 1;
+
+    dst = (CARD8*)(pMga->FbStart + offset) + srcy * tex_scratch_pitch + (srcx << 2);
+    i = height;
+    while(i--) {
+        memcpy(dst, texPtr, width * tex_bytes_per_pixel);
+        texPtr += tex_mem_pitch;
+        dst += tex_scratch_pitch;
+    }
 
     WAITFIFO(4);
     OUTREG(MGAREG_TMR6, (srcx << 20) / tex_padw);

Reply via email to