Mesa (map-texture-image-v4): mesa: push gl_texture_image:: _IsPowerOfTwo into swrast

Brian Paul brianp at kemper.freedesktop.org
Fri Jul 15 03:09:47 UTC 2011


Module: Mesa
Branch: map-texture-image-v4
Commit: 3a99e2f1ffa9f04adb841fd6a8f3cdcb7ce080a9
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3a99e2f1ffa9f04adb841fd6a8f3cdcb7ce080a9

Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jul 14 20:57:35 2011 -0600

mesa: push gl_texture_image::_IsPowerOfTwo into swrast

---

 src/mesa/main/mtypes.h        |    1 -
 src/mesa/main/teximage.c      |    7 -------
 src/mesa/swrast/s_context.h   |    1 +
 src/mesa/swrast/s_texfilter.c |   23 ++++++++++++++---------
 src/mesa/swrast/s_texture.c   |   19 +++++++++++++++++++
 src/mesa/swrast/s_triangle.c  |    2 +-
 6 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index f86b1e8..36e747f 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1242,7 +1242,6 @@ struct gl_texture_image
    GLuint DepthLog2;		/**< = log2(Depth2) */
    GLuint MaxLog2;		/**< = MAX(WidthLog2, HeightLog2) */
    GLboolean IsClientData;	/**< Data owned by client? */
-   GLboolean _IsPowerOfTwo;	/**< Are all dimensions powers of two? */
 
    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 930c0e9..8aa50c7 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -1101,13 +1101,6 @@ _mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
 
    img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2);
 
-   if ((width == 1 || _mesa_is_pow_two(img->Width2)) &&
-       (height == 1 || _mesa_is_pow_two(img->Height2)) &&
-       (depth == 1 || _mesa_is_pow_two(img->Depth2)))
-      img->_IsPowerOfTwo = GL_TRUE;
-   else
-      img->_IsPowerOfTwo = GL_FALSE;
-
    img->TexFormat = format;
 }
 
diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index ecb5291..4949beb 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -138,6 +138,7 @@ struct swrast_texture_image
 
    /** used for mipmap LOD computation */
    GLfloat WidthScale, HeightScale, DepthScale;
+   GLboolean _IsPowerOfTwo;  /**< Are all dimensions powers of two? */
 
    GLubyte *Data;    /**< The actual texture data in malloc'd memory */
 
diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c
index e027134..59c26d7 100644
--- a/src/mesa/swrast/s_texfilter.c
+++ b/src/mesa/swrast/s_texfilter.c
@@ -159,11 +159,12 @@ linear_texel_locations(GLenum wrapMode,
                        GLint size, GLfloat s,
                        GLint *i0, GLint *i1, GLfloat *weight)
 {
+   const struct swrast_texture_image *swImg = swrast_texture_image_const(img);
    GLfloat u;
    switch (wrapMode) {
    case GL_REPEAT:
       u = s * size - 0.5F;
-      if (img->_IsPowerOfTwo) {
+      if (swImg->_IsPowerOfTwo) {
          *i0 = IFLOOR(u) & (size - 1);
          *i1 = (*i0 + 1) & (size - 1);
       }
@@ -285,6 +286,7 @@ nearest_texel_location(GLenum wrapMode,
                        const struct gl_texture_image *img,
                        GLint size, GLfloat s)
 {
+   const struct swrast_texture_image *swImg = swrast_texture_image_const(img);
    GLint i;
 
    switch (wrapMode) {
@@ -292,7 +294,7 @@ nearest_texel_location(GLenum wrapMode,
       /* s limited to [0,1) */
       /* i limited to [0,size-1] */
       i = IFLOOR(s * size);
-      if (img->_IsPowerOfTwo)
+      if (swImg->_IsPowerOfTwo)
          i &= (size - 1);
       else
          i = REMAINDER(i, size);
@@ -1174,7 +1176,7 @@ sample_2d_linear_repeat(struct gl_context *ctx,
    ASSERT(tObj->Sampler.WrapT == GL_REPEAT);
    ASSERT(img->Border == 0);
    ASSERT(img->_BaseFormat != GL_COLOR_INDEX);
-   ASSERT(img->_IsPowerOfTwo);
+   ASSERT(swImg->_IsPowerOfTwo);
 
    linear_repeat_texel_location(width,  texcoord[0], &i0, &i1, &wi);
    linear_repeat_texel_location(height, texcoord[1], &j0, &j1, &wj);
@@ -1321,10 +1323,11 @@ sample_linear_2d(struct gl_context *ctx,
 {
    GLuint i;
    struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel];
+   const struct swrast_texture_image *swImg = swrast_texture_image_const(image);
    (void) lambda;
    if (tObj->Sampler.WrapS == GL_REPEAT &&
        tObj->Sampler.WrapT == GL_REPEAT &&
-       image->_IsPowerOfTwo &&
+       swImg->_IsPowerOfTwo &&
        image->Border == 0) {
       for (i = 0; i < n; i++) {
          sample_2d_linear_repeat(ctx, tObj, image, texcoords[i], rgba[i]);
@@ -1366,7 +1369,7 @@ opt_sample_rgb_2d(struct gl_context *ctx,
    ASSERT(tObj->Sampler.WrapT==GL_REPEAT);
    ASSERT(img->Border==0);
    ASSERT(img->TexFormat == MESA_FORMAT_RGB888);
-   ASSERT(img->_IsPowerOfTwo);
+   ASSERT(swImg->_IsPowerOfTwo);
 
    for (k=0; k<n; k++) {
       GLint i = IFLOOR(texcoords[k][0] * width) & colMask;
@@ -1409,7 +1412,7 @@ opt_sample_rgba_2d(struct gl_context *ctx,
    ASSERT(tObj->Sampler.WrapT==GL_REPEAT);
    ASSERT(img->Border==0);
    ASSERT(img->TexFormat == MESA_FORMAT_RGBA8888);
-   ASSERT(img->_IsPowerOfTwo);
+   ASSERT(swImg->_IsPowerOfTwo);
 
    for (i = 0; i < n; i++) {
       const GLint col = IFLOOR(texcoords[i][0] * width) & colMask;
@@ -1440,7 +1443,7 @@ sample_lambda_2d(struct gl_context *ctx,
       && (tObj->Sampler.WrapT == GL_REPEAT)
       && (tImg->Border == 0 && (tImg->Width == swImg->RowStride))
       && (tImg->_BaseFormat != GL_COLOR_INDEX)
-      && tImg->_IsPowerOfTwo;
+      && swImg->_IsPowerOfTwo;
 
    ASSERT(lambda != NULL);
    compute_min_mag_ranges(tObj, n, lambda,
@@ -3640,17 +3643,19 @@ _swrast_choose_texture_sample_func( struct gl_context *ctx,
          else {
             /* check for a few optimized cases */
             const struct gl_texture_image *img = t->Image[0][t->BaseLevel];
+            const struct swrast_texture_image *swImg =
+               swrast_texture_image_const(img);
             ASSERT(t->Sampler.MinFilter == GL_NEAREST);
             if (t->Sampler.WrapS == GL_REPEAT &&
                 t->Sampler.WrapT == GL_REPEAT &&
-                img->_IsPowerOfTwo &&
+                swImg->_IsPowerOfTwo &&
                 img->Border == 0 &&
                 img->TexFormat == MESA_FORMAT_RGB888) {
                return &opt_sample_rgb_2d;
             }
             else if (t->Sampler.WrapS == GL_REPEAT &&
                      t->Sampler.WrapT == GL_REPEAT &&
-                     img->_IsPowerOfTwo &&
+                     swImg->_IsPowerOfTwo &&
                      img->Border == 0 &&
                      img->TexFormat == MESA_FORMAT_RGBA8888) {
                return &opt_sample_rgba_2d;
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index 1602abd..9424316 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -94,6 +94,18 @@ _swrast_unmap_renderbuffer(struct gl_context *ctx,
 
 
 /**
+ * Are the dimensions of the texture image all powers of two?
+ */
+static GLboolean
+is_power_of_two_teximage(const struct gl_texture_image *texImage)
+{
+   return ((texImage->Width == 1 || _mesa_is_pow_two(texImage->Width2)) &&
+           (texImage->Height == 1 || _mesa_is_pow_two(texImage->Height2)) &&
+           (texImage->Depth == 1 || _mesa_is_pow_two(texImage->Depth2)));
+}
+
+
+/**
  * Error checking for debugging only.
  */
 static void
@@ -366,6 +378,13 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
    struct swrast_texture_image *swImage = swrast_texture_image(texImage);
    GLuint bytes = _mesa_format_image_size(format, width, height, depth);
 
+   /* This _should_ be true (revisit if these ever fail) */
+   assert(texImage->Width == width);
+   assert(texImage->Height == height);
+   assert(texImage->Depth == depth);
+
+   swImage->_IsPowerOfTwo = is_power_of_two_teximage(texImage);
+
    assert(!swImage->Data);
    swImage->Data = _mesa_align_malloc(bytes, 512);
 
diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c
index b81a906..7fb1c52 100644
--- a/src/mesa/swrast/s_triangle.c
+++ b/src/mesa/swrast/s_triangle.c
@@ -1067,7 +1067,7 @@ _swrast_choose_triangle( struct gl_context *ctx )
              && texObj2D->Sampler.WrapS == GL_REPEAT
              && texObj2D->Sampler.WrapT == GL_REPEAT
              && texObj2D->_Swizzle == SWIZZLE_NOOP
-             && texImg->_IsPowerOfTwo
+             && swImg->_IsPowerOfTwo
              && texImg->Border == 0
              && texImg->Width == swImg->RowStride
              && (format == MESA_FORMAT_RGB888 || format == MESA_FORMAT_RGBA8888)




More information about the mesa-commit mailing list