radeon: go back and repick texture formats.
authorDave Airlie <airlied@redhat.com>
Wed, 1 Apr 2009 06:13:30 +0000 (16:13 +1000)
committerDave Airlie <airlied@redhat.com>
Wed, 1 Apr 2009 06:13:30 +0000 (16:13 +1000)
This might trip up some serious FBO users, will have to see, but
it avoids the slow paths for all the demos I have.

src/mesa/drivers/dri/r200/r200_tex.c
src/mesa/drivers/dri/r200/r200_texstate.c
src/mesa/drivers/dri/r300/r300_tex.c
src/mesa/drivers/dri/r300/r300_texstate.c
src/mesa/drivers/dri/radeon/radeon_fbo.c
src/mesa/drivers/dri/radeon/radeon_tex.c
src/mesa/drivers/dri/radeon/radeon_texstate.c
src/mesa/drivers/dri/radeon/radeon_texture.c
src/mesa/drivers/dri/radeon/radeon_texture.h

index 19a6cad80bd4f239344c1a1a0365281069d22ca9..fc2caabb5acc0b20381db56d3c6893b87a4274b9 100644 (file)
@@ -493,7 +493,7 @@ void r200InitTextureFuncs( struct dd_function_table *functions )
    /* Note: we only plug in the functions we implement in the driver
     * since _mesa_init_driver_functions() was already called.
     */
-   functions->ChooseTextureFormat      = radeonChooseTextureFormat;
+   functions->ChooseTextureFormat      = radeonChooseTextureFormat_mesa;
    functions->TexImage1D               = radeonTexImage1D;
    functions->TexImage2D               = radeonTexImage2D;
 #if ENABLE_HW_3D_TEXTURE
index 72b7f3dafa2c771e7772ecbda487322d4ab0ceb5..9797f77ec4f2bf40230b0d499c1b5ad44e5f072d 100644 (file)
@@ -839,7 +839,7 @@ void r200SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint glx_texture_fo
        texImage->RowStride = rb->pitch / rb->cpp;
        texImage->TexFormat = radeonChooseTextureFormat(radeon->glCtx,
                                                        internalFormat,
-                                                       type, format);
+                                                       type, format, 0);
        rImage->bo = rb->bo;
        radeon_bo_ref(rImage->bo);
        t->bo = rb->bo;
index 0f5afbfa298afe6ecc6ae3e79435565818d66692..0cbb2bcf3f17ef554510d85b7daa42bd873cf04c 100644 (file)
@@ -323,7 +323,7 @@ void r300InitTextureFuncs(struct dd_function_table *functions)
        functions->MapTexture = radeonMapTexture;
        functions->UnmapTexture = radeonUnmapTexture;
 
-       functions->ChooseTextureFormat = radeonChooseTextureFormat;
+       functions->ChooseTextureFormat = radeonChooseTextureFormat_mesa;
        functions->TexImage1D = radeonTexImage1D;
        functions->TexImage2D = radeonTexImage2D;
        functions->TexImage3D = radeonTexImage3D;
index 0c6d092df360ea142837bcaf9f77edab7d596a30..baaca5f1e59605306a733b63f0b824d48444a109 100644 (file)
@@ -457,7 +457,7 @@ void r300SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint glx_texture_fo
        texImage->RowStride = rb->pitch / rb->cpp;
        texImage->TexFormat = radeonChooseTextureFormat(radeon->glCtx,
                                                        internalFormat,
-                                                       type, format);
+                                                       type, format, 0);
        rImage->bo = rb->bo;
        radeon_bo_ref(rImage->bo);
        t->bo = rb->bo;
