Merge branch '7.8'
[mesa.git] / src / gallium / drivers / i965 / brw_screen_tex_layout.c
index 8377d30564b60bc27e6101527ae4ef5f8f177491..894f4bea40188b68985a0b80f59f36269341898f 100644 (file)
@@ -1,3 +1,29 @@
+/*
+ Copyright (C) Intel Corp.  2006.  All Rights Reserved.
+ Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
+ develop this 3D driver.
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+ The above copyright notice and this permission notice (including the
+ next paragraph) shall be included in all copies or substantial
+ portions of the Software.
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ **********************************************************************/
 
 #include "pipe/p_format.h"
 
@@ -6,6 +32,10 @@
 
 #include "brw_screen.h"
 #include "brw_debug.h"
+#include "brw_winsys.h"
+
+/* Code to layout images in a mipmap tree for i965.
+ */
 
 static int 
 brw_tex_pitch_align (struct brw_texture *tex,
@@ -72,16 +102,13 @@ brw_tex_set_level_info(struct brw_texture *tex,
                       GLuint x, GLuint y,
                       GLuint w, GLuint h, GLuint d)
 {
-   assert(tex->base.width[level] == w);
-   assert(tex->base.height[level] == h);
-   assert(tex->base.depth[level] == d);
-   assert(tex->image_offset[level] == NULL);
-   assert(nr_images >= 1);
 
    if (BRW_DEBUG & DEBUG_TEXTURE)
       debug_printf("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
                   level, w, h, d, x, y, tex->level_offset[level]);
 
+   assert(tex->image_offset[level] == NULL);
+   assert(nr_images >= 1);
 
    tex->level_offset[level] = (x + y * tex->pitch) * tex->cpp;
    tex->nr_images[level] = nr_images;
@@ -116,14 +143,14 @@ static void brw_layout_2d( struct brw_texture *tex )
    GLuint level;
    GLuint x = 0;
    GLuint y = 0;
-   GLuint width = tex->base.width[0];
-   GLuint height = tex->base.height[0];
+   GLuint width = tex->base.width0;
+   GLuint height = tex->base.height0;
 
-   tex->pitch = tex->base.width[0];
+   tex->pitch = tex->base.width0;
    brw_tex_alignment_unit(tex->base.format, &align_w, &align_h);
 
    if (tex->compressed) {
-       tex->pitch = align(tex->base.width[0], align_w);
+       tex->pitch = align(tex->base.width0, align_w);
    }
 
    /* May need to adjust pitch to accomodate the placement of
@@ -135,11 +162,11 @@ static void brw_layout_2d( struct brw_texture *tex )
        GLuint mip1_width;
 
        if (tex->compressed) {
-           mip1_width = align(minify(tex->base.width[0]), align_w)
-               + align(minify(minify(tex->base.width[0])), align_w);
+          mip1_width = (align(u_minify(tex->base.width0, 1), align_w) + 
+                        align(u_minify(tex->base.width0, 2), align_w));
        } else {
-           mip1_width = align(minify(tex->base.width[0]), align_w)
-               + minify(minify(tex->base.width[0]));
+          mip1_width = (align(u_minify(tex->base.width0, 1), align_w) + 
+                        u_minify(tex->base.width0, 2));
        }
 
        if (mip1_width > tex->pitch) {
@@ -178,8 +205,8 @@ static void brw_layout_2d( struct brw_texture *tex )
         y += img_height;
       }
 
-      width  = minify(width);
-      height = minify(height);
+      width  = u_minify(width, 1);
+      height = u_minify(height, 1);
    }
 }
 
@@ -191,28 +218,28 @@ brw_layout_cubemap_idgng( struct brw_texture *tex )
    GLuint level;
    GLuint x = 0;
    GLuint y = 0;
-   GLuint width = tex->base.width[0];
-   GLuint height = tex->base.height[0];
+   GLuint width = tex->base.width0;
+   GLuint height = tex->base.height0;
    GLuint qpitch = 0;
    GLuint y_pitch = 0;
 
-   tex->pitch = tex->base.width[0];
+   tex->pitch = tex->base.width0;
    brw_tex_alignment_unit(tex->base.format, &align_w, &align_h);
    y_pitch = align(height, align_h);
 
    if (tex->compressed) {
-      tex->pitch = align(tex->base.width[0], align_w);
+      tex->pitch = align(tex->base.width0, align_w);
    }
 
    if (tex->base.last_level != 0) {
       GLuint mip1_width;
 
       if (tex->compressed) {
-        mip1_width = (align(minify(tex->base.width[0]), align_w) +
-                      align(minify(minify(tex->base.width[0])), align_w));
+        mip1_width = (align(u_minify(tex->base.width0, 1), align_w) +
+                      align(u_minify(tex->base.width0, 2), align_w));
       } else {
-        mip1_width = (align(minify(tex->base.width[0]), align_w) +
-                      minify(minify(tex->base.width[0])));
+        mip1_width = (align(u_minify(tex->base.width0, 1), align_w) +
+                      u_minify(tex->base.width0, 2));
       }
 
       if (mip1_width > tex->pitch) {
@@ -224,19 +251,19 @@ brw_layout_cubemap_idgng( struct brw_texture *tex )
 
    if (tex->compressed) {
       qpitch = ((y_pitch + 
-                align(minify(y_pitch), align_h) +
+                align(u_minify(y_pitch, 1), align_h) +
                 11 * align_h) / 4) * tex->pitch * tex->cpp;
 
       tex->total_height = ((y_pitch + 
-                           align(minify(y_pitch), align_h) + 
+                           align(u_minify(y_pitch, 1), align_h) + 
                            11 * align_h) / 4) * 6;
    } else {
       qpitch = (y_pitch + 
-               align(minify(y_pitch), align_h) + 
+               align(u_minify(y_pitch, 1), align_h) + 
                11 * align_h) * tex->pitch * tex->cpp;
 
       tex->total_height = (y_pitch +
-                          align(minify(y_pitch), align_h) +
+                          align(u_minify(y_pitch, 1), align_h) +
                           11 * align_h) * 6;
    }
 
@@ -262,8 +289,8 @@ brw_layout_cubemap_idgng( struct brw_texture *tex )
         y += img_height;
       }
 
-      width  = minify(width);
-      height = minify(height);
+      width  = u_minify(width, 1);
+      height = u_minify(height, 1);
    }
 
    return TRUE;
@@ -273,9 +300,9 @@ brw_layout_cubemap_idgng( struct brw_texture *tex )
 static boolean
 brw_layout_3d_cube( struct brw_texture *tex )
 {
-   GLuint width  = tex->base.width[0];
-   GLuint height = tex->base.height[0];
-   GLuint depth = tex->base.depth[0];
+   GLuint width  = tex->base.width0;
+   GLuint height = tex->base.height0;
+   GLuint depth = tex->base.depth0;
    GLuint pack_x_pitch, pack_x_nr;
    GLuint pack_y_pitch;
    GLuint level;
@@ -289,8 +316,8 @@ brw_layout_3d_cube( struct brw_texture *tex )
       tex->pitch = align(width, align_w);
       pack_y_pitch = (height + 3) / 4;
    } else {
-      tex->pitch = brw_tex_pitch_align(tex, tex->base.width[0]);
-      pack_y_pitch = align(tex->base.height[0], align_h);
+      tex->pitch = brw_tex_pitch_align(tex, tex->base.width0);
+      pack_y_pitch = align(tex->base.height0, align_h);
    }
 
    pack_x_pitch = width;
@@ -318,9 +345,9 @@ brw_layout_3d_cube( struct brw_texture *tex )
 
 
       tex->total_height += y;
-      width  = minify(width);
-      height = minify(height);
-      depth  = minify(depth);
+      width  = u_minify(width, 1);
+      height = u_minify(height, 1);
+      depth  = u_minify(depth, 1);
 
       if (tex->compressed) {
         pack_y_pitch = (height + 3) / 4;