1 /**************************************************************************
3 * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * 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, sub license, 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 portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 /* Code to layout images in a mipmap tree for i915 and i945
32 #include "intel_mipmap_tree.h"
33 #include "intel_tex_layout.h"
35 #include "intel_context.h"
37 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
39 static GLint initial_offsets
[6][2] = { {0, 0},
48 static GLint step_offsets
[6][2] = { {0, 2},
57 i915_miptree_layout(struct intel_context
*intel
, struct intel_mipmap_tree
* mt
)
62 case GL_TEXTURE_CUBE_MAP
:{
63 const GLuint dim
= mt
->width0
;
65 GLuint lvlWidth
= mt
->width0
, lvlHeight
= mt
->height0
;
67 assert(lvlWidth
== lvlHeight
); /* cubemap images are square */
69 /* double pitch for cube layouts */
70 mt
->pitch
= intel_miptree_pitch_align (intel
, mt
, dim
* 2);
71 mt
->total_height
= dim
* 4;
73 for (level
= mt
->first_level
; level
<= mt
->last_level
; level
++) {
74 intel_miptree_set_level_info(mt
, level
, 6,
76 /*OLD: mt->pitch, mt->total_height,*/
83 for (face
= 0; face
< 6; face
++) {
84 GLuint x
= initial_offsets
[face
][0] * dim
;
85 GLuint y
= initial_offsets
[face
][1] * dim
;
88 for (level
= mt
->first_level
; level
<= mt
->last_level
; level
++) {
89 intel_miptree_set_image_offset(mt
, level
, face
, x
, y
);
92 _mesa_printf("cube mipmap %d/%d (%d..%d) is 0x0\n",
93 face
, level
, mt
->first_level
, mt
->last_level
);
96 x
+= step_offsets
[face
][0] * d
;
97 y
+= step_offsets
[face
][1] * d
;
103 GLuint width
= mt
->width0
;
104 GLuint height
= mt
->height0
;
105 GLuint depth
= mt
->depth0
;
106 GLuint stack_height
= 0;
108 /* Calculate the size of a single slice.
110 mt
->pitch
= intel_miptree_pitch_align (intel
, mt
, mt
->width0
);
112 /* XXX: hardware expects/requires 9 levels at minimum.
114 for (level
= mt
->first_level
; level
<= MAX2(8, mt
->last_level
);
116 intel_miptree_set_level_info(mt
, level
, depth
, 0, mt
->total_height
,
117 width
, height
, depth
);
120 stack_height
+= MAX2(2, height
);
122 width
= minify(width
);
123 height
= minify(height
);
124 depth
= minify(depth
);
127 /* Fixup depth image_offsets:
130 for (level
= mt
->first_level
; level
<= mt
->last_level
; level
++) {
132 for (i
= 0; i
< depth
; i
++)
133 intel_miptree_set_image_offset(mt
, level
, i
,
134 0, i
* stack_height
);
136 depth
= minify(depth
);
140 /* Multiply slice size by texture depth for total size. It's
141 * remarkable how wasteful of memory the i915 texture layouts
142 * are. They are largely fixed in the i945.
144 mt
->total_height
= stack_height
* mt
->depth0
;
149 GLuint width
= mt
->width0
;
150 GLuint height
= mt
->height0
;
153 mt
->pitch
= intel_miptree_pitch_align (intel
, mt
, mt
->width0
);
154 mt
->total_height
= 0;
156 for (level
= mt
->first_level
; level
<= mt
->last_level
; level
++) {
157 intel_miptree_set_level_info(mt
, level
, 1,
162 img_height
= MAX2(1, height
/ 4);
164 img_height
= (MAX2(2, height
) + 1) & ~1;
166 mt
->total_height
+= img_height
;
168 width
= minify(width
);
169 height
= minify(height
);
174 DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__
,
176 mt
->total_height
, mt
->cpp
, mt
->pitch
* mt
->total_height
* mt
->cpp
);
183 i945_miptree_layout(struct intel_context
*intel
, struct intel_mipmap_tree
* mt
)
187 switch (mt
->target
) {
188 case GL_TEXTURE_CUBE_MAP
:{
189 const GLuint dim
= mt
->width0
;
191 GLuint lvlWidth
= mt
->width0
, lvlHeight
= mt
->height0
;
193 assert(lvlWidth
== lvlHeight
); /* cubemap images are square */
195 /* Depending on the size of the largest images, pitch can be
196 * determined either by the old-style packing of cubemap faces,
197 * or the final row of 4x4, 2x2 and 1x1 faces below this.
200 mt
->pitch
= intel_miptree_pitch_align (intel
, mt
, dim
);
204 mt
->total_height
= dim
* 4 + 4;
206 /* Set all the levels to effectively occupy the whole rectangular region.
208 for (level
= mt
->first_level
; level
<= mt
->last_level
; level
++) {
209 intel_miptree_set_level_info(mt
, level
, 6,
211 lvlWidth
, lvlHeight
, 1);
217 for (face
= 0; face
< 6; face
++) {
218 GLuint x
= initial_offsets
[face
][0] * dim
;
219 GLuint y
= initial_offsets
[face
][1] * dim
;
222 if (dim
== 4 && face
>= 4) {
223 y
= mt
->total_height
- 4;
226 else if (dim
< 4 && (face
> 0 || mt
->first_level
> 0)) {
227 y
= mt
->total_height
- 4;
231 for (level
= mt
->first_level
; level
<= mt
->last_level
; level
++) {
232 intel_miptree_set_image_offset(mt
, level
, face
, x
, y
);
241 x
+= step_offsets
[face
][0] * d
;
242 y
+= step_offsets
[face
][1] * d
;
251 y
= mt
->total_height
- 4;
257 y
= mt
->total_height
- 4;
266 x
+= step_offsets
[face
][0] * d
;
267 y
+= step_offsets
[face
][1] * d
;
275 GLuint width
= mt
->width0
;
276 GLuint height
= mt
->height0
;
277 GLuint depth
= mt
->depth0
;
278 GLuint pack_x_pitch
, pack_x_nr
;
282 mt
->pitch
= intel_miptree_pitch_align (intel
, mt
, mt
->width0
);
283 mt
->total_height
= 0;
285 pack_y_pitch
= MAX2(mt
->height0
, 2);
286 pack_x_pitch
= mt
->pitch
;
289 for (level
= mt
->first_level
; level
<= mt
->last_level
; level
++) {
290 GLuint nr_images
= mt
->target
== GL_TEXTURE_3D
? depth
: 6;
295 intel_miptree_set_level_info(mt
, level
, nr_images
,
297 width
, height
, depth
);
299 for (q
= 0; q
< nr_images
;) {
300 for (j
= 0; j
< pack_x_nr
&& q
< nr_images
; j
++, q
++) {
301 intel_miptree_set_image_offset(mt
, level
, q
, x
, y
);
310 mt
->total_height
+= y
;
312 if (pack_x_pitch
> 4) {
315 assert(pack_x_pitch
* pack_x_nr
<= mt
->pitch
);
318 if (pack_y_pitch
> 2) {
322 width
= minify(width
);
323 height
= minify(height
);
324 depth
= minify(depth
);
331 case GL_TEXTURE_RECTANGLE_ARB
:
332 i945_miptree_layout_2d(intel
, mt
);
335 _mesa_problem(NULL
, "Unexpected tex target in i945_miptree_layout()");
338 DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__
,
340 mt
->total_height
, mt
->cpp
, mt
->pitch
* mt
->total_height
* mt
->cpp
);