1 #include "main/mtypes.h"
2 #include "main/macros.h"
3 #include "main/samplerobj.h"
4 #include "main/texobj.h"
6 #include "brw_context.h"
7 #include "intel_mipmap_tree.h"
8 #include "intel_blit.h"
11 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
14 * Sets our driver-specific variant of tObj->_MaxLevel for later surface state
17 * If we're only ensuring that there is storage for the first miplevel of a
18 * texture, then in texture setup we're going to have to make sure we don't
19 * allow sampling beyond level 0.
22 intel_update_max_level(struct intel_texture_object
*intelObj
,
23 struct gl_sampler_object
*sampler
)
25 struct gl_texture_object
*tObj
= &intelObj
->base
;
27 if (sampler
->MinFilter
== GL_NEAREST
||
28 sampler
->MinFilter
== GL_LINEAR
) {
29 intelObj
->_MaxLevel
= tObj
->BaseLevel
;
31 intelObj
->_MaxLevel
= tObj
->_MaxLevel
;
36 * At rendering-from-a-texture time, make sure that the texture object has a
37 * miptree that can hold the entire texture based on
38 * BaseLevel/MaxLevel/filtering, and copy in any texture images that are
39 * stored in other miptrees.
42 intel_finalize_mipmap_tree(struct brw_context
*brw
, GLuint unit
)
44 struct gl_context
*ctx
= &brw
->ctx
;
45 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[unit
]._Current
;
46 struct intel_texture_object
*intelObj
= intel_texture_object(tObj
);
47 struct gl_sampler_object
*sampler
= _mesa_get_samplerobj(ctx
, unit
);
50 struct intel_texture_image
*firstImage
;
51 int width
, height
, depth
;
53 /* TBOs require no validation -- they always just point to their BO. */
54 if (tObj
->Target
== GL_TEXTURE_BUFFER
)
57 /* We know that this is true by now, and if it wasn't, we might have
58 * mismatched level sizes and the copies would fail.
60 assert(intelObj
->base
._BaseComplete
);
62 intel_update_max_level(intelObj
, sampler
);
64 /* What levels does this validated texture image require? */
65 int validate_first_level
= tObj
->BaseLevel
;
66 int validate_last_level
= intelObj
->_MaxLevel
;
68 /* Skip the loop over images in the common case of no images having
69 * changed. But if the GL_BASE_LEVEL or GL_MAX_LEVEL change to something we
70 * haven't looked at, then we do need to look at those new images.
72 if (!intelObj
->needs_validate
&&
73 validate_first_level
>= intelObj
->validated_first_level
&&
74 validate_last_level
<= intelObj
->validated_last_level
) {
78 firstImage
= intel_texture_image(tObj
->Image
[0][tObj
->BaseLevel
]);
80 /* Check tree can hold all active levels. Check tree matches
81 * target, imageFormat, etc.
83 * For pre-gen4, we have to match first_level == tObj->BaseLevel,
84 * because we don't have the control that gen4 does to make min/mag
85 * determination happen at a nonzero (hardware) baselevel. Because
86 * of that, we just always relayout on baselevel change.
89 (!intel_miptree_match_image(intelObj
->mt
, &firstImage
->base
.Base
) ||
90 validate_first_level
< intelObj
->mt
->first_level
||
91 validate_last_level
> intelObj
->mt
->last_level
)) {
92 intel_miptree_release(&intelObj
->mt
);
96 /* May need to create a new tree:
99 intel_miptree_get_dimensions_for_image(&firstImage
->base
.Base
,
100 &width
, &height
, &depth
);
102 perf_debug("Creating new %s %dx%dx%d %d-level miptree to handle "
103 "finalized texture miptree.\n",
104 _mesa_get_format_name(firstImage
->base
.Base
.TexFormat
),
105 width
, height
, depth
, validate_last_level
+ 1);
107 intelObj
->mt
= intel_miptree_create(brw
,
108 intelObj
->base
.Target
,
109 firstImage
->base
.Base
.TexFormat
,
117 INTEL_MIPTREE_TILING_ANY
);
122 /* Pull in any images not in the object's tree:
124 nr_faces
= _mesa_num_tex_faces(intelObj
->base
.Target
);
125 for (face
= 0; face
< nr_faces
; face
++) {
126 for (i
= validate_first_level
; i
<= validate_last_level
; i
++) {
127 struct intel_texture_image
*intelImage
=
128 intel_texture_image(intelObj
->base
.Image
[face
][i
]);
129 /* skip too small size mipmap */
130 if (intelImage
== NULL
)
133 if (intelObj
->mt
!= intelImage
->mt
) {
134 intel_miptree_copy_teximage(brw
, intelImage
, intelObj
->mt
,
135 false /* invalidate */);
138 /* After we're done, we'd better agree that our layout is
139 * appropriate, or we'll end up hitting this function again on the
142 assert(intel_miptree_match_image(intelObj
->mt
, &intelImage
->base
.Base
));
146 intelObj
->validated_first_level
= validate_first_level
;
147 intelObj
->validated_last_level
= validate_last_level
;
148 intelObj
->needs_validate
= false;