2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
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:
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.
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.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
32 /* Code to layout images in a mipmap tree for i965.
35 #include "intel_mipmap_tree.h"
36 #include "intel_tex_layout.h"
37 #include "intel_context.h"
38 #include "main/macros.h"
39 #include "intel_chipset.h"
41 #define FILE_DEBUG_FLAG DEBUG_MIPTREE
43 GLboolean
brw_miptree_layout(struct intel_context
*intel
,
44 struct intel_mipmap_tree
*mt
,
47 /* XXX: these vary depending on image format: */
48 /* GLint align_w = 4; */
51 case GL_TEXTURE_CUBE_MAP
:
52 if (IS_IGDNG(intel
->intelScreen
->deviceID
)) {
53 GLuint align_h
= 2, align_w
= 4;
57 GLuint width
= mt
->width0
;
58 GLuint height
= mt
->height0
;
62 mt
->pitch
= mt
->width0
;
63 intel_get_texture_alignment_unit(mt
->internal_format
, &align_w
, &align_h
);
64 y_pitch
= ALIGN(height
, align_h
);
67 mt
->pitch
= ALIGN(mt
->width0
, align_w
);
68 qpitch
= (y_pitch
+ ALIGN(minify(y_pitch
), align_h
) + 11 * align_h
) / 4 * mt
->pitch
* mt
->cpp
;
69 mt
->total_height
= (y_pitch
+ ALIGN(minify(y_pitch
), align_h
) + 11 * align_h
) / 4 * 6;
71 qpitch
= (y_pitch
+ ALIGN(minify(y_pitch
), align_h
) + 11 * align_h
) * mt
->pitch
* mt
->cpp
;
72 mt
->total_height
= (y_pitch
+ ALIGN(minify(y_pitch
), align_h
) + 11 * align_h
) * 6;
75 if (mt
->first_level
!= mt
->last_level
) {
79 mip1_width
= ALIGN(minify(mt
->width0
), align_w
)
80 + ALIGN(minify(minify(mt
->width0
)), align_w
);
82 mip1_width
= ALIGN(minify(mt
->width0
), align_w
)
83 + minify(minify(mt
->width0
));
86 if (mip1_width
> mt
->pitch
) {
87 mt
->pitch
= mip1_width
;
91 mt
->pitch
= intel_miptree_pitch_align(intel
, mt
, tiling
, mt
->pitch
);
93 for (level
= mt
->first_level
; level
<= mt
->last_level
; level
++) {
98 intel_miptree_set_level_info(mt
, level
, nr_images
, x
, y
, width
,
101 for (q
= 0; q
< nr_images
; q
++)
102 intel_miptree_set_image_offset_ex(mt
, level
, q
, x
, y
, q
* qpitch
);
105 img_height
= MAX2(1, height
/4);
107 img_height
= ALIGN(height
, align_h
);
109 if (level
== mt
->first_level
+ 1) {
110 x
+= ALIGN(width
, align_w
);
116 width
= minify(width
);
117 height
= minify(height
);
123 case GL_TEXTURE_3D
: {
124 GLuint width
= mt
->width0
;
125 GLuint height
= mt
->height0
;
126 GLuint depth
= mt
->depth0
;
127 GLuint pack_x_pitch
, pack_x_nr
;
133 mt
->total_height
= 0;
134 intel_get_texture_alignment_unit(mt
->internal_format
, &align_w
, &align_h
);
136 if (mt
->compressed
) {
137 mt
->pitch
= ALIGN(width
, align_w
);
138 pack_y_pitch
= (height
+ 3) / 4;
140 mt
->pitch
= intel_miptree_pitch_align (intel
, mt
, tiling
, mt
->width0
);
141 pack_y_pitch
= ALIGN(mt
->height0
, align_h
);
144 pack_x_pitch
= width
;
147 for (level
= mt
->first_level
; level
<= mt
->last_level
; level
++) {
148 GLuint nr_images
= mt
->target
== GL_TEXTURE_3D
? depth
: 6;
153 intel_miptree_set_level_info(mt
, level
, nr_images
,
155 width
, height
, depth
);
157 for (q
= 0; q
< nr_images
;) {
158 for (j
= 0; j
< pack_x_nr
&& q
< nr_images
; j
++, q
++) {
159 intel_miptree_set_image_offset(mt
, level
, q
, x
, y
);
168 mt
->total_height
+= y
;
169 width
= minify(width
);
170 height
= minify(height
);
171 depth
= minify(depth
);
173 if (mt
->compressed
) {
174 pack_y_pitch
= (height
+ 3) / 4;
176 if (pack_x_pitch
> ALIGN(width
, align_w
)) {
177 pack_x_pitch
= ALIGN(width
, align_w
);
181 if (pack_x_pitch
> 4) {
184 assert(pack_x_pitch
* pack_x_nr
<= mt
->pitch
);
187 if (pack_y_pitch
> 2) {
189 pack_y_pitch
= ALIGN(pack_y_pitch
, align_h
);
198 i945_miptree_layout_2d(intel
, mt
, tiling
);
201 DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__
,
205 mt
->pitch
* mt
->total_height
* mt
->cpp
);