1 #include "swrast/swrast.h"
2 #include "main/texobj.h"
3 #include "main/teximage.h"
4 #include "main/mipmap.h"
5 #include "drivers/common/meta.h"
6 #include "intel_context.h"
7 #include "intel_mipmap_tree.h"
10 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
13 intelIsTextureResident(GLcontext
* ctx
, struct gl_texture_object
*texObj
)
16 struct intel_context
*intel
= intel_context(ctx
);
17 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
21 intelObj
->mt
->region
&&
22 intel_is_region_resident(intel
, intelObj
->mt
->region
);
29 static struct gl_texture_image
*
30 intelNewTextureImage(GLcontext
* ctx
)
32 DBG("%s\n", __FUNCTION__
);
34 return (struct gl_texture_image
*) CALLOC_STRUCT(intel_texture_image
);
38 static struct gl_texture_object
*
39 intelNewTextureObject(GLcontext
* ctx
, GLuint name
, GLenum target
)
41 struct intel_texture_object
*obj
= CALLOC_STRUCT(intel_texture_object
);
43 DBG("%s\n", __FUNCTION__
);
44 _mesa_initialize_texture_object(&obj
->base
, name
, target
);
50 intelDeleteTextureObject(GLcontext
*ctx
,
51 struct gl_texture_object
*texObj
)
53 struct intel_context
*intel
= intel_context(ctx
);
54 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
57 intel_miptree_release(intel
, &intelObj
->mt
);
59 _mesa_delete_texture_object(ctx
, texObj
);
64 intelFreeTextureImageData(GLcontext
* ctx
, struct gl_texture_image
*texImage
)
66 struct intel_context
*intel
= intel_context(ctx
);
67 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
69 DBG("%s\n", __FUNCTION__
);
72 intel_miptree_release(intel
, &intelImage
->mt
);
76 _mesa_free_texmemory(texImage
->Data
);
77 texImage
->Data
= NULL
;
82 /* The system memcpy (at least on ubuntu 5.10) has problems copying
83 * to agp (writecombined) memory from a source which isn't 64-byte
84 * aligned - there is a 4x performance falloff.
86 * The x86 __memcpy is immune to this but is slightly slower
87 * (10%-ish) than the system memcpy.
89 * The sse_memcpy seems to have a slight cliff at 64/32 bytes, but
90 * isn't much faster than x86_memcpy for agp copies.
92 * TODO: switch dynamically.
95 do_memcpy(void *dest
, const void *src
, size_t n
)
97 if ((((unsigned long) src
) & 63) || (((unsigned long) dest
) & 63)) {
98 return __memcpy(dest
, src
, n
);
101 return memcpy(dest
, src
, n
);
105 #if DO_DEBUG && !defined(__ia64__)
112 __asm__
volatile ("\t"
114 "cpuid\n\t" ".byte 0x0f, 0x31\n\t"
115 "popl %%ebx\n":"=a" (eax
)
117 :"ecx", "edx", "cc");
126 __asm__
volatile ("\t" "cpuid\n\t" ".byte 0x0f, 0x31\n\t":"=a" (eax
)
128 :"ecx", "edx", "ebx", "cc");
135 time_diff(unsigned t
, unsigned t2
)
137 return ((t
< t2
) ? t2
- t
: 0xFFFFFFFFU
- (t
- t2
- 1));
142 timed_memcpy(void *dest
, const void *src
, size_t n
)
148 if ((((unsigned) src
) & 63) || (((unsigned) dest
) & 63))
149 _mesa_printf("Warning - non-aligned texture copy!\n");
152 ret
= do_memcpy(dest
, src
, n
);
155 rate
= time_diff(t1
, t2
);
157 _mesa_printf("timed_memcpy: %u %u --> %f clocks/byte\n", t1
, t2
, rate
);
160 #endif /* DO_DEBUG */
164 * Called via ctx->Driver.GenerateMipmap()
165 * This is basically a wrapper for _mesa_meta_GenerateMipmap() which checks
166 * if we'll be using software mipmap generation. In that case, we need to
167 * map/unmap the base level texture image.
170 intelGenerateMipmap(GLcontext
*ctx
, GLenum target
,
171 struct gl_texture_object
*texObj
)
173 if (_mesa_meta_check_generate_mipmap_fallback(ctx
, target
, texObj
)) {
174 /* sw path: need to map texture images */
175 struct intel_context
*intel
= intel_context(ctx
);
176 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
177 intel_tex_map_level_images(intel
, intelObj
, texObj
->BaseLevel
);
178 _mesa_generate_mipmap(ctx
, target
, texObj
);
179 intel_tex_unmap_level_images(intel
, intelObj
, texObj
->BaseLevel
);
182 GLuint nr_faces
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
184 /* Update the level information in our private data in the new images,
185 * since it didn't get set as part of a normal TexImage path.
187 for (face
= 0; face
< nr_faces
; face
++) {
188 for (i
= texObj
->BaseLevel
+ 1; i
< texObj
->MaxLevel
; i
++) {
189 struct intel_texture_image
*intelImage
=
190 intel_texture_image(texObj
->Image
[face
][i
]);
193 intelImage
->level
= i
;
194 intelImage
->face
= face
;
195 /* Unreference the miptree to signal that the new Data is a
196 * bare pointer from mesa.
198 intel_miptree_release(intel
, &intelImage
->mt
);
204 _mesa_meta_GenerateMipmap(ctx
, target
, texObj
);
210 intelInitTextureFuncs(struct dd_function_table
*functions
)
212 functions
->ChooseTextureFormat
= intelChooseTextureFormat
;
213 functions
->GenerateMipmap
= intelGenerateMipmap
;
215 functions
->NewTextureObject
= intelNewTextureObject
;
216 functions
->NewTextureImage
= intelNewTextureImage
;
217 functions
->DeleteTexture
= intelDeleteTextureObject
;
218 functions
->FreeTexImageData
= intelFreeTextureImageData
;
219 functions
->UpdateTexturePalette
= 0;
220 functions
->IsTextureResident
= intelIsTextureResident
;
222 #if DO_DEBUG && !defined(__ia64__)
223 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
224 functions
->TextureMemCpy
= timed_memcpy
;
227 functions
->TextureMemCpy
= do_memcpy
;