intel: Add a helper function for getting miptree size from a texture image.
[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 struct intel_texture_image;
60
61 /**
62 * Describes the location of each texture image within a texture region.
63 */
64 struct intel_mipmap_level
65 {
66 /** Offset to this miptree level, used in computing x_offset. */
67 GLuint level_x;
68 /** Offset to this miptree level, used in computing y_offset. */
69 GLuint level_y;
70 GLuint width;
71 GLuint height;
72 /** Depth of the mipmap at this level: 1 for 1D/2D/CUBE, n for 3D. */
73 GLuint depth;
74 /** Number of images at this level: 1 for 1D/2D, 6 for CUBE, depth for 3D */
75 GLuint nr_images;
76
77 /** @{
78 * offsets from level_[xy] to the image for each cube face or depth
79 * level.
80 *
81 * Pretty much have to accept that hardware formats
82 * are going to be so diverse that there is no unified way to
83 * compute the offsets of depth/cube images within a mipmap level,
84 * so have to store them as a lookup table.
85 */
86 GLuint *x_offset, *y_offset;
87 /** @} */
88 };
89
90 struct intel_mipmap_tree
91 {
92 /* Effectively the key:
93 */
94 GLenum target;
95 gl_format format;
96
97 GLuint first_level;
98 GLuint last_level;
99
100 GLuint width0, height0, depth0; /**< Level zero image dimensions */
101 GLuint cpp;
102 GLboolean compressed;
103
104 /* Derived from the above:
105 */
106 GLuint total_width;
107 GLuint total_height;
108
109 /* Includes image offset tables:
110 */
111 struct intel_mipmap_level level[MAX_TEXTURE_LEVELS];
112
113 /* The data is held here:
114 */
115 struct intel_region *region;
116
117 /**
118 * This points to an auxillary hiz region if all of the following hold:
119 * 1. The texture has been attached to an FBO as a depthbuffer.
120 * 2. The texture format is hiz compatible.
121 * 3. The intel context supports hiz.
122 *
123 * When a texture is attached to multiple FBO's, a separate renderbuffer
124 * wrapper is created for each attachment. This necessitates storing the
125 * hiz region in the texture itself instead of the renderbuffer wrapper.
126 *
127 * \see intel_fbo.c:intel_wrap_texture()
128 */
129 struct intel_region *hiz_region;
130
131 /* These are also refcounted:
132 */
133 GLuint refcount;
134 };
135
136
137
138 struct intel_mipmap_tree *intel_miptree_create(struct intel_context *intel,
139 GLenum target,
140 gl_format format,
141 GLuint first_level,
142 GLuint last_level,
143 GLuint width0,
144 GLuint height0,
145 GLuint depth0,
146 GLboolean expect_accelerated_upload);
147
148 struct intel_mipmap_tree *
149 intel_miptree_create_for_region(struct intel_context *intel,
150 GLenum target,
151 gl_format format,
152 struct intel_region *region);
153
154 int intel_miptree_pitch_align (struct intel_context *intel,
155 struct intel_mipmap_tree *mt,
156 uint32_t tiling,
157 int pitch);
158
159 void intel_miptree_reference(struct intel_mipmap_tree **dst,
160 struct intel_mipmap_tree *src);
161
162 void intel_miptree_release(struct intel_mipmap_tree **mt);
163
164 /* Check if an image fits an existing mipmap tree layout
165 */
166 GLboolean intel_miptree_match_image(struct intel_mipmap_tree *mt,
167 struct gl_texture_image *image);
168
169 void
170 intel_miptree_get_image_offset(struct intel_mipmap_tree *mt,
171 GLuint level, GLuint face, GLuint depth,
172 GLuint *x, GLuint *y);
173
174 void
175 intel_miptree_get_dimensions_for_image(struct gl_texture_image *image,
176 int *width, int *height, int *depth);
177
178 void intel_miptree_set_level_info(struct intel_mipmap_tree *mt,
179 GLuint level,
180 GLuint nr_images,
181 GLuint x, GLuint y,
182 GLuint w, GLuint h, GLuint d);
183
184 void intel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
185 GLuint level,
186 GLuint img, GLuint x, GLuint y);
187
188 void
189 intel_miptree_copy_teximage(struct intel_context *intel,
190 struct intel_texture_image *intelImage,
191 struct intel_mipmap_tree *dst_mt);
192
193 /* i915_mipmap_tree.c:
194 */
195 void i915_miptree_layout(struct intel_mipmap_tree *mt);
196 void i945_miptree_layout(struct intel_mipmap_tree *mt);
197 void brw_miptree_layout(struct intel_context *intel,
198 struct intel_mipmap_tree *mt);
199
200 #endif