[Mesa-dev] [PATCH 36/41] intel: Store miptree alignment units in the miptree

Chad Versace chad.versace at linux.intel.com
Thu Nov 17 19:59:03 PST 2011


This allows us to replace all the calls to
intel_get_texture_alignment_unit() with a single call at miptree creation.

Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 src/mesa/drivers/dri/i965/brw_tex_layout.c     |   26 +++++++----------------
 src/mesa/drivers/dri/intel/intel_mipmap_tree.c |    9 +++----
 src/mesa/drivers/dri/intel/intel_mipmap_tree.h |    7 ++++++
 src/mesa/drivers/dri/intel/intel_tex_layout.c  |   16 ++++++--------
 4 files changed, 26 insertions(+), 32 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_tex_layout.c b/src/mesa/drivers/dri/i965/brw_tex_layout.c
index ac6ade6..eaea49b 100644
--- a/src/mesa/drivers/dri/i965/brw_tex_layout.c
+++ b/src/mesa/drivers/dri/i965/brw_tex_layout.c
@@ -43,17 +43,13 @@ static void
 brw_miptree_layout_texture_array(struct intel_context *intel,
 				 struct intel_mipmap_tree *mt)
 {
-   GLuint align_w;
-   GLuint align_h;
    GLuint level;
    GLuint qpitch = 0;
    int h0, h1, q;
 
-   intel_get_texture_alignment_unit(mt->format, &align_w, &align_h);
-
-   h0 = ALIGN(mt->height0, align_h);
-   h1 = ALIGN(minify(mt->height0), align_h);
-   qpitch = (h0 + h1 + (intel->gen >= 7 ? 12 : 11) * align_h);
+   h0 = ALIGN(mt->height0, mt->align_h);
+   h1 = ALIGN(minify(mt->height0), mt->align_h);
+   qpitch = (h0 + h1 + (intel->gen >= 7 ? 12 : 11) * mt->align_h);
    if (mt->compressed)
       qpitch /= 4;
 
@@ -70,9 +66,6 @@ brw_miptree_layout_texture_array(struct intel_context *intel,
 void
 brw_miptree_layout(struct intel_context *intel, struct intel_mipmap_tree *mt)
 {
-   /* XXX: these vary depending on image format: */
-   /* GLint align_w = 4; */
-
    switch (mt->target) {
    case GL_TEXTURE_CUBE_MAP:
       if (intel->gen >= 5) {
@@ -93,18 +86,15 @@ brw_miptree_layout(struct intel_context *intel, struct intel_mipmap_tree *mt)
       GLuint pack_x_pitch, pack_x_nr;
       GLuint pack_y_pitch;
       GLuint level;
-      GLuint align_h = 2;
-      GLuint align_w = 4;
 
       mt->total_height = 0;
-      intel_get_texture_alignment_unit(mt->format, &align_w, &align_h);
 
       if (mt->compressed) {
-          mt->total_width = ALIGN(width, align_w);
+          mt->total_width = ALIGN(width, mt->align_w);
           pack_y_pitch = (height + 3) / 4;
       } else {
 	 mt->total_width = mt->width0;
-	 pack_y_pitch = ALIGN(mt->height0, align_h);
+	 pack_y_pitch = ALIGN(mt->height0, mt->align_h);
       }
 
       pack_x_pitch = width;
@@ -139,8 +129,8 @@ brw_miptree_layout(struct intel_context *intel, struct intel_mipmap_tree *mt)
 	 if (mt->compressed) {
 	    pack_y_pitch = (height + 3) / 4;
 
-	    if (pack_x_pitch > ALIGN(width, align_w)) {
-	       pack_x_pitch = ALIGN(width, align_w);
+	    if (pack_x_pitch > ALIGN(width, mt->align_w)) {
+	       pack_x_pitch = ALIGN(width, mt->align_w);
 	       pack_x_nr <<= 1;
 	    }
 	 } else {
@@ -152,7 +142,7 @@ brw_miptree_layout(struct intel_context *intel, struct intel_mipmap_tree *mt)
 
 	    if (pack_y_pitch > 2) {
 	       pack_y_pitch >>= 1;
-	       pack_y_pitch = ALIGN(pack_y_pitch, align_h);
+	       pack_y_pitch = ALIGN(pack_y_pitch, mt->align_h);
 	    }
 	 }
 
diff --git a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
index 9ebeefc..17cf50e 100644
--- a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
@@ -89,6 +89,8 @@ intel_miptree_create_internal(struct intel_context *intel,
    mt->compressed = compress_byte ? 1 : 0;
    mt->refcount = 1; 
 
+   intel_get_texture_alignment_unit(format, &mt->align_w, &mt->align_h);
+
    if (target == GL_TEXTURE_CUBE_MAP) {
       assert(depth0 == 1);
       mt->depth0 = 6;
@@ -402,11 +404,8 @@ intel_miptree_copy_slice(struct intel_context *intel,
    assert(depth < src_mt->level[level].depth);
 
    if (dst_mt->compressed) {
-      uint32_t align_w, align_h;
-      intel_get_texture_alignment_unit(format,
-				       &align_w, &align_h);
-      height = ALIGN(height, align_h) / align_h;
-      width = ALIGN(width, align_w);
+      height = ALIGN(height, dst_mt->align_h) / dst_mt->align_h;
+      width = ALIGN(width, dst_mt->align_w);
    }
 
    uint32_t dst_x, dst_y, src_x, src_y;
diff --git a/src/mesa/drivers/dri/intel/intel_mipmap_tree.h b/src/mesa/drivers/dri/intel/intel_mipmap_tree.h
index d0bf409..2318d1b 100644
--- a/src/mesa/drivers/dri/intel/intel_mipmap_tree.h
+++ b/src/mesa/drivers/dri/intel/intel_mipmap_tree.h
@@ -120,6 +120,13 @@ struct intel_mipmap_tree
    GLenum target;
    gl_format format;
 
+   /**
+    * The X offset of each image in the miptree must be aligned to this. See
+    * the "Alignment Unit Size" section of the BSpec.
+    */
+   unsigned int align_w;
+   unsigned int align_h; /**< \see align_w */
+
    GLuint first_level;
    GLuint last_level;
 
diff --git a/src/mesa/drivers/dri/intel/intel_tex_layout.c b/src/mesa/drivers/dri/intel/intel_tex_layout.c
index e6324cf..a428d56 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_layout.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_layout.c
@@ -52,7 +52,6 @@ intel_get_texture_alignment_unit(gl_format format,
 
 void i945_miptree_layout_2d(struct intel_mipmap_tree *mt)
 {
-   GLuint align_h, align_w;
    GLuint level;
    GLuint x = 0;
    GLuint y = 0;
@@ -61,10 +60,9 @@ void i945_miptree_layout_2d(struct intel_mipmap_tree *mt)
    GLuint depth = mt->depth0; /* number of array layers. */
 
    mt->total_width = mt->width0;
-   intel_get_texture_alignment_unit(mt->format, &align_w, &align_h);
 
    if (mt->compressed) {
-       mt->total_width = ALIGN(mt->width0, align_w);
+       mt->total_width = ALIGN(mt->width0, mt->align_w);
    }
 
    /* May need to adjust width to accomodate the placement of
@@ -76,10 +74,10 @@ void i945_miptree_layout_2d(struct intel_mipmap_tree *mt)
        GLuint mip1_width;
 
        if (mt->compressed) {
-           mip1_width = ALIGN(minify(mt->width0), align_w)
-               + ALIGN(minify(minify(mt->width0)), align_w);
+           mip1_width = ALIGN(minify(mt->width0), mt->align_w)
+               + ALIGN(minify(minify(mt->width0)), mt->align_w);
        } else {
-           mip1_width = ALIGN(minify(mt->width0), align_w)
+           mip1_width = ALIGN(minify(mt->width0), mt->align_w)
                + minify(minify(mt->width0));
        }
 
@@ -96,9 +94,9 @@ void i945_miptree_layout_2d(struct intel_mipmap_tree *mt)
       intel_miptree_set_level_info(mt, level, x, y, width,
 				   height, depth);
 
-      img_height = ALIGN(height, align_h);
+      img_height = ALIGN(height, mt->align_h);
       if (mt->compressed)
-	 img_height /= align_h;
+	 img_height /= mt->align_h;
 
       /* Because the images are packed better, the final offset
        * might not be the maximal one:
@@ -108,7 +106,7 @@ void i945_miptree_layout_2d(struct intel_mipmap_tree *mt)
       /* Layout_below: step right after second mipmap.
        */
       if (level == mt->first_level + 1) {
-	 x += ALIGN(width, align_w);
+	 x += ALIGN(width, mt->align_w);
       }
       else {
 	 y += img_height;
-- 
1.7.7.1



More information about the mesa-dev mailing list