Merge remote branch 'origin/7.8'
[mesa.git] / src / mesa / drivers / dri / intel / intel_mipmap_tree.h
1 /**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #ifndef INTEL_MIPMAP_TREE_H
29 #define INTEL_MIPMAP_TREE_H
30
31 #include "intel_regions.h"
32
33 /* A layer on top of the intel_regions code which adds:
34 *
35 * - Code to size and layout a region to hold a set of mipmaps.
36 * - Query to determine if a new image fits in an existing tree.
37 * - More refcounting
38 * - maybe able to remove refcounting from intel_region?
39 * - ?
40 *
41 * The fixed mipmap layout of intel hardware where one offset
42 * specifies the position of all images in a mipmap hierachy
43 * complicates the implementation of GL texture image commands,
44 * compared to hardware where each image is specified with an
45 * independent offset.
46 *
47 * In an ideal world, each texture object would be associated with a
48 * single bufmgr buffer or 2d intel_region, and all the images within
49 * the texture object would slot into the tree as they arrive. The
50 * reality can be a little messier, as images can arrive from the user
51 * with sizes that don't fit in the existing tree, or in an order
52 * where the tree layout cannot be guessed immediately.
53 *
54 * This structure encodes an idealized mipmap tree. The GL image
55 * commands build these where possible, otherwise store the images in
56 * temporary system buffers.
57 */
58
59
60 /**
61 * Describes the location of each texture image within a texture region.
62 */
63 struct intel_mipmap_level
64 {
65 /** Offset to this miptree level, used in computing x_offset. */
66 GLuint level_x;
67 /** Offset to this miptree level, used in computing y_offset. */
68 GLuint level_y;
69 GLuint width;
70 GLuint height;
71 /** Depth of the mipmap at this level: 1 for 1D/2D/CUBE, n for 3D. */
72 GLuint depth;
73 /** Number of images at this level: 1 for 1D/2D, 6 for CUBE, depth for 3D */
74 GLuint nr_images;
75
76 /** @{
77 * offsets from level_[xy] to the image for each cube face or depth
78 * level.
79 *
80 * Pretty much have to accept that hardware formats
81 * are going to be so diverse that there is no unified way to
82 * compute the offsets of depth/cube images within a mipmap level,
83 * so have to store them as a lookup table.
84 */
85 GLuint *x_offset, *y_offset;
86 /** @} */
87 };
88
89 struct intel_mipmap_tree
90 {
91 /* Effectively the key:
92 */
93 GLenum target;
94 GLenum internal_format;
95
96 GLuint first_level;
97 GLuint last_level;
98
99 GLuint width0, height0, depth0; /**< Level zero image dimensions */
100 GLuint cpp;
101 GLboolean compressed;
102
103 /* Derived from the above:
104 */
105 GLuint total_width;
106 GLuint total_height;
107
108 /* Includes image offset tables:
109 */
110 struct intel_mipmap_level level[MAX_TEXTURE_LEVELS];
111
112 /* The data is held here:
113 */
114 struct intel_region *region;
115
116 /* These are also refcounted:
117 */
118 GLuint refcount;
119 };
120
121
122
123 struct intel_mipmap_tree *intel_miptree_create(struct intel_context *intel,
124 GLenum target,
125 GLenum base_format,
126 GLenum internal_format,
127 GLuint first_level,
128 GLuint last_level,
129 GLuint width0,
130 GLuint height0,
131 GLuint depth0,
132 GLuint cpp,
133 GLuint compress_byte,
134 GLboolean expect_accelerated_upload);
135
136 struct intel_mipmap_tree *
137 intel_miptree_create_for_region(struct intel_context *intel,
138 GLenum target,
139 GLenum internal_format,
140 GLuint first_level,
141 GLuint last_level,
142 struct intel_region *region,
143 GLuint depth0,
144 GLuint compress_byte);
145
146 int intel_miptree_pitch_align (struct intel_context *intel,
147 struct intel_mipmap_tree *mt,
148 uint32_t tiling,
149 int pitch);
150
151 void intel_miptree_reference(struct intel_mipmap_tree **dst,
152 struct intel_mipmap_tree *src);
153
154 void intel_miptree_release(struct intel_context *intel,
155 struct intel_mipmap_tree **mt);
156
157 /* Check if an image fits an existing mipmap tree layout
158 */
159 GLboolean intel_miptree_match_image(struct intel_mipmap_tree *mt,
160 struct gl_texture_image *image);
161
162 /* Return a pointer to an image within a tree. Return image stride as
163 * well.
164 */
165 GLubyte *intel_miptree_image_map(struct intel_context *intel,
166 struct intel_mipmap_tree *mt,
167 GLuint face,
168 GLuint level,
169 GLuint * row_stride, GLuint * image_stride);
170
171 void intel_miptree_image_unmap(struct intel_context *intel,
172 struct intel_mipmap_tree *mt);
173
174 void
175 intel_miptree_get_image_offset(struct intel_mipmap_tree *mt,
176 GLuint level, GLuint face, GLuint depth,
177 GLuint *x, GLuint *y);
178
179 void intel_miptree_set_level_info(struct intel_mipmap_tree *mt,
180 GLuint level,
181 GLuint nr_images,
182 GLuint x, GLuint y,
183 GLuint w, GLuint h, GLuint d);
184
185 void intel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
186 GLuint level,
187 GLuint img, GLuint x, GLuint y);
188
189 /* Upload an image into a tree
190 */
191 void intel_miptree_image_data(struct intel_context *intel,
192 struct intel_mipmap_tree *dst,
193 GLuint face,
194 GLuint level,
195 void *src,
196 GLuint src_row_pitch, GLuint src_image_pitch);
197
198 /* Copy an image between two trees
199 */
200 void intel_miptree_image_copy(struct intel_context *intel,
201 struct intel_mipmap_tree *dst,
202 GLuint face, GLuint level,
203 struct intel_mipmap_tree *src);
204
205 /* i915_mipmap_tree.c:
206 */
207 GLboolean i915_miptree_layout(struct intel_context *intel,
208 struct intel_mipmap_tree *mt,
209 uint32_t tiling);
210 GLboolean i945_miptree_layout(struct intel_context *intel,
211 struct intel_mipmap_tree *mt,
212 uint32_t tiling);
213 GLboolean brw_miptree_layout(struct intel_context *intel,
214 struct intel_mipmap_tree *mt,
215 uint32_t tiling);
216
217 #endif