index d17835bb12c30eba246a16d699eb3ae7f20fbc89..f62ca7f9eb397dc5eaed6e520064358d1d59db78 100644 (file)
@@ -382,54 +382,65 @@ static GLboolean
 radeon_update_wrapper(GLcontext *ctx, struct radeon_renderbuffer *rrb, 
                     struct gl_texture_image *texImage)
 {
-   if (texImage->TexFormat == &_mesa_texformat_argb8888) {
-      rrb->cpp = 4;
-      rrb->base._ActualFormat = GL_RGBA8;
-      rrb->base._BaseFormat = GL_RGBA;
-      rrb->base.DataType = GL_UNSIGNED_BYTE;
-      DBG("Render to RGBA8 texture OK\n");
-   }
-   else if (texImage->TexFormat == &_mesa_texformat_rgb565) {
-      rrb->cpp = 2;
-      rrb->base._ActualFormat = GL_RGB5;
-      rrb->base._BaseFormat = GL_RGB;
-      rrb->base.DataType = GL_UNSIGNED_SHORT;
-      DBG("Render to RGB5 texture OK\n");
-   }
-   else if (texImage->TexFormat == &_mesa_texformat_z16) {
-      rrb->cpp = 2;
-      rrb->base._ActualFormat = GL_DEPTH_COMPONENT16;
-      rrb->base._BaseFormat = GL_DEPTH_COMPONENT;
-      rrb->base.DataType = GL_UNSIGNED_SHORT;
-      DBG("Render to DEPTH16 texture OK\n");
-   }
-   else if (texImage->TexFormat == &_mesa_texformat_s8_z24) {
-      rrb->cpp = 4;
-      rrb->base._ActualFormat = GL_DEPTH24_STENCIL8_EXT;
-      rrb->base._BaseFormat = GL_DEPTH_STENCIL_EXT;
-      rrb->base.DataType = GL_UNSIGNED_INT_24_8_EXT;
-      DBG("Render to DEPTH_STENCIL texture OK\n");
-   }
-   else {
-      DBG("Render to texture BAD FORMAT %d\n",
-         texImage->TexFormat->MesaFormat);
-      return GL_FALSE;
-   }
-
-   rrb->pitch = texImage->Width * rrb->cpp;
-   rrb->base.InternalFormat = rrb->base._ActualFormat;
-   rrb->base.Width = texImage->Width;
-   rrb->base.Height = texImage->Height;
-   rrb->base.RedBits = texImage->TexFormat->RedBits;
-   rrb->base.GreenBits = texImage->TexFormat->GreenBits;
-   rrb->base.BlueBits = texImage->TexFormat->BlueBits;
-   rrb->base.AlphaBits = texImage->TexFormat->AlphaBits;
-   rrb->base.DepthBits = texImage->TexFormat->DepthBits;
-
-   rrb->base.Delete = radeon_delete_renderbuffer;
-   rrb->base.AllocStorage = radeon_nop_alloc_storage;
-
-   return GL_TRUE;
+       int retry = 0;
+restart:
+       if (texImage->TexFormat == &_mesa_texformat_argb8888) {
+               rrb->cpp = 4;
+               rrb->base._ActualFormat = GL_RGBA8;
+               rrb->base._BaseFormat = GL_RGBA;
+               rrb->base.DataType = GL_UNSIGNED_BYTE;
+               DBG("Render to RGBA8 texture OK\n");
+       }
+       else if (texImage->TexFormat == &_mesa_texformat_rgb565) {
+               rrb->cpp = 2;
+               rrb->base._ActualFormat = GL_RGB5;
+               rrb->base._BaseFormat = GL_RGB;
+               rrb->base.DataType = GL_UNSIGNED_SHORT;
+               DBG("Render to RGB5 texture OK\n");
+       }
+       else if (texImage->TexFormat == &_mesa_texformat_z16) {
+               rrb->cpp = 2;
+               rrb->base._ActualFormat = GL_DEPTH_COMPONENT16;
+               rrb->base._BaseFormat = GL_DEPTH_COMPONENT;
+               rrb->base.DataType = GL_UNSIGNED_SHORT;
+               DBG("Render to DEPTH16 texture OK\n");
+       }
+       else if (texImage->TexFormat == &_mesa_texformat_s8_z24) {
+               rrb->cpp = 4;
+               rrb->base._ActualFormat = GL_DEPTH24_STENCIL8_EXT;
+               rrb->base._BaseFormat = GL_DEPTH_STENCIL_EXT;
+               rrb->base.DataType = GL_UNSIGNED_INT_24_8_EXT;
+               DBG("Render to DEPTH_STENCIL texture OK\n");
+       }
+       else {
+               /* try redoing the FBO */
+               if (retry == 1) {
+                       DBG("Render to texture BAD FORMAT %d\n",
+                           texImage->TexFormat->MesaFormat);
+                       return GL_FALSE;
+               }
+               texImage->TexFormat = radeonChooseTextureFormat(ctx, texImage->InternalFormat, 0,
+                                                               texImage->TexFormat->DataType,
+                                                               1);
+
+               retry++;
+               goto restart;
+       }
+       
+       rrb->pitch = texImage->Width * rrb->cpp;
+       rrb->base.InternalFormat = rrb->base._ActualFormat;
+       rrb->base.Width = texImage->Width;
+       rrb->base.Height = texImage->Height;
+       rrb->base.RedBits = texImage->TexFormat->RedBits;
+       rrb->base.GreenBits = texImage->TexFormat->GreenBits;
+       rrb->base.BlueBits = texImage->TexFormat->BlueBits;
+       rrb->base.AlphaBits = texImage->TexFormat->AlphaBits;
+       rrb->base.DepthBits = texImage->TexFormat->DepthBits;
+       
+       rrb->base.Delete = radeon_delete_renderbuffer;
+       rrb->base.AllocStorage = radeon_nop_alloc_storage;
+       
+       return GL_TRUE;
 }
 
 
