1 #include "swrast/swrast.h"
2 #include "main/texobj.h"
3 #include "main/teximage.h"
4 #include "main/mipmap.h"
5 #include "intel_context.h"
6 #include "intel_mipmap_tree.h"
9 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
12 intelIsTextureResident(GLcontext
* ctx
, struct gl_texture_object
*texObj
)
15 struct intel_context
*intel
= intel_context(ctx
);
16 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
20 intelObj
->mt
->region
&&
21 intel_is_region_resident(intel
, intelObj
->mt
->region
);
28 static struct gl_texture_image
*
29 intelNewTextureImage(GLcontext
* ctx
)
31 DBG("%s\n", __FUNCTION__
);
33 return (struct gl_texture_image
*) CALLOC_STRUCT(intel_texture_image
);
37 static struct gl_texture_object
*
38 intelNewTextureObject(GLcontext
* ctx
, GLuint name
, GLenum target
)
40 struct intel_texture_object
*obj
= CALLOC_STRUCT(intel_texture_object
);
42 DBG("%s\n", __FUNCTION__
);
43 _mesa_initialize_texture_object(&obj
->base
, name
, target
);
49 intelDeleteTextureObject(GLcontext
*ctx
,
50 struct gl_texture_object
*texObj
)
52 struct intel_context
*intel
= intel_context(ctx
);
53 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
56 intel_miptree_release(intel
, &intelObj
->mt
);
58 _mesa_delete_texture_object(ctx
, texObj
);
63 intelFreeTextureImageData(GLcontext
* ctx
, struct gl_texture_image
*texImage
)
65 struct intel_context
*intel
= intel_context(ctx
);
66 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
68 DBG("%s\n", __FUNCTION__
);
71 intel_miptree_release(intel
, &intelImage
->mt
);
75 _mesa_free_texmemory(texImage
->Data
);
76 texImage
->Data
= NULL
;
81 /* The system memcpy (at least on ubuntu 5.10) has problems copying
82 * to agp (writecombined) memory from a source which isn't 64-byte
83 * aligned - there is a 4x performance falloff.
85 * The x86 __memcpy is immune to this but is slightly slower
86 * (10%-ish) than the system memcpy.
88 * The sse_memcpy seems to have a slight cliff at 64/32 bytes, but
89 * isn't much faster than x86_memcpy for agp copies.
91 * TODO: switch dynamically.
94 do_memcpy(void *dest
, const void *src
, size_t n
)
96 if ((((unsigned long) src
) & 63) || (((unsigned long) dest
) & 63)) {
97 return __memcpy(dest
, src
, n
);
100 return memcpy(dest
, src
, n
);
104 #if DO_DEBUG && !defined(__ia64__)
111 __asm__
volatile ("\t"
113 "cpuid\n\t" ".byte 0x0f, 0x31\n\t"
114 "popl %%ebx\n":"=a" (eax
)
116 :"ecx", "edx", "cc");
125 __asm__
volatile ("\t" "cpuid\n\t" ".byte 0x0f, 0x31\n\t":"=a" (eax
)
127 :"ecx", "edx", "ebx", "cc");
134 time_diff(unsigned t
, unsigned t2
)
136 return ((t
< t2
) ? t2
- t
: 0xFFFFFFFFU
- (t
- t2
- 1));
141 timed_memcpy(void *dest
, const void *src
, size_t n
)
147 if ((((unsigned) src
) & 63) || (((unsigned) dest
) & 63))
148 _mesa_printf("Warning - non-aligned texture copy!\n");
151 ret
= do_memcpy(dest
, src
, n
);
154 rate
= time_diff(t1
, t2
);
156 _mesa_printf("timed_memcpy: %u %u --> %f clocks/byte\n", t1
, t2
, rate
);
159 #endif /* DO_DEBUG */
162 * Generate new mipmap data from BASE+1 to BASE+p (the minimally-sized mipmap
165 * The texture object's miptree must be mapped.
167 * It would be really nice if this was just called by Mesa whenever mipmaps
168 * needed to be regenerated, rather than us having to remember to do so in
169 * each texture image modification path.
171 * This function should also include an accelerated path.
174 intel_generate_mipmap(GLcontext
*ctx
, GLenum target
,
175 struct gl_texture_object
*texObj
)
177 struct intel_context
*intel
= intel_context(ctx
);
178 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
179 GLuint nr_faces
= (intelObj
->base
.Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
182 _mesa_generate_mipmap(ctx
, target
, texObj
);
184 /* Update the level information in our private data in the new images, since
185 * 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
;
191 intelImage
= intel_texture_image(texObj
->Image
[face
][i
]);
192 if (intelImage
== NULL
)
195 intelImage
->level
= i
;
196 intelImage
->face
= face
;
197 /* Unreference the miptree to signal that the new Data is a bare
200 intel_miptree_release(intel
, &intelImage
->mt
);
205 static void intelGenerateMipmap(GLcontext
*ctx
, GLenum target
, struct gl_texture_object
*texObj
)
207 struct intel_context
*intel
= intel_context(ctx
);
208 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
210 intel_tex_map_level_images(intel
, intelObj
, texObj
->BaseLevel
);
211 intel_generate_mipmap(ctx
, target
, texObj
);
212 intel_tex_unmap_level_images(intel
, intelObj
, texObj
->BaseLevel
);
216 intelInitTextureFuncs(struct dd_function_table
*functions
)
218 functions
->ChooseTextureFormat
= intelChooseTextureFormat
;
219 functions
->TexImage1D
= intelTexImage1D
;
220 functions
->TexImage2D
= intelTexImage2D
;
221 functions
->TexImage3D
= intelTexImage3D
;
222 functions
->TexSubImage1D
= intelTexSubImage1D
;
223 functions
->TexSubImage2D
= intelTexSubImage2D
;
224 functions
->TexSubImage3D
= intelTexSubImage3D
;
225 functions
->CopyTexImage1D
= intelCopyTexImage1D
;
226 functions
->CopyTexImage2D
= intelCopyTexImage2D
;
227 functions
->CopyTexSubImage1D
= intelCopyTexSubImage1D
;
228 functions
->CopyTexSubImage2D
= intelCopyTexSubImage2D
;
229 functions
->GetTexImage
= intelGetTexImage
;
230 functions
->GenerateMipmap
= intelGenerateMipmap
;
232 /* compressed texture functions */
233 functions
->CompressedTexImage2D
= intelCompressedTexImage2D
;
234 functions
->CompressedTexSubImage2D
= intelCompressedTexSubImage2D
;
235 functions
->GetCompressedTexImage
= intelGetCompressedTexImage
;
237 functions
->NewTextureObject
= intelNewTextureObject
;
238 functions
->NewTextureImage
= intelNewTextureImage
;
239 functions
->DeleteTexture
= intelDeleteTextureObject
;
240 functions
->FreeTexImageData
= intelFreeTextureImageData
;
241 functions
->UpdateTexturePalette
= 0;
242 functions
->IsTextureResident
= intelIsTextureResident
;
244 #if DO_DEBUG && !defined(__ia64__)
245 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
246 functions
->TextureMemCpy
= timed_memcpy
;
249 functions
->TextureMemCpy
= do_memcpy
;