1 #include "main/mtypes.h"
2 #include "main/macros.h"
3 #include "main/samplerobj.h"
5 #include "intel_context.h"
6 #include "intel_mipmap_tree.h"
9 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
12 * When validating, we only care about the texture images that could
13 * be seen, so for non-mipmapped modes we want to ignore everything
17 intel_update_max_level(struct intel_texture_object
*intelObj
,
18 struct gl_sampler_object
*sampler
)
20 struct gl_texture_object
*tObj
= &intelObj
->base
;
22 if (sampler
->MinFilter
== GL_NEAREST
||
23 sampler
->MinFilter
== GL_LINEAR
) {
24 intelObj
->_MaxLevel
= tObj
->BaseLevel
;
26 intelObj
->_MaxLevel
= tObj
->_MaxLevel
;
31 * Copies the image's contents at its level into the object's miptree,
32 * and updates the image to point at the object's miptree.
35 copy_image_data_to_tree(struct intel_context
*intel
,
36 struct intel_texture_object
*intelObj
,
37 struct intel_texture_image
*intelImage
)
40 /* Copy potentially with the blitter:
42 intel_miptree_image_copy(intel
,
44 intelImage
->base
.Face
,
45 intelImage
->base
.Level
, intelImage
->mt
);
47 intel_miptree_release(intel
, &intelImage
->mt
);
50 assert(intelImage
->base
.Data
!= NULL
);
52 /* More straightforward upload.
54 intel_miptree_image_data(intel
,
56 intelImage
->base
.Face
,
57 intelImage
->base
.Level
,
58 intelImage
->base
.Data
,
59 intelImage
->base
.RowStride
,
60 intelImage
->base
.RowStride
*
61 intelImage
->base
.Height
);
62 _mesa_align_free(intelImage
->base
.Data
);
63 intelImage
->base
.Data
= NULL
;
66 intel_miptree_reference(&intelImage
->mt
, intelObj
->mt
);
73 intel_finalize_mipmap_tree(struct intel_context
*intel
, GLuint unit
)
75 struct gl_context
*ctx
= &intel
->ctx
;
76 struct gl_texture_object
*tObj
= intel
->ctx
.Texture
.Unit
[unit
]._Current
;
77 struct intel_texture_object
*intelObj
= intel_texture_object(tObj
);
78 struct gl_sampler_object
*sampler
= _mesa_get_samplerobj(ctx
, unit
);
81 struct intel_texture_image
*firstImage
;
83 /* We know/require this is true by now:
85 assert(intelObj
->base
._Complete
);
87 /* What levels must the tree include at a minimum?
89 intel_update_max_level(intelObj
, sampler
);
90 firstImage
= intel_texture_image(tObj
->Image
[0][tObj
->BaseLevel
]);
94 if (firstImage
->base
.Border
) {
96 intel_miptree_release(intel
, &intelObj
->mt
);
101 /* Check tree can hold all active levels. Check tree matches
102 * target, imageFormat, etc.
104 * For pre-gen4, we have to match first_level == tObj->BaseLevel,
105 * because we don't have the control that gen4 does to make min/mag
106 * determination happen at a nonzero (hardware) baselevel. Because
107 * of that, we just always relayout on baselevel change.
110 (intelObj
->mt
->target
!= intelObj
->base
.Target
||
111 intelObj
->mt
->format
!= firstImage
->base
.TexFormat
||
112 intelObj
->mt
->first_level
!= tObj
->BaseLevel
||
113 intelObj
->mt
->last_level
< intelObj
->_MaxLevel
||
114 intelObj
->mt
->width0
!= firstImage
->base
.Width
||
115 intelObj
->mt
->height0
!= firstImage
->base
.Height
||
116 intelObj
->mt
->depth0
!= firstImage
->base
.Depth
)) {
117 intel_miptree_release(intel
, &intelObj
->mt
);
121 /* May need to create a new tree:
124 intelObj
->mt
= intel_miptree_create(intel
,
125 intelObj
->base
.Target
,
126 firstImage
->base
.TexFormat
,
129 firstImage
->base
.Width
,
130 firstImage
->base
.Height
,
131 firstImage
->base
.Depth
,
137 /* Pull in any images not in the object's tree:
139 nr_faces
= (intelObj
->base
.Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
140 for (face
= 0; face
< nr_faces
; face
++) {
141 for (i
= tObj
->BaseLevel
; i
<= intelObj
->_MaxLevel
; i
++) {
142 struct intel_texture_image
*intelImage
=
143 intel_texture_image(intelObj
->base
.Image
[face
][i
]);
144 /* skip too small size mipmap */
145 if (intelImage
== NULL
)
147 /* Need to import images in main memory or held in other trees.
148 * If it's a render target, then its data isn't needed to be in
149 * the object tree (otherwise we'd be FBO incomplete), and we need
150 * to keep track of the image's MT as needing to be pulled in still,
151 * or we'll lose the rendering that's done to it.
153 if (intelObj
->mt
!= intelImage
->mt
&&
154 !intelImage
->used_as_render_target
) {
155 copy_image_data_to_tree(intel
, intelObj
, intelImage
);
164 intel_tex_map_level_images(struct intel_context
*intel
,
165 struct intel_texture_object
*intelObj
,
168 GLuint nr_faces
= (intelObj
->base
.Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
171 for (face
= 0; face
< nr_faces
; face
++) {
172 struct intel_texture_image
*intelImage
=
173 intel_texture_image(intelObj
->base
.Image
[face
][level
]);
175 if (intelImage
&& intelImage
->mt
) {
176 intelImage
->base
.Data
=
177 intel_miptree_image_map(intel
,
179 intelImage
->base
.Face
,
180 intelImage
->base
.Level
,
181 &intelImage
->base
.RowStride
,
182 intelImage
->base
.ImageOffsets
);
183 /* convert stride to texels, not bytes */
184 intelImage
->base
.RowStride
/= intelImage
->mt
->cpp
;
185 /* intelImage->base.ImageStride /= intelImage->mt->cpp; */
191 intel_tex_unmap_level_images(struct intel_context
*intel
,
192 struct intel_texture_object
*intelObj
,
195 GLuint nr_faces
= (intelObj
->base
.Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
198 for (face
= 0; face
< nr_faces
; face
++) {
199 struct intel_texture_image
*intelImage
=
200 intel_texture_image(intelObj
->base
.Image
[face
][level
]);
202 if (intelImage
&& intelImage
->mt
) {
203 intel_miptree_image_unmap(intel
, intelImage
->mt
);
204 intelImage
->base
.Data
= NULL
;
210 intel_tex_map_images(struct intel_context
*intel
,
211 struct intel_texture_object
*intelObj
)
215 DBG("%s\n", __FUNCTION__
);
217 for (i
= intelObj
->base
.BaseLevel
; i
<= intelObj
->_MaxLevel
; i
++)
218 intel_tex_map_level_images(intel
, intelObj
, i
);
222 intel_tex_unmap_images(struct intel_context
*intel
,
223 struct intel_texture_object
*intelObj
)
227 for (i
= intelObj
->base
.BaseLevel
; i
<= intelObj
->_MaxLevel
; i
++)
228 intel_tex_unmap_level_images(intel
, intelObj
, i
);