[Mesa-dev] [PATCH 1/6] mesa: add MaxNumLevels to gl_texture_image, remove MaxLog2
Marek Olšák
maraeo at gmail.com
Sun Nov 11 08:39:57 PST 2012
MaxLog2 led to bugs, because it didn't work well with 1D and 3D textures.
NOTE: This is a candidate for the stable branches.
---
src/mesa/drivers/dri/nouveau/nouveau_texture.c | 2 +-
src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c | 6 ++--
src/mesa/main/mtypes.h | 3 +-
src/mesa/main/teximage.c | 41 +++++++++++++++++++++-
src/mesa/main/teximage.h | 3 ++
5 files changed, 49 insertions(+), 6 deletions(-)
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_texture.c b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
index 37f7577..288b510 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_texture.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
@@ -369,7 +369,7 @@ get_last_level(struct gl_texture_object *t)
t->Sampler.MinFilter == GL_LINEAR || !base)
return t->BaseLevel;
else
- return MIN2(t->BaseLevel + base->MaxLog2, t->MaxLevel);
+ return MIN2(t->BaseLevel + base->MaxNumLevels - 1, t->MaxLevel);
}
static void
diff --git a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
index 668ef9f..b0c49ba 100644
--- a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
+++ b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
@@ -270,7 +270,7 @@ static void calculate_min_max_lod(struct gl_sampler_object *samp, struct gl_text
minLod = MIN2(minLod, tObj->MaxLevel);
maxLod = tObj->BaseLevel + (GLint)(samp->MaxLod + 0.5);
maxLod = MIN2(maxLod, tObj->MaxLevel);
- maxLod = MIN2(maxLod, tObj->Image[0][minLod]->MaxLog2 + minLod);
+ maxLod = MIN2(maxLod, tObj->Image[0][minLod]->MaxNumLevels - 1 + minLod);
maxLod = MAX2(maxLod, minLod); /* need at least one level */
}
break;
@@ -329,7 +329,7 @@ static GLboolean radeon_miptree_matches_texture(radeon_mipmap_tree *mt, struct g
mtBaseLevel = &mt->levels[texObj->BaseLevel - mt->baseLevel];
firstImage = texObj->Image[0][texObj->BaseLevel];
- numLevels = MIN2(texObj->_MaxLevel - texObj->BaseLevel + 1, firstImage->MaxLog2 + 1);
+ numLevels = MIN2(texObj->_MaxLevel - texObj->BaseLevel + 1, firstImage->MaxNumLevels);
if (radeon_is_debug_enabled(RADEON_TEXTURE,RADEON_TRACE)) {
fprintf(stderr, "Checking if miptree %p matches texObj %p\n", mt, texObj);
@@ -378,7 +378,7 @@ void radeon_try_alloc_miptree(radeonContextPtr rmesa, radeonTexObj *t)
}
- numLevels = MIN2(texObj->MaxLevel - texObj->BaseLevel + 1, texImg->MaxLog2 + 1);
+ numLevels = MIN2(texObj->MaxLevel - texObj->BaseLevel + 1, texImg->MaxNumLevels);
t->mt = radeon_miptree_create(rmesa, t->base.Target,
texImg->TexFormat, texObj->BaseLevel,
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index b99e710..da327aa 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1203,7 +1203,8 @@ struct gl_texture_image
GLuint WidthLog2; /**< = log2(Width2) */
GLuint HeightLog2; /**< = log2(Height2) */
GLuint DepthLog2; /**< = log2(Depth2) */
- GLuint MaxLog2; /**< = MAX(WidthLog2, HeightLog2) */
+ GLuint MaxNumLevels; /**< = maximum possible number of mipmaps,
+ computed from the dimensions */
struct gl_texture_object *TexObject; /**< Pointer back to parent object */
GLuint Level; /**< Which mipmap level am I? */
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 0f28009..cd1772a 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -1027,6 +1027,43 @@ _mesa_get_texture_dimensions(GLenum target)
}
+/**
+ * Return the maximum number of mipmap levels for the given target
+ * and the dimensions.
+ * The dimensions are expected not to include the border.
+ */
+GLsizei
+_mesa_get_tex_max_num_levels(GLenum target, GLsizei width, GLsizei height,
+ GLsizei depth)
+{
+ GLsizei size;
+
+ switch (target) {
+ case GL_TEXTURE_1D:
+ case GL_TEXTURE_1D_ARRAY:
+ size = width;
+ break;
+ case GL_TEXTURE_CUBE_MAP:
+ case GL_TEXTURE_CUBE_MAP_ARRAY:
+ ASSERT(width == height);
+ size = width;
+ break;
+ case GL_TEXTURE_2D:
+ case GL_TEXTURE_2D_ARRAY:
+ size = MAX2(width, height);
+ break;
+ case GL_TEXTURE_3D:
+ size = MAX3(width, height, depth);
+ break;
+ case GL_TEXTURE_RECTANGLE:
+ return 1;
+ default:
+ assert(0);
+ return 1;
+ }
+
+ return _mesa_logbase2(size) + 1;
+}
#if 000 /* not used anymore */
@@ -1214,7 +1251,9 @@ _mesa_init_teximage_fields(struct gl_context *ctx,
target);
}
- img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2);
+ img->MaxNumLevels =
+ _mesa_get_tex_max_num_levels(target,
+ img->Width2, img->Height2, img->Depth2);
img->TexFormat = format;
}
diff --git a/src/mesa/main/teximage.h b/src/mesa/main/teximage.h
index e1b15d2..101b385 100644
--- a/src/mesa/main/teximage.h
+++ b/src/mesa/main/teximage.h
@@ -138,6 +138,9 @@ _mesa_tex_target_to_face(GLenum target);
extern GLint
_mesa_get_texture_dimensions(GLenum target);
+extern GLsizei
+_mesa_get_tex_max_num_levels(GLenum target, GLsizei width, GLsizei height,
+ GLsizei depth);
extern GLboolean
_mesa_legal_texture_dimensions(struct gl_context *ctx, GLenum target,
--
1.7.9.5
More information about the mesa-dev
mailing list