Had some odd problems with add and temps so doing it with mad. Adding some MAD_2...
[mesa.git] / src / mesa / drivers / dri / r300 / r300_texstate.c
index 76be5c649aaf547493d9bdf622edda0fac0f83cd..ccdf2a49b9531bcb2e35c3ae460ad59dad43db3e 100644 (file)
@@ -68,12 +68,15 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define _INVALID(f) \
     [ MESA_FORMAT_ ## f ] = { 0xffffffff, 0 }
 #define VALID_FORMAT(f) ( ((f) <= MESA_FORMAT_YCBCR_REV) \
-                            && (tx_table[f].format != 0xffffffff) )
+                            && tx_table[f].flag )
+
+#define _ASSIGN(entry, format) \
+       [ MESA_FORMAT_ ## entry ] = { format, 0, 1}
 
 static const struct {
        GLuint format, filter;
 } tx_table0[] = {
-_ALPHA(RGBA8888),
+           _ALPHA(RGBA8888),
            _ALPHA_REV(RGBA8888),
            _ALPHA(ARGB8888),
            _ALPHA_REV(ARGB8888),
@@ -88,36 +91,50 @@ _ALPHA(RGBA8888),
            _ALPHA_REV(AL88),
            _ALPHA(A8),
            _COLOR(L8),
-           _ALPHA(I8), _INVALID(CI8), _YUV(YCBCR), _YUV(YCBCR_REV),};
+           _ALPHA(I8),
+           _INVALID(CI8),
+           _YUV(YCBCR),
+           _YUV(YCBCR_REV),
+           };
 
 static const struct {
-       GLuint format, filter;
+       GLuint format, filter, flag;
 } tx_table[] = {
-           {R300_EASY_TX_FORMAT(Y, Z, W, X, W8Z8Y8X8), 0},
-           {1, 0},
-           {2, 0},
-           {3, 0},
-           {4, 0},
-           {5, 0},
-           {6, 0},
-           {7, 0},
-           {8, 0},
-           {9, 0},
-           {10, 0},
-           {11, 0},
-           {12, 0},
-           {13, 0},
-           {14, 0},
-           {15,  0},
-           {16,  0},
-           {17, 0},
+       /*
+        * Note that the _REV formats are the same as the non-REV formats.
+        * This is because the REV and non-REV formats are identical as a
+        * byte string, but differ when accessed as 16-bit or 32-bit words
+        * depending on the endianness of the host.  Since the textures are
+        * transferred to the R300 as a byte string (i.e. without any
+        * byte-swapping), the R300 sees the REV and non-REV formats
+        * identically.  -- paulus
+        */
+           _ASSIGN(RGBA8888, R300_EASY_TX_FORMAT(Y, Z, W, X, W8Z8Y8X8)),
+           _ASSIGN(RGBA8888_REV, R300_EASY_TX_FORMAT(Y, Z, W, X, W8Z8Y8X8)),
+           _ASSIGN(ARGB8888, R300_EASY_TX_FORMAT(X, Y, Z, W, W8Z8Y8X8)),
+           _ASSIGN(ARGB8888_REV, R300_EASY_TX_FORMAT(X, Y, Z, W, W8Z8Y8X8)),
+           _ASSIGN(RGB888, 0xffffffff),
+           _ASSIGN(RGB565, R300_EASY_TX_FORMAT(X, Y, Z, ONE, Z5Y6X5)),
+           _ASSIGN(RGB565_REV, R300_EASY_TX_FORMAT(X, Y, Z, ONE, Z5Y6X5)),
+           _ASSIGN(ARGB4444, R300_EASY_TX_FORMAT(X, Y, Z, W, W4Z4Y4X4)),
+           _ASSIGN(ARGB4444_REV, R300_EASY_TX_FORMAT(X, Y, Z, W, W4Z4Y4X4)),
+           _ASSIGN(ARGB1555, R300_EASY_TX_FORMAT(Z, Y, X, W, W1Z5Y5X5)),
+           _ASSIGN(ARGB1555_REV, R300_EASY_TX_FORMAT(Z, Y, X, W, W1Z5Y5X5)),
+           _ASSIGN(AL88, R300_EASY_TX_FORMAT(Y, Y, Y, X, Y8X8)),
+           _ASSIGN(AL88_REV, R300_EASY_TX_FORMAT(Y, Y, Y, X, Y8X8)),
+           _ASSIGN(RGB332, R300_EASY_TX_FORMAT(X, Y, Z, ONE, Z3Y3X2)),
+           _ASSIGN(A8, R300_EASY_TX_FORMAT(ZERO, ZERO, ZERO, X, X8)),
+           _ASSIGN(L8, R300_EASY_TX_FORMAT(X, X, X, ONE, X8)),
+           _ASSIGN(I8, R300_EASY_TX_FORMAT(X, X, X, X, X8)),
+           _ASSIGN(CI8, R300_EASY_TX_FORMAT(X, X, X, X, X8)),
+           _ASSIGN(YCBCR, R300_EASY_TX_FORMAT(X, Y, Z, ONE, G8R8_G8B8)|R300_TX_FORMAT_YUV_MODE ),
+           _ASSIGN(YCBCR_REV, R300_EASY_TX_FORMAT(X, Y, Z, ONE, G8R8_G8B8)|R300_TX_FORMAT_YUV_MODE),
            };
 
