mesa/drivers: use _mesa_get_format_bytes()
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_mipmap_tree.c
index 55aa4502dae01920c84635959437734e5c3984cf..11c21037c4494ea7db70705da972004946bc5f45 100644 (file)
@@ -90,16 +90,18 @@ static void compute_tex_image_offset(radeonContextPtr rmesa, radeon_mipmap_tree
        GLuint face, GLuint level, GLuint* curOffset)
 {
        radeon_mipmap_level *lvl = &mt->levels[level];
-       uint32_t row_align = rmesa->texture_row_align - 1;
+       uint32_t row_align;
 
        /* Find image size in bytes */
        if (mt->compressed) {
                /* TODO: Is this correct? Need test cases for compressed textures! */
-               lvl->rowstride = (lvl->width * mt->bpp + 63) & ~63;
+               row_align = rmesa->texture_compressed_row_align - 1;
+               lvl->rowstride = (lvl->width * mt->bpp + row_align) & ~row_align;
                lvl->size = radeon_compressed_texture_size(mt->radeon->glCtx,
                                                           lvl->width, lvl->height, lvl->depth, mt->compressed);
        } else if (mt->target == GL_TEXTURE_RECTANGLE_NV) {
-               lvl->rowstride = (lvl->width * mt->bpp + 63) & ~63;
+               row_align = rmesa->texture_rect_row_align - 1;
+               lvl->rowstride = (lvl->width * mt->bpp + row_align) & ~row_align;
                lvl->size = lvl->rowstride * lvl->height;
        } else if (mt->tilebits & RADEON_TXO_MICRO_TILE) {
                /* tile pattern is 16 bytes x2. mipmaps stay 32 byte aligned,
@@ -108,6 +110,7 @@ static void compute_tex_image_offset(radeonContextPtr rmesa, radeon_mipmap_tree
                lvl->rowstride = (lvl->width * mt->bpp * 2 + 31) & ~31;
                lvl->size = lvl->rowstride * ((lvl->height + 1) / 2) * lvl->depth;
        } else {
+               row_align = rmesa->texture_row_align - 1;
                lvl->rowstride = (lvl->width * mt->bpp + row_align) & ~row_align;
                lvl->size = lvl->rowstride * lvl->height * lvl->depth;
        }
@@ -118,7 +121,7 @@ static void compute_tex_image_offset(radeonContextPtr rmesa, radeon_mipmap_tree
        lvl->faces[face].offset = *curOffset;
        *curOffset += lvl->size;
 
-       if (RADEON_DEBUG & DEBUG_TEXTURE)
+       if (RADEON_DEBUG & RADEON_TEXTURE)
          fprintf(stderr,
                  "level %d, face %d: rs:%d %dx%d at %d\n",
                  level, face, lvl->rowstride, lvl->width, lvl->height, lvl->faces[face].offset);
@@ -187,13 +190,14 @@ static void calculate_miptree_layout_r300(radeonContextPtr rmesa, radeon_mipmap_
  * Create a new mipmap tree, calculate its layout and allocate memory.
  */
 radeon_mipmap_tree* radeon_miptree_create(radeonContextPtr rmesa, radeonTexObj *t,
-               GLenum target, GLuint firstLevel, GLuint lastLevel,
+               GLenum target, GLenum internal_format, GLuint firstLevel, GLuint lastLevel,
                GLuint width0, GLuint height0, GLuint depth0,
                GLuint bpp, GLuint tilebits, GLuint compressed)
 {
        radeon_mipmap_tree *mt = CALLOC_STRUCT(_radeon_mipmap_tree);
 
        mt->radeon = rmesa;
+       mt->internal_format = internal_format;
        mt->refcount = 1;
        mt->t = t;
        mt->target = target;
@@ -315,12 +319,13 @@ GLboolean radeon_miptree_matches_image(radeon_mipmap_tree *mt,
        if (face >= mt->faces || level < mt->firstLevel || level > mt->lastLevel)
                return GL_FALSE;
 
-       if (texImage->IsCompressed != mt->compressed)
+       if (texImage->InternalFormat != mt->internal_format ||
+           texImage->IsCompressed != mt->compressed)
                return GL_FALSE;
 
        if (!texImage->IsCompressed &&
            !mt->compressed &&
-           texImage->TexFormat->TexelBytes != mt->bpp)
+           _mesa_get_format_bytes(texImage->TexFormat->MesaFormat) != mt->bpp)
                return GL_FALSE;
 
        lvl = &mt->levels[level - mt->firstLevel];
@@ -355,8 +360,8 @@ GLboolean radeon_miptree_matches_texture(radeon_mipmap_tree *mt, struct gl_textu
                mt->width0 == firstImage->Width &&
                mt->height0 == firstImage->Height &&
                mt->depth0 == firstImage->Depth &&
-               mt->bpp == firstImage->TexFormat->TexelBytes &&
-               mt->compressed == compressed);
+               mt->compressed == compressed &&
+               (!mt->compressed ? (mt->bpp == firstImage->TexFormat->TexelBytes) : 1));
 }
 
 
@@ -365,9 +370,9 @@ GLboolean radeon_miptree_matches_texture(radeon_mipmap_tree *mt, struct gl_textu
  * given image in the given position.
  */
 void radeon_try_alloc_miptree(radeonContextPtr rmesa, radeonTexObj *t,
-               struct gl_texture_image *texImage, GLuint face, GLuint level)
+               radeon_texture_image *image, GLuint face, GLuint level)
 {
-       GLuint compressed = texImage->IsCompressed ? texImage->TexFormat->MesaFormat : 0;
+       GLuint compressed = image->base.IsCompressed ? image->base.TexFormat->MesaFormat : 0;
        GLuint numfaces = 1;
        GLuint firstLevel, lastLevel;
 
@@ -381,9 +386,10 @@ void radeon_try_alloc_miptree(radeonContextPtr rmesa, radeonTexObj *t,
                return;
 
        t->mt = radeon_miptree_create(rmesa, t, t->base.Target,
+               image->base.InternalFormat,
                firstLevel, lastLevel,
-               texImage->Width, texImage->Height, texImage->Depth,
-               texImage->TexFormat->TexelBytes, t->tile_bits, compressed);
+               image->base.Width, image->base.Height, image->base.Depth,
+               image->base.TexFormat->TexelBytes, t->tile_bits, compressed);
 }
 
 /* Although we use the image_offset[] array to store relative offsets