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"
39 /* A layer on top of the intel_regions code which adds:
41 * - Code to size and layout a region to hold a set of mipmaps.
42 * - Query to determine if a new image fits in an existing tree.
44 * - maybe able to remove refcounting from intel_region?
47 * The fixed mipmap layout of intel hardware where one offset
48 * specifies the position of all images in a mipmap hierachy
49 * complicates the implementation of GL texture image commands,
50 * compared to hardware where each image is specified with an
53 * In an ideal world, each texture object would be associated with a
54 * single bufmgr buffer or 2d intel_region, and all the images within
55 * the texture object would slot into the tree as they arrive. The
56 * reality can be a little messier, as images can arrive from the user
57 * with sizes that don't fit in the existing tree, or in an order
58 * where the tree layout cannot be guessed immediately.
60 * This structure encodes an idealized mipmap tree. The GL image
61 * commands build these where possible, otherwise store the images in
62 * temporary system buffers.
65 struct intel_texture_image
;
68 * When calling intel_miptree_map() on an ETC-transcoded-to-RGB miptree or a
69 * depthstencil-split-to-separate-stencil miptree, we'll normally make a
70 * tmeporary and recreate the kind of data requested by Mesa core, since we're
71 * satisfying some glGetTexImage() request or something.
73 * However, occasionally you want to actually map the miptree's current data
74 * without transcoding back. This flag to intel_miptree_map() gets you that.
76 #define BRW_MAP_DIRECT_BIT 0x80000000
78 struct intel_miptree_map
{
79 /** Bitfield of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT, GL_MAP_INVALIDATE_BIT */
81 /** Region of interest for the map. */
83 /** Possibly malloced temporary buffer for the mapping. */
85 /** Possible pointer to a temporary linear miptree for the mapping. */
86 struct intel_mipmap_tree
*mt
;
87 /** Pointer to the start of (map_x, map_y) returned by the mapping. */
89 /** Stride of the mapping. */
94 * Describes the location of each texture image within a texture region.
96 struct intel_mipmap_level
98 /** Offset to this miptree level, used in computing x_offset. */
100 /** Offset to this miptree level, used in computing y_offset. */
106 * \brief Number of 2D slices in this miplevel.
108 * The exact semantics of depth varies according to the texture target:
109 * - For GL_TEXTURE_CUBE_MAP, depth is 6.
110 * - For GL_TEXTURE_2D_ARRAY, depth is the number of array slices. It is
111 * identical for all miplevels in the texture.
112 * - For GL_TEXTURE_3D, it is the texture's depth at this miplevel. Its
113 * value, like width and height, varies with miplevel.
114 * - For other texture types, depth is 1.
119 * \brief List of 2D images in this mipmap level.
121 * This may be a list of cube faces, array slices in 2D array texture, or
122 * layers in a 3D texture. The list's length is \c depth.
124 struct intel_mipmap_slice
{
126 * \name Offset to slice
129 * Hardware formats are so diverse that that there is no unified way to
130 * compute the slice offsets, so we store them in this table.
132 * The (x, y) offset to slice \c s at level \c l relative the miptrees
135 * x = mt->level[l].slice[s].x_offset
136 * y = mt->level[l].slice[s].y_offset
143 * Mapping information. Persistent for the duration of
144 * intel_miptree_map/unmap on this slice.
146 struct intel_miptree_map
*map
;
151 struct intel_mipmap_tree
153 /* Effectively the key:
158 * Generally, this is just the same as the gl_texture_image->TexFormat or
159 * gl_renderbuffer->Format.
161 * However, for textures and renderbuffers with packed depth/stencil formats
162 * on hardware where we want or need to use separate stencil, there will be
163 * two miptrees for storing the data. If the depthstencil texture or rb is
164 * MESA_FORMAT_Z32_FLOAT_X24S8, then mt->format will be
165 * MESA_FORMAT_Z32_FLOAT, otherwise for MESA_FORMAT_S8_Z24 objects it will be
166 * MESA_FORMAT_X8_Z24.
168 * For ETC1/ETC2 textures, this is one of the uncompressed mesa texture
169 * formats if the hardware lacks support for ETC1/ETC2. See @ref wraps_etc.
173 /** This variable stores the value of ETC compressed texture format */
174 gl_format etc_format
;
177 * The X offset of each image in the miptree must be aligned to this. See
178 * the "Alignment Unit Size" section of the BSpec.
180 unsigned int align_w
;
181 unsigned int align_h
; /**< \see align_w */
187 * Level zero image dimensions. These dimensions correspond to the
188 * physical layout of data in memory. Accordingly, they account for the
189 * extra width, height, and or depth that must be allocated in order to
190 * accommodate multisample formats, and they account for the extra factor
191 * of 6 in depth that must be allocated in order to accommodate cubemap
194 GLuint physical_width0
, physical_height0
, physical_depth0
;
200 * Level zero image dimensions. These dimensions correspond to the
201 * logical width, height, and depth of the region as seen by client code.
202 * Accordingly, they do not account for the extra width, height, and/or
203 * depth that must be allocated in order to accommodate multisample
204 * formats, nor do they account for the extra factor of 6 in depth that
205 * must be allocated in order to accommodate cubemap textures.
207 uint32_t logical_width0
, logical_height0
, logical_depth0
;
210 * For 1D array, 2D array, cube, and 2D multisampled surfaces on Gen7: true
211 * if the surface only contains LOD 0, and hence no space is for LOD's
212 * other than 0 in between array slices.
214 * Corresponds to the surface_array_spacing bit in gen7_surface_state.
216 bool array_spacing_lod0
;
218 /* Derived from the above:
223 /* Includes image offset tables:
225 struct intel_mipmap_level level
[MAX_TEXTURE_LEVELS
];
227 /* The data is held here:
229 struct intel_region
*region
;
231 /* Offset into region bo where miptree starts:
236 * \brief Stencil miptree for depthstencil textures.
238 * This miptree is used for depthstencil textures and renderbuffers that
239 * require separate stencil. It always has the true copy of the stencil
240 * bits, regardless of mt->format.
242 * \see intel_miptree_map_depthstencil()
243 * \see intel_miptree_unmap_depthstencil()
245 struct intel_mipmap_tree
*stencil_mt
;
247 /* These are also refcounted:
252 enum intel_miptree_tiling_mode
{
253 INTEL_MIPTREE_TILING_ANY
,
254 INTEL_MIPTREE_TILING_Y
,
255 INTEL_MIPTREE_TILING_NONE
,
258 struct intel_mipmap_tree
*intel_miptree_create(struct intel_context
*intel
,
266 bool expect_accelerated_upload
,
267 enum intel_miptree_tiling_mode
);
269 struct intel_mipmap_tree
*
270 intel_miptree_create_layout(struct intel_context
*intel
,
280 struct intel_mipmap_tree
*
281 intel_miptree_create_for_bo(struct intel_context
*intel
,
290 struct intel_mipmap_tree
*
291 intel_miptree_create_for_dri2_buffer(struct intel_context
*intel
,
292 unsigned dri_attachment
,
294 struct intel_region
*region
);
297 * Create a miptree appropriate as the storage for a non-texture renderbuffer.
298 * The miptree has the following properties:
299 * - The target is GL_TEXTURE_2D.
300 * - There are no levels other than the base level 0.
303 struct intel_mipmap_tree
*
304 intel_miptree_create_for_renderbuffer(struct intel_context
*intel
,
309 /** \brief Assert that the level and layer are valid for the miptree. */
311 intel_miptree_check_level_layer(struct intel_mipmap_tree
*mt
,
315 assert(level
>= mt
->first_level
);
316 assert(level
<= mt
->last_level
);
317 assert(layer
< mt
->level
[level
].depth
);
320 int intel_miptree_pitch_align (struct intel_context
*intel
,
321 struct intel_mipmap_tree
*mt
,
325 void intel_miptree_reference(struct intel_mipmap_tree
**dst
,
326 struct intel_mipmap_tree
*src
);
328 void intel_miptree_release(struct intel_mipmap_tree
**mt
);
330 /* Check if an image fits an existing mipmap tree layout
332 bool intel_miptree_match_image(struct intel_mipmap_tree
*mt
,
333 struct gl_texture_image
*image
);
336 intel_miptree_get_image_offset(struct intel_mipmap_tree
*mt
,
337 GLuint level
, GLuint slice
,
338 GLuint
*x
, GLuint
*y
);
341 intel_miptree_get_dimensions_for_image(struct gl_texture_image
*image
,
342 int *width
, int *height
, int *depth
);
345 intel_miptree_get_tile_offsets(struct intel_mipmap_tree
*mt
,
346 GLuint level
, GLuint slice
,
350 void intel_miptree_set_level_info(struct intel_mipmap_tree
*mt
,
353 GLuint w
, GLuint h
, GLuint d
);
355 void intel_miptree_set_image_offset(struct intel_mipmap_tree
*mt
,
357 GLuint img
, GLuint x
, GLuint y
);
360 intel_miptree_copy_teximage(struct intel_context
*intel
,
361 struct intel_texture_image
*intelImage
,
362 struct intel_mipmap_tree
*dst_mt
, bool invalidate
);
365 * Copy the stencil data from \c mt->stencil_mt->region to \c mt->region for
366 * the given miptree slice.
368 * \see intel_mipmap_tree::stencil_mt
371 intel_miptree_s8z24_scatter(struct intel_context
*intel
,
372 struct intel_mipmap_tree
*mt
,
377 * Copy the stencil data in \c mt->stencil_mt->region to \c mt->region for the
378 * given miptree slice.
380 * \see intel_mipmap_tree::stencil_mt
383 intel_miptree_s8z24_gather(struct intel_context
*intel
,
384 struct intel_mipmap_tree
*mt
,
390 /* i915_mipmap_tree.c:
392 void i915_miptree_layout(struct intel_mipmap_tree
*mt
);
393 void i945_miptree_layout(struct intel_mipmap_tree
*mt
);
394 void brw_miptree_layout(struct intel_context
*intel
,
395 struct intel_mipmap_tree
*mt
);
397 void *intel_miptree_map_raw(struct intel_context
*intel
,
398 struct intel_mipmap_tree
*mt
);
400 void intel_miptree_unmap_raw(struct intel_context
*intel
,
401 struct intel_mipmap_tree
*mt
);
404 intel_miptree_map(struct intel_context
*intel
,
405 struct intel_mipmap_tree
*mt
,
417 intel_miptree_unmap(struct intel_context
*intel
,
418 struct intel_mipmap_tree
*mt
,