-
 #undef _COLOR
 #undef _ALPHA
 #undef _INVALID
-
+#undef _ASSIGN
 
 
 /**
@@ -147,7 +164,7 @@ static void r300SetTexImages(r300ContextPtr rmesa,
 
        t->format &= ~(R200_TXFORMAT_FORMAT_MASK |
                            R200_TXFORMAT_ALPHA_IN_MAP);
-#if 0  
+#if 0
        t->filter &= ~R200_YUV_TO_RGB;
 #endif
        if (VALID_FORMAT(baseImage->TexFormat->MesaFormat)) {
@@ -156,7 +173,7 @@ static void r300SetTexImages(r300ContextPtr rmesa,
 #if 1
                t->filter |=
                    tx_table[baseImage->TexFormat->MesaFormat].filter;
-#endif         
+#endif
        } else {
                _mesa_problem(NULL, "unexpected texture format in %s",
                              __FUNCTION__);
@@ -275,7 +292,7 @@ static void r300SetTexImages(r300ContextPtr rmesa,
        t->filter &= ~R200_MAX_MIP_LEVEL_MASK;
        t->filter |= (numLevels - 1) << R200_MAX_MIP_LEVEL_SHIFT;
 #endif
-       #if 0
+#if 0
        t->format &= ~(R200_TXFORMAT_WIDTH_MASK |
                            R200_TXFORMAT_HEIGHT_MASK |
                            R200_TXFORMAT_CUBIC_MAP_ENABLE |
@@ -283,8 +300,8 @@ static void r300SetTexImages(r300ContextPtr rmesa,
                            R200_TXFORMAT_F5_HEIGHT_MASK);
        t->format |= ((log2Width << R200_TXFORMAT_WIDTH_SHIFT) |
                           (log2Height << R200_TXFORMAT_HEIGHT_SHIFT));
-       #endif
-                          
+#endif
+
        t->format_x &= ~(R200_DEPTH_LOG2_MASK | R200_TEXCOORD_MASK);
        if (tObj->Target == GL_TEXTURE_3D) {
                t->format_x |= (log2Depth << R200_DEPTH_LOG2_SHIFT);
@@ -304,7 +321,7 @@ static void r300SetTexImages(r300ContextPtr rmesa,
                                     (log2Width << R200_FACE_WIDTH_4_SHIFT) |
                                     (log2Height << R200_FACE_HEIGHT_4_SHIFT));
        }
-       
+
        t->size = (((tObj->Image[0][t->base.firstLevel]->Width - 1) << R300_TX_WIDTHMASK_SHIFT)
                        |((tObj->Image[0][t->base.firstLevel]->Height - 1) << R300_TX_HEIGHTMASK_SHIFT)
                        |((log2Width>log2Height)?log2Width:log2Height)<<R300_TX_SIZE_SHIFT);
@@ -463,16 +480,16 @@ static GLboolean r300UpdateTextureEnv(GLcontext * ctx, int unit)
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
        const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
        GLuint color_combine, alpha_combine;
-       
-       #if 0 /* disable for now.. */
+
+#if 0 /* disable for now.. */
        GLuint color_scale = rmesa->hw.pix[unit].cmd[PIX_PP_TXCBLEND2] &
            ~(R200_TXC_SCALE_MASK);
        GLuint alpha_scale = rmesa->hw.pix[unit].cmd[PIX_PP_TXABLEND2] &
            ~(R200_TXA_DOT_ALPHA | R200_TXA_SCALE_MASK);
