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 #ifndef INTEL_MIPMAP_TREE_H
29 #define INTEL_MIPMAP_TREE_H
33 #include "intel_regions.h"
34 #include "intel_resolve_map.h"
36 /* A layer on top of the intel_regions code which adds:
38 * - Code to size and layout a region to hold a set of mipmaps.
39 * - Query to determine if a new image fits in an existing tree.
41 * - maybe able to remove refcounting from intel_region?
44 * The fixed mipmap layout of intel hardware where one offset
45 * specifies the position of all images in a mipmap hierachy
46 * complicates the implementation of GL texture image commands,
47 * compared to hardware where each image is specified with an
50 * In an ideal world, each texture object would be associated with a
51 * single bufmgr buffer or 2d intel_region, and all the images within
52 * the texture object would slot into the tree as they arrive. The
53 * reality can be a little messier, as images can arrive from the user
54 * with sizes that don't fit in the existing tree, or in an order
55 * where the tree layout cannot be guessed immediately.
57 * This structure encodes an idealized mipmap tree. The GL image
58 * commands build these where possible, otherwise store the images in
59 * temporary system buffers.
62 struct intel_resolve_map
;
63 struct intel_texture_image
;
66 * Describes the location of each texture image within a texture region.
68 struct intel_mipmap_level
70 /** Offset to this miptree level, used in computing x_offset. */
72 /** Offset to this miptree level, used in computing y_offset. */
78 * \brief Number of 2D slices in this miplevel.
80 * The exact semantics of depth varies according to the texture target:
81 * - For GL_TEXTURE_CUBE_MAP, depth is 6.
82 * - For GL_TEXTURE_2D_ARRAY, depth is the number of array slices. It is
83 * identical for all miplevels in the texture.
84 * - For GL_TEXTURE_3D, it is the texture's depth at this miplevel. Its
85 * value, like width and height, varies with miplevel.
86 * - For other texture types, depth is 1.
91 * \brief List of 2D images in this mipmap level.
93 * This may be a list of cube faces, array slices in 2D array texture, or
94 * layers in a 3D texture. The list's length is \c depth.
96 struct intel_mipmap_slice
{
98 * \name Offset to slice
101 * Hardware formats are so diverse that that there is no unified way to
102 * compute the slice offsets, so we store them in this table.
104 * The (x, y) offset to slice \c s at level \c l relative the miptrees
107 * x = mt->level[l].slice[s].x_offset
108 * y = mt->level[l].slice[s].y_offset
116 struct intel_mipmap_tree
118 /* Effectively the key:
124 * The X offset of each image in the miptree must be aligned to this. See
125 * the "Alignment Unit Size" section of the BSpec.
127 unsigned int align_w
;
128 unsigned int align_h
; /**< \see align_w */
133 GLuint width0
, height0
, depth0
; /**< Level zero image dimensions */
137 /* Derived from the above:
142 /* Includes image offset tables:
144 struct intel_mipmap_level level
[MAX_TEXTURE_LEVELS
];
146 /* The data is held here:
148 struct intel_region
*region
;
153 * This is non-null only if HiZ is enabled for this miptree.
155 * \see intel_miptree_alloc_hiz()
157 struct intel_mipmap_tree
*hiz_mt
;
160 * \brief Map of miptree slices to needed resolves.
162 * This is used only when the miptree has a child HiZ miptree.
164 * Let \c mt be a depth miptree with HiZ enabled. Then the resolve map is
165 * \c mt->hiz_map. The resolve map of the child HiZ miptree, \c
166 * mt->hiz_mt->hiz_map, is unused.
168 struct intel_resolve_map hiz_map
;
171 * \brief Stencil miptree for depthstencil textures.
173 * This miptree is used for depthstencil textures that require separate
174 * stencil. The stencil miptree's data is the golden copy of the
175 * parent miptree's stencil bits. When necessary, we scatter/gather the
176 * stencil bits between the parent miptree and the stencil miptree.
178 * \see intel_miptree_s8z24_scatter()
179 * \see intel_miptree_s8z24_gather()
181 struct intel_mipmap_tree
*stencil_mt
;
183 /* These are also refcounted:
190 struct intel_mipmap_tree
*intel_miptree_create(struct intel_context
*intel
,
198 bool expect_accelerated_upload
);
200 struct intel_mipmap_tree
*
201 intel_miptree_create_for_region(struct intel_context
*intel
,
204 struct intel_region
*region
);
207 * Create a miptree appropriate as the storage for a non-texture renderbuffer.
208 * The miptree has the following properties:
209 * - The target is GL_TEXTURE_2D.
210 * - There are no levels other than the base level 0.
213 struct intel_mipmap_tree
*
214 intel_miptree_create_for_renderbuffer(struct intel_context
*intel
,
221 /** \brief Assert that the level and layer are valid for the miptree. */
223 intel_miptree_check_level_layer(struct intel_mipmap_tree
*mt
,
227 assert(level
>= mt
->first_level
);
228 assert(level
<= mt
->last_level
);
229 assert(layer
< mt
->level
[level
].depth
);
232 int intel_miptree_pitch_align (struct intel_context
*intel
,
233 struct intel_mipmap_tree
*mt
,
237 void intel_miptree_reference(struct intel_mipmap_tree
**dst
,
238 struct intel_mipmap_tree
*src
);
240 void intel_miptree_release(struct intel_mipmap_tree
**mt
);
242 /* Check if an image fits an existing mipmap tree layout
244 bool intel_miptree_match_image(struct intel_mipmap_tree
*mt
,
245 struct gl_texture_image
*image
);
248 intel_miptree_get_image_offset(struct intel_mipmap_tree
*mt
,
249 GLuint level
, GLuint face
, GLuint depth
,
250 GLuint
*x
, GLuint
*y
);
253 intel_miptree_get_dimensions_for_image(struct gl_texture_image
*image
,
254 int *width
, int *height
, int *depth
);
256 void intel_miptree_set_level_info(struct intel_mipmap_tree
*mt
,
259 GLuint w
, GLuint h
, GLuint d
);
261 void intel_miptree_set_image_offset(struct intel_mipmap_tree
*mt
,
263 GLuint img
, GLuint x
, GLuint y
);
266 intel_miptree_copy_teximage(struct intel_context
*intel
,
267 struct intel_texture_image
*intelImage
,
268 struct intel_mipmap_tree
*dst_mt
);
271 * Copy the stencil data from \c mt->stencil_mt->region to \c mt->region for
272 * the given miptree slice.
274 * \see intel_mipmap_tree::stencil_mt
277 intel_miptree_s8z24_scatter(struct intel_context
*intel
,
278 struct intel_mipmap_tree
*mt
,
283 * Copy the stencil data in \c mt->stencil_mt->region to \c mt->region for the
284 * given miptree slice.
286 * \see intel_mipmap_tree::stencil_mt
289 intel_miptree_s8z24_gather(struct intel_context
*intel
,
290 struct intel_mipmap_tree
*mt
,
295 * \name Miptree HiZ functions
298 * It is safe to call the "slice_set_need_resolve" and "slice_resolve"
299 * functions on a miptree without HiZ. In that case, each function is a no-op.
303 * \brief Allocate the miptree's embedded HiZ miptree.
304 * \see intel_mipmap_tree:hiz_mt
305 * \return false if allocation failed
309 intel_miptree_alloc_hiz(struct intel_context
*intel
,
310 struct intel_mipmap_tree
*mt
);
313 intel_miptree_slice_set_needs_hiz_resolve(struct intel_mipmap_tree
*mt
,
317 intel_miptree_slice_set_needs_depth_resolve(struct intel_mipmap_tree
*mt
,
321 intel_miptree_all_slices_set_need_hiz_resolve(struct intel_mipmap_tree
*mt
);
324 intel_miptree_all_slices_set_need_depth_resolve(struct intel_mipmap_tree
*mt
);
327 * \return false if no resolve was needed
330 intel_miptree_slice_resolve_hiz(struct intel_context
*intel
,
331 struct intel_mipmap_tree
*mt
,
336 * \return false if no resolve was needed
339 intel_miptree_slice_resolve_depth(struct intel_context
*intel
,
340 struct intel_mipmap_tree
*mt
,
345 * \return false if no resolve was needed
348 intel_miptree_all_slices_resolve_hiz(struct intel_context
*intel
,
349 struct intel_mipmap_tree
*mt
);
352 * \return false if no resolve was needed
355 intel_miptree_all_slices_resolve_depth(struct intel_context
*intel
,
356 struct intel_mipmap_tree
*mt
);
360 /* i915_mipmap_tree.c:
362 void i915_miptree_layout(struct intel_mipmap_tree
*mt
);
363 void i945_miptree_layout(struct intel_mipmap_tree
*mt
);
364 void brw_miptree_layout(struct intel_context
*intel
,
365 struct intel_mipmap_tree
*mt
);
368 intel_miptree_map(struct intel_context
*intel
,
369 struct intel_mipmap_tree
*mt
,
381 intel_miptree_unmap(struct intel_context
*intel
,
382 struct intel_mipmap_tree
*mt
,