1 #include "swrast/swrast.h"
4 #include "intel_context.h"
5 #include "intel_mipmap_tree.h"
8 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
11 intelIsTextureResident(GLcontext
* ctx
, struct gl_texture_object
*texObj
)
14 struct intel_context
*intel
= intel_context(ctx
);
15 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
19 intelObj
->mt
->region
&&
20 intel_is_region_resident(intel
, intelObj
->mt
->region
);
27 static struct gl_texture_image
*
28 intelNewTextureImage(GLcontext
* ctx
)
30 DBG("%s\n", __FUNCTION__
);
32 return (struct gl_texture_image
*) CALLOC_STRUCT(intel_texture_image
);
36 static struct gl_texture_object
*
37 intelNewTextureObject(GLcontext
* ctx
, GLuint name
, GLenum target
)
39 struct intel_texture_object
*obj
= CALLOC_STRUCT(intel_texture_object
);
41 DBG("%s\n", __FUNCTION__
);
42 _mesa_initialize_texture_object(&obj
->base
, name
, target
);
48 intelDeleteTextureObject(GLcontext
*ctx
,
49 struct gl_texture_object
*texObj
)
51 struct intel_context
*intel
= intel_context(ctx
);
52 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
55 intel_miptree_release(intel
, &intelObj
->mt
);
57 _mesa_delete_texture_object(ctx
, texObj
);
62 intelFreeTextureImageData(GLcontext
* ctx
, struct gl_texture_image
*texImage
)
64 struct intel_context
*intel
= intel_context(ctx
);
65 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
67 DBG("%s\n", __FUNCTION__
);
70 intel_miptree_release(intel
, &intelImage
->mt
);
75 texImage
->Data
= NULL
;
80 /* The system memcpy (at least on ubuntu 5.10) has problems copying
81 * to agp (writecombined) memory from a source which isn't 64-byte
82 * aligned - there is a 4x performance falloff.
84 * The x86 __memcpy is immune to this but is slightly slower
85 * (10%-ish) than the system memcpy.
87 * The sse_memcpy seems to have a slight cliff at 64/32 bytes, but
88 * isn't much faster than x86_memcpy for agp copies.
90 * TODO: switch dynamically.
93 do_memcpy(void *dest
, const void *src
, size_t n
)
95 if ((((unsigned) src
) & 63) || (((unsigned) dest
) & 63)) {
96 return __memcpy(dest
, src
, n
);
99 return memcpy(dest
, src
, n
);
110 __asm__
volatile ("\t"
112 "cpuid\n\t" ".byte 0x0f, 0x31\n\t"
113 "popl %%ebx\n":"=a" (eax
)
115 :"ecx", "edx", "cc");
124 __asm__
volatile ("\t" "cpuid\n\t" ".byte 0x0f, 0x31\n\t":"=a" (eax
)
126 :"ecx", "edx", "ebx", "cc");
133 time_diff(unsigned t
, unsigned t2
)
135 return ((t
< t2
) ? t2
- t
: 0xFFFFFFFFU
- (t
- t2
- 1));
140 timed_memcpy(void *dest
, const void *src
, size_t n
)
146 if ((((unsigned) src
) & 63) || (((unsigned) dest
) & 63))
147 _mesa_printf("Warning - non-aligned texture copy!\n");
150 ret
= do_memcpy(dest
, src
, n
);
153 rate
= time_diff(t1
, t2
);
155 _mesa_printf("timed_memcpy: %u %u --> %f clocks/byte\n", t1
, t2
, rate
);
158 #endif /* DO_DEBUG */
161 * Generate new mipmap data from BASE+1 to BASE+p (the minimally-sized mipmap
164 * The texture object's miptree must be mapped.
166 * It would be really nice if this was just called by Mesa whenever mipmaps
167 * needed to be regenerated, rather than us having to remember to do so in
168 * each texture image modification path.
170 * This function should also include an accelerated path.
173 intel_generate_mipmap(GLcontext
*ctx
, GLenum target
,
174 const struct gl_texture_unit
*texUnit
,
175 struct gl_texture_object
*texObj
)
177 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
178 GLuint nr_faces
= (intelObj
->base
.Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
181 _mesa_generate_mipmap(ctx
, target
, texUnit
, texObj
);
183 /* Update the level information in our private data in the new images, since
184 * it didn't get set as part of a normal TexImage path.
186 for (face
= 0; face
< nr_faces
; face
++) {
187 for (i
= texObj
->BaseLevel
+ 1; i
< texObj
->MaxLevel
; i
++) {
188 struct intel_texture_image
*intelImage
;
190 intelImage
= intel_texture_image(texObj
->Image
[face
][i
]);
191 if (intelImage
== NULL
)
194 intelImage
->level
= i
;
195 intelImage
->face
= face
;
202 intelInitTextureFuncs(struct dd_function_table
*functions
)
204 functions
->ChooseTextureFormat
= intelChooseTextureFormat
;
205 functions
->TexImage1D
= intelTexImage1D
;
206 functions
->TexImage2D
= intelTexImage2D
;
207 functions
->TexImage3D
= intelTexImage3D
;
208 functions
->TexSubImage1D
= intelTexSubImage1D
;
209 functions
->TexSubImage2D
= intelTexSubImage2D
;
210 functions
->TexSubImage3D
= intelTexSubImage3D
;
212 functions
->CopyTexImage1D
= intelCopyTexImage1D
;
213 functions
->CopyTexImage2D
= intelCopyTexImage2D
;
214 functions
->CopyTexSubImage1D
= intelCopyTexSubImage1D
;
215 functions
->CopyTexSubImage2D
= intelCopyTexSubImage2D
;
217 functions
->CopyTexImage1D
= _swrast_copy_teximage1d
;
218 functions
->CopyTexImage2D
= _swrast_copy_teximage2d
;
219 functions
->CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
220 functions
->CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
222 functions
->GetTexImage
= intelGetTexImage
;
224 /* compressed texture functions */
225 functions
->CompressedTexImage2D
= intelCompressedTexImage2D
;
226 functions
->GetCompressedTexImage
= intelGetCompressedTexImage
;
228 functions
->NewTextureObject
= intelNewTextureObject
;
229 functions
->NewTextureImage
= intelNewTextureImage
;
230 functions
->DeleteTexture
= intelDeleteTextureObject
;
231 functions
->FreeTexImageData
= intelFreeTextureImageData
;
232 functions
->UpdateTexturePalette
= 0;
233 functions
->IsTextureResident
= intelIsTextureResident
;
236 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
237 functions
->TextureMemCpy
= timed_memcpy
;
240 functions
->TextureMemCpy
= do_memcpy
;