-       #endif
-       
+#endif
+
        GLuint color_scale=0, alpha_scale=0;
-           
+
        /* texUnit->_Current can be NULL if and only if the texture unit is
         * not actually enabled.
         */
@@ -492,12 +509,12 @@ static GLboolean r300UpdateTextureEnv(GLcontext * ctx, int unit)
         */
        /* Don't cache these results.
         */
-       #if 0
+#if 0
        rmesa->state.texture.unit[unit].format = 0;
-       #endif
+#endif
        rmesa->state.texture.unit[unit].envMode = 0;
 
-       
+
        if (!texUnit->_ReallyEnabled) {
                if (unit == 0) {
                        color_combine =
@@ -768,12 +785,12 @@ static GLboolean r300UpdateTextureEnv(GLcontext * ctx, int unit)
                 */
        }
 
-       #if 0
-       fprintf(stderr, "color_combine=%08x alpha_combine=%08x color_scale=%08x alpha_scale=%08x\n", 
+#if 0
+       fprintf(stderr, "color_combine=%08x alpha_combine=%08x color_scale=%08x alpha_scale=%08x\n",
                color_combine, alpha_combine, color_scale, alpha_scale);
-       #endif
-       
-       #if 0
+#endif
+
+#if 0
        if (rmesa->hw.pix[unit].cmd[PIX_PP_TXCBLEND] != color_combine ||
            rmesa->hw.pix[unit].cmd[PIX_PP_TXABLEND] != alpha_combine ||
            rmesa->hw.pix[unit].cmd[PIX_PP_TXCBLEND2] != color_scale ||
@@ -785,8 +802,8 @@ static GLboolean r300UpdateTextureEnv(GLcontext * ctx, int unit)
                rmesa->hw.pix[unit].cmd[PIX_PP_TXABLEND2] = alpha_scale;
        }
 
-       #endif
-       
+#endif
+
        return GL_TRUE;
 }
 
@@ -817,7 +834,7 @@ static GLboolean r300UpdateTextureEnv(GLcontext * ctx, int unit)
 static void import_tex_obj_state(r300ContextPtr rmesa,
                                 int unit, r300TexObjPtr texobj)
 {
-       #if 0 /* needs fixing.. or should be done elsewhere */
+#if 0 /* needs fixing.. or should be done elsewhere */
        GLuint *cmd = R300_DB_STATE(tex[unit]);
 
        cmd[TEX_PP_TXFILTER] &= ~TEXOBJ_TXFILTER_MASK;
@@ -852,7 +869,7 @@ static void import_tex_obj_state(r300ContextPtr rmesa,
        }
 
        texobj->dirty_state &= ~(1 << unit);
-       #endif
+#endif
 }
 
 static void set_texgen_matrix(r300ContextPtr rmesa,
@@ -1020,7 +1037,7 @@ static void disable_tex(GLcontext * ctx, int unit)
 {
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
 
-       #if 0 /* This needs to be redone.. or done elsewhere */
+#if 0 /* This needs to be redone.. or done elsewhere */
        if (rmesa->hw.ctx.cmd[CTX_PP_CNTL] & (R200_TEX_0_ENABLE << unit)) {
                /* Texture unit disabled */
                if (rmesa->state.texture.unit[unit].texobj != NULL) {
@@ -1076,7 +1093,7 @@ static void disable_tex(GLcontext * ctx, int unit)
                        }
                }
        }
-       #endif
+#endif
 }
 
 static GLboolean enable_tex_2d(GLcontext * ctx, int unit)
@@ -1088,10 +1105,12 @@ static GLboolean enable_tex_2d(GLcontext * ctx, int unit)
 
        /* Need to load the 2d images associated with this unit.
         */
+       #if 0
        if (t->format & R200_TXFORMAT_NON_POWER2) {
                t->format &= ~R200_TXFORMAT_NON_POWER2;
                t->base.dirty_images[0] = ~0;
        }
+       #endif
 
        ASSERT(tObj->Target == GL_TEXTURE_2D || tObj->Target == GL_TEXTURE_1D);
 
@@ -1192,10 +1211,12 @@ static GLboolean enable_tex_rect(GLcontext * ctx, int unit)
        struct gl_texture_object *tObj = texUnit->_Current;
        r300TexObjPtr t = (r300TexObjPtr) tObj->DriverData;
 
+       #if 0
        if (!(t->format & R200_TXFORMAT_NON_POWER2)) {
                t->format |= R200_TXFORMAT_NON_POWER2;
                t->base.dirty_images[0] = ~0;
        }
+       #endif
 
        ASSERT(tObj->Target == GL_TEXTURE_RECTANGLE_NV);
 
@@ -1241,7 +1262,7 @@ static GLboolean update_tex_common(GLcontext * ctx, int unit)
                driUpdateTextureLRU((driTextureObject *) t);    /* XXX: should be locked! */
        }
 
