brw_tex_layout.c revision dd1a868b74ac47ac26f600f2f1eb0dc3f535f31b
1/* 2 Copyright (C) Intel Corp. 2006. All Rights Reserved. 3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to 4 develop this 3D driver. 5 6 Permission is hereby granted, free of charge, to any person obtaining 7 a copy of this software and associated documentation files (the 8 "Software"), to deal in the Software without restriction, including 9 without limitation the rights to use, copy, modify, merge, publish, 10 distribute, sublicense, and/or sell copies of the Software, and to 11 permit persons to whom the Software is furnished to do so, subject to 12 the following conditions: 13 14 The above copyright notice and this permission notice (including the 15 next paragraph) shall be included in all copies or substantial 16 portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 26 **********************************************************************/ 27 /* 28 * Authors: 29 * Keith Whitwell <keith@tungstengraphics.com> 30 */ 31 32 33/* Code to layout images in a mipmap tree for i965. 34 */ 35 36#include "intel_mipmap_tree.h" 37#include "intel_tex_layout.h" 38#include "intel_context.h" 39#include "macros.h" 40 41#define FILE_DEBUG_FLAG DEBUG_MIPTREE 42 43GLboolean brw_miptree_layout( struct intel_context *intel, struct intel_mipmap_tree *mt ) 44{ 45 /* XXX: these vary depending on image format: 46 */ 47/* GLint align_w = 4; */ 48 49 switch (mt->target) { 50 case GL_TEXTURE_CUBE_MAP: 51 case GL_TEXTURE_3D: { 52 GLuint width = mt->width0; 53 GLuint height = mt->height0; 54 GLuint depth = mt->depth0; 55 GLuint pack_x_pitch, pack_x_nr; 56 GLuint pack_y_pitch; 57 GLuint level; 58 GLuint align_h = 2; 59 GLuint align_w = 4; 60 61 mt->total_height = 0; 62 63 if (mt->compressed) { 64 align_w = intel_compressed_alignment(mt->internal_format); 65 mt->pitch = ALIGN(width, align_w); 66 pack_y_pitch = (height + 3) / 4; 67 } else { 68 mt->pitch = intel_miptree_pitch_align (intel, mt, mt->width0); 69 pack_y_pitch = ALIGN(mt->height0, align_h); 70 } 71 72 pack_x_pitch = mt->pitch; 73 pack_x_nr = 1; 74 75 for ( level = mt->first_level ; level <= mt->last_level ; level++ ) { 76 GLuint nr_images = mt->target == GL_TEXTURE_3D ? depth : 6; 77 GLint x = 0; 78 GLint y = 0; 79 GLint q, j; 80 81 intel_miptree_set_level_info(mt, level, nr_images, 82 0, mt->total_height, 83 width, height, depth); 84 85 for (q = 0; q < nr_images;) { 86 for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) { 87 intel_miptree_set_image_offset(mt, level, q, x, y); 88 x += pack_x_pitch; 89 } 90 91 x = 0; 92 y += pack_y_pitch; 93 } 94 95 96 mt->total_height += y; 97 width = minify(width); 98 height = minify(height); 99 depth = minify(depth); 100 101 if (mt->compressed) { 102 pack_y_pitch = (height + 3) / 4; 103 104 if (pack_x_pitch > ALIGN(width, align_w)) { 105 pack_x_pitch = ALIGN(width, align_w); 106 pack_x_nr <<= 1; 107 } 108 } else { 109 if (pack_x_pitch > 4) { 110 pack_x_pitch >>= 1; 111 pack_x_nr <<= 1; 112 assert(pack_x_pitch * pack_x_nr <= mt->pitch); 113 } 114 115 if (pack_y_pitch > 2) { 116 pack_y_pitch >>= 1; 117 pack_y_pitch = ALIGN(pack_y_pitch, align_h); 118 } 119 } 120 121 } 122 break; 123 } 124 125 default: 126 i945_miptree_layout_2d(intel, mt); 127 break; 128 } 129 DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, 130 mt->pitch, 131 mt->total_height, 132 mt->cpp, 133 mt->pitch * mt->total_height * mt->cpp ); 134 135 return GL_TRUE; 136} 137 138