index 2dfb5042ecc23d5db5b69029b2f9c31290e3f725..21509c6e5e7adf2f86335b3857f6bfb23106adbe 100644 (file)
@@ -447,7 +447,7 @@ radeonNewTextureObject( GLcontext *ctx, GLuint name, GLenum target )
 
 void radeonInitTextureFuncs( struct dd_function_table *functions )
 {
-   functions->ChooseTextureFormat      = radeonChooseTextureFormat;
+   functions->ChooseTextureFormat      = radeonChooseTextureFormat_mesa;
    functions->TexImage1D               = radeonTexImage1D;
    functions->TexImage2D               = radeonTexImage2D;
    functions->TexSubImage1D            = radeonTexSubImage1D;
index dab0df0ff3bf17e836c8ea7628f516e483bbccfd..e4df33766eb763172b77011beb76f479fa9a2f90 100644 (file)
@@ -710,7 +710,7 @@ void radeonSetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint glx_texture_
        texImage->RowStride = rb->pitch / rb->cpp;
        texImage->TexFormat = radeonChooseTextureFormat(radeon->glCtx,
                                                        internalFormat,
-                                                       type, format);
+                                                       type, format, 0);
        rImage->bo = rb->bo;
        radeon_bo_ref(rImage->bo);
        t->bo = rb->bo;
index 21529f62fa5344b068553225ae3d441e60f4e322..35ed54243116fe512afb7017c0e679e939408312 100644 (file)
@@ -257,13 +257,13 @@ void radeonGenerateMipmap(GLcontext* ctx, GLenum target, struct gl_texture_objec
 /* try to find a format which will only need a memcopy */
 static const struct gl_texture_format *radeonChoose8888TexFormat(radeonContextPtr rmesa,
                                                                 GLenum srcFormat,
-                                                                GLenum srcType)
+                                                                GLenum srcType, GLboolean fbo)
 {
        const GLuint ui = 1;
        const GLubyte littleEndian = *((const GLubyte *)&ui);
 
        /* r100 can only do this */
-       if (IS_R100_CLASS(rmesa->radeonScreen))
+       if (IS_R100_CLASS(rmesa->radeonScreen) || fbo)
          return _dri_texformat_argb8888;
 
        if ((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8) ||
@@ -288,10 +288,19 @@ static const struct gl_texture_format *radeonChoose8888TexFormat(radeonContextPt
                return _dri_texformat_argb8888;
 }
 
-const struct gl_texture_format *radeonChooseTextureFormat(GLcontext * ctx,
+const struct gl_texture_format *radeonChooseTextureFormat_mesa(GLcontext * ctx,
                                                          GLint internalFormat,
                                                          GLenum format,
                                                          GLenum type)
+{
+       return radeonChooseTextureFormat(ctx, internalFormat, format,
+                                        type, 0);
+}
+
+const struct gl_texture_format *radeonChooseTextureFormat(GLcontext * ctx,
+                                                         GLint internalFormat,
+                                                         GLenum format,
+                                                         GLenum type, GLboolean fbo)
 {
        radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
        const GLboolean do32bpt =
@@ -323,7 +332,7 @@ const struct gl_texture_format *radeonChooseTextureFormat(GLcontext * ctx,
                case GL_UNSIGNED_SHORT_1_5_5_5_REV:
                        return _dri_texformat_argb1555;
                default:
-                       return do32bpt ? radeonChoose8888TexFormat(rmesa, format, type) :
+                       return do32bpt ? radeonChoose8888TexFormat(rmesa, format, type, fbo) :
                            _dri_texformat_argb4444;
                }
 
@@ -350,7 +359,7 @@ const struct gl_texture_format *radeonChooseTextureFormat(GLcontext * ctx,
        case GL_RGBA12:
        case GL_RGBA16:
                return !force16bpt ?
-                       radeonChoose8888TexFormat(rmesa, format,type) :
+                       radeonChoose8888TexFormat(rmesa, format, type, fbo) :
                        _dri_texformat_argb4444;
 
        case GL_RGBA4:
@@ -510,7 +519,7 @@ static void radeon_teximage(
        }
 
        /* Choose and fill in the texture format for this image */
-       texImage->TexFormat = radeonChooseTextureFormat(ctx, internalFormat, format, type);
+       texImage->TexFormat = radeonChooseTextureFormat(ctx, internalFormat, format, type, 0);
        _mesa_set_fetch_functions(texImage, dims);
 
        if (texImage->TexFormat->TexelBytes == 0) {
index d90fda7868fa03337509c020587c81eeecbc238f..888a55ba911309cbdba4c8386574c13a551f277f 100644 (file)
@@ -40,10 +40,14 @@ void radeonUnmapTexture(GLcontext *ctx, struct gl_texture_object *texObj);
 void radeonGenerateMipmap(GLcontext* ctx, GLenum target, struct gl_texture_object *texObj);
 int radeon_validate_texture_miptree(GLcontext * ctx, struct gl_texture_object *texObj);
 GLuint radeon_face_for_target(GLenum target);
-const struct gl_texture_format *radeonChooseTextureFormat(GLcontext * ctx,
+const struct gl_texture_format *radeonChooseTextureFormat_mesa(GLcontext * ctx,
                                                          GLint internalFormat,
                                                          GLenum format,
                                                          GLenum type);
+const struct gl_texture_format *radeonChooseTextureFormat(GLcontext * ctx,
+                                                         GLint internalFormat,
+                                                         GLenum format,
+                                                         GLenum type, GLboolean fbo);
 
 void radeonTexImage1D(GLcontext * ctx, GLenum target, GLint level,
                      GLint internalFormat,