Hi,

I tracked down the Savage4 texture corruption problem last night. A
patch is attached, but it'll break ProSavages. A real solution will have
to wait at least until the 3D driver can determine the chipset. The
whole texture upload code is terribly inefficient the way it implements
tiling and sub-tiling of texture memory right now. I'm going to rewrite
that sometime.

Regards,
  Felix
Index: savagetex.c
===================================================================
RCS file: /cvs/dri/xc/xc/lib/GL/mesa/src/drv/savage/Attic/savagetex.c,v
retrieving revision 1.1.4.2
diff -u -r1.1.4.2 savagetex.c
--- savagetex.c 8 Feb 2004 15:18:42 -0000       1.1.4.2
+++ savagetex.c 9 Feb 2004 14:55:06 -0000
@@ -88,8 +88,8 @@
                                               GLint y )
 {
     GLint  x106;
-    GLint  x20;
-    GLint  x53;
+    GLint  x10;
+    GLint  x52;
     GLint  y104;
     GLint  y20;
     GLint  y3;
@@ -101,17 +101,17 @@
 
     uiWidthInTiles = (iBufferWidth + 63) >> 6;
 
-    x20  =  x & 0x7;
-    x53  = (x & 0x38 ) >> 3;
+    x10  =  x & 0x3;
+    x52  = (x & 0x3c ) >> 2;
     x106 = (x & 0x7c0) >> 6;
 
     y20  =  y & 0x7;
     y3   = (y & 8    ) >> 3;
     y104 = (y & 0x7f0) >> 4;
 
-    return( (x20 << 1)  |
-            (y20 << 4)  |
-            (x53 << 7)  |
+    return( (x10 << 1)  |
+            (y20 << 3)  |
+            (x52 << 6)  |
             (y3  << 10) |
             ((y104 * uiWidthInTiles) + x106) << 11 );
 }
@@ -120,10 +120,10 @@
                                               GLint x,
                                               GLint y )
 {
-    GLint  x20;
+    GLint  x10;
     GLint  y20;
     GLuint uiWidthInTiles;
-    GLint  x43;
+    GLint  x42;
     GLint  x105;
     GLint  y3;
     GLint  y104;
@@ -134,17 +134,17 @@
 
     uiWidthInTiles = (iBufferWidth + 31) >> 5;
 
-    x20  =  x & 0x7;
-    x43  = (x & 0x18 ) >> 3;
+    x10  =  x & 0x3;
+    x42  = (x & 0x1c ) >> 2;
     x105 = (x & 0x7e0) >> 5;
 
     y20  =  y & 0x7;
     y3   = (y & 8    ) >> 3;
     y104 = (y & 0x7f0) >> 4;
 
-    return( (x20 << 2)  |
-            (y20 << 5)  |
-            (x43 << 8)  |
+    return( (x10 << 2)  |
+            (y20 << 4)  |
+            (x42 << 7)  |
             (y3  << 10) |
             ((y104 * uiWidthInTiles) + x105) << 11 );
 }
@@ -154,6 +154,32 @@
                                             GLint x,
                                             GLint y )
 {
+#if 0
+    /* Generic version for easier debugging and for understanding this
+     * tiling and sub-tiling horror */
+    unsigned tileWidth = gTileWidth[iDepth >> 3];
+    unsigned tileHeight = gTileHeight[iDepth >> 3];
+    unsigned subWidth = 4; /* Up to Savage4 this is 4, on ProSavages it's 8 */
+    unsigned subHeight = 8;
+    unsigned widthInTiles = (iBufferWidth + tileWidth - 1) / tileWidth;
+    unsigned tileWidthInSub = (tileWidth + subWidth - 1) / subWidth;
+    unsigned tileHeightInSub = (tileHeight + subHeight - 1) / subHeight;
+    unsigned xTile = x / tileWidth;
+    unsigned yTile = y / tileHeight;
+    unsigned xInTile = x % tileWidth;
+    unsigned yInTile = y % tileHeight;
+    unsigned xSub = xInTile / subWidth;
+    unsigned ySub = yInTile / subHeight;
+    unsigned xInSub = xInTile % subWidth;
+    unsigned yInSub = yInTile % subHeight;
+    unsigned tileAddr = yTile * widthInTiles + xTile;
+    unsigned subAddr = tileAddr * tileWidthInSub * tileHeightInSub +
+       ySub * tileWidthInSub + xSub;
+    unsigned pixAddr = subAddr * subWidth * subHeight +
+       yInSub * subWidth + xInSub;
+    return pixAddr * (iDepth>>3);
+#endif
+
     /*
     // don't check for 4 since we only have 3 types of fb
     */

Reply via email to