Merge git://proxy01.pd.intel.com:9419/git/mesa/mesa into crestline
[mesa.git] / src / mesa / drivers / dri / i965 / brw_tex_layout.c
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 "macros.h"
39
40
41 GLboolean brw_miptree_layout( struct intel_mipmap_tree *mt )
42 {
43 /* XXX: these vary depending on image format:
44 */
45 /* GLint align_w = 4; */
46
47 switch (mt->target) {
48 case GL_TEXTURE_CUBE_MAP:
49 case GL_TEXTURE_3D: {
50 GLuint width = mt->width0;
51 GLuint height = mt->height0;
52 GLuint depth = mt->depth0;
53 GLuint pack_x_pitch, pack_x_nr;
54 GLuint pack_y_pitch;
55 GLuint level;
56
57 mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp;
58 mt->total_height = 0;
59
60 pack_y_pitch = MAX2(mt->height0, 2);
61 pack_x_pitch = mt->pitch;
62 pack_x_nr = 1;
63
64 for ( level = mt->first_level ; level <= mt->last_level ; level++ ) {
65 GLuint nr_images = mt->target == GL_TEXTURE_3D ? depth : 6;
66 GLint x = 0;
67 GLint y = 0;
68 GLint q, j;
69
70 intel_miptree_set_level_info(mt, level, nr_images,
71 0, mt->total_height,
72 width, height, depth);
73
74 for (q = 0; q < nr_images;) {
75 for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) {
76 intel_miptree_set_image_offset(mt, level, q, x, y);
77 x += pack_x_pitch;
78 }
79
80 x = 0;
81 y += pack_y_pitch;
82 }
83
84
85 mt->total_height += y;
86
87 if (pack_x_pitch > 4) {
88 pack_x_pitch >>= 1;
89 pack_x_nr <<= 1;
90 assert(pack_x_pitch * pack_x_nr <= mt->pitch);
91 }
92
93 if (pack_y_pitch > 2) {
94 pack_y_pitch >>= 1;
95 }
96
97 width = minify(width);
98 height = minify(height);
99 depth = minify(depth);
100 }
101 break;
102 }
103
104 default:
105 i945_miptree_layout_2d(mt);
106 break;
107 }
108 DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__,
109 mt->pitch,
110 mt->total_height,
111 mt->cpp,
112 mt->pitch * mt->total_height * mt->cpp );
113
114 return GL_TRUE;
115 }
116