intel: Kill intel_mipmap_level::nr_images [v4]
[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
73 /**
74 * \brief Number of 2D slices in this miplevel.
75 *
76 * The exact semantics of depth varies according to the texture target:
77 * - For GL_TEXTURE_CUBE_MAP, depth is 6.
78 * - For GL_TEXTURE_2D_ARRAY, depth is the number of array slices. It is
79 * identical for all miplevels in the texture.
80 * - For GL_TEXTURE_3D, it is the texture's depth at this miplevel. Its
81 * value, like width and height, varies with miplevel.
82 * - For other texture types, depth is 1.
83 */
84 GLuint depth;
85
86 /**
87 * \brief List of 2D images in this mipmap level.
88 *
89 * This may be a list of cube faces, array slices in 2D array texture, or
90 * layers in a 3D texture. The list's length is \c depth.
91 */
92 struct intel_mipmap_slice {
93 /**
94 * \name Offset to slice
95 * \{
96 *
97 * Hardware formats are so diverse that that there is no unified way to
98 * compute the slice offsets, so we store them in this table.
99 *
100 * The (x, y) offset to slice \c s at level \c l relative the miptrees
101 * base address is
102 * \code
103 * x = mt->level[l].slice[s].x_offset
104 * y = mt->level[l].slice[s].y_offset
105 */
106 GLuint x_offset;
107 GLuint y_offset;
108 /** \} */
109 } *slice;
110 };
111
112 struct intel_mipmap_tree
113 {
114 /* Effectively the key:
115 */
116 GLenum target;
117 gl_format format;
118
119 GLuint first_level;
120 GLuint last_level;
121
122 GLuint width0, height0, depth0; /**< Level zero image dimensions */
123 GLuint cpp;
124 bool compressed;
125
126 /* Derived from the above:
127 */
128 GLuint total_width;
129 GLuint total_height;
130
131 /* Includes image offset tables:
132 */
133 struct intel_mipmap_level level[MAX_TEXTURE_LEVELS];
134
135 /* The data is held here:
136 */
137 struct intel_region *region;
138
139 /**
140 * This points to an auxillary hiz region if all of the following hold:
141 * 1. The texture has been attached to an FBO as a depthbuffer.
142 * 2. The texture format is hiz compatible.
143 * 3. The intel context supports hiz.
144 *
145 * When a texture is attached to multiple FBO's, a separate renderbuffer
146 * wrapper is created for each attachment. This necessitates storing the
147 * hiz region in the texture itself instead of the renderbuffer wrapper.
148 *
149 * \see intel_fbo.c:intel_wrap_texture()
150 */
151 struct intel_region *hiz_region;
152
153 /* These are also refcounted:
154 */
155 GLuint refcount;
156 };
157
158
159
160 struct intel_mipmap_tree *intel_miptree_create(struct intel_context *intel,
161 GLenum target,
162 gl_format format,
163 GLuint first_level,
164 GLuint last_level,
165 GLuint width0,
166 GLuint height0,
167 GLuint depth0,
168 bool expect_accelerated_upload);
169
170 struct intel_mipmap_tree *
171 intel_miptree_create_for_region(struct intel_context *intel,
172 GLenum target,
173 gl_format format,
174 struct intel_region *region);
175
176 /**
177 * Create a miptree appropriate as the storage for a non-texture renderbuffer.
178 * The miptree has the following properties:
179 * - The target is GL_TEXTURE_2D.
180 * - There are no levels other than the base level 0.
181 * - Depth is 1.
182 */
183 struct intel_mipmap_tree*
184 intel_miptree_create_for_renderbuffer(struct intel_context *intel,
185 gl_format format,
186 uint32_t tiling,
187 uint32_t cpp,
188 uint32_t width,
189 uint32_t height);
190
191 int intel_miptree_pitch_align (struct intel_context *intel,
192 struct intel_mipmap_tree *mt,
193 uint32_t tiling,
194 int pitch);
195
196 void intel_miptree_reference(struct intel_mipmap_tree **dst,
197 struct intel_mipmap_tree *src);
198
199 void intel_miptree_release(struct intel_mipmap_tree **mt);
200
201 /* Check if an image fits an existing mipmap tree layout
202 */
203 bool intel_miptree_match_image(struct intel_mipmap_tree *mt,
204 struct gl_texture_image *image);
205
206 void
207 intel_miptree_get_image_offset(struct intel_mipmap_tree *mt,
208 GLuint level, GLuint face, GLuint depth,
209 GLuint *x, GLuint *y);
210
211 void
212 intel_miptree_get_dimensions_for_image(struct gl_texture_image *image,
213 int *width, int *height, int *depth);
214
215 void intel_miptree_set_level_info(struct intel_mipmap_tree *mt,
216 GLuint level,
217 GLuint x, GLuint y,
218 GLuint w, GLuint h, GLuint d);
219
220 void intel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
221 GLuint level,
222 GLuint img, GLuint x, GLuint y);
223
224 void
225 intel_miptree_copy_teximage(struct intel_context *intel,
226 struct intel_texture_image *intelImage,
227 struct intel_mipmap_tree *dst_mt);
228
229 /* i915_mipmap_tree.c:
230 */
231 void i915_miptree_layout(struct intel_mipmap_tree *mt);
232 void i945_miptree_layout(struct intel_mipmap_tree *mt);
233 void brw_miptree_layout(struct intel_context *intel,
234 struct intel_mipmap_tree *mt);
235
236 #endif