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"
40 /* A layer on top of the intel_regions code which adds:
42 * - Code to size and layout a region to hold a set of mipmaps.
43 * - Query to determine if a new image fits in an existing tree.
45 * - maybe able to remove refcounting from intel_region?
48 * The fixed mipmap layout of intel hardware where one offset
49 * specifies the position of all images in a mipmap hierachy
50 * complicates the implementation of GL texture image commands,
51 * compared to hardware where each image is specified with an
54 * In an ideal world, each texture object would be associated with a
55 * single bufmgr buffer or 2d intel_region, and all the images within
56 * the texture object would slot into the tree as they arrive. The
57 * reality can be a little messier, as images can arrive from the user
58 * with sizes that don't fit in the existing tree, or in an order
59 * where the tree layout cannot be guessed immediately.
61 * This structure encodes an idealized mipmap tree. The GL image
62 * commands build these where possible, otherwise store the images in
63 * temporary system buffers.
66 struct intel_resolve_map
;
67 struct intel_texture_image
;
69 struct intel_miptree_map
{
70 /** Bitfield of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT, GL_MAP_INVALIDATE_BIT */
72 /** Region of interest for the map. */
74 /** Possibly malloced temporary buffer for the mapping. */
76 /** Possible pointer to a BO temporary for the mapping. */
78 /** Pointer to the start of (map_x, map_y) returned by the mapping. */
80 /** Stride of the mapping. */
85 * Describes the location of each texture image within a texture region.
87 struct intel_mipmap_level
89 /** Offset to this miptree level, used in computing x_offset. */
91 /** Offset to this miptree level, used in computing y_offset. */
97 * \brief Number of 2D slices in this miplevel.
99 * The exact semantics of depth varies according to the texture target:
100 * - For GL_TEXTURE_CUBE_MAP, depth is 6.
101 * - For GL_TEXTURE_2D_ARRAY, depth is the number of array slices. It is
102 * identical for all miplevels in the texture.
103 * - For GL_TEXTURE_3D, it is the texture's depth at this miplevel. Its
104 * value, like width and height, varies with miplevel.
105 * - For other texture types, depth is 1.
110 * \brief List of 2D images in this mipmap level.
112 * This may be a list of cube faces, array slices in 2D array texture, or
113 * layers in a 3D texture. The list's length is \c depth.
115 struct intel_mipmap_slice
{
117 * \name Offset to slice
120 * Hardware formats are so diverse that that there is no unified way to
121 * compute the slice offsets, so we store them in this table.
123 * The (x, y) offset to slice \c s at level \c l relative the miptrees
126 * x = mt->level[l].slice[s].x_offset
127 * y = mt->level[l].slice[s].y_offset
134 * Pointer to mapping information, present across
135 * intel_tex_image_map()/unmap of the slice.
137 struct intel_miptree_map
*map
;
141 struct intel_mipmap_tree
143 /* Effectively the key:
148 * Generally, this is just the same as the gl_texture_image->TexFormat or
149 * gl_renderbuffer->Format.
151 * However, for textures and renderbuffers with packed depth/stencil formats
152 * on hardware where we want or need to use separate stencil, there will be
153 * two miptrees for storing the data. If the depthstencil texture or rb is
154 * MESA_FORMAT_Z32_FLOAT_X24S8, then mt->format will be
155 * MESA_FORMAT_Z32_FLOAT, otherwise for MESA_FORMAT_S8_Z24 objects it will be
156 * MESA_FORMAT_X8_Z24.
161 * The X offset of each image in the miptree must be aligned to this. See
162 * the "Alignment Unit Size" section of the BSpec.
164 unsigned int align_w
;
165 unsigned int align_h
; /**< \see align_w */
170 GLuint width0
, height0
, depth0
; /**< Level zero image dimensions */
174 /* Derived from the above:
179 /* Includes image offset tables:
181 struct intel_mipmap_level level
[MAX_TEXTURE_LEVELS
];
183 /* The data is held here:
185 struct intel_region
*region
;
190 * This is non-null only if HiZ is enabled for this miptree.
192 * \see intel_miptree_alloc_hiz()
194 struct intel_mipmap_tree
*hiz_mt
;
197 * \brief Map of miptree slices to needed resolves.
199 * This is used only when the miptree has a child HiZ miptree.
201 * Let \c mt be a depth miptree with HiZ enabled. Then the resolve map is
202 * \c mt->hiz_map. The resolve map of the child HiZ miptree, \c
203 * mt->hiz_mt->hiz_map, is unused.
205 struct intel_resolve_map hiz_map
;
208 * \brief Stencil miptree for depthstencil textures.
210 * This miptree is used for depthstencil textures and renderbuffers that
211 * require separate stencil. It always has the true copy of the stencil
212 * bits, regardless of mt->format.
214 * \see intel_miptree_map_depthstencil()
215 * \see intel_miptree_unmap_depthstencil()
217 struct intel_mipmap_tree
*stencil_mt
;
219 /* These are also refcounted:
226 struct intel_mipmap_tree
*intel_miptree_create(struct intel_context
*intel
,
234 bool expect_accelerated_upload
);
236 struct intel_mipmap_tree
*
237 intel_miptree_create_for_region(struct intel_context
*intel
,
240 struct intel_region
*region
);
243 * Create a miptree appropriate as the storage for a non-texture renderbuffer.
244 * The miptree has the following properties:
245 * - The target is GL_TEXTURE_2D.
246 * - There are no levels other than the base level 0.
249 struct intel_mipmap_tree
*
250 intel_miptree_create_for_renderbuffer(struct intel_context
*intel
,
255 /** \brief Assert that the level and layer are valid for the miptree. */
257 intel_miptree_check_level_layer(struct intel_mipmap_tree
*mt
,
261 assert(level
>= mt
->first_level
);
262 assert(level
<= mt
->last_level
);
263 assert(layer
< mt
->level
[level
].depth
);
266 int intel_miptree_pitch_align (struct intel_context
*intel
,
267 struct intel_mipmap_tree
*mt
,
271 void intel_miptree_reference(struct intel_mipmap_tree
**dst
,
272 struct intel_mipmap_tree
*src
);
274 void intel_miptree_release(struct intel_mipmap_tree
**mt
);
276 /* Check if an image fits an existing mipmap tree layout
278 bool intel_miptree_match_image(struct intel_mipmap_tree
*mt
,
279 struct gl_texture_image
*image
);
282 intel_miptree_get_image_offset(struct intel_mipmap_tree
*mt
,
283 GLuint level
, GLuint face
, GLuint depth
,
284 GLuint
*x
, GLuint
*y
);
287 intel_miptree_get_dimensions_for_image(struct gl_texture_image
*image
,
288 int *width
, int *height
, int *depth
);
290 void intel_miptree_set_level_info(struct intel_mipmap_tree
*mt
,
293 GLuint w
, GLuint h
, GLuint d
);
295 void intel_miptree_set_image_offset(struct intel_mipmap_tree
*mt
,
297 GLuint img
, GLuint x
, GLuint y
);
300 intel_miptree_copy_teximage(struct intel_context
*intel
,
301 struct intel_texture_image
*intelImage
,
302 struct intel_mipmap_tree
*dst_mt
);
305 * Copy the stencil data from \c mt->stencil_mt->region to \c mt->region for
306 * the given miptree slice.
308 * \see intel_mipmap_tree::stencil_mt
311 intel_miptree_s8z24_scatter(struct intel_context
*intel
,
312 struct intel_mipmap_tree
*mt
,
317 * Copy the stencil data in \c mt->stencil_mt->region to \c mt->region for the
318 * given miptree slice.
320 * \see intel_mipmap_tree::stencil_mt
323 intel_miptree_s8z24_gather(struct intel_context
*intel
,
324 struct intel_mipmap_tree
*mt
,
329 * \name Miptree HiZ functions
332 * It is safe to call the "slice_set_need_resolve" and "slice_resolve"
333 * functions on a miptree without HiZ. In that case, each function is a no-op.
337 * \brief Allocate the miptree's embedded HiZ miptree.
338 * \see intel_mipmap_tree:hiz_mt
339 * \return false if allocation failed
343 intel_miptree_alloc_hiz(struct intel_context
*intel
,
344 struct intel_mipmap_tree
*mt
);
347 intel_miptree_slice_set_needs_hiz_resolve(struct intel_mipmap_tree
*mt
,
351 intel_miptree_slice_set_needs_depth_resolve(struct intel_mipmap_tree
*mt
,
355 intel_miptree_all_slices_set_need_hiz_resolve(struct intel_mipmap_tree
*mt
);
358 intel_miptree_all_slices_set_need_depth_resolve(struct intel_mipmap_tree
*mt
);
361 * \return false if no resolve was needed
364 intel_miptree_slice_resolve_hiz(struct intel_context
*intel
,
365 struct intel_mipmap_tree
*mt
,
370 * \return false if no resolve was needed
373 intel_miptree_slice_resolve_depth(struct intel_context
*intel
,
374 struct intel_mipmap_tree
*mt
,
379 * \return false if no resolve was needed
382 intel_miptree_all_slices_resolve_hiz(struct intel_context
*intel
,
383 struct intel_mipmap_tree
*mt
);
386 * \return false if no resolve was needed
389 intel_miptree_all_slices_resolve_depth(struct intel_context
*intel
,
390 struct intel_mipmap_tree
*mt
);
394 /* i915_mipmap_tree.c:
396 void i915_miptree_layout(struct intel_mipmap_tree
*mt
);
397 void i945_miptree_layout(struct intel_mipmap_tree
*mt
);
398 void brw_miptree_layout(struct intel_context
*intel
,
399 struct intel_mipmap_tree
*mt
);
402 intel_miptree_map(struct intel_context
*intel
,
403 struct intel_mipmap_tree
*mt
,
415 intel_miptree_unmap(struct intel_context
*intel
,
416 struct intel_mipmap_tree
*mt
,