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"
7 #include "intel_blit.h"
9 #include "intel_tex_layout.h"
11 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
14 * When validating, we only care about the texture images that could
15 * be seen, so for non-mipmapped modes we want to ignore everything
19 intel_update_max_level(struct intel_texture_object
*intelObj
,
20 struct gl_sampler_object
*sampler
)
22 struct gl_texture_object
*tObj
= &intelObj
->base
;
24 if (sampler
->MinFilter
== GL_NEAREST
||
25 sampler
->MinFilter
== GL_LINEAR
) {
26 intelObj
->_MaxLevel
= tObj
->BaseLevel
;
28 intelObj
->_MaxLevel
= tObj
->_MaxLevel
;
35 intel_finalize_mipmap_tree(struct intel_context
*intel
, GLuint unit
)
37 struct gl_context
*ctx
= &intel
->ctx
;
38 struct gl_texture_object
*tObj
= intel
->ctx
.Texture
.Unit
[unit
]._Current
;
39 struct intel_texture_object
*intelObj
= intel_texture_object(tObj
);
40 struct gl_sampler_object
*sampler
= _mesa_get_samplerobj(ctx
, unit
);
43 struct intel_texture_image
*firstImage
;
44 int width
, height
, depth
;
46 /* We know/require this is true by now:
48 assert(intelObj
->base
._Complete
);
50 /* What levels must the tree include at a minimum?
52 intel_update_max_level(intelObj
, sampler
);
53 firstImage
= intel_texture_image(tObj
->Image
[0][tObj
->BaseLevel
]);
55 intel_miptree_get_dimensions_for_image(&firstImage
->base
.Base
,
56 &width
, &height
, &depth
);
58 /* Check tree can hold all active levels. Check tree matches
59 * target, imageFormat, etc.
61 * For pre-gen4, we have to match first_level == tObj->BaseLevel,
62 * because we don't have the control that gen4 does to make min/mag
63 * determination happen at a nonzero (hardware) baselevel. Because
64 * of that, we just always relayout on baselevel change.
67 (intelObj
->mt
->target
!= intelObj
->base
.Target
||
68 intelObj
->mt
->format
!= firstImage
->base
.Base
.TexFormat
||
69 intelObj
->mt
->first_level
!= tObj
->BaseLevel
||
70 intelObj
->mt
->last_level
< intelObj
->_MaxLevel
||
71 intelObj
->mt
->width0
!= width
||
72 intelObj
->mt
->height0
!= height
||
73 intelObj
->mt
->depth0
!= depth
)) {
74 intel_miptree_release(&intelObj
->mt
);
78 /* May need to create a new tree:
81 intelObj
->mt
= intel_miptree_create(intel
,
82 intelObj
->base
.Target
,
83 firstImage
->base
.Base
.TexFormat
,
94 /* Pull in any images not in the object's tree:
96 nr_faces
= (intelObj
->base
.Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
97 for (face
= 0; face
< nr_faces
; face
++) {
98 for (i
= tObj
->BaseLevel
; i
<= intelObj
->_MaxLevel
; i
++) {
99 struct intel_texture_image
*intelImage
=
100 intel_texture_image(intelObj
->base
.Image
[face
][i
]);
101 /* skip too small size mipmap */
102 if (intelImage
== NULL
)
104 /* Need to import images in main memory or held in other trees.
105 * If it's a render target, then its data isn't needed to be in
106 * the object tree (otherwise we'd be FBO incomplete), and we need
107 * to keep track of the image's MT as needing to be pulled in still,
108 * or we'll lose the rendering that's done to it.
110 if (intelObj
->mt
!= intelImage
->mt
&&
111 !intelImage
->used_as_render_target
) {
112 intel_miptree_copy_teximage(intel
, intelImage
, intelObj
->mt
);
121 * \param mode bitmask of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT
124 intel_tex_map_image_for_swrast(struct intel_context
*intel
,
125 struct intel_texture_image
*intel_image
,
130 struct intel_mipmap_tree
*mt
;
133 if (!intel_image
|| !intel_image
->mt
)
136 level
= intel_image
->base
.Base
.Level
;
137 face
= intel_image
->base
.Base
.Face
;
138 mt
= intel_image
->mt
;
140 if (mt
->target
== GL_TEXTURE_3D
||
141 mt
->target
== GL_TEXTURE_2D_ARRAY
||
142 mt
->target
== GL_TEXTURE_1D_ARRAY
) {
145 /* ImageOffsets[] is only used for swrast's fetch_texel_3d, so we can't
146 * share code with the normal path.
148 for (i
= 0; i
< mt
->level
[level
].depth
; i
++) {
149 intel_miptree_get_image_offset(mt
, level
, face
, i
, &x
, &y
);
150 intel_image
->base
.ImageOffsets
[i
] = x
+ y
* mt
->region
->pitch
;
153 DBG("%s \n", __FUNCTION__
);
155 intel_image
->base
.Data
= intel_region_map(intel
, mt
->region
, mode
);
157 assert(mt
->level
[level
].depth
== 1);
158 intel_miptree_get_image_offset(mt
, level
, face
, 0, &x
, &y
);
160 DBG("%s: (%d,%d) -> (%d, %d)/%d\n",
161 __FUNCTION__
, face
, level
, x
, y
, mt
->region
->pitch
* mt
->cpp
);
163 intel_image
->base
.Data
= intel_region_map(intel
, mt
->region
, mode
) +
164 (x
+ y
* mt
->region
->pitch
) * mt
->cpp
;
167 intel_image
->base
.RowStride
= mt
->region
->pitch
;
171 intel_tex_unmap_image_for_swrast(struct intel_context
*intel
,
172 struct intel_texture_image
*intel_image
)
174 if (intel_image
&& intel_image
->mt
) {
175 intel_region_unmap(intel
, intel_image
->mt
->region
);
176 intel_image
->base
.Data
= NULL
;
181 * \param mode bitmask of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT
184 intel_tex_map_images(struct intel_context
*intel
,
185 struct intel_texture_object
*intelObj
,
188 GLuint nr_faces
= (intelObj
->base
.Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
191 DBG("%s\n", __FUNCTION__
);
193 for (i
= intelObj
->base
.BaseLevel
; i
<= intelObj
->_MaxLevel
; i
++) {
194 for (face
= 0; face
< nr_faces
; face
++) {
195 struct intel_texture_image
*intel_image
=
196 intel_texture_image(intelObj
->base
.Image
[face
][i
]);
198 intel_tex_map_image_for_swrast(intel
, intel_image
, mode
);
204 intel_tex_unmap_images(struct intel_context
*intel
,
205 struct intel_texture_object
*intelObj
)
207 GLuint nr_faces
= (intelObj
->base
.Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
210 for (i
= intelObj
->base
.BaseLevel
; i
<= intelObj
->_MaxLevel
; i
++) {
211 for (face
= 0; face
< nr_faces
; face
++) {
212 struct intel_texture_image
*intel_image
=
213 intel_texture_image(intelObj
->base
.Image
[face
][i
]);
215 intel_tex_unmap_image_for_swrast(intel
, intel_image
);