-       #if 0 /* do elsewhere ? */
+#if 0 /* do elsewhere ? */
        /* Newly enabled?
         */
        if (1
@@ -1269,7 +1290,7 @@ static GLboolean update_tex_common(GLcontext * ctx, int unit)
                rmesa->recheck_texgen[unit] = 0;
                rmesa->NewGLState |= _NEW_TEXTURE_MATRIX;
        }
-       #endif
+#endif
 
        format = tObj->Image[0][tObj->BaseLevel]->Format;
        if (rmesa->state.texture.unit[unit].format != format ||
@@ -1280,7 +1301,7 @@ static GLboolean update_tex_common(GLcontext * ctx, int unit)
                        return GL_FALSE;
                }
        }
-       
+
        FALLBACK(&rmesa->radeon, RADEON_FALLBACK_BORDER_MODE, t->border_fallback);
        return !t->border_fallback;
 }
@@ -1324,20 +1345,20 @@ void r300UpdateTextureState(GLcontext * ctx)
              r300UpdateTextureUnit(ctx, 1) &&
              r300UpdateTextureUnit(ctx, 2) &&
              r300UpdateTextureUnit(ctx, 3) &&
-             r300UpdateTextureUnit(ctx, 4) && 
+             r300UpdateTextureUnit(ctx, 4) &&
              r300UpdateTextureUnit(ctx, 5) &&
-             r300UpdateTextureUnit(ctx, 6) && 
+             r300UpdateTextureUnit(ctx, 6) &&
              r300UpdateTextureUnit(ctx, 7)
              );
 
        FALLBACK(&rmesa->radeon, RADEON_FALLBACK_TEXTURE, !ok);
 
-       /* This needs correction, or just be done elsewhere 
+       /* This needs correction, or just be done elsewhere
        if (rmesa->radeon.TclFallback)
                r300ChooseVertexState(ctx);
        */
-               
-       #if 0 /* Workaround - disable.. */
+
+#if 0 /* Workaround - disable.. */
        if (GET_CHIP(rmesa->radeon.radeonScreen) == RADEON_CHIP_REAL_R200) {
                /*
                 * T0 hang workaround -------------
@@ -1435,5 +1456,5 @@ void r300UpdateTextureState(GLcontext * ctx)
                                       dbg);
                }
        }
-       #endif
+#endif
 }