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"
34
#include "intel_context.h"
36
#define FILE_DEBUG_FLAG DEBUG_TEXTURE
38
static GLint initial_offsets[6][2] = { {0, 0},
47
static GLint step_offsets[6][2] = { {0, 2},
58
return MAX2(1, d >> 1);
62
i915_miptree_layout(struct intel_mipmap_tree * mt)
67
case GL_TEXTURE_CUBE_MAP:{
68
const GLuint dim = mt->width0;
71
/* double pitch for cube layouts */
72
mt->pitch = ((dim * mt->cpp * 2 + 3) & ~3) / mt->cpp;
73
mt->total_height = dim * 4;
75
for (level = mt->first_level; level <= mt->last_level; level++)
76
intel_miptree_set_level_info(mt, level, 6,
78
mt->pitch, mt->total_height, 1);
80
for (face = 0; face < 6; face++) {
81
GLuint x = initial_offsets[face][0] * dim;
82
GLuint y = initial_offsets[face][1] * dim;
85
for (level = mt->first_level; level <= mt->last_level; level++) {
86
intel_miptree_set_image_offset(mt, level, face, x, y);
89
_mesa_printf("cube mipmap %d/%d (%d..%d) is 0x0\n",
90
face, level, mt->first_level, mt->last_level);
93
x += step_offsets[face][0] * d;
94
y += step_offsets[face][1] * d;
100
GLuint width = mt->width0;
101
GLuint height = mt->height0;
102
GLuint depth = mt->depth0;
103
GLuint stack_height = 0;
105
/* Calculate the size of a single slice.
107
mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp;
109
/* XXX: hardware expects/requires 9 levels at minimum.
111
for (level = mt->first_level; level <= MAX2(8, mt->last_level);
113
intel_miptree_set_level_info(mt, level, 1, 0, mt->total_height,
114
width, height, depth);
117
stack_height += MAX2(2, height);
119
width = minify(width);
120
height = minify(height);
121
depth = minify(depth);
124
/* Fixup depth image_offsets:
127
for (level = mt->first_level; level <= mt->last_level; level++) {
129
for (i = 0; i < depth; i++)
130
intel_miptree_set_image_offset(mt, level, i,
131
0, i * stack_height);
133
depth = minify(depth);
137
/* Multiply slice size by texture depth for total size. It's
138
* remarkable how wasteful of memory the i915 texture layouts
139
* are. They are largely fixed in the i945.
141
mt->total_height = stack_height * mt->depth0;
146
GLuint width = mt->width0;
147
GLuint height = mt->height0;
150
mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp;
151
mt->total_height = 0;
153
for (level = mt->first_level; level <= mt->last_level; level++) {
154
intel_miptree_set_level_info(mt, level, 1,
159
img_height = MAX2(1, height / 4);
161
img_height = MAX2(2, height);
163
mt->total_height += img_height;
164
mt->total_height += 1;
165
mt->total_height &= ~1;
167
width = minify(width);
168
height = minify(height);
173
DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__,
175
mt->total_height, mt->cpp, mt->pitch * mt->total_height * mt->cpp);
182
i945_miptree_layout(struct intel_mipmap_tree * mt)
186
switch (mt->target) {
187
case GL_TEXTURE_CUBE_MAP:{
188
const GLuint dim = mt->width0;
191
/* Depending on the size of the largest images, pitch can be
192
* determined either by the old-style packing of cubemap faces,
193
* or the final row of 4x4, 2x2 and 1x1 faces below this.
196
mt->pitch = ((dim * mt->cpp * 2 + 3) & ~3) / mt->cpp;
200
mt->total_height = dim * 4 + 4;
202
/* Set all the levels to effectively occupy the whole rectangular region.
204
for (level = mt->first_level; level <= mt->last_level; level++)
205
intel_miptree_set_level_info(mt, level, 6,
207
mt->pitch, mt->total_height, 1);
211
for (face = 0; face < 6; face++) {
212
GLuint x = initial_offsets[face][0] * dim;
213
GLuint y = initial_offsets[face][1] * dim;
216
if (dim == 4 && face >= 4) {
217
y = mt->total_height - 4;
221
y = mt->total_height - 4;
225
for (level = mt->first_level; level <= mt->last_level; level++) {
226
intel_miptree_set_image_offset(mt, level, face, x, y);
235
x += step_offsets[face][0] * d;
236
y += step_offsets[face][1] * d;
245
y = mt->total_height - 4;
251
y = mt->total_height - 4;
260
x += step_offsets[face][0] * d;
261
y += step_offsets[face][1] * d;
269
GLuint width = mt->width0;
270
GLuint height = mt->height0;
271
GLuint depth = mt->depth0;
272
GLuint pack_x_pitch, pack_x_nr;
276
mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp;
277
mt->total_height = 0;
279
pack_y_pitch = MAX2(mt->height0, 2);
280
pack_x_pitch = mt->pitch;
283
for (level = mt->first_level; level <= mt->last_level; level++) {
284
GLuint nr_images = mt->target == GL_TEXTURE_3D ? depth : 6;
289
intel_miptree_set_level_info(mt, level, nr_images,
291
width, height, depth);
293
for (q = 0; q < nr_images;) {
294
for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) {
295
intel_miptree_set_image_offset(mt, level, q, x, y);
304
mt->total_height += y;
306
if (pack_x_pitch > 4) {
309
assert(pack_x_pitch * pack_x_nr <= mt->pitch);
312
if (pack_y_pitch > 2) {
316
width = minify(width);
317
height = minify(height);
318
depth = minify(depth);
325
case GL_TEXTURE_RECTANGLE_ARB:{
328
GLuint width = mt->width0;
329
GLuint height = mt->height0;
332
mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp;
333
mt->total_height = 0;
335
for (level = mt->first_level; level <= mt->last_level; level++) {
338
intel_miptree_set_level_info(mt, level, 1,
341
mt->compressed ? height/4 : height, 1);
345
img_height = MAX2(1, height / 4);
347
img_height = MAX2(align_h, height);
349
/* LPT change: step right after second mipmap.
351
if (level == mt->first_level + 1) {
361
/* Because the images are packed better, the final offset
362
* might not be the maximal one:
364
mt->total_height = MAX2(mt->total_height, y);
366
width = minify(width);
367
height = minify(height);
372
_mesa_problem(NULL, "Unexpected tex target in i945_miptree_layout()");
375
DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__,
377
mt->total_height, mt->cpp, mt->pitch * mt->total_height * mt->cpp);