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"
35 /* A layer on top of the intel_regions code which adds:
37 * - Code to size and layout a region to hold a set of mipmaps.
38 * - Query to determine if a new image fits in an existing tree.
40 * - maybe able to remove refcounting from intel_region?
43 * The fixed mipmap layout of intel hardware where one offset
44 * specifies the position of all images in a mipmap hierachy
45 * complicates the implementation of GL texture image commands,
46 * compared to hardware where each image is specified with an
49 * In an ideal world, each texture object would be associated with a
50 * single bufmgr buffer or 2d intel_region, and all the images within
51 * the texture object would slot into the tree as they arrive. The
52 * reality can be a little messier, as images can arrive from the user
53 * with sizes that don't fit in the existing tree, or in an order
54 * where the tree layout cannot be guessed immediately.
56 * This structure encodes an idealized mipmap tree. The GL image
57 * commands build these where possible, otherwise store the images in
58 * temporary system buffers.
61 struct intel_texture_image
;
64 * Describes the location of each texture image within a texture region.
66 struct intel_mipmap_level
68 /** Offset to this miptree level, used in computing x_offset. */
70 /** Offset to this miptree level, used in computing y_offset. */
76 * \brief Number of 2D slices in this miplevel.
78 * The exact semantics of depth varies according to the texture target:
79 * - For GL_TEXTURE_CUBE_MAP, depth is 6.
80 * - For GL_TEXTURE_2D_ARRAY, depth is the number of array slices. It is
81 * identical for all miplevels in the texture.
82 * - For GL_TEXTURE_3D, it is the texture's depth at this miplevel. Its
83 * value, like width and height, varies with miplevel.
84 * - For other texture types, depth is 1.
89 * \brief List of 2D images in this mipmap level.
91 * This may be a list of cube faces, array slices in 2D array texture, or
92 * layers in a 3D texture. The list's length is \c depth.
94 struct intel_mipmap_slice
{
96 * \name Offset to slice
99 * Hardware formats are so diverse that that there is no unified way to
100 * compute the slice offsets, so we store them in this table.
102 * The (x, y) offset to slice \c s at level \c l relative the miptrees
105 * x = mt->level[l].slice[s].x_offset
106 * y = mt->level[l].slice[s].y_offset
114 struct intel_mipmap_tree
116 /* Effectively the key:
124 GLuint width0
, height0
, depth0
; /**< Level zero image dimensions */
128 /* Derived from the above:
133 /* Includes image offset tables:
135 struct intel_mipmap_level level
[MAX_TEXTURE_LEVELS
];
137 /* The data is held here:
139 struct intel_region
*region
;
142 * This points to an auxillary hiz region if all of the following hold:
143 * 1. The texture has been attached to an FBO as a depthbuffer.
144 * 2. The texture format is hiz compatible.
145 * 3. The intel context supports hiz.
147 * When a texture is attached to multiple FBO's, a separate renderbuffer
148 * wrapper is created for each attachment. This necessitates storing the
149 * hiz region in the texture itself instead of the renderbuffer wrapper.
151 * \see intel_fbo.c:intel_wrap_texture()
153 struct intel_region
*hiz_region
;
155 /* These are also refcounted:
162 struct intel_mipmap_tree
*intel_miptree_create(struct intel_context
*intel
,
170 bool expect_accelerated_upload
);
172 struct intel_mipmap_tree
*
173 intel_miptree_create_for_region(struct intel_context
*intel
,
176 struct intel_region
*region
);
179 * Create a miptree appropriate as the storage for a non-texture renderbuffer.
180 * The miptree has the following properties:
181 * - The target is GL_TEXTURE_2D.
182 * - There are no levels other than the base level 0.
185 struct intel_mipmap_tree
*
186 intel_miptree_create_for_renderbuffer(struct intel_context
*intel
,
193 /** \brief Assert that the level and layer are valid for the miptree. */
195 intel_miptree_check_level_layer(struct intel_mipmap_tree
*mt
,
199 assert(level
>= mt
->first_level
);
200 assert(level
<= mt
->last_level
);
201 assert(layer
< mt
->level
[level
].depth
);
204 int intel_miptree_pitch_align (struct intel_context
*intel
,
205 struct intel_mipmap_tree
*mt
,
209 void intel_miptree_reference(struct intel_mipmap_tree
**dst
,
210 struct intel_mipmap_tree
*src
);
212 void intel_miptree_release(struct intel_mipmap_tree
**mt
);
214 /* Check if an image fits an existing mipmap tree layout
216 bool intel_miptree_match_image(struct intel_mipmap_tree
*mt
,
217 struct gl_texture_image
*image
);
220 intel_miptree_get_image_offset(struct intel_mipmap_tree
*mt
,
221 GLuint level
, GLuint face
, GLuint depth
,
222 GLuint
*x
, GLuint
*y
);
225 intel_miptree_get_dimensions_for_image(struct gl_texture_image
*image
,
226 int *width
, int *height
, int *depth
);
228 void intel_miptree_set_level_info(struct intel_mipmap_tree
*mt
,
231 GLuint w
, GLuint h
, GLuint d
);
233 void intel_miptree_set_image_offset(struct intel_mipmap_tree
*mt
,
235 GLuint img
, GLuint x
, GLuint y
);
238 intel_miptree_copy_teximage(struct intel_context
*intel
,
239 struct intel_texture_image
*intelImage
,
240 struct intel_mipmap_tree
*dst_mt
);
242 /* i915_mipmap_tree.c:
244 void i915_miptree_layout(struct intel_mipmap_tree
*mt
);
245 void i945_miptree_layout(struct intel_mipmap_tree
*mt
);
246 void brw_miptree_layout(struct intel_context
*intel
,
247 struct intel_mipmap_tree
